Skip to content

Commit 619bede

Browse files
authored
Merge pull request #6412 from NuGet/dev
* Update bootstrap dependencies (#6325) Addresses https://github.com/NuGet/Engineering/issues/1634 * Simplify the security policy service to have 1 handler list for all accounts (#6330) * Set-StrictMode in build script (#6338) * Add member/add owner/transform to org fails with specific message if email is input instead of username (#6329) * Move admin pages to redesigned layout and remove unused scripts (#6323) * Use strong name version of third party dependencies (#6337) Progress on https://github.com/NuGet/Engineering/issues/1577 Address #3849 Copy in ServiceResponse from NuGet.Services.Platform to eliminate a dependency * Typosquatting: add typosquatting check service codes (#6315) Add the codes of typosquatting algorithms and retrieve the latest owner list info. 1. Typosquatting check service with distance calculation and comparison; 2. Normalize the string before checking; 3. Call `public bool IsDistanceLessThanThreshold(string str1, string str2, int threshold)` to compare two strings; (changed to private) 4. Call `public bool IsUploadedPackageIdTyposquatting(string uploadedPackageId)` to check typosquatting in the checlist. Fixes: https://github.com/NuGet/Engineering/issues/1593 * Validation warnings for repository URLs (#6335) * works * improve log * PR comments * Fix comments * bug fix * repo url warnings * add UT * align * Update _VerifyMetadata.cshtml Fixed: issue**s**(s) to issue(s) * PR feedback * support explicit 443 port for github * fix build * Add MicroBuild dependency and signing of output DLLs (#6344) Progress on https://github.com/NuGet/Engineering/issues/1577 * Gallery: enable blocking packages with too many package entries (#6358) Progress on #6357. * Fix PackageRef dependencies * PR feedback * Add max-age for the symbol packages (#6343) * Fix repo url validation message UI (#6366) * tablist is not under a menubar (#6345) * Log search service exceptions encountered during retry (#6232) * Typo squatting checklist retrieval (#6361) * Typo squatting checklist retrieval * refactor and delete PackagesCheckListService * update codes based on the review * Change linq and Delete concurrent dictionary for normalized Ids * Update index migration files and Fix issues in reviews * include ID in the index * Delete unnecessary codes in Facts * Fix threshold * Add tool to verify the clear-text of an API key (#6383) * Additional copyright values for auto-add MSFT feature (#6376) * Additional copyright values for auto-add MSFT feature #1664 * Removing support for a specific copyright value in MicrosoftTeamSubscription * improve test readability * Fix inconsistent messaging around expired legacy API key (#6384) Address #6318 * Add BlockSearchEngineIndexing to allow site-wide search engine blocking (#6385) Progress on #6381 * Fix incorrect pending revalidation count (#6382) Fixes #6362 Depends on NuGet/ServerCommon#190 * Telemetry metrics for symbol push. (#6372) * Add gallery telemetry metrics for the symbol push. * ApiController actions should not throw exceptions when called with an unparseable version (#6089) * Typosquatting: finish configuration file and feature flags (#6390) * Typosquatting: finish configuration file and feature flags * Update unit tests * Update * update unit tests * Transform Project Url scheme to HTTPs for known domains (#6398) * Transform Project Url scheme to HTTPs for known domains * PR feedback * Add telemetry for auto-add package owner feature (#6374) * Fix msa login account selection (#6400) * [NuGet Symbol Server]Symbols validation status view (#6407) * Obfuscate secret tokens in logging (#6399) Issue 1670 fix - obfuscate secret tokens. * Covert to https URLs in known domains in release notes, description (#6408) * Covert to https URLs in known domains in release notes, description * another UT * PR comments
2 parents 1b98757 + a9ed486 commit 619bede

216 files changed

Lines changed: 3679 additions & 21993 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.ps1

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ param (
1010
[string]$PackageSuffix,
1111
[string]$Branch,
1212
[string]$CommitSHA,
13-
[string]$BuildBranch = '37ff6e758c38b3f513af39f881399ce85f4ff20b'
13+
[string]$BuildBranch = 'cb604c2cd1b2f7f71fb574cdda4c83ddb1464cc7'
1414
)
1515

16+
Set-StrictMode -Version 1.0
17+
1618
# This script should fail the build if any issue occurs.
1719
trap {
1820
Write-Host "BUILD FAILED: $_" -ForegroundColor Red
@@ -91,11 +93,11 @@ Invoke-BuildStep 'Building solution' {
9193
-ev +BuildErrors
9294

9395
Invoke-BuildStep 'Creating artifacts' {
94-
$packageId = 'NuGetGallery.Core'+$PackageSuffix
95-
New-Package (Join-Path $PSScriptRoot "src\NuGetGallery.Core\NuGetGallery.Core.csproj") -Configuration $Configuration -Symbols -BuildNumber $BuildNumber -Version $SemanticVersion -PackageId $packageId `
96-
-ev +BuildErrors
97-
}
98-
96+
$packageId = 'NuGetGallery.Core'+$PackageSuffix
97+
New-ProjectPackage (Join-Path $PSScriptRoot "src\NuGetGallery.Core\NuGetGallery.Core.csproj") -Configuration $Configuration -Symbols -BuildNumber $BuildNumber -Version $SemanticVersion -PackageId $packageId `
98+
-ev +BuildErrors
99+
}
100+
99101
Trace-Log ('-' * 60)
100102

101103
## Calculating Build time
@@ -110,4 +112,4 @@ if ($BuildErrors) {
110112
Error-Log "Builds completed with $($BuildErrors.Count) error(s):`r`n$($ErrorLines -join "`r`n")" -Fatal
111113
}
112114

113-
Write-Host ("`r`n" * 3)
115+
Write-Host ("`r`n" * 3)

src/Bootstrap/package-lock.json

Lines changed: 62 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Bootstrap/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@
8787
]
8888
},
8989
"dependencies": {
90+
"debug": "^2.6.9",
9091
"fresh": "^0.5.2",
92+
"hoek": "^4.2.1",
9193
"mime": "^1.4.1",
9294
"no-case": "^2.3.2",
9395
"tough-cookie": "^2.3.3"
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.Extensions.CommandLineUtils;
7+
using NuGetGallery;
8+
using NuGetGallery.Infrastructure.Authentication;
9+
10+
namespace GalleryTools.Commands
11+
{
12+
public static class VerifyApiKeyCommand
13+
{
14+
public static void Configure(CommandLineApplication config)
15+
{
16+
config.Description = "Verify a clear text API key matches a hashed API key.";
17+
config.HelpOption("-? | -h | --help");
18+
19+
var plainTextOption = config.Option(
20+
"--clear-text",
21+
"The clear text value of the API key.",
22+
CommandOptionType.SingleValue);
23+
24+
var credentialTypesOption = config.Option(
25+
"--type",
26+
"One or more credential types.",
27+
CommandOptionType.MultipleValue);
28+
29+
var credentialValuesOption = config.Option(
30+
"--value",
31+
"One or more credential values.",
32+
CommandOptionType.MultipleValue);
33+
34+
config.OnExecute(() => Execute(
35+
plainTextOption,
36+
credentialTypesOption,
37+
credentialValuesOption));
38+
}
39+
40+
private static int Execute(
41+
CommandOption clearTextOption,
42+
CommandOption credentialTypesOption,
43+
CommandOption credentialValuesOption)
44+
{
45+
if (!clearTextOption.HasValue())
46+
{
47+
Console.Error.WriteLine($"The {clearTextOption.Template} option is required.");
48+
return 1;
49+
}
50+
51+
if (!credentialTypesOption.HasValue())
52+
{
53+
Console.Error.WriteLine($"The {credentialTypesOption.Template} option is required.");
54+
return 1;
55+
}
56+
57+
if (!credentialValuesOption.HasValue())
58+
{
59+
Console.Error.WriteLine($"The {credentialValuesOption.Template} option is required.");
60+
return 1;
61+
}
62+
63+
if (credentialTypesOption.Values.Count != credentialValuesOption.Values.Count)
64+
{
65+
Console.Error.WriteLine($"The should be the same number of {credentialTypesOption.Template} options as {credentialValuesOption.Template} options.");
66+
return 1;
67+
}
68+
69+
var credentialValidator = new CredentialValidator();
70+
71+
Console.WriteLine($"Testing {credentialTypesOption.Values.Count} API key(s).");
72+
73+
for (var i = 0; i < credentialTypesOption.Values.Count; i++)
74+
{
75+
var credential = new Credential
76+
{
77+
Type = credentialTypesOption.Values[i],
78+
Value = credentialValuesOption.Values[i],
79+
};
80+
81+
var validCredentials = credentialValidator.GetValidCredentialsForApiKey(
82+
new[] { credential }.AsQueryable(),
83+
clearTextOption.Value());
84+
85+
Console.WriteLine();
86+
Console.WriteLine($"API key {i + 1}:");
87+
Console.WriteLine($" Type: {credential.Type}");
88+
Console.WriteLine($" Value: {credential.Value}");
89+
Console.WriteLine($" Matches: {validCredentials.Any().ToString().ToUpperInvariant()}");
90+
}
91+
92+
return 0;
93+
}
94+
}
95+
}

src/GalleryTools/GalleryTools.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<Compile Include="Commands\BackfillRepositoryMetadataCommand.cs" />
4848
<Compile Include="Commands\HashCommand.cs" />
4949
<Compile Include="Commands\ReflowCommand.cs" />
50+
<Compile Include="Commands\VerifyApiKeyCommand.cs" />
5051
<Compile Include="Program.cs" />
5152
<Compile Include="Properties\AssemblyInfo.cs" />
5253
</ItemGroup>

src/GalleryTools/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static int Main(params string[] args)
1717
commandLineApplication.Command("hash", HashCommand.Configure);
1818
commandLineApplication.Command("reflow", ReflowCommand.Configure);
1919
commandLineApplication.Command("fillrepodata", BackfillRepositoryMetadataCommand.Configure);
20+
commandLineApplication.Command("verifyapikey", VerifyApiKeyCommand.Configure);
2021

2122
try
2223
{

src/NuGet.Services.Search.Client/Client/RetryingHttpClientWrapper.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public sealed class RetryingHttpClientWrapper
1515
{
1616
private readonly HttpClient _httpClient;
1717
private readonly IEndpointHealthIndicatorStore _endpointHealthIndicatorStore;
18+
private readonly Action<Exception> _onException;
1819

1920
private static readonly int PeriodToDelayAlternateRequest = 3000;
2021
private static readonly IComparer<int> HealthComparer;
@@ -24,16 +25,16 @@ static RetryingHttpClientWrapper()
2425
HealthComparer = new WeightedRandomComparer();
2526
}
2627

27-
public RetryingHttpClientWrapper(HttpClient httpClient)
28-
: this (httpClient, new BaseUrlHealthIndicatorStore(new NullHealthIndicatorLogger()))
28+
public RetryingHttpClientWrapper(HttpClient httpClient, Action<Exception> onException)
29+
: this (httpClient, new BaseUrlHealthIndicatorStore(new NullHealthIndicatorLogger()), onException)
2930
{
30-
_httpClient = httpClient;
3131
}
3232

33-
public RetryingHttpClientWrapper(HttpClient httpClient, IEndpointHealthIndicatorStore endpointHealthIndicatorStore)
33+
public RetryingHttpClientWrapper(HttpClient httpClient, IEndpointHealthIndicatorStore endpointHealthIndicatorStore, Action<Exception> onException)
3434
{
35-
_httpClient = httpClient;
36-
_endpointHealthIndicatorStore = endpointHealthIndicatorStore;
35+
_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
36+
_endpointHealthIndicatorStore = endpointHealthIndicatorStore ?? throw new ArgumentNullException(nameof(endpointHealthIndicatorStore));
37+
_onException = onException ?? throw new ArgumentNullException(nameof(onException));
3738
}
3839

3940
public async Task<string> GetStringAsync(IEnumerable<Uri> endpoints)
@@ -91,6 +92,11 @@ private async Task<HttpResponseMessage> GetWithRetry(IEnumerable<Uri> endpoints,
9192
cancellationTokenSource.Cancel(false);
9293
}
9394

95+
foreach (var exception in exceptions)
96+
{
97+
_onException(exception);
98+
}
99+
94100
if (completedTask.IsFaulted || completedTask.IsCanceled)
95101
{
96102
var exceptionsToThrow = exceptions.Where(e => !(e is TaskCanceledException || e.InnerException is TaskCanceledException)).ToList();

src/NuGet.Services.Search.Client/Client/SearchClient.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Net.Http;
99
using System.Threading.Tasks;
1010
using Newtonsoft.Json.Linq;
11-
using NuGet.Services.Client;
1211
using NuGet.Services.Search.Models;
1312

1413
namespace NuGet.Services.Search.Client
@@ -25,8 +24,8 @@ public class SearchClient
2524
/// </summary>
2625
/// <param name="baseUri">The URL to the root of the service</param>
2726
/// <param name="handlers">Handlers to apply to the request in order from first to last</param>
28-
public SearchClient(Uri baseUri, params DelegatingHandler[] handlers)
29-
: this(baseUri, "SearchGalleryQueryService/3.0.0-rc", null, new BaseUrlHealthIndicatorStore(new NullHealthIndicatorLogger()), handlers)
27+
public SearchClient(Uri baseUri, Action<Exception> onException, params DelegatingHandler[] handlers)
28+
: this(baseUri, "SearchGalleryQueryService/3.0.0-rc", null, new BaseUrlHealthIndicatorStore(new NullHealthIndicatorLogger()), onException, handlers)
3029
{
3130
}
3231

@@ -38,7 +37,7 @@ public SearchClient(Uri baseUri, params DelegatingHandler[] handlers)
3837
/// <param name="credentials">The credentials to connect to the service with</param>
3938
/// <param name="healthIndicatorStore">Health indicator store</param>
4039
/// <param name="handlers">Handlers to apply to the request in order from first to last</param>
41-
public SearchClient(Uri baseUri, string resourceType, ICredentials credentials, IEndpointHealthIndicatorStore healthIndicatorStore, params DelegatingHandler[] handlers)
40+
public SearchClient(Uri baseUri, string resourceType, ICredentials credentials, IEndpointHealthIndicatorStore healthIndicatorStore, Action<Exception> onException, params DelegatingHandler[] handlers)
4241
{
4342
_resourceType = resourceType;
4443

@@ -58,7 +57,7 @@ public SearchClient(Uri baseUri, string resourceType, ICredentials credentials,
5857

5958
_httpClient = new HttpClient(handler, disposeHandler: true);
6059

61-
_retryingHttpClientWrapper = new RetryingHttpClientWrapper(_httpClient, healthIndicatorStore);
60+
_retryingHttpClientWrapper = new RetryingHttpClientWrapper(_httpClient, healthIndicatorStore, onException);
6261
_discoveryClient = new ServiceDiscoveryClient(_httpClient, baseUri);
6362
}
6463

0 commit comments

Comments
 (0)