From b9d529a794be99e488c8de860c7411042254ea5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20J=C3=B6rz?= Date: Fri, 16 Dec 2022 10:01:55 +0100 Subject: [PATCH] fixed token tests error --- grpc-server-go/helper/generators/tokens_test.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/grpc-server-go/helper/generators/tokens_test.go b/grpc-server-go/helper/generators/tokens_test.go index 900e734..f2eb05a 100644 --- a/grpc-server-go/helper/generators/tokens_test.go +++ b/grpc-server-go/helper/generators/tokens_test.go @@ -1,6 +1,7 @@ package generators_test import ( + "strings" "template/server/helper/generators" "testing" ) @@ -21,8 +22,12 @@ func TestJwt(t *testing.T) { if userId != 10 { t.Errorf("Expected 10, got %d", userId) } - // Manipulate token - s = s[:len(s)-1] + "a" + splitted := strings.Split(s, ".") + for i, v := range splitted { + splitted[i] = v + "a" + } + s = strings.Join(splitted, ".") + t.Logf("Token (manipulated): %v", s) userId, err = generators.VerifyJwt(s) if err == nil { t.Errorf("Expected error, got %d", userId) @@ -58,7 +63,13 @@ func TestS3Jwt(t *testing.T) { t.Errorf("Expected image/png, got %s", fileType) } // Manipulate token - s = s[:len(s)-1] + "a" + // add a to each block + splitted := strings.Split(s, ".") + for i, v := range splitted { + splitted[i] = v + "a" + } + s = strings.Join(splitted, ".") + t.Logf("Token (manipulated): %v", s) filename, _, _, err = generators.VerifyJwtForS3Upload(s) if err == nil { t.Errorf("Expected error, got %s", filename)