@@ -5,15 +5,14 @@ import (
55 "net/http"
66 "net/http/httptest"
77 "net/url"
8- "strings"
98 "testing"
109
1110 "cuelabs.dev/go/oci/ociregistry"
1211 "cuelabs.dev/go/oci/ociregistry/ociauth"
1312 "cuelabs.dev/go/oci/ociregistry/ocimem"
1413 "cuelabs.dev/go/oci/ociregistry/ociserver"
14+ "cuelabs.dev/go/oci/ociregistry/ocitest"
1515 "github.com/go-quicktest/qt"
16- "github.com/opencontainers/go-digest"
1716)
1817
1918func TestAuthScopes (t * testing.T ) {
@@ -26,74 +25,35 @@ func TestAuthScopes(t *testing.T) {
2625 defer srv .Close ()
2726 srvURL , _ := url .Parse (srv .URL )
2827
29- assertScope := func (scope string , f func (ctx context.Context , r ociregistry.Interface )) {
30- assertAuthScope (t , srvURL .Host , scope , f )
28+ wantScopes := map [ocitest.Method ]string {
29+ ocitest .GetBlob : "repository:foo/read:pull" ,
30+ ocitest .GetBlobRange : "repository:foo/read:pull" ,
31+ ocitest .GetManifest : "repository:foo/read:pull" ,
32+ ocitest .GetTag : "repository:foo/read:pull" ,
33+ ocitest .ResolveBlob : "repository:foo/read:pull" ,
34+ ocitest .ResolveManifest : "repository:foo/read:pull" ,
35+ ocitest .ResolveTag : "repository:foo/read:pull" ,
36+ ocitest .PushBlob : "repository:foo/write:push" ,
37+ ocitest .PushBlobChunked : "repository:foo/write:push" ,
38+ ocitest .PushBlobChunkedResume : "repository:foo/write:push" ,
39+ ocitest .MountBlob : "repository:foo/read:pull repository:foo/write:push" ,
40+ ocitest .PushManifest : "repository:foo/write:push" ,
41+ ocitest .DeleteBlob : "repository:foo/write:push" ,
42+ ocitest .DeleteManifest : "repository:foo/write:push" ,
43+ ocitest .DeleteTag : "repository:foo/write:push" ,
44+ ocitest .Repositories : "registry:catalog:*" ,
45+ ocitest .Tags : "repository:foo/read:pull" ,
46+ ocitest .Referrers : "repository:foo/read:pull" ,
3147 }
32-
33- assertScope ("repository:foo/bar:pull" , func (ctx context.Context , r ociregistry.Interface ) {
34- r .GetBlob (ctx , "foo/bar" , "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" )
35- })
36- assertScope ("repository:foo/bar:pull" , func (ctx context.Context , r ociregistry.Interface ) {
37- r .GetBlobRange (ctx , "foo/bar" , "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" , 100 , 200 )
38- })
39- assertScope ("repository:foo/bar:pull" , func (ctx context.Context , r ociregistry.Interface ) {
40- r .GetManifest (ctx , "foo/bar" , "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" )
41- })
42- assertScope ("repository:foo/bar:pull" , func (ctx context.Context , r ociregistry.Interface ) {
43- r .GetTag (ctx , "foo/bar" , "sometag" )
44- })
45- assertScope ("repository:foo/bar:pull" , func (ctx context.Context , r ociregistry.Interface ) {
46- r .ResolveBlob (ctx , "foo/bar" , "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" )
47- })
48- assertScope ("repository:foo/bar:pull" , func (ctx context.Context , r ociregistry.Interface ) {
49- r .ResolveManifest (ctx , "foo/bar" , "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" )
50- })
51- assertScope ("repository:foo/bar:pull" , func (ctx context.Context , r ociregistry.Interface ) {
52- r .ResolveTag (ctx , "foo/bar" , "sometag" )
53- })
54- assertScope ("repository:foo/bar:push" , func (ctx context.Context , r ociregistry.Interface ) {
55- r .PushBlob (ctx , "foo/bar" , ociregistry.Descriptor {
56- MediaType : "application/json" ,
57- Digest : "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ,
58- Size : 3 ,
59- }, strings .NewReader ("foo" ))
60- })
61- assertScope ("repository:foo/bar:push" , func (ctx context.Context , r ociregistry.Interface ) {
62- w , err := r .PushBlobChunked (ctx , "foo/bar" , 0 )
63- qt .Assert (t , qt .IsNil (err ))
64- w .Write ([]byte ("foo" ))
65- w .Close ()
66-
67- id := w .ID ()
68- w , err = r .PushBlobChunkedResume (ctx , "foo/bar" , id , 3 , 0 )
69- qt .Assert (t , qt .IsNil (err ))
70- w .Write ([]byte ("bar" ))
71- _ , err = w .Commit (digest .FromString ("foobar" ))
72- qt .Assert (t , qt .IsNil (err ))
73- })
74- assertScope ("repository:x/y:pull repository:z/w:push" , func (ctx context.Context , r ociregistry.Interface ) {
75- r .MountBlob (ctx , "x/y" , "z/w" , "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" )
76- })
77- assertScope ("repository:foo/bar:push" , func (ctx context.Context , r ociregistry.Interface ) {
78- r .PushManifest (ctx , "foo/bar" , "sometag" , []byte ("something" ), "application/json" )
79- })
80- assertScope ("repository:foo/bar:push" , func (ctx context.Context , r ociregistry.Interface ) {
81- r .DeleteBlob (ctx , "foo/bar" , "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" )
82- })
83- assertScope ("repository:foo/bar:push" , func (ctx context.Context , r ociregistry.Interface ) {
84- r .DeleteManifest (ctx , "foo/bar" , "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" )
85- })
86- assertScope ("repository:foo/bar:push" , func (ctx context.Context , r ociregistry.Interface ) {
87- r .DeleteTag (ctx , "foo/bar" , "sometag" )
88- })
89- assertScope ("registry:catalog:*" , func (ctx context.Context , r ociregistry.Interface ) {
90- ociregistry .All (r .Repositories (ctx , "" ))
91- })
92- assertScope ("repository:foo/bar:pull" , func (ctx context.Context , r ociregistry.Interface ) {
93- ociregistry .All (r .Tags (ctx , "foo/bar" , "" ))
94- })
95- assertScope ("repository:foo/bar:pull" , func (ctx context.Context , r ociregistry.Interface ) {
96- ociregistry .All (r .Referrers (ctx , "foo/bar" , "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" , "" ))
48+ // TODO(go1.23) for method, call := range ocitest.MethodCalls() {
49+ ocitest .MethodCalls ()(func (method ocitest.Method , call ocitest.MethodCall ) bool {
50+ t .Run (method .String (), func (t * testing.T ) {
51+ assertAuthScope (t , srvURL .Host , wantScopes [method ], func (ctx context.Context , r ociregistry.Interface ) {
52+ err := call (ctx , r )
53+ t .Logf ("call error: %v" , err )
54+ })
55+ })
56+ return true
9757 })
9858}
9959
0 commit comments