MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestCustomHeadersAreSentOnLoginRequest

Function TestCustomHeadersAreSentOnLoginRequest

action/command/api_test.go:97–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

95}
96
97func TestCustomHeadersAreSentOnLoginRequest(t *testing.T) {
98 t.Parallel()
99
100 customHeaders := http.Header{}
101 customHeaders.Set("Cookie", "CF_Authorization=token")
102 customHeaders.Set("X-Request-Id", "run-123")
103
104 transport := roundTripFunc(func(req *http.Request) (*http.Response, error) {
105 require.Equal(t, "CF_Authorization=token", req.Header.Get("Cookie"))
106 require.Equal(t, "run-123", req.Header.Get("X-Request-Id"))
107 return &http.Response{
108 StatusCode: http.StatusUnauthorized,
109 Header: make(http.Header),
110 Body: io.NopCloser(strings.NewReader("unauthorized")),
111 Request: req,
112 }, nil
113 })
114
115 httpClient := &http.Client{Transport: transport}
116 client, err := newClient("https://example.com", "", "sa@example.com", "secret", clientOptions{
117 httpClient: httpClient,
118 customHeaders: customHeaders,
119 })
120 require.NoError(t, err)
121 t.Cleanup(client.close)
122 refreshToken := getTokenRefresher(client.httpClient, "sa@example.com", "secret", "https://example.com")
123
124 _, err = refreshToken(t.Context())
125 require.Error(t, err)
126}
127
128func TestNewClientDoesNotMutateProvidedHTTPClientTransport(t *testing.T) {
129 t.Parallel()

Callers

nothing calls this directly

Calls 7

roundTripFuncFuncType · 0.85
getTokenRefresherFunction · 0.85
GetMethod · 0.80
newClientFunction · 0.70
EqualMethod · 0.65
SetMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected