From a42a8a1e6ba3fe5cb6b531713a77ac1d7c9e92e9 Mon Sep 17 00:00:00 2001 From: zachmann <gabriel.zachmann@kit.edu> Date: Wed, 24 Feb 2021 11:09:35 +0100 Subject: [PATCH] fix tests --- .../authcodeinforepo/state/stateinfo_test.go} | 10 ++++----- .../dbrepo/supertokenrepo/supertoken_test.go | 13 +++++++++--- .../capabilities/capability_test.go | 20 +++++++++--------- shared/supertoken/pkg/supertoken_test.go | 21 ------------------- 4 files changed, 25 insertions(+), 39 deletions(-) rename internal/{oidc/authcode/authcode_test.go => db/dbrepo/authcodeinforepo/state/stateinfo_test.go} (81%) diff --git a/internal/oidc/authcode/authcode_test.go b/internal/db/dbrepo/authcodeinforepo/state/stateinfo_test.go similarity index 81% rename from internal/oidc/authcode/authcode_test.go rename to internal/db/dbrepo/authcodeinforepo/state/stateinfo_test.go index c5f3ab1e..8bba52fd 100644 --- a/internal/oidc/authcode/authcode_test.go +++ b/internal/db/dbrepo/authcodeinforepo/state/stateinfo_test.go @@ -1,4 +1,4 @@ -package authcode +package state import ( "testing" @@ -7,7 +7,7 @@ import ( ) func TestParseState(t *testing.T) { - stateInfos := []stateInfo{ + stateInfos := []Info{ {Native: false}, {Native: true}, {Native: false, ResponseType: model.ResponseTypeToken}, @@ -18,10 +18,10 @@ func TestParseState(t *testing.T) { {Native: true, ResponseType: model.ResponseTypeTransferCode}, } for _, stateInfo := range stateInfos { - state := createState(stateInfo) - parsed := parseState(state) + s, _ := CreateState(stateInfo) + parsed := s.Parse() if stateInfo != parsed { - t.Errorf("%+v was not correctly converted, instead got %+v from state '%s'", stateInfo, parsed, state) + t.Errorf("%+v was not correctly converted, instead got %+v from state '%+v'", stateInfo, parsed, s) } } } diff --git a/internal/db/dbrepo/supertokenrepo/supertoken_test.go b/internal/db/dbrepo/supertokenrepo/supertoken_test.go index b4077537..9e8e896d 100644 --- a/internal/db/dbrepo/supertokenrepo/supertoken_test.go +++ b/internal/db/dbrepo/supertokenrepo/supertoken_test.go @@ -1,6 +1,10 @@ package supertokenrepo -import "testing" +import ( + "testing" + + "github.com/oidc-mytoken/server/shared/supertoken/pkg/stid" +) func testRoot(t *testing.T, a SuperTokenEntry, expected bool) { root := a.Root() @@ -18,10 +22,13 @@ func TestSuperTokenEntry_RootEmpty(t *testing.T) { testRoot(t, a, true) } func TestSuperTokenEntry_RootHasParentAsRoot(t *testing.T) { - a := SuperTokenEntry{ParentID: "id", RootID: "id"} + id := stid.New() + a := SuperTokenEntry{ParentID: id, RootID: id} testRoot(t, a, false) } func TestSuperTokenEntry_RootHasRoot(t *testing.T) { - a := SuperTokenEntry{ParentID: "parentid", RootID: "rootid"} + pid := stid.New() + rid := stid.New() + a := SuperTokenEntry{ParentID: pid, RootID: rid} testRoot(t, a, false) } diff --git a/shared/supertoken/capabilities/capability_test.go b/shared/supertoken/capabilities/capability_test.go index 6ddfcfca..e9720a0e 100644 --- a/shared/supertoken/capabilities/capability_test.go +++ b/shared/supertoken/capabilities/capability_test.go @@ -26,33 +26,33 @@ func TestTightenAllEmpty(t *testing.T) { } func TestTightenOneEmpty(t *testing.T) { a := Capabilities{} - b := Capabilities{"not", "empty"} + b := NewCapabilities([]string{"not", "empty"}) expected := Capabilities{} testTighten(t, a, b, expected) testTighten(t, b, a, expected) } func TestTightenNoIntersection(t *testing.T) { - a := Capabilities{"some", "values"} - b := Capabilities{"completly", "different"} + a := NewCapabilities([]string{"some", "values"}) + b := NewCapabilities([]string{"completly", "different"}) expected := Capabilities{} testTighten(t, a, b, expected) testTighten(t, b, a, expected) } func TestTightenSame(t *testing.T) { - a := Capabilities{"some", "values"} + a := NewCapabilities([]string{"some", "values"}) testTighten(t, a, a, a) } func TestTightenSomeIntersection(t *testing.T) { - a := Capabilities{"some", "values"} - b := Capabilities{"some", "different"} - expected := Capabilities{"some"} + a := NewCapabilities([]string{"some", "values"}) + b := NewCapabilities([]string{"some", "different"}) + expected := NewCapabilities([]string{"some"}) testTighten(t, a, b, expected) testTighten(t, b, a, expected) } func TestTightenSubSet(t *testing.T) { - a := Capabilities{"some", "values"} - b := Capabilities{"some", "more", "values"} - expected := Capabilities{"some", "values"} + a := NewCapabilities([]string{"some", "values"}) + b := NewCapabilities([]string{"some", "more", "values"}) + expected := NewCapabilities([]string{"some", "values"}) testTighten(t, a, b, expected) testTighten(t, b, a, expected) } diff --git a/shared/supertoken/pkg/supertoken_test.go b/shared/supertoken/pkg/supertoken_test.go index 89433378..c8acb296 100644 --- a/shared/supertoken/pkg/supertoken_test.go +++ b/shared/supertoken/pkg/supertoken_test.go @@ -3,29 +3,8 @@ package supertoken import ( "testing" "time" - - "github.com/oidc-mytoken/server/internal/config" - "github.com/oidc-mytoken/server/internal/jws" - "github.com/oidc-mytoken/server/shared/supertoken/capabilities" ) -func TestSuperTokenJWTUnique(t *testing.T) { - config.Load() - jws.LoadKey() - st := NewSuperToken("sub", "iss", nil, capabilities.AllCapabilities, nil) - jwt1, err := st.ToJWT() - if err != nil { - t.Error(err) - } - jwt2, err := st.ToJWT() - if err != nil { - t.Error(err) - } - if jwt1 == jwt2 { - t.Errorf("JWTs not unique: '%s'", jwt1) - } -} - func TestSuperToken_ExpiresIn_Unset(t *testing.T) { st := SuperToken{} expIn := st.ExpiresIn() -- GitLab