github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/rust/parse_cargo_lock_test.go (about) 1 package rust 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/anchore/syft/syft/artifact" 9 "github.com/anchore/syft/syft/file" 10 "github.com/anchore/syft/syft/pkg" 11 "github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest" 12 ) 13 14 func TestParseCargoLock(t *testing.T) { 15 fixture := "test-fixtures/Cargo.lock" 16 locations := file.NewLocationSet(file.NewLocation(fixture)) 17 ansiTerm := pkg.Package{ 18 Name: "ansi_term", 19 Version: "0.12.1", 20 PURL: "pkg:cargo/ansi_term@0.12.1", 21 Locations: locations, 22 Language: pkg.Rust, 23 Type: pkg.RustPkg, 24 Licenses: pkg.NewLicenseSet(), 25 Metadata: pkg.RustCargoLockEntry{ 26 Name: "ansi_term", 27 Version: "0.12.1", 28 Source: "registry+https://github.com/rust-lang/crates.io-index", 29 Checksum: "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2", 30 Dependencies: []string{ 31 "winapi", 32 }, 33 }, 34 } 35 errno := pkg.Package{ 36 Name: "errno", 37 Version: "0.3.9", 38 PURL: "pkg:cargo/errno@0.3.9", 39 Locations: locations, 40 Language: pkg.Rust, 41 Type: pkg.RustPkg, 42 Licenses: pkg.NewLicenseSet(), 43 Metadata: pkg.RustCargoLockEntry{ 44 Name: "errno", 45 Version: "0.3.9", 46 Source: "registry+https://github.com/rust-lang/crates.io-index", 47 Checksum: "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba", 48 Dependencies: []string{ 49 "windows-sys 0.52.0", 50 }, 51 }, 52 } 53 matches := pkg.Package{ 54 Name: "matches", 55 Version: "0.1.8", 56 PURL: "pkg:cargo/matches@0.1.8", 57 Locations: locations, 58 Language: pkg.Rust, 59 Type: pkg.RustPkg, 60 Licenses: pkg.NewLicenseSet(), 61 Metadata: pkg.RustCargoLockEntry{ 62 Name: "matches", 63 Version: "0.1.8", 64 Source: "registry+https://github.com/rust-lang/crates.io-index", 65 Checksum: "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08", 66 Dependencies: []string{}, 67 }, 68 } 69 memchr := pkg.Package{ 70 Name: "memchr", 71 Version: "2.3.3", 72 PURL: "pkg:cargo/memchr@2.3.3", 73 Locations: locations, 74 Language: pkg.Rust, 75 Type: pkg.RustPkg, 76 Licenses: pkg.NewLicenseSet(), 77 Metadata: pkg.RustCargoLockEntry{ 78 Name: "memchr", 79 Version: "2.3.3", 80 Source: "registry+https://github.com/rust-lang/crates.io-index", 81 Checksum: "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400", 82 Dependencies: []string{}, 83 }, 84 } 85 86 natord := pkg.Package{ 87 Name: "natord", 88 Version: "1.0.9", 89 PURL: "pkg:cargo/natord@1.0.9", 90 Locations: locations, 91 Language: pkg.Rust, 92 Type: pkg.RustPkg, 93 Licenses: pkg.NewLicenseSet(), 94 Metadata: pkg.RustCargoLockEntry{ 95 Name: "natord", 96 Version: "1.0.9", 97 Source: "registry+https://github.com/rust-lang/crates.io-index", 98 Checksum: "308d96db8debc727c3fd9744aac51751243420e46edf401010908da7f8d5e57c", 99 Dependencies: []string{}, 100 }, 101 } 102 103 nom := pkg.Package{ 104 Name: "nom", 105 Version: "4.2.3", 106 PURL: "pkg:cargo/nom@4.2.3", 107 Locations: locations, 108 Language: pkg.Rust, 109 Type: pkg.RustPkg, 110 Licenses: pkg.NewLicenseSet(), 111 Metadata: pkg.RustCargoLockEntry{ 112 Name: "nom", 113 Version: "4.2.3", 114 Source: "registry+https://github.com/rust-lang/crates.io-index", 115 Checksum: "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6", 116 Dependencies: []string{ 117 "memchr", 118 "version_check", 119 }, 120 }, 121 } 122 schannel := pkg.Package{ 123 Name: "schannel", 124 Version: "0.1.26", 125 PURL: "pkg:cargo/schannel@0.1.26", 126 Locations: locations, 127 Language: pkg.Rust, 128 Type: pkg.RustPkg, 129 Licenses: pkg.NewLicenseSet(), 130 Metadata: pkg.RustCargoLockEntry{ 131 Name: "schannel", 132 Version: "0.1.26", 133 Source: "registry+https://github.com/rust-lang/crates.io-index", 134 Checksum: "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1", 135 Dependencies: []string{ 136 "windows-sys 0.59.0", 137 }, 138 }, 139 } 140 141 unicodeBidi := pkg.Package{ 142 Name: "unicode-bidi", 143 Version: "0.3.4", 144 PURL: "pkg:cargo/unicode-bidi@0.3.4", 145 Locations: locations, 146 Language: pkg.Rust, 147 Type: pkg.RustPkg, 148 Licenses: pkg.NewLicenseSet(), 149 Metadata: pkg.RustCargoLockEntry{ 150 Name: "unicode-bidi", 151 Version: "0.3.4", 152 Source: "registry+https://github.com/rust-lang/crates.io-index", 153 Checksum: "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5", 154 Dependencies: []string{ 155 "matches", 156 "bogus", // a bad dependency to test error handling 157 }, 158 }, 159 } 160 161 versionCheck := pkg.Package{ 162 Name: "version_check", 163 Version: "0.1.5", 164 PURL: "pkg:cargo/version_check@0.1.5", 165 Locations: locations, 166 Language: pkg.Rust, 167 Type: pkg.RustPkg, 168 Licenses: pkg.NewLicenseSet(), 169 Metadata: pkg.RustCargoLockEntry{ 170 Name: "version_check", 171 Version: "0.1.5", 172 Source: "registry+https://github.com/rust-lang/crates.io-index", 173 Checksum: "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd", 174 Dependencies: []string{}, 175 }, 176 } 177 178 winapi := pkg.Package{ 179 Name: "winapi", 180 Version: "0.3.9", 181 PURL: "pkg:cargo/winapi@0.3.9", 182 Locations: locations, 183 Language: pkg.Rust, 184 Type: pkg.RustPkg, 185 Licenses: pkg.NewLicenseSet(), 186 Metadata: pkg.RustCargoLockEntry{ 187 Name: "winapi", 188 Version: "0.3.9", 189 Source: "registry+https://github.com/rust-lang/crates.io-index", 190 Checksum: "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419", 191 Dependencies: []string{ 192 "winapi-i686-pc-windows-gnu", 193 "winapi-x86_64-pc-windows-gnu", 194 }, 195 }, 196 } 197 198 winAPIi686PCWindowsGNU := pkg.Package{ 199 Name: "winapi-i686-pc-windows-gnu", 200 Version: "0.4.0", 201 PURL: "pkg:cargo/winapi-i686-pc-windows-gnu@0.4.0", 202 Locations: locations, 203 Language: pkg.Rust, 204 Type: pkg.RustPkg, 205 Licenses: pkg.NewLicenseSet(), 206 Metadata: pkg.RustCargoLockEntry{ 207 Name: "winapi-i686-pc-windows-gnu", 208 Version: "0.4.0", 209 Source: "registry+https://github.com/rust-lang/crates.io-index", 210 Checksum: "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6", 211 Dependencies: []string{}, 212 }, 213 } 214 215 winAPIx8664PCWindowsGNU := pkg.Package{ 216 Name: "winapi-x86_64-pc-windows-gnu", 217 Version: "0.4.0", 218 PURL: "pkg:cargo/winapi-x86_64-pc-windows-gnu@0.4.0", 219 Locations: locations, 220 Language: pkg.Rust, 221 Type: pkg.RustPkg, 222 Licenses: pkg.NewLicenseSet(), 223 Metadata: pkg.RustCargoLockEntry{ 224 Name: "winapi-x86_64-pc-windows-gnu", 225 Version: "0.4.0", 226 Source: "registry+https://github.com/rust-lang/crates.io-index", 227 Checksum: "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f", 228 Dependencies: []string{}, 229 }, 230 } 231 232 windowsSys52 := pkg.Package{ 233 Name: "windows-sys", 234 Version: "0.52.0", 235 PURL: "pkg:cargo/windows-sys@0.52.0", 236 Locations: locations, 237 Language: pkg.Rust, 238 Type: pkg.RustPkg, 239 Licenses: pkg.NewLicenseSet(), 240 Metadata: pkg.RustCargoLockEntry{ 241 Name: "windows-sys", 242 Version: "0.52.0", 243 Source: "registry+https://github.com/rust-lang/crates.io-index", 244 Checksum: "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d", 245 Dependencies: []string{}, 246 }, 247 } 248 249 windowsSys59 := pkg.Package{ 250 Name: "windows-sys", 251 Version: "0.59.0", 252 PURL: "pkg:cargo/windows-sys@0.59.0", 253 Locations: locations, 254 Language: pkg.Rust, 255 Type: pkg.RustPkg, 256 Licenses: pkg.NewLicenseSet(), 257 Metadata: pkg.RustCargoLockEntry{ 258 Name: "windows-sys", 259 Version: "0.59.0", 260 Source: "registry+https://github.com/rust-lang/crates.io-index", 261 Checksum: "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b", 262 Dependencies: []string{}, 263 }, 264 } 265 expectedPkgs := []pkg.Package{ 266 ansiTerm, 267 errno, 268 matches, 269 memchr, 270 natord, 271 nom, 272 schannel, 273 unicodeBidi, 274 versionCheck, 275 winapi, 276 winAPIi686PCWindowsGNU, 277 winAPIx8664PCWindowsGNU, 278 windowsSys52, 279 windowsSys59, 280 } 281 282 expectedRelationships := []artifact.Relationship{ 283 { 284 To: ansiTerm, 285 From: winapi, 286 Type: artifact.DependencyOfRelationship, 287 }, 288 { 289 To: errno, 290 From: windowsSys52, 291 Type: artifact.DependencyOfRelationship, 292 }, 293 { 294 To: nom, 295 From: memchr, 296 Type: artifact.DependencyOfRelationship, 297 }, 298 { 299 To: nom, 300 From: versionCheck, 301 Type: artifact.DependencyOfRelationship, 302 }, 303 { 304 To: schannel, 305 From: windowsSys59, 306 Type: artifact.DependencyOfRelationship, 307 }, 308 { 309 To: unicodeBidi, 310 From: matches, 311 Type: artifact.DependencyOfRelationship, 312 }, 313 { 314 To: winapi, 315 From: winAPIi686PCWindowsGNU, 316 Type: artifact.DependencyOfRelationship, 317 }, 318 { 319 To: winapi, 320 From: winAPIx8664PCWindowsGNU, 321 Type: artifact.DependencyOfRelationship, 322 }, 323 } 324 325 pkgtest.TestFileParser(t, fixture, parseCargoLock, expectedPkgs, expectedRelationships) 326 } 327 328 func TestCargoLockWithGitDependencies(t *testing.T) { 329 fixture := "test-fixtures/Cargo.lock-with-git-deps" 330 locations := file.NewLocationSet(file.NewLocation(fixture)) 331 332 ahoCorasick := pkg.Package{ 333 Name: "aho-corasick", 334 Version: "1.1.3", 335 PURL: "pkg:cargo/aho-corasick@1.1.3", 336 Locations: locations, 337 Language: pkg.Rust, 338 Type: pkg.RustPkg, 339 Licenses: pkg.NewLicenseSet(), 340 Metadata: pkg.RustCargoLockEntry{ 341 Name: "aho-corasick", 342 Version: "1.1.3", 343 Source: "registry+https://github.com/rust-lang/crates.io-index", 344 Checksum: "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916", 345 Dependencies: []string{ 346 "memchr", 347 }, 348 }, 349 } 350 351 helloWorld := pkg.Package{ 352 Name: "hello_world", 353 Version: "0.1.0", 354 PURL: "pkg:cargo/hello_world@0.1.0", 355 Locations: locations, 356 Language: pkg.Rust, 357 Type: pkg.RustPkg, 358 Licenses: pkg.NewLicenseSet(), 359 Metadata: pkg.RustCargoLockEntry{ 360 Name: "hello_world", 361 Version: "0.1.0", 362 Dependencies: []string{ 363 "nom-regex", 364 "regex 1.11.1 (git+https://github.com/rust-lang/regex.git)", 365 }, 366 }, 367 } 368 369 memchr := pkg.Package{ 370 Name: "memchr", 371 Version: "2.7.4", 372 PURL: "pkg:cargo/memchr@2.7.4", 373 Locations: locations, 374 Language: pkg.Rust, 375 Type: pkg.RustPkg, 376 Licenses: pkg.NewLicenseSet(), 377 Metadata: pkg.RustCargoLockEntry{ 378 Name: "memchr", 379 Version: "2.7.4", 380 Source: "registry+https://github.com/rust-lang/crates.io-index", 381 Checksum: "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3", 382 Dependencies: []string{}, 383 }, 384 } 385 386 minimalLexical := pkg.Package{ 387 Name: "minimal-lexical", 388 Version: "0.2.1", 389 PURL: "pkg:cargo/minimal-lexical@0.2.1", 390 Locations: locations, 391 Language: pkg.Rust, 392 Type: pkg.RustPkg, 393 Licenses: pkg.NewLicenseSet(), 394 Metadata: pkg.RustCargoLockEntry{ 395 Name: "minimal-lexical", 396 Version: "0.2.1", 397 Source: "registry+https://github.com/rust-lang/crates.io-index", 398 Checksum: "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a", 399 Dependencies: []string{}, 400 }, 401 } 402 403 nom := pkg.Package{ 404 Name: "nom", 405 Version: "7.1.3", 406 PURL: "pkg:cargo/nom@7.1.3", 407 Locations: locations, 408 Language: pkg.Rust, 409 Type: pkg.RustPkg, 410 Licenses: pkg.NewLicenseSet(), 411 Metadata: pkg.RustCargoLockEntry{ 412 Name: "nom", 413 Version: "7.1.3", 414 Source: "registry+https://github.com/rust-lang/crates.io-index", 415 Checksum: "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a", 416 Dependencies: []string{ 417 "memchr", 418 "minimal-lexical", 419 }, 420 }, 421 } 422 423 nomRegex := pkg.Package{ 424 Name: "nom-regex", 425 Version: "0.2.0", 426 PURL: "pkg:cargo/nom-regex@0.2.0", 427 Locations: locations, 428 Language: pkg.Rust, 429 Type: pkg.RustPkg, 430 Licenses: pkg.NewLicenseSet(), 431 Metadata: pkg.RustCargoLockEntry{ 432 Name: "nom-regex", 433 Version: "0.2.0", 434 Source: "registry+https://github.com/rust-lang/crates.io-index", 435 Checksum: "72e5c7731c4c1370b61604ed52a2475e861aac9e08dec9f23903d4ddfdc91c18", 436 Dependencies: []string{ 437 "nom", 438 "regex 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", 439 }, 440 }, 441 } 442 443 regexCrates := pkg.Package{ 444 Name: "regex", 445 Version: "1.11.1", 446 PURL: "pkg:cargo/regex@1.11.1", 447 Locations: locations, 448 Language: pkg.Rust, 449 Type: pkg.RustPkg, 450 Licenses: pkg.NewLicenseSet(), 451 Metadata: pkg.RustCargoLockEntry{ 452 Name: "regex", 453 Version: "1.11.1", 454 Source: "registry+https://github.com/rust-lang/crates.io-index", 455 Checksum: "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191", 456 Dependencies: []string{ 457 "aho-corasick", 458 "memchr", 459 "regex-automata 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", 460 "regex-syntax 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", 461 }, 462 }, 463 } 464 465 regexGit := pkg.Package{ 466 Name: "regex", 467 Version: "1.11.1", 468 PURL: "pkg:cargo/regex@1.11.1", 469 Locations: locations, 470 Language: pkg.Rust, 471 Type: pkg.RustPkg, 472 Licenses: pkg.NewLicenseSet(), 473 Metadata: pkg.RustCargoLockEntry{ 474 Name: "regex", 475 Version: "1.11.1", 476 Source: "git+https://github.com/rust-lang/regex.git#1a069b9232c607b34c4937122361aa075ef573fa", 477 Dependencies: []string{ 478 "aho-corasick", 479 "memchr", 480 "regex-automata 0.4.9 (git+https://github.com/rust-lang/regex.git)", 481 "regex-syntax 0.8.5 (git+https://github.com/rust-lang/regex.git)", 482 }, 483 }, 484 } 485 486 regexAutomataCrates := pkg.Package{ 487 Name: "regex-automata", 488 Version: "0.4.9", 489 PURL: "pkg:cargo/regex-automata@0.4.9", 490 Locations: locations, 491 Language: pkg.Rust, 492 Type: pkg.RustPkg, 493 Licenses: pkg.NewLicenseSet(), 494 Metadata: pkg.RustCargoLockEntry{ 495 Name: "regex-automata", 496 Version: "0.4.9", 497 Source: "registry+https://github.com/rust-lang/crates.io-index", 498 Checksum: "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908", 499 Dependencies: []string{ 500 "aho-corasick", 501 "memchr", 502 "regex-syntax 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", 503 }, 504 }, 505 } 506 507 regexAutomataGit := pkg.Package{ 508 Name: "regex-automata", 509 Version: "0.4.9", 510 PURL: "pkg:cargo/regex-automata@0.4.9", 511 Locations: locations, 512 Language: pkg.Rust, 513 Type: pkg.RustPkg, 514 Licenses: pkg.NewLicenseSet(), 515 Metadata: pkg.RustCargoLockEntry{ 516 Name: "regex-automata", 517 Version: "0.4.9", 518 Source: "git+https://github.com/rust-lang/regex.git#1a069b9232c607b34c4937122361aa075ef573fa", 519 Dependencies: []string{ 520 "aho-corasick", 521 "memchr", 522 "regex-syntax 0.8.5 (git+https://github.com/rust-lang/regex.git)", 523 }, 524 }, 525 } 526 527 regexSyntaxCrates := pkg.Package{ 528 Name: "regex-syntax", 529 Version: "0.8.5", 530 PURL: "pkg:cargo/regex-syntax@0.8.5", 531 Locations: locations, 532 Language: pkg.Rust, 533 Type: pkg.RustPkg, 534 Licenses: pkg.NewLicenseSet(), 535 Metadata: pkg.RustCargoLockEntry{ 536 Name: "regex-syntax", 537 Version: "0.8.5", 538 Source: "registry+https://github.com/rust-lang/crates.io-index", 539 Checksum: "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c", 540 Dependencies: []string{}, 541 }, 542 } 543 544 regexSyntaxGit := pkg.Package{ 545 Name: "regex-syntax", 546 Version: "0.8.5", 547 PURL: "pkg:cargo/regex-syntax@0.8.5", 548 Locations: locations, 549 Language: pkg.Rust, 550 Type: pkg.RustPkg, 551 Licenses: pkg.NewLicenseSet(), 552 Metadata: pkg.RustCargoLockEntry{ 553 Name: "regex-syntax", 554 Version: "0.8.5", 555 Source: "git+https://github.com/rust-lang/regex.git#1a069b9232c607b34c4937122361aa075ef573fa", 556 Dependencies: []string{}, 557 }, 558 } 559 560 expectedPkgs := []pkg.Package{ 561 ahoCorasick, helloWorld, memchr, minimalLexical, nom, nomRegex, regexCrates, regexGit, 562 regexAutomataCrates, regexAutomataGit, regexSyntaxCrates, regexSyntaxGit, 563 } 564 expectedRelationships := []artifact.Relationship{ 565 { 566 From: memchr, 567 To: ahoCorasick, 568 Type: artifact.DependencyOfRelationship, 569 }, 570 { 571 From: nomRegex, 572 To: helloWorld, 573 Type: artifact.DependencyOfRelationship, 574 }, 575 { 576 From: regexGit, 577 To: helloWorld, 578 Type: artifact.DependencyOfRelationship, 579 }, 580 { 581 From: memchr, 582 To: nom, 583 Type: artifact.DependencyOfRelationship, 584 }, 585 { 586 From: minimalLexical, 587 To: nom, 588 Type: artifact.DependencyOfRelationship, 589 }, 590 { 591 From: nom, 592 To: nomRegex, 593 Type: artifact.DependencyOfRelationship, 594 }, 595 { 596 From: regexCrates, 597 To: nomRegex, 598 Type: artifact.DependencyOfRelationship, 599 }, 600 { 601 From: ahoCorasick, 602 To: regexCrates, 603 Type: artifact.DependencyOfRelationship, 604 }, 605 { 606 From: memchr, 607 To: regexCrates, 608 Type: artifact.DependencyOfRelationship, 609 }, 610 { 611 From: regexAutomataCrates, 612 To: regexCrates, 613 Type: artifact.DependencyOfRelationship, 614 }, 615 { 616 From: regexSyntaxCrates, 617 To: regexCrates, 618 Type: artifact.DependencyOfRelationship, 619 }, 620 { 621 From: regexSyntaxCrates, 622 To: regexAutomataCrates, 623 Type: artifact.DependencyOfRelationship, 624 }, 625 { 626 From: ahoCorasick, 627 To: regexGit, 628 Type: artifact.DependencyOfRelationship, 629 }, 630 { 631 From: memchr, 632 To: regexGit, 633 Type: artifact.DependencyOfRelationship, 634 }, 635 { 636 From: regexAutomataGit, 637 To: regexGit, 638 Type: artifact.DependencyOfRelationship, 639 }, 640 { 641 From: regexSyntaxGit, 642 To: regexAutomataGit, 643 Type: artifact.DependencyOfRelationship, 644 }, 645 { 646 From: regexSyntaxGit, 647 To: regexGit, 648 Type: artifact.DependencyOfRelationship, 649 }, 650 { 651 From: ahoCorasick, 652 To: regexAutomataCrates, 653 Type: artifact.DependencyOfRelationship, 654 }, 655 { 656 From: memchr, 657 To: regexAutomataCrates, 658 Type: artifact.DependencyOfRelationship, 659 }, 660 { 661 From: ahoCorasick, 662 To: regexAutomataGit, 663 Type: artifact.DependencyOfRelationship, 664 }, 665 { 666 From: memchr, 667 To: regexAutomataGit, 668 Type: artifact.DependencyOfRelationship, 669 }, 670 } 671 // what I know so far - it's not sorting, it's not 672 673 pkgtest.TestFileParser(t, fixture, parseCargoLock, expectedPkgs, expectedRelationships) 674 } 675 676 func TestCargoLockDependencySpecification(t *testing.T) { 677 tests := []struct { 678 name string 679 p pkg.Package 680 provides []string 681 requires []string 682 }{ 683 { 684 name: "requires git source", 685 p: pkg.Package{ 686 Name: "hello_world", 687 Version: "0.1.0", 688 PURL: "pkg:cargo/hello_world@0.1.0", 689 Locations: file.NewLocationSet(), 690 Language: pkg.Rust, 691 Type: pkg.RustPkg, 692 Licenses: pkg.NewLicenseSet(), 693 Metadata: pkg.RustCargoLockEntry{ 694 Name: "hello_world", 695 Version: "0.1.0", 696 Dependencies: []string{ 697 "nom-regex", 698 "regex 1.11.1 (git+https://github.com/rust-lang/regex.git)", 699 }, 700 }, 701 }, 702 provides: []string{ 703 "hello_world", 704 "hello_world 0.1.0", 705 }, 706 requires: []string{ 707 "nom-regex", 708 "regex 1.11.1 (git+https://github.com/rust-lang/regex.git)", 709 }, 710 }, 711 { 712 name: "provides git source", 713 p: pkg.Package{ 714 Name: "regex-automata", 715 Version: "0.4.9", 716 PURL: "pkg:cargo/regex-automata@0.4.9", 717 Locations: file.NewLocationSet(), 718 Language: pkg.Rust, 719 Type: pkg.RustPkg, 720 Licenses: pkg.NewLicenseSet(), 721 Metadata: pkg.RustCargoLockEntry{ 722 Name: "regex-automata", 723 Version: "0.4.9", 724 Source: "git+https://github.com/rust-lang/regex.git#1a069b9232c607b34c4937122361aa075ef573fa", 725 Dependencies: []string{ 726 "aho-corasick", 727 "memchr", 728 "regex-syntax 0.8.5 (git+https://github.com/rust-lang/regex.git)", 729 }, 730 }, 731 }, 732 provides: []string{ 733 "regex-automata", 734 "regex-automata 0.4.9", 735 "regex-automata 0.4.9 (git+https://github.com/rust-lang/regex.git)", 736 }, 737 requires: []string{ 738 "aho-corasick", 739 "memchr", 740 "regex-syntax 0.8.5 (git+https://github.com/rust-lang/regex.git)", 741 }, 742 }, 743 { 744 name: "regex-automata git", 745 p: pkg.Package{ 746 Name: "regex-automata", 747 Version: "0.4.9", 748 PURL: "pkg:cargo/regex-automata@0.4.9", 749 Locations: file.NewLocationSet(), 750 Language: pkg.Rust, 751 Type: pkg.RustPkg, 752 Licenses: pkg.NewLicenseSet(), 753 Metadata: pkg.RustCargoLockEntry{ 754 Name: "regex-automata", 755 Version: "0.4.9", 756 Source: "git+https://github.com/rust-lang/regex.git#1a069b9232c607b34c4937122361aa075ef573fa", 757 Dependencies: []string{ 758 "aho-corasick", 759 "memchr", 760 "regex-syntax 0.8.5 (git+https://github.com/rust-lang/regex.git)", 761 }, 762 }, 763 }, 764 provides: []string{ 765 "regex-automata", 766 "regex-automata 0.4.9", 767 "regex-automata 0.4.9 (git+https://github.com/rust-lang/regex.git)", 768 }, 769 requires: []string{ 770 "aho-corasick", 771 "memchr", 772 "regex-syntax 0.8.5 (git+https://github.com/rust-lang/regex.git)", 773 }, 774 }, 775 { 776 name: "regex-syntax git", 777 p: pkg.Package{ 778 Name: "regex-syntax", 779 Version: "0.8.5", 780 PURL: "pkg:cargo/regex-syntax@0.8.5", 781 Locations: file.NewLocationSet(), 782 Language: pkg.Rust, 783 Type: pkg.RustPkg, 784 Licenses: pkg.NewLicenseSet(), 785 Metadata: pkg.RustCargoLockEntry{ 786 Name: "regex-syntax", 787 Version: "0.8.5", 788 Source: "git+https://github.com/rust-lang/regex.git#1a069b9232c607b34c4937122361aa075ef573fa", 789 Dependencies: []string{}, 790 }, 791 }, 792 provides: []string{ 793 "regex-syntax", 794 "regex-syntax 0.8.5", 795 "regex-syntax 0.8.5 (git+https://github.com/rust-lang/regex.git)", 796 }, 797 requires: []string{}, 798 }, 799 { 800 name: "regex-syntax crates", 801 p: pkg.Package{ 802 Name: "regex-syntax", 803 Version: "0.8.5", 804 PURL: "pkg:cargo/regex-syntax@0.8.5", 805 Locations: file.NewLocationSet(), 806 Language: pkg.Rust, 807 Type: pkg.RustPkg, 808 Licenses: pkg.NewLicenseSet(), 809 Metadata: pkg.RustCargoLockEntry{ 810 Name: "regex-syntax", 811 Version: "0.8.5", 812 Source: "registry+https://github.com/rust-lang/crates.io-index", 813 Checksum: "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c", 814 Dependencies: []string{}, 815 }, 816 }, 817 provides: []string{ 818 "regex-syntax", 819 "regex-syntax 0.8.5", 820 "regex-syntax 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", 821 }, 822 requires: []string{}, 823 }, 824 } 825 826 for _, test := range tests { 827 t.Run(test.name, func(t *testing.T) { 828 spec := dependencySpecification(test.p) 829 assert.Equal(t, test.provides, spec.Provides) 830 assert.Equal(t, test.requires, spec.Requires) 831 }) 832 } 833 } 834 835 func Test_corruptCargoLock(t *testing.T) { 836 pkgtest.NewCatalogTester(). 837 FromFile(t, "test-fixtures/glob-paths/src/Cargo.lock"). 838 WithError(). 839 TestParser(t, parseCargoLock) 840 }