From 5487aa424d14704302f1065ea5dec1080c58366b Mon Sep 17 00:00:00 2001 From: Martti Tamm Date: Thu, 15 Feb 2024 10:58:50 +0200 Subject: [PATCH] Fix auth_test.go, minor err-check in auth_oidc.go --- server/auth_oidc.go | 7 +++++++ tests/auth/auth_test.go | 16 ++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/server/auth_oidc.go b/server/auth_oidc.go index f90a306b..cd12fd30 100644 --- a/server/auth_oidc.go +++ b/server/auth_oidc.go @@ -159,6 +159,13 @@ func (c *OidcConfig) isJwtActive(token string) bool { c.remote.IntrospectionEndpoint, strings.NewReader(params)) + if err != nil { + fmt.Printf("[ERROR] Failed to create a new request for the OIDC "+ + "introspection endpoint (POST %s): %s\n", + c.remote.IntrospectionEndpoint, err) + return false + } + request.Header.Set("Content-Type", "application/x-www-form-urlencoded") if c.local.ClientId != "" && c.local.ClientSecret != "" { diff --git a/tests/auth/auth_test.go b/tests/auth/auth_test.go index 44ae3c1b..02c935ba 100644 --- a/tests/auth/auth_test.go +++ b/tests/auth/auth_test.go @@ -33,26 +33,26 @@ func TestBasicAuthFail(t *testing.T) { Id: "1", View: tes.TaskView_MINIMAL, }) - if err == nil || !strings.Contains(err.Error(), "STATUS CODE - 403") { + if err == nil || !strings.Contains(err.Error(), "STATUS CODE - 401") { t.Fatal("expected error") } _, err = fun.HTTP.ListTasks(ctx, &tes.ListTasksRequest{ View: tes.TaskView_MINIMAL, }) - if err == nil || !strings.Contains(err.Error(), "STATUS CODE - 403") { + if err == nil || !strings.Contains(err.Error(), "STATUS CODE - 401") { t.Fatal("expected error") } _, err = fun.HTTP.CreateTask(ctx, extask) - if err == nil || !strings.Contains(err.Error(), "STATUS CODE - 403") { + if err == nil || !strings.Contains(err.Error(), "STATUS CODE - 401") { t.Fatal("expected error") } _, err = fun.HTTP.CancelTask(ctx, &tes.CancelTaskRequest{ Id: "1", }) - if err == nil || !strings.Contains(err.Error(), "STATUS CODE - 403") { + if err == nil || !strings.Contains(err.Error(), "STATUS CODE - 401") { t.Fatal("expected error") } @@ -61,26 +61,26 @@ func TestBasicAuthFail(t *testing.T) { Id: "1", View: tes.TaskView_MINIMAL, }) - if err == nil || !strings.Contains(err.Error(), "PermissionDenied") { + if err == nil || !strings.Contains(err.Error(), "Unauthenticated") { t.Fatal("expected error") } _, err = fun.RPC.ListTasks(ctx, &tes.ListTasksRequest{ View: tes.TaskView_MINIMAL, }) - if err == nil || !strings.Contains(err.Error(), "PermissionDenied") { + if err == nil || !strings.Contains(err.Error(), "Unauthenticated") { t.Fatal("expected error") } _, err = fun.RPC.CreateTask(ctx, tests.HelloWorld()) - if err == nil || !strings.Contains(err.Error(), "PermissionDenied") { + if err == nil || !strings.Contains(err.Error(), "Unauthenticated") { t.Fatal("expected error") } _, err = fun.RPC.CancelTask(ctx, &tes.CancelTaskRequest{ Id: "1", }) - if err == nil || !strings.Contains(err.Error(), "PermissionDenied") { + if err == nil || !strings.Contains(err.Error(), "Unauthenticated") { t.Fatal("expected error") }