Skip to content

Commit

Permalink
fix an issue preventing proper scan. fix livetests (#8800)
Browse files Browse the repository at this point in the history
  • Loading branch information
scbedd authored Aug 8, 2024
1 parent 9b208af commit 0e13e3b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ public async Task SecretProtectionPreventsPush(string inputJson)

// no changes should be committed
var pendingChanges = store.DetectPendingChanges(parsedConfiguration);
Assert.Equal(2, pendingChanges.Count());
Assert.Equal(3, pendingChanges.Count());

// now double check the actual scan results to ensure they are where we expect
var detectedSecrets = store.SecretScanner.DiscoverSecrets(parsedConfiguration.AssetsRepoLocation, pendingChanges);
Expand Down
28 changes: 16 additions & 12 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/SecretScanner.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -41,24 +42,27 @@ public List<Tuple<string, Detection>> DiscoverSecrets(string assetRepoRoot, IEnu

Parallel.ForEach(relativePaths, options, (filePath) =>
{
var path = Path.Combine(assetRepoRoot, filePath);

if (File.Exists(path))
{
var content = File.ReadAllText(path);
var fileDetections = DetectSecrets(content);
if (!filePath.StartsWith("D")) {
var isolatedPath = filePath.Trim().TrimStart('?', 'M').Trim();
var path = Path.Combine(assetRepoRoot, isolatedPath);

if (fileDetections != null && fileDetections.Count > 0)
if (File.Exists(path))
{
foreach (Detection detection in fileDetections)
var content = File.ReadAllText(path);
var fileDetections = DetectSecrets(content);

if (fileDetections != null && fileDetections.Count > 0)
{
detectedSecrets.Add(Tuple.Create(filePath, detection));
foreach (Detection detection in fileDetections)
{
detectedSecrets.Add(Tuple.Create(filePath, detection));
}
}
}

Interlocked.Increment(ref seen);
Interlocked.Increment(ref seen);

Console.Write($"\r\u001b[2KScanned {seen}/{total}.");
Console.Write($"\r\u001b[2KScanned {seen}/{total}.");
}
}
});

Expand Down
8 changes: 7 additions & 1 deletion tools/test-proxy/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,18 @@ stages:
CLONE_LOCATION: "$(Agent.BuildDirectory)/net_repo"

steps:
- task: UseDotNet@2 # About UseDotNet@2 task:
- task: UseDotNet@2
displayName: "Install .NET 8"
retryCountOnTaskFailure: 3
inputs:
version: "8.x"

- task: UseDotNet@2
displayName: "Install .NET 7"
retryCountOnTaskFailure: 3
inputs:
version: "7.x"

- template: /eng/pipelines/templates/steps/install-dotnet.yml

- pwsh: |
Expand Down

0 comments on commit 0e13e3b

Please sign in to comment.