MCPcopy
hub / github.com/cli/cli / Test_HasMinimumScopes

Function Test_HasMinimumScopes

pkg/cmd/auth/shared/oauth_scopes_test.go:13–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func Test_HasMinimumScopes(t *testing.T) {
14 tests := []struct {
15 name string
16 header string
17 wantErr string
18 }{
19 {
20 name: "write:org satisfies read:org",
21 header: "repo, write:org",
22 wantErr: "",
23 },
24 {
25 name: "insufficient scope",
26 header: "repo",
27 wantErr: "missing required scope 'read:org'",
28 },
29 }
30 for _, tt := range tests {
31 t.Run(tt.name, func(t *testing.T) {
32 fakehttp := &httpmock.Registry{}
33 defer fakehttp.Verify(t)
34
35 var gotAuthorization string
36 fakehttp.Register(httpmock.REST("GET", ""), func(req *http.Request) (*http.Response, error) {
37 gotAuthorization = req.Header.Get("authorization")
38 return &http.Response{
39 Request: req,
40 StatusCode: 200,
41 Body: io.NopCloser(&bytes.Buffer{}),
42 Header: map[string][]string{
43 "X-Oauth-Scopes": {tt.header},
44 },
45 }, nil
46 })
47
48 client := http.Client{Transport: fakehttp}
49 err := HasMinimumScopes(&client, "github.com", "ATOKEN")
50 if tt.wantErr != "" {
51 assert.EqualError(t, err, tt.wantErr)
52 } else {
53 assert.NoError(t, err)
54 }
55 assert.Equal(t, gotAuthorization, "token ATOKEN")
56 })
57 }
58}
59
60func Test_HeaderHasMinimumScopes(t *testing.T) {
61 tests := []struct {

Callers

nothing calls this directly

Calls 7

VerifyMethod · 0.95
RegisterMethod · 0.95
RESTFunction · 0.92
HasMinimumScopesFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected