MCPcopy
hub / github.com/ory/kratos / NewHTTPClientWithArbitrarySessionCookie

Function NewHTTPClientWithArbitrarySessionCookie

pkg/testhelpers/session.go:155–170  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T, reg *driver.RegistryDefault)

Source from the content-addressed store, hash-verified

153}
154
155func NewHTTPClientWithArbitrarySessionCookie(ctx context.Context, t *testing.T, reg *driver.RegistryDefault) *http.Client {
156 req := NewTestHTTPRequest(t, "GET", "/sessions/whoami", nil)
157 req = req.WithContext(contextx.WithConfigValue(ctx, "session.lifespan", time.Hour))
158 id := x.NewUUID()
159 s, err := NewActiveSession(req, reg,
160 &identity.Identity{ID: id, State: identity.StateActive, Traits: []byte("{}"), Credentials: map[identity.CredentialsType]identity.Credentials{
161 identity.CredentialsTypePassword: {Type: "password", Identifiers: []string{id.String()}, Config: []byte(`{"hashed_password":"$2a$04$zvZz1zV"}`)},
162 }},
163 time.Now(),
164 identity.CredentialsTypePassword,
165 identity.AuthenticatorAssuranceLevel1,
166 )
167 require.NoError(t, err, "Could not initialize session from identity.")
168
169 return NewHTTPClientWithSessionCookie(ctx, t, reg, s)
170}
171
172func NewNoRedirectHTTPClientWithArbitrarySessionCookie(ctx context.Context, t *testing.T, reg *driver.RegistryDefault) *http.Client {
173 req := NewTestHTTPRequest(t, "GET", "/sessions/whoami", nil)

Callers 4

AssertCommonErrorCasesFunction · 0.92
TestHandlerFunction · 0.92
TestDisabledEndpointFunction · 0.92
TestDisabledEndpointFunction · 0.92

Calls 7

NewUUIDFunction · 0.92
NewTestHTTPRequestFunction · 0.85
NewActiveSessionFunction · 0.85
WithContextMethod · 0.80
StringMethod · 0.65
NowMethod · 0.65

Tested by 3

TestHandlerFunction · 0.74
TestDisabledEndpointFunction · 0.74
TestDisabledEndpointFunction · 0.74