Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shaopeng-gh committed Aug 21, 2024
1 parent 00e498e commit a0b950d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ private async Task<bool> EnumerateFilesFromArtifactsProvider(TContext globalCont
{
globalContext.CancellationToken.ThrowIfCancellationRequested();

string filePath = artifact.Uri.OriginalString;
string filePath = artifact.Uri.GetFilePath();

if (globalContext.CompiledGlobalFileDenyRegex?.Match(filePath).Success == true)
{
Expand Down
17 changes: 14 additions & 3 deletions src/Test.UnitTests.Sarif.Driver/Sdk/AnalyzeCommandBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -831,14 +831,25 @@ public Run AnalyzeFile(string fileName,
}

[Fact]
[Trait(TestTraits.WindowsOnly, "true")]
public void AnalyzeCommand_EncodedPaths()
{
var logger = new MemoryStreamSarifLogger(dataToInsert: OptionallyEmittedData.Hashes);
var command = new TestMultithreadedAnalyzeCommand();
var uri = new Uri("/new folder/0%1%20%.txt", UriKind.Relative);
string path = @"C:\new folder\repro%2DCopy2.txt";
var uri = new Uri(path, UriKind.Absolute);

string content = "foo foo";
var mockFileSystem = new Mock<IFileSystem>();
mockFileSystem.Setup(x => x.IsSymbolicLink(path)).Returns(false);
mockFileSystem.Setup(x => x.FileStreamLength(path)).Returns(content.Length);
mockFileSystem.Setup(x => x.FileInfoLength(path)).Returns(content.Length);
mockFileSystem.Setup(x => x.FileReadAllText(path)).Returns(content);
mockFileSystem.Setup(x => x.FileOpenRead(path)).Returns(new MemoryStream(Encoding.UTF8.GetBytes(content)));

var target = new EnumeratedArtifact(FileSystem.Instance) { Uri = uri, Contents = "foo foo" };
var target = new EnumeratedArtifact(mockFileSystem.Object)
{
Uri = uri
};

var options = new TestAnalyzeOptions
{
Expand Down

0 comments on commit a0b950d

Please sign in to comment.