@@ -957,6 +957,42 @@ func TestTokenFromCookieConfigured(t *testing.T) {
957957 }
958958}
959959
960+ func TestTokenFromCookieConfiguredButNotSet (t * testing.T ) {
961+ cfg := * CreateConfig ()
962+ cfg .JwtCookieKey = "jwt"
963+ ctx := context .Background ()
964+ nextCalled := false
965+ next := http .HandlerFunc (func (rw http.ResponseWriter , req * http.Request ) { nextCalled = true })
966+
967+ jwt , err := New (ctx , next , & cfg , "test-traefik-jwt-plugin" )
968+ if err != nil {
969+ t .Fatal (err )
970+ }
971+
972+ recorder := httptest .NewRecorder ()
973+
974+ req , err := http .NewRequestWithContext (ctx , http .MethodGet , "http://localhost" , nil )
975+ if err != nil {
976+ t .Fatal (err )
977+ }
978+
979+ jwt .ServeHTTP (recorder , req )
980+
981+ resp := recorder .Result ()
982+ if resp .StatusCode != http .StatusForbidden {
983+ t .Fatalf ("Expected status code %d, received %d" , http .StatusForbidden , resp .StatusCode )
984+ }
985+ body , _ := io .ReadAll (resp .Body )
986+ responseBodyExpected := "http: named cookie not present"
987+ if strings .TrimSpace (string (body )) != responseBodyExpected {
988+ t .Fatalf ("The body response is expected to be %q, but found: %s" , responseBodyExpected , string (body ))
989+ }
990+
991+ if nextCalled == true {
992+ t .Fatal ("next.ServeHTTP was called, but should not" )
993+ }
994+ }
995+
960996func TestTokenFromCookieNotConfigured (t * testing.T ) {
961997 cfg := * CreateConfig ()
962998 ctx := context .Background ()
0 commit comments