(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func TestClientRedirectReplay(t *testing.T) { |
| 21 | const expected = "hello world" |
| 22 | mux := http.NewServeMux() |
| 23 | ts := httptest.NewServer(mux) |
| 24 | mux.HandleFunc("/auth/method", func(w http.ResponseWriter, r *http.Request) { |
| 25 | s := bsupbytes.NewSerializer() |
| 26 | s.Write(api.AuthMethodResponse{ |
| 27 | Kind: api.AuthMethodAuth0, |
| 28 | Auth0: &api.AuthMethodAuth0Details{ |
| 29 | Domain: ts.URL, |
| 30 | }, |
| 31 | }) |
| 32 | s.Close() |
| 33 | w.Write(s.Bytes()) |
| 34 | }) |
| 35 | mux.HandleFunc("/oauth/token", func(w http.ResponseWriter, r *http.Request) { |
| 36 | json.NewEncoder(w).Encode(struct { |
| 37 | AccessToken string `json:"access_token"` |
| 38 | }{"12345"}) |
| 39 | }) |
| 40 | var requests int |
| 41 | var body string |
| 42 | mux.HandleFunc("/pool/", func(w http.ResponseWriter, r *http.Request) { |
| 43 | if requests == 0 { |
| 44 | requests++ |
| 45 | w.WriteHeader(401) |
| 46 | io.WriteString(w, "invalid token") |
| 47 | return |
| 48 | } |
| 49 | b, err := io.ReadAll(r.Body) |
| 50 | require.NoError(t, err) |
| 51 | body = string(b) |
| 52 | }) |
| 53 | conn := NewConnectionTo(ts.URL) |
| 54 | store := auth0.NewStore(filepath.Join(t.TempDir(), "credentials.json")) |
| 55 | store.SetTokens(ts.URL, auth0.Tokens{ |
| 56 | Access: "012345", |
| 57 | Refresh: "98765", |
| 58 | }) |
| 59 | conn.SetAuthStore(store) |
| 60 | _, err := conn.Load(t.Context(), ksuid.New(), "main", "", strings.NewReader(expected), api.CommitMessage{}) |
| 61 | require.NoError(t, err) |
| 62 | assert.Equal(t, expected, body) |
| 63 | } |
nothing calls this directly
no test coverage detected