MCPcopy Create free account
hub / github.com/clouditor/clouditor / Test_oauthAuthorizer_Token

Function Test_oauthAuthorizer_Token

api/authorizer_test.go:42–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40)
41
42func Test_oauthAuthorizer_Token(t *testing.T) {
43 var (
44 srv *oauth2.AuthorizationServer
45 port uint16
46 err error
47 )
48 srv, port, err = testutil.StartAuthenticationServer()
49
50 defer func() {
51 err = srv.Close()
52 if err != http.ErrServerClosed {
53 assert.NoError(t, err)
54 }
55 }()
56
57 type fields struct {
58 TokenSource oauth2.TokenSource
59 }
60 type args struct {
61 }
62 tests := []struct {
63 name string
64 fields fields
65 args args
66 wantToken assert.Want[*oauth2.Token]
67 wantErr assert.WantErr
68 }{
69 {
70 name: "fetch token without refresh token",
71 fields: fields{
72 TokenSource: oauth2.ReuseTokenSource(nil,
73 (&clientcredentials.Config{
74 ClientID: testdata.MockAuthClientID,
75 ClientSecret: testdata.MockAuthClientSecret,
76 TokenURL: fmt.Sprintf("http://localhost:%d/v1/auth/token", port),
77 }).TokenSource(context.Background()),
78 ),
79 },
80 wantToken: func(t *testing.T, token *oauth2.Token) bool {
81 return assert.NotNil(t, token) && assert.NotEmpty(t, token.AccessToken)
82 },
83 wantErr: assert.Nil[error],
84 },
85 }
86
87 for _, tt := range tests {
88 t.Run(tt.name, func(t *testing.T) {
89 o := &oauthAuthorizer{
90 TokenSource: tt.fields.TokenSource,
91 }
92
93 gotToken, err := o.Token()
94
95 tt.wantErr(t, err)
96 tt.wantToken(t, gotToken)
97 })
98 }
99}

Callers

nothing calls this directly

Calls 2

NotNilFunction · 0.92

Tested by

no test coverage detected