@@ -13,56 +13,60 @@ func TestValidateOCI_RegistryAllowlist(t *testing.T) {
1313 ctx := context .Background ()
1414
1515 tests := []struct {
16- name string
17- identifier string
18- expectError bool
19- errorMsg string
16+ name string
17+ identifier string
18+ expectError bool
19+ errorMsg string
20+ mustNotContainMsg string // Error message that must NOT appear (for allowed registries)
2021 }{
2122 // Allowed registries - use real public images that exist
22- // These should fail with "missing required annotation" (no MCP label )
23+ // These should fail with annotation-related errors (missing or mismatched )
2324 // NOT with "unsupported registry", "does not exist", or "is private" errors
2425 {
25- name : "Docker Hub should be allowed" ,
26- identifier : "docker.io/library/alpine:latest" ,
27- expectError : true ,
28- errorMsg : "missing required annotation" ,
26+ name : "Docker Hub should be allowed" ,
27+ identifier : "docker.io/library/alpine:latest" ,
28+ expectError : true ,
29+ errorMsg : "missing required annotation" ,
30+ mustNotContainMsg : "unsupported OCI registry" ,
2931 },
3032 {
31- name : "Docker Hub without explicit registry should default and be allowed" ,
32- identifier : "library/hello-world:latest" ,
33- expectError : true ,
34- errorMsg : "missing required annotation" ,
33+ name : "Docker Hub without explicit registry should default and be allowed" ,
34+ identifier : "library/hello-world:latest" ,
35+ expectError : true ,
36+ errorMsg : "missing required annotation" ,
37+ mustNotContainMsg : "unsupported OCI registry" ,
3538 },
3639 {
37- name : "GHCR should be allowed" ,
38- identifier : "ghcr.io/containerbase/base:latest" ,
39- expectError : true ,
40- errorMsg : "missing required annotation" ,
40+ name : "GHCR should be allowed" ,
41+ identifier : "ghcr.io/containerbase/base:latest" ,
42+ expectError : true ,
43+ errorMsg : "missing required annotation" ,
44+ mustNotContainMsg : "unsupported OCI registry" ,
4145 },
4246 {
4347 name : "Artifact Registry regional should be allowed" ,
4448 identifier : "us-central1-docker.pkg.dev/database-toolbox/toolbox/toolbox:latest" ,
4549 expectError : true ,
46- errorMsg : "missing required annotation" ,
47- },
48- {
49- name : "Artifact Registry multi-region should be allowed" ,
50- identifier : "us-docker.pkg.dev/berglas/berglas/berglas:latest" ,
51- expectError : true ,
52- errorMsg : "missing required annotation" ,
50+ // This image has an MCP annotation but with a different server name,
51+ // so we get "ownership validation failed" instead of "missing required annotation"
52+ // Both are acceptable - what matters is the registry is allowed
53+ mustNotContainMsg : "unsupported OCI registry" ,
5354 },
5455 {
55- name : "MCR should be allowed" ,
56- identifier : "mcr.microsoft.com/dotnet/aspire-dashboard:9.5.0" ,
57- expectError : true ,
58- errorMsg : "missing required annotation" ,
56+ name : "Artifact Registry multi-region should be allowed" ,
57+ identifier : "us-docker.pkg.dev/berglas/berglas/berglas:latest" ,
58+ expectError : true ,
59+ errorMsg : "missing required annotation" ,
60+ mustNotContainMsg : "unsupported OCI registry" ,
5961 },
6062 {
61- name : "ACR should be allowed" ,
62- identifier : "azurearcjumpstart.azurecr.io/hello-arc:latest" ,
63- expectError : true ,
64- errorMsg : "missing required annotation" ,
63+ name : "MCR should be allowed" ,
64+ identifier : "mcr.microsoft.com/dotnet/aspire-dashboard:9.5.0" ,
65+ expectError : true ,
66+ errorMsg : "missing required annotation" ,
67+ mustNotContainMsg : "unsupported OCI registry" ,
6568 },
69+ // Removed ACR test with non-existent host - ACR support is tested elsewhere
6670
6771 // Disallowed registries
6872 {
@@ -114,15 +118,75 @@ func TestValidateOCI_RegistryAllowlist(t *testing.T) {
114118
115119 if tt .expectError {
116120 assert .Error (t , err )
117- // Should contain the specific error message
118- assert .Contains (t , err .Error (), tt .errorMsg )
121+ // For allowed registries, verify they don't get rejected at the registry check
122+ if tt .mustNotContainMsg != "" {
123+ assert .NotContains (t , err .Error (), tt .mustNotContainMsg )
124+ }
125+ // If a specific error message is expected, check for it
126+ if tt .errorMsg != "" {
127+ assert .Contains (t , err .Error (), tt .errorMsg )
128+ }
119129 } else {
120130 assert .NoError (t , err )
121131 }
122132 })
123133 }
124134}
125135
136+ func TestValidateOCI_RegistryPatterns (t * testing.T ) {
137+ // This test verifies registry pattern matching (wildcards like *.azurecr.io and *.pkg.dev)
138+ // without relying on external images that may not exist
139+ tests := []struct {
140+ name string
141+ identifier string
142+ shouldFail bool // true if should fail at registry allowlist check
143+ }{
144+ {
145+ name : "ACR registry pattern should be allowed" ,
146+ identifier : "myregistry.azurecr.io/test/image:latest" ,
147+ shouldFail : false , // Registry is allowed, will fail later on missing annotation
148+ },
149+ {
150+ name : "Another ACR registry should be allowed" ,
151+ identifier : "contoso.azurecr.io/app:v1" ,
152+ shouldFail : false ,
153+ },
154+ {
155+ name : "Artifact Registry should be allowed" ,
156+ identifier : "us-west1-docker.pkg.dev/project/repo/image:tag" ,
157+ shouldFail : false ,
158+ },
159+ {
160+ name : "GCR should be rejected at registry check" ,
161+ identifier : "gcr.io/project/image:latest" ,
162+ shouldFail : true , // Should fail at registry allowlist check
163+ },
164+ }
165+
166+ for _ , tt := range tests {
167+ t .Run (tt .name , func (t * testing.T ) {
168+ pkg := model.Package {
169+ RegistryType : model .RegistryTypeOCI ,
170+ Identifier : tt .identifier ,
171+ }
172+
173+ ctx := context .Background ()
174+ err := registries .ValidateOCI (ctx , pkg , "com.example/test" )
175+
176+ // All test cases should error (either at registry check or annotation check)
177+ assert .Error (t , err )
178+
179+ if tt .shouldFail {
180+ // Should fail at the registry allowlist check
181+ assert .Contains (t , err .Error (), "unsupported OCI registry" )
182+ } else {
183+ // Should NOT fail at registry check (allowed registry)
184+ assert .NotContains (t , err .Error (), "unsupported OCI registry" )
185+ }
186+ })
187+ }
188+ }
189+
126190func TestValidateOCI_RejectsOldFormat (t * testing.T ) {
127191 ctx := context .Background ()
128192
0 commit comments