Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected override Task<IObservable<ProcessRequest>> OnPrepareDetectionAsync(
IDictionary<string, string> detectorArgs,
CancellationToken cancellationToken = default) =>
Task.FromResult(processRequests.Where(processRequest =>
!processRequest.ComponentStream.Location.EndsWith(".dockerignore", StringComparison.OrdinalIgnoreCase) &&
!this.IsInSkippedFolder(processRequest.ComponentStream.Location)));

protected override async Task OnFileFoundAsync(ProcessRequest processRequest, IDictionary<string, string> detectorArgs, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,48 @@ public async Task TestDockerfile_ExtensionFilenameAsync()
}

[TestMethod]
public async Task TestDockerfile_PrefixedFilenameAsync()
[DataRow("Dockerfile.prod")]
[DataRow("Dockerfile.runtime")]
[DataRow("Dockerfile.dockerignore.runtime")]
public async Task TestDockerfile_PrefixedFilenameAsync(string fileName)
{
var dockerfile = @"FROM redis:7-alpine";

var (scanResult, componentRecorder) = await this.DetectorTestUtility
.WithFile("Dockerfile.prod", dockerfile)
.WithFile(fileName, dockerfile)
.ExecuteDetectorAsync();

scanResult.ResultCode.Should().Be(ProcessingResultCode.Success);
componentRecorder.GetDetectedComponents().Should().ContainSingle();
}

[TestMethod]
[DataRow("Dockerfile.dockerignore", "node_modules\n*.log")]
[DataRow("Dockerfile.runtime.dockerignore", "node_modules\n*.log")]
[DataRow("app.dockerfile.dockerignore", "node_modules\n*.log")]
[DataRow("DOCKERFILE.DOCKERIGNORE", "node_modules\n*.log")]
[DataRow("Dockerfile.dockerignore", "FROM redis:7-alpine")]
public async Task TestDockerfile_DockerignoreIsSilentlyIgnoredAsync(string fileName, string contents)
{
var loggerMock = new Mock<ILogger<DockerfileComponentDetector>>();

var (scanResult, componentRecorder) = await this.DetectorTestUtility
.WithFile(fileName, contents)
.AddServiceMock(loggerMock)
.ExecuteDetectorAsync();

scanResult.ResultCode.Should().Be(ProcessingResultCode.Success);
componentRecorder.GetDetectedComponents().Should().BeEmpty();
loggerMock.Verify(
logger => logger.Log(
It.Is<LogLevel>(level => level == LogLevel.Warning || level == LogLevel.Error),
It.IsAny<EventId>(),
It.IsAny<It.IsAnyType>(),
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception?, string>>()),
Times.Never);
}

[TestMethod]
[DataRow("dockerfile.mjs")]
[DataRow("dockerfile.d.mts")]
Expand Down
Loading