(t *testing.T)
| 215 | } |
| 216 | |
| 217 | func TestViewOauthCallback(t *testing.T) { |
| 218 | t.Run("success", func(t *testing.T) { |
| 219 | app := &MockOAuthDatastoreProvider{} |
| 220 | h := oauthHandler{ |
| 221 | Config: app.Config(), |
| 222 | DB: app.DB(), |
| 223 | Store: app.SessionStore(), |
| 224 | EmailKey: []byte{0xd, 0xe, 0xc, 0xa, 0xf, 0xf, 0xb, 0xa, 0xd}, |
| 225 | oauthClient: writeAsOauthClient{ |
| 226 | ClientID: app.Config().WriteAsOauth.ClientID, |
| 227 | ClientSecret: app.Config().WriteAsOauth.ClientSecret, |
| 228 | ExchangeLocation: app.Config().WriteAsOauth.TokenLocation, |
| 229 | InspectLocation: app.Config().WriteAsOauth.InspectLocation, |
| 230 | AuthLocation: app.Config().WriteAsOauth.AuthLocation, |
| 231 | CallbackLocation: "http://localhost/oauth/callback", |
| 232 | HttpClient: &MockHTTPClient{ |
| 233 | DoDo: func(req *http.Request) (*http.Response, error) { |
| 234 | switch req.URL.String() { |
| 235 | case "https://write.as/oauth/token": |
| 236 | return &http.Response{ |
| 237 | StatusCode: 200, |
| 238 | Body: &StringReadCloser{strings.NewReader(`{"access_token": "access_token", "expires_in": 1000, "refresh_token": "refresh_token", "token_type": "access"}`)}, |
| 239 | }, nil |
| 240 | case "https://write.as/oauth/inspect": |
| 241 | return &http.Response{ |
| 242 | StatusCode: 200, |
| 243 | Body: &StringReadCloser{strings.NewReader(`{"client_id": "development", "user_id": "1", "expires_at": "2019-12-19T11:42:01Z", "username": "nick", "email": "nick@testing.write.as"}`)}, |
| 244 | }, nil |
| 245 | } |
| 246 | |
| 247 | return &http.Response{ |
| 248 | StatusCode: http.StatusNotFound, |
| 249 | }, nil |
| 250 | }, |
| 251 | }, |
| 252 | }, |
| 253 | } |
| 254 | req, err := http.NewRequest("GET", "/oauth/callback", nil) |
| 255 | assert.NoError(t, err) |
| 256 | rr := httptest.NewRecorder() |
| 257 | err = h.viewOauthCallback(&App{cfg: app.Config(), sessionStore: app.SessionStore()}, rr, req) |
| 258 | assert.NoError(t, err) |
| 259 | assert.Equal(t, http.StatusTemporaryRedirect, rr.Code) |
| 260 | }) |
| 261 | } |
nothing calls this directly
no test coverage detected