MCPcopy Create free account
hub / github.com/UiPath/uipathcli / TestOAuthFlowIsCached

Function TestOAuthFlowIsCached

auth/oauth_authenticator_test.go:121–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

119}
120
121func TestOAuthFlowIsCached(t *testing.T) {
122 calls := 0
123 identityServerFake := identityServerFake{
124 ResponseHandler: func(data map[string]string) (int, string) {
125 calls++
126 if calls > 1 {
127 return http.StatusInternalServerError, "There was an error"
128 }
129 body := `{"access_token": "my-access-token", "expires_in": 3600, "token_type": "Bearer", "scope": "OR.Users"}`
130 return http.StatusOK, body
131 },
132 }
133 identityBaseUrl := identityServerFake.Start(t, false)
134
135 context := createNonConfidentialAuthContext(identityBaseUrl)
136 loginUrl, resultChannel := callAuthenticator(context)
137 performLogin(loginUrl, t)
138 <-resultChannel
139
140 authenticator := NewOAuthAuthenticator(cache.NewFileCache(), *NewBrowserLauncher())
141 result := authenticator.Auth(context)
142
143 if result.Error != "" {
144 t.Errorf("Expected no error when performing oauth flow, but got: %v", result.Error)
145 }
146 if result.Token.Type != "Bearer" {
147 t.Errorf("Expected JWT bearer token, but got: %v", result.Token.Type)
148 }
149 if result.Token.Value != "my-access-token" {
150 t.Errorf("Expected value for JWT bearer token, but got: %v", result.Token.Value)
151 }
152 if calls != 1 {
153 t.Errorf("Expected only one call to identity server, but got: %d", calls)
154 }
155}
156
157func TestOAuthFlowUsesRefreshToken(t *testing.T) {
158 identityServerFake := identityServerFake{

Callers

nothing calls this directly

Calls 8

StartMethod · 0.95
AuthMethod · 0.95
NewFileCacheFunction · 0.92
callAuthenticatorFunction · 0.85
performLoginFunction · 0.85
NewOAuthAuthenticatorFunction · 0.85
NewBrowserLauncherFunction · 0.85

Tested by

no test coverage detected