@@ -5,15 +5,14 @@ import (
5
5
"net/http"
6
6
"net/http/httptest"
7
7
"net/url"
8
- "strings"
9
8
"testing"
10
9
11
10
"cuelabs.dev/go/oci/ociregistry"
12
11
"cuelabs.dev/go/oci/ociregistry/ociauth"
13
12
"cuelabs.dev/go/oci/ociregistry/ocimem"
14
13
"cuelabs.dev/go/oci/ociregistry/ociserver"
14
+ "cuelabs.dev/go/oci/ociregistry/ocitest"
15
15
"github.com/go-quicktest/qt"
16
- "github.com/opencontainers/go-digest"
17
16
)
18
17
19
18
func TestAuthScopes (t * testing.T ) {
@@ -26,74 +25,35 @@ func TestAuthScopes(t *testing.T) {
26
25
defer srv .Close ()
27
26
srvURL , _ := url .Parse (srv .URL )
28
27
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" ,
31
47
}
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
97
57
})
98
58
}
99
59
0 commit comments