@@ -17,11 +17,13 @@ import (
1717 "github.com/steveiliop56/tinyauth/internal/controller"
1818 "github.com/steveiliop56/tinyauth/internal/repository"
1919 "github.com/steveiliop56/tinyauth/internal/service"
20+ "github.com/steveiliop56/tinyauth/internal/utils/tlog"
2021 "github.com/stretchr/testify/assert"
2122 "github.com/stretchr/testify/require"
2223)
2324
2425func TestOIDCController (t * testing.T ) {
26+ tlog .NewTestLogger ().Init ()
2527 tempDir := t .TempDir ()
2628
2729 oidcServiceCfg := service.OIDCServiceConfig {
@@ -473,6 +475,7 @@ func TestOIDCController(t *testing.T) {
473475 assert .NotEmpty (t , code )
474476
475477 // Now exchange the code for a token
478+ recorder = httptest .NewRecorder ()
476479 tokenReqBody := controller.TokenRequest {
477480 GrantType : "authorization_code" ,
478481 Code : code ,
@@ -499,7 +502,7 @@ func TestOIDCController(t *testing.T) {
499502 hasher := sha256 .New ()
500503 hasher .Write ([]byte ("some-challenge" ))
501504 codeChallenge := hasher .Sum (nil )
502- codeChallengeEncoded := base64 .URLEncoding .EncodeToString (codeChallenge )
505+ codeChallengeEncoded := base64 .RawURLEncoding .EncodeToString (codeChallenge )
503506 reqBody := service.AuthorizeRequest {
504507 Scope : "openid" ,
505508 ResponseType : "code" ,
@@ -533,6 +536,7 @@ func TestOIDCController(t *testing.T) {
533536 assert .NotEmpty (t , code )
534537
535538 // Now exchange the code for a token
539+ recorder = httptest .NewRecorder ()
536540 tokenReqBody := controller.TokenRequest {
537541 GrantType : "authorization_code" ,
538542 Code : code ,
@@ -559,7 +563,7 @@ func TestOIDCController(t *testing.T) {
559563 hasher := sha256 .New ()
560564 hasher .Write ([]byte ("some-challenge" ))
561565 codeChallenge := hasher .Sum (nil )
562- codeChallengeEncoded := base64 .URLEncoding .EncodeToString (codeChallenge )
566+ codeChallengeEncoded := base64 .RawURLEncoding .EncodeToString (codeChallenge )
563567 reqBody := service.AuthorizeRequest {
564568 Scope : "openid" ,
565569 ResponseType : "code" ,
@@ -593,6 +597,7 @@ func TestOIDCController(t *testing.T) {
593597 assert .NotEmpty (t , code )
594598
595599 // Now exchange the code for a token
600+ recorder = httptest .NewRecorder ()
596601 tokenReqBody := controller.TokenRequest {
597602 GrantType : "authorization_code" ,
598603 Code : code ,
@@ -607,7 +612,7 @@ func TestOIDCController(t *testing.T) {
607612 req .SetBasicAuth ("some-client-id" , "some-client-secret" )
608613 router .ServeHTTP (recorder , req )
609614
610- assert .Equal (t , 200 , recorder .Code )
615+ assert .Equal (t , 400 , recorder .Code )
611616 },
612617 },
613618 }
0 commit comments