@@ -615,6 +615,47 @@ func TestOIDCController(t *testing.T) {
615615 assert .Equal (t , 400 , recorder .Code )
616616 },
617617 },
618+ {
619+ description : "Ensure request with invalid challenge method fails" ,
620+ middlewares : []gin.HandlerFunc {
621+ simpleCtx ,
622+ },
623+ run : func (t * testing.T , router * gin.Engine , recorder * httptest.ResponseRecorder ) {
624+ hasher := sha256 .New ()
625+ hasher .Write ([]byte ("some-challenge" ))
626+ codeChallenge := hasher .Sum (nil )
627+ codeChallengeEncoded := base64 .RawURLEncoding .EncodeToString (codeChallenge )
628+ reqBody := service.AuthorizeRequest {
629+ Scope : "openid" ,
630+ ResponseType : "code" ,
631+ ClientID : "some-client-id" ,
632+ RedirectURI : "https://test.example.com/callback" ,
633+ State : "some-state" ,
634+ Nonce : "some-nonce" ,
635+ CodeChallenge : codeChallengeEncoded ,
636+ CodeChallengeMethod : "foo" ,
637+ }
638+ reqBodyBytes , err := json .Marshal (reqBody )
639+ assert .NoError (t , err )
640+
641+ req := httptest .NewRequest ("POST" , "/api/oidc/authorize" , strings .NewReader (string (reqBodyBytes )))
642+ req .Header .Set ("Content-Type" , "application/json" )
643+ router .ServeHTTP (recorder , req )
644+ assert .Equal (t , 200 , recorder .Code )
645+
646+ var res map [string ]any
647+ err = json .Unmarshal (recorder .Body .Bytes (), & res )
648+ assert .NoError (t , err )
649+
650+ redirectURI := res ["redirect_uri" ].(string )
651+ url , err := url .Parse (redirectURI )
652+ assert .NoError (t , err )
653+
654+ queryParams := url .Query ()
655+ code := queryParams .Get ("error" )
656+ assert .NotEmpty (t , code )
657+ },
658+ },
618659 }
619660
620661 app := bootstrap .NewBootstrapApp (config.Config {})
0 commit comments