(t *testing.T)
| 119 | } |
| 120 | |
| 121 | func 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 | |
| 157 | func TestOAuthFlowUsesRefreshToken(t *testing.T) { |
| 158 | identityServerFake := identityServerFake{ |
nothing calls this directly
no test coverage detected