|
| 1 | +package policies_test |
| 2 | + |
| 3 | +import data.policies |
| 4 | +import data.fixtures |
| 5 | + |
| 6 | +# From org should pass if at least one correct org is provided |
| 7 | +test_from_org_pass if { |
| 8 | + policies.fromOrg(fixtures.octo_org, ["unkown", "octoorg"]) |
| 9 | +} |
| 10 | + |
| 11 | +# Should fail when issuer is not matching |
| 12 | +test_from_org_issuer if { |
| 13 | + not policies.fromOrg(fixtures.custom_issuer, ["unkown", "octoorg"]) |
| 14 | +} |
| 15 | + |
| 16 | +# Empty org should fail |
| 17 | +test_from_org_empty if { |
| 18 | + not policies.fromOrg(fixtures.octo_org, [""]) |
| 19 | +} |
| 20 | + |
| 21 | +test_from_org_empty if { |
| 22 | + not policies.fromOrg(fixtures.octo_org, []) |
| 23 | +} |
| 24 | + |
| 25 | +# Verify that no prefix weakness exists |
| 26 | +test_from_org_invalid if { |
| 27 | + not policies.fromOrg(fixtures.octo_org, ["unkown", "octoorga", "ctoorg", "aoctoorg"]) |
| 28 | +} |
| 29 | + |
| 30 | +test_from_org_non_provenance if { |
| 31 | + not policies.fromOrg(fixtures.non_provenance, ["octoorg"]) |
| 32 | +} |
| 33 | + |
| 34 | +# From repo should pass if at least one repo is valid |
| 35 | +test_from_repo_pass if { |
| 36 | + policies.fromRepo(fixtures.octo_org, ["unkown/unkown", "octoorg/octorepo"]) |
| 37 | +} |
| 38 | + |
| 39 | +# Should fail when issuer is not matching |
| 40 | +test_from_repo_issuer if { |
| 41 | + not policies.fromRepo(fixtures.custom_issuer, ["unkown/unkown", "octoorg/octorepo"]) |
| 42 | +} |
| 43 | + |
| 44 | +# Empty repo shoud fail |
| 45 | +test_from_repo_empty if { |
| 46 | + not policies.fromRepo(fixtures.octo_org, [""]) |
| 47 | +} |
| 48 | + |
| 49 | +test_from_repo_empty if { |
| 50 | + not policies.fromRepo(fixtures.octo_org, []) |
| 51 | +} |
| 52 | + |
| 53 | +# Verify that no prefix weakness exists |
| 54 | +test_from_repo_invalid if { |
| 55 | + not policies.fromRepo(fixtures.octo_org, ["unkown/unkown", "ctoorg/octorepo", "aoctoorg/octorepo", "octoorga/octorepo", "octoorg/aoctorepo", "octoorg/octorep", "octoorg/octorepoa"]) |
| 56 | +} |
| 57 | + |
| 58 | +test_from_repo_non_provenance if { |
| 59 | + not policies.fromRepo(fixtures.non_provenance, ["octoorg/octorepo"]) |
| 60 | +} |
| 61 | + |
| 62 | +# Same repo and signer |
| 63 | +test_with_signer_pass if { |
| 64 | + policies.fromOrgWithSignerRepo(fixtures.octo_org, ["unknown", "octoorg"], ["unkown/octorepo", "octoorg/octorepo"]) |
| 65 | +} |
| 66 | + |
| 67 | +# With a signer from a different org |
| 68 | +test_with_signer_pass if { |
| 69 | + policies.fromOrgWithSignerRepo(fixtures.reusable, ["unknown", "octoorg"], ["octoorg/octorepo", "buildorg/build-scripts"]) |
| 70 | +} |
| 71 | + |
| 72 | +# Should fail when issuer is not matching |
| 73 | +test_with_signer_issuer if { |
| 74 | + not policies.fromOrgWithSignerRepo(fixtures.custom_issuer, ["unknown", "octoorg"], ["octoorg/octorepo", "buildorg/build-scripts"]) |
| 75 | +} |
| 76 | + |
| 77 | +# Empty input |
| 78 | +test_with_signer_empty if { |
| 79 | + not policies.fromOrgWithSignerRepo(fixtures.reusable, [], []) |
| 80 | +} |
| 81 | + |
| 82 | +test_with_signer_empty if { |
| 83 | + not policies.fromOrgWithSignerRepo(fixtures.reusable, [""], []) |
| 84 | +} |
| 85 | + |
| 86 | +test_with_signer_empty if { |
| 87 | + not policies.fromOrgWithSignerRepo(fixtures.reusable, [], [""]) |
| 88 | +} |
| 89 | + |
| 90 | +test_with_signer_empty if { |
| 91 | + not policies.fromOrgWithSignerRepo(fixtures.reusable, [""], [""]) |
| 92 | +} |
| 93 | + |
| 94 | +# Verify that no prefix weakness exists for the orgs |
| 95 | +test_with_signer_invalid if { |
| 96 | + not policies.fromOrgWithSignerRepo(fixtures.reusable, ["unkown", "ctoorg", "octoor", "aoctoorg", "octoorga"], ["octoorg/octorepo"]) |
| 97 | +} |
| 98 | + |
| 99 | +# Verify that no prefix weakness exists for the signer repos |
| 100 | +test_with_signer_invalid if { |
| 101 | + not policies.fromOrgWithSignerRepo(fixtures.reusable, ["octoorg"], ["ctoorg/octorepo", "octoorg/octorep", "octoor/octorepo", "octoorg/ctorepo"]) |
| 102 | +} |
| 103 | + |
| 104 | +# Make sure that a JSON doc matching the provenance does not pass |
| 105 | +# if the predicate type is differing |
| 106 | +test_with_signer_non_provenance if { |
| 107 | + not policies.fromOrgWithSignerRepo(fixtures.non_provenance, ["octoorg"], ["buildorg/build-scripts"]) |
| 108 | +} |
| 109 | + |
| 110 | +# If multiple attestations are returned, the verification should still pass |
| 111 | +test_multiple_attestations if { |
| 112 | + policies.fromOrgWithSignerRepo(fixtures.multiple, ["octoorg"], ["octoorg/octorepo"]) |
| 113 | +} |
| 114 | + |
| 115 | +# Custom attestations should also work |
| 116 | +test_custom_attestation if { |
| 117 | + policies.customAttestation(fixtures.multiple, "value1") |
| 118 | +} |
0 commit comments