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

Function TestIsNotAuthenticated

session/handler_test.go:381–435  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

379}
380
381func TestIsNotAuthenticated(t *testing.T) {
382 t.Parallel()
383
384 ctx := context.Background()
385 conf, reg := pkg.NewFastRegistryWithMocks(t)
386 r := httprouterx.NewTestRouterPublic(t)
387
388 reg.WithCSRFHandler(new(nosurfx.FakeCSRFHandler))
389 h, _ := testhelpers.MockSessionCreateHandler(t, reg)
390 r.GET("/set", h)
391 r.GET("/public/with-callback", reg.SessionHandler().IsNotAuthenticated(send(http.StatusOK), send(http.StatusBadRequest)))
392 r.GET("/public/without-callback", reg.SessionHandler().IsNotAuthenticated(send(http.StatusOK), nil))
393 ts := httptest.NewServer(r)
394 defer ts.Close()
395
396 conf.MustSet(ctx, config.ViperKeyPublicBaseURL, ts.URL)
397
398 sessionClient := testhelpers.NewClientWithCookies(t)
399 testhelpers.MockHydrateCookieClient(t, sessionClient, ts.URL+"/set")
400
401 for k, tc := range []struct {
402 c *http.Client
403 call string
404 code int
405 }{
406 {
407 c: sessionClient,
408 call: "/public/with-callback",
409 code: http.StatusBadRequest,
410 },
411 {
412 c: http.DefaultClient,
413 call: "/public/with-callback",
414 code: http.StatusOK,
415 },
416
417 {
418 c: sessionClient,
419 call: "/public/without-callback",
420 code: http.StatusForbidden,
421 },
422 {
423 c: http.DefaultClient,
424 call: "/public/without-callback",
425 code: http.StatusOK,
426 },
427 } {
428 t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
429 res, err := tc.c.Get(ts.URL + tc.call)
430 require.NoError(t, err)
431
432 assert.EqualValues(t, tc.code, res.StatusCode)
433 })
434 }
435}
436
437func TestIsAuthenticated(t *testing.T) {
438 t.Parallel()

Callers

nothing calls this directly

Calls 13

NewFastRegistryWithMocksFunction · 0.92
MockSessionCreateHandlerFunction · 0.92
NewClientWithCookiesFunction · 0.92
MockHydrateCookieClientFunction · 0.92
sendFunction · 0.85
IsNotAuthenticatedMethod · 0.80
MustSetMethod · 0.80
WithCSRFHandlerMethod · 0.65
GETMethod · 0.65
SessionHandlerMethod · 0.65
CloseMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected