(t *testing.T)
| 80 | } |
| 81 | |
| 82 | func TestPolicyScopeMatches(t *testing.T) { |
| 83 | testCases := []struct { |
| 84 | name string |
| 85 | scope string |
| 86 | pname string // policy metadata name |
| 87 | ref string // attachment raw ref |
| 88 | want bool |
| 89 | }{ |
| 90 | { |
| 91 | name: "exact metadata name", |
| 92 | scope: "trusted-binaries-signed", |
| 93 | pname: "trusted-binaries-signed", |
| 94 | ref: "chainloop://trusted-binaries-signed@sha256:abc", |
| 95 | want: true, |
| 96 | }, |
| 97 | { |
| 98 | name: "exact raw ref", |
| 99 | scope: "chainloop://trusted-binaries-signed@sha256:abc", |
| 100 | pname: "", |
| 101 | ref: "chainloop://trusted-binaries-signed@sha256:abc", |
| 102 | want: true, |
| 103 | }, |
| 104 | { |
| 105 | name: "bare name matches versioned ref when unversioned", |
| 106 | scope: "trusted-binaries-signed", |
| 107 | pname: "", |
| 108 | ref: "chainloop://trusted-binaries-signed@sha256:abc", |
| 109 | want: true, |
| 110 | }, |
| 111 | { |
| 112 | name: "bare name matches plain ref", |
| 113 | scope: "trusted-binaries-signed", |
| 114 | pname: "", |
| 115 | ref: "trusted-binaries-signed", |
| 116 | want: true, |
| 117 | }, |
| 118 | { |
| 119 | name: "org-scoped scope matches org-scoped ref", |
| 120 | scope: "myorg/trusted-binaries-signed", |
| 121 | pname: "trusted-binaries-signed", |
| 122 | ref: "chainloop://myorg/trusted-binaries-signed", |
| 123 | want: true, |
| 124 | }, |
| 125 | { |
| 126 | name: "pinned digest matches same digest", |
| 127 | scope: "trusted-binaries-signed@sha256:abc", |
| 128 | pname: "trusted-binaries-signed", |
| 129 | ref: "chainloop://trusted-binaries-signed@sha256:abc", |
| 130 | want: true, |
| 131 | }, |
| 132 | { |
| 133 | name: "pinned digest does not match different digest", |
| 134 | scope: "trusted-binaries-signed@sha256:abc", |
| 135 | pname: "trusted-binaries-signed", |
| 136 | ref: "chainloop://trusted-binaries-signed@sha256:xyz", |
| 137 | want: false, |
| 138 | }, |
| 139 | { |
nothing calls this directly
no test coverage detected