Skip to content

Commit e0f27d3

Browse files
Copilotbcollamore
andcommitted
test(PH2155): Add comprehensive validation test for issue scenarios
Co-authored-by: bcollamore <57269455+bcollamore@users.noreply.github.com>
1 parent a3cc40e commit e0f27d3

1 file changed

Lines changed: 51 additions & 8 deletions

File tree

Philips.CodeAnalysis.Test/Security/LicenseAnalyzerTest.cs

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -891,17 +891,60 @@ public void LicenseAnalyzerHandlesTypeExpressionCorrectly()
891891

892892
[TestMethod]
893893
[TestCategory(TestDefinitions.UnitTests)]
894-
public void LicenseAnalyzerDeprecatedUrlNoLongerAcceptable()
894+
public void LicenseAnalyzerManualValidationOfIssueScenarios()
895895
{
896-
// Test that "aka.ms/deprecateLicenseUrl" is no longer in default acceptable licenses
897-
var analyzer = new LicenseAnalyzer();
896+
// Test 1: The exact scenario from the issue - should return UNKNOWN_FILE_LICENSE
897+
const string issueScenario = @"<?xml version=""1.0""?>
898+
<package>
899+
<metadata>
900+
<id>TestPackage</id>
901+
<version>1.0.0</version>
902+
<license type=""file"">LICENSE.md</license>
903+
<licenseUrl>https://aka.ms/deprecateLicenseUrl</licenseUrl>
904+
</metadata>
905+
</package>";
898906

899-
// This is an indirect test - we can't directly access the private DefaultAcceptableLicenses,
900-
// but we've removed it from the list, so this test documents the change
901-
Assert.IsNotNull(analyzer);
907+
var result1 = LicenseAnalyzer.ExtractLicenseFromNuspecContent(issueScenario);
908+
Assert.AreEqual("UNKNOWN_FILE_LICENSE", result1, "type='file' should return UNKNOWN_FILE_LICENSE");
909+
910+
// Test 2: Only deprecated URL (no license element) - should return the URL itself
911+
const string onlyDeprecatedUrl = @"<?xml version=""1.0""?>
912+
<package>
913+
<metadata>
914+
<id>TestPackage</id>
915+
<version>1.0.0</version>
916+
<licenseUrl>https://aka.ms/deprecateLicenseUrl</licenseUrl>
917+
</metadata>
918+
</package>";
919+
920+
var result2 = LicenseAnalyzer.ExtractLicenseFromNuspecContent(onlyDeprecatedUrl);
921+
Assert.AreEqual("https://aka.ms/deprecateLicenseUrl", result2, "Should return deprecated URL for further checking");
922+
923+
// Test 3: MIT via SPDX expression should still work
924+
const string mitExpression = @"<?xml version=""1.0""?>
925+
<package>
926+
<metadata>
927+
<id>TestPackage</id>
928+
<version>1.0.0</version>
929+
<license type=""expression"">MIT</license>
930+
</metadata>
931+
</package>";
932+
933+
var result3 = LicenseAnalyzer.ExtractLicenseFromNuspecContent(mitExpression);
934+
Assert.AreEqual("MIT", result3, "SPDX expressions should continue to work");
935+
936+
// Test 4: MIT via license URL should still work
937+
const string mitUrl = @"<?xml version=""1.0""?>
938+
<package>
939+
<metadata>
940+
<id>TestPackage</id>
941+
<version>1.0.0</version>
942+
<licenseUrl>https://opensource.org/licenses/MIT</licenseUrl>
943+
</metadata>
944+
</package>";
902945

903-
// The actual behavior will be tested through integration testing
904-
// when packages with this URL will now trigger findings
946+
var result4 = LicenseAnalyzer.ExtractLicenseFromNuspecContent(mitUrl);
947+
Assert.AreEqual("MIT", result4, "Recognizable license URLs should continue to work");
905948
}
906949

907950
[TestMethod]

0 commit comments

Comments
 (0)