Skip to content
Snippets Groups Projects
Commit a42a8a1e authored by Gabriel Zachmann's avatar Gabriel Zachmann
Browse files

fix tests

parent 77249613
No related branches found
No related tags found
No related merge requests found
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)
}
}
}
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)
}
......@@ -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)
}
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment