|
17 | 17 | */ |
18 | 18 | package org.owasp.dependencycheck.analyzer; |
19 | 19 |
|
| 20 | +import com.github.packageurl.MalformedPackageURLException; |
| 21 | +import com.github.packageurl.PackageURL; |
| 22 | +import org.jspecify.annotations.NonNull; |
20 | 23 | import org.junit.jupiter.api.AfterEach; |
21 | 24 | import org.junit.jupiter.api.BeforeEach; |
22 | 25 | import org.junit.jupiter.api.Test; |
|
27 | 30 | import org.owasp.dependencycheck.dependency.Dependency; |
28 | 31 | import org.owasp.dependencycheck.dependency.Evidence; |
29 | 32 | import org.owasp.dependencycheck.dependency.EvidenceType; |
| 33 | +import org.owasp.dependencycheck.dependency.naming.PurlIdentifier; |
30 | 34 | import org.owasp.dependencycheck.exception.InitializationException; |
31 | 35 | import org.owasp.dependencycheck.utils.Settings; |
| 36 | +import org.owasp.dependencycheck.xml.assembly.AssemblyData; |
32 | 37 | import org.slf4j.Logger; |
33 | 38 | import org.slf4j.LoggerFactory; |
34 | 39 |
|
35 | 40 | import java.io.File; |
| 41 | +import java.util.Set; |
36 | 42 |
|
37 | 43 | import static org.junit.jupiter.api.Assertions.assertEquals; |
38 | 44 | import static org.junit.jupiter.api.Assertions.assertThrows; |
@@ -175,6 +181,117 @@ void testWithSettingMono() { |
175 | 181 | } |
176 | 182 | } |
177 | 183 |
|
| 184 | + @Test |
| 185 | + void testAzureIdentity() throws MalformedPackageURLException { |
| 186 | + // Given |
| 187 | + var data = newAzureIdentityAssemblyData(); |
| 188 | + var dependency = newAzureIdentityDependency(); |
| 189 | + |
| 190 | + var expectedDescription = "Microsoft Azure.Identity Component\n\nThis is the implementation of the Azure SDK " + |
| 191 | + "Client Library for Azure Identity"; |
| 192 | + var expectedVersionEvidences = expectedAzureIdentityVersionEvidences(); |
| 193 | + var expectedVersion = "1.7.0"; |
| 194 | + var expectedProductEvidences = expectedAzureIdentityProductEvidences(); |
| 195 | + var expectedVendorEvidences = expectedAzureIdentityVendorEvidences(); |
| 196 | + var expectedName = "Azure.Identity"; |
| 197 | + var expectedIdentifiers = Set.of(new PurlIdentifier(new PackageURL("pkg:generic/Azure.Identity@1.7.0"), |
| 198 | + Confidence.MEDIUM)); |
| 199 | + var expectedEcosystem = "dotnet"; |
| 200 | + |
| 201 | + // When |
| 202 | + analyzer.updateDependency(data, dependency); |
| 203 | + |
| 204 | + // Then |
| 205 | + assertEquals(expectedDescription, dependency.getDescription()); |
| 206 | + assertEquals(expectedVersionEvidences, dependency.getEvidence(EvidenceType.VERSION)); |
| 207 | + assertEquals(expectedVersion, dependency.getVersion()); |
| 208 | + assertEquals(expectedProductEvidences, dependency.getEvidence(EvidenceType.PRODUCT)); |
| 209 | + assertEquals(expectedVendorEvidences, dependency.getEvidence(EvidenceType.VENDOR)); |
| 210 | + assertEquals(expectedName, dependency.getName()); |
| 211 | + assertEquals(expectedIdentifiers, dependency.getSoftwareIdentifiers()); |
| 212 | + assertEquals(expectedEcosystem, dependency.getEcosystem()); |
| 213 | + } |
| 214 | + |
| 215 | + private static @NonNull AssemblyData newAzureIdentityAssemblyData() { |
| 216 | + var data = new AssemblyData(); |
| 217 | + data.setCompanyName("Microsoft Corporation"); |
| 218 | + data.setProductName("Azure .NET SDK"); |
| 219 | + data.setProductVersion("1.7.0+3627e3cbc75c628f659d033ed9270c9d02ab9038"); |
| 220 | + data.setComments("This is the implementation of the Azure SDK Client Library for Azure Identity"); |
| 221 | + data.setFileDescription("Microsoft Azure.Identity Component"); |
| 222 | + data.setFileName("/home/jdoe/ScanFolder/Azure.Identity.dll"); |
| 223 | + data.setFileVersion("1.700.22.46903"); |
| 224 | + data.setInternalName("Azure.Identity.dll"); |
| 225 | + data.setOriginalFilename("Azure.Identity.dll"); |
| 226 | + data.setFullName("Azure.Identity, Version=1.7.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8"); |
| 227 | + |
| 228 | + data.addNamespace("Microsoft.CodeAnalysis"); |
| 229 | + data.addNamespace("System.Runtime.CompilerServices"); |
| 230 | + data.addNamespace("Azure.Core"); |
| 231 | + data.addNamespace("Azure.Core.Pipeline"); |
| 232 | + data.addNamespace("Azure.Core.Diagnostics"); |
| 233 | + // The following duplication is on purpose, this use case has one |
| 234 | + data.addNamespace("Azure.Identitiy"); |
| 235 | + data.addNamespace("Azure.Identitiy"); |
| 236 | + return data; |
| 237 | + } |
| 238 | + |
| 239 | + private static @NonNull Dependency newAzureIdentityDependency() { |
| 240 | + var dependency = new Dependency(); |
| 241 | + dependency.setActualFilePath("/home/jdoe/ScanFolder/Azure.Identity.dll"); |
| 242 | + dependency.setFilePath("/home/jdoe/ScanFolder/Azure.Identity.dll"); |
| 243 | + dependency.setFileName("Azure.Identity.dll"); |
| 244 | + dependency.setPackagePath("/home/jdoe/ScanFolder/Azure.Identity.dll"); |
| 245 | + dependency.setMd5sum("19f72346b3952c135c121e30235d4064"); |
| 246 | + dependency.setSha1sum("1ac0e967367aa7679a89b2eb652a7996870d9043"); |
| 247 | + dependency.setSha256sum("666973af908cf82a495530b2ea23074004dead445e1bb46ef75a5e3c879a6321"); |
| 248 | + |
| 249 | + var nameEvidence = new Evidence("file", "name", "Azure.Identity", Confidence.HIGH); |
| 250 | + |
| 251 | + dependency.addEvidence(EvidenceType.VENDOR, nameEvidence); |
| 252 | + dependency.addEvidence(EvidenceType.PRODUCT, nameEvidence); |
| 253 | + |
| 254 | + return dependency; |
| 255 | + } |
| 256 | + |
| 257 | + private static @NonNull Set<Evidence> expectedAzureIdentityVersionEvidences() { |
| 258 | + var fileVersionEvidence = new Evidence("grokassembly", "FileVersion", "1.700.22.46903", Confidence.HIGH); |
| 259 | + var productVersionEvidence = new Evidence("grokassembly", "ProductVersion", "1.7.0+3627e3cbc75c628f659d033ed9270c9d02ab9038", Confidence.HIGHEST); |
| 260 | + |
| 261 | + return Set.of(fileVersionEvidence, productVersionEvidence); |
| 262 | + } |
| 263 | + |
| 264 | + private static @NonNull Set<Evidence> expectedAzureIdentityProductEvidences() { |
| 265 | + var nameEvidence = new Evidence("file", "name", "Azure.Identity", Confidence.HIGH); |
| 266 | + var companyNameLowEvidence = new Evidence("grokassembly", "CompanyName", "Microsoft Corporation", Confidence.LOW); |
| 267 | + var fileDescriptionHighEvidence = new Evidence("grokassembly", "FileDescription", |
| 268 | + "Microsoft Azure.Identity Component", Confidence.HIGH); |
| 269 | + var internalNameMediumEvidence = new Evidence("grokassembly", "InternalName", "Azure.Identity.dll", |
| 270 | + Confidence.MEDIUM); |
| 271 | + var originalFilenameMediumEvidence = new Evidence("grokassembly", "OriginalFilename", "Azure.Identity.dll", |
| 272 | + Confidence.MEDIUM); |
| 273 | + var productNameHighestEvidence = new Evidence("grokassembly", "ProductName", "Azure .NET SDK", Confidence.HIGHEST); |
| 274 | + |
| 275 | + return Set.of(nameEvidence, companyNameLowEvidence, fileDescriptionHighEvidence, |
| 276 | + internalNameMediumEvidence, originalFilenameMediumEvidence, productNameHighestEvidence); |
| 277 | + } |
| 278 | + |
| 279 | + private static @NonNull Set<Evidence> expectedAzureIdentityVendorEvidences() { |
| 280 | + var nameEvidence = new Evidence("file", "name", "Azure.Identity", Confidence.HIGH); |
| 281 | + var companyNameHighestEvidence = new Evidence("grokassembly", "CompanyName", "Microsoft Corporation", |
| 282 | + Confidence.HIGHEST); |
| 283 | + var fileDescriptionLowEvidence = new Evidence("grokassembly", "FileDescription", |
| 284 | + "Microsoft Azure.Identity Component", Confidence.LOW); |
| 285 | + var internalNameLowEvidence = new Evidence("grokassembly", "InternalName", "Azure.Identity.dll", |
| 286 | + Confidence.LOW); |
| 287 | + var originalFilenameLowEvidence = new Evidence("grokassembly", "OriginalFilename", "Azure.Identity.dll", |
| 288 | + Confidence.LOW); |
| 289 | + var productNameMediumEvidence = new Evidence("grokassembly", "ProductName", "Azure .NET SDK", |
| 290 | + Confidence.MEDIUM); |
| 291 | + return Set.of(nameEvidence, companyNameHighestEvidence, fileDescriptionLowEvidence, |
| 292 | + internalNameLowEvidence, originalFilenameLowEvidence, productNameMediumEvidence); |
| 293 | + } |
| 294 | + |
178 | 295 | @AfterEach |
179 | 296 | @Override |
180 | 297 | public void tearDown() throws Exception { |
|
0 commit comments