From 67efb0600f9c993fbc8baaed6e6079681de3fe33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=90=99PiperYxzzy?= Date: Sun, 1 May 2022 20:55:49 +0200 Subject: [PATCH] Adding util test class --- util/util_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 util/util_test.go diff --git a/util/util_test.go b/util/util_test.go new file mode 100644 index 0000000..1e71eac --- /dev/null +++ b/util/util_test.go @@ -0,0 +1,24 @@ +package util + +import ( + "testing" +) + +func TestParseJwt(t *testing.T) { + premadeJwt := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGFpbTEiOiJjbGFpbTEtdmFsIiwiY2xhaW0yIjoyMjJ9.n1rVLigY5Q6CNKqcGD38i27dqytY2qaWhXexq6PKyIY" + premadeHmac := []byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4} + + parsed, err := ParseJwt(premadeJwt, premadeHmac) + if err != nil { + t.Errorf("should not fail parsing JWT") + } + + if parsed["claim1"] != "claim1-val" { + t.Errorf("did not contain expected value for claim1, %v", parsed) + } + + if parsed["claim2"] != 222.0 { + t.Errorf("did not contain expected value for claim2, %v", parsed) + } + +}