Skip to content
Merged
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
3 changes: 3 additions & 0 deletions docs/reqstream/sarifmark/utilities/utilities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ sections:
- SarifMark-PathHelpers-PostCombineCheck
tests:
- Utilities_SafePathHandling_ValidPaths_CombinesSuccessfully
- Utilities_SafePathHandling_PathTraversal_ThrowsException
- Utilities_SafePathHandling_AbsolutePath_ThrowsException
- Utilities_SafePathHandling_NullInput_ThrowsException
44 changes: 44 additions & 0 deletions test/DemaConsulting.SarifMark.Tests/Utilities/UtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,48 @@ public void Utilities_SafePathHandling_ValidPaths_CombinesSuccessfully()
// Assert
Assert.AreEqual(Path.Combine(basePath, relativePath), result);
}

/// <summary>
/// Test that the Utilities subsystem rejects path-traversal attacks.
/// </summary>
[TestMethod]
public void Utilities_SafePathHandling_PathTraversal_ThrowsException()
{
// Arrange
var basePath = Path.GetTempPath();
var maliciousPath = "../../../etc/passwd";

// Act & Assert
Assert.Throws<ArgumentException>(() =>
PathHelpers.SafePathCombine(basePath, maliciousPath));
}

/// <summary>
/// Test that the Utilities subsystem rejects absolute paths.
/// </summary>
[TestMethod]
public void Utilities_SafePathHandling_AbsolutePath_ThrowsException()
{
// Arrange
var basePath = Path.GetTempPath();
var absolutePath = "/etc/passwd";

// Act & Assert
Assert.Throws<ArgumentException>(() =>
PathHelpers.SafePathCombine(basePath, absolutePath));
}

/// <summary>
/// Test that the Utilities subsystem rejects null inputs.
/// </summary>
[TestMethod]
public void Utilities_SafePathHandling_NullInput_ThrowsException()
{
// Arrange
var basePath = Path.GetTempPath();

// Act & Assert
Assert.Throws<ArgumentNullException>(() =>
PathHelpers.SafePathCombine(basePath, null!));
}
}