MCPcopy Create free account
hub / github.com/brimdata/super / TestClientRedirectReplay

Function TestClientRedirectReplay

api/client/connection_test.go:20–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func 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}

Callers

nothing calls this directly

Calls 15

WriteMethod · 0.95
CloseMethod · 0.95
BytesMethod · 0.95
SetTokensMethod · 0.95
NewSerializerFunction · 0.92
NewStoreFunction · 0.92
NewConnectionToFunction · 0.85
WriteHeaderMethod · 0.80
ReadAllMethod · 0.80
SetAuthStoreMethod · 0.80
ContextMethod · 0.80
NewMethod · 0.80

Tested by

no test coverage detected