tests: fix user tests with for new behavior
This commit is contained in:
parent
85113748a8
commit
ce8b0a4c9e
2 changed files with 19 additions and 9 deletions
|
@ -59,7 +59,7 @@ func TestNewEmailVerification(t *testing.T) {
|
||||||
}
|
}
|
||||||
ev := NewEmailVerification(tt.user, tt.clientID, tt.issuer, *cbURL, tt.expires)
|
ev := NewEmailVerification(tt.user, tt.clientID, tt.issuer, *cbURL, tt.expires)
|
||||||
|
|
||||||
if diff := pretty.Compare(tt.want, ev.claims); diff != "" {
|
if diff := pretty.Compare(tt.want, ev.Claims); diff != "" {
|
||||||
t.Errorf("case %d: Compare(want, got): %v", i, diff)
|
t.Errorf("case %d: Compare(want, got): %v", i, diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,10 +127,11 @@ func TestEmailVerificationParseAndVerify(t *testing.T) {
|
||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
|
|
||||||
token, err := tt.ev.Token(tt.signer)
|
jwt, err := jose.NewSignedJWT(tt.ev.Claims, tt.signer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("case %d: non-nil error creating token: %v", i, err)
|
t.Fatalf("Failed to generate JWT, error=%v", err)
|
||||||
}
|
}
|
||||||
|
token := jwt.Encode()
|
||||||
|
|
||||||
ev, err := ParseAndVerifyEmailVerificationToken(token, *issuer,
|
ev, err := ParseAndVerifyEmailVerificationToken(token, *issuer,
|
||||||
[]key.PublicKey{*key.NewPublicKey(privKey.JWK())})
|
[]key.PublicKey{*key.NewPublicKey(privKey.JWK())})
|
||||||
|
@ -148,7 +149,7 @@ func TestEmailVerificationParseAndVerify(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if diff := pretty.Compare(tt.ev.claims, ev.claims); diff != "" {
|
if diff := pretty.Compare(tt.ev.Claims, ev.Claims); diff != "" {
|
||||||
t.Errorf("case %d: Compare(want, got): %v", i, diff)
|
t.Errorf("case %d: Compare(want, got): %v", i, diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ func TestNewPasswordReset(t *testing.T) {
|
||||||
}
|
}
|
||||||
ev := NewPasswordReset(tt.user, tt.password, tt.issuer, tt.clientID, *cbURL, tt.expires)
|
ev := NewPasswordReset(tt.user, tt.password, tt.issuer, tt.clientID, *cbURL, tt.expires)
|
||||||
|
|
||||||
if diff := pretty.Compare(tt.want, ev.claims); diff != "" {
|
if diff := pretty.Compare(tt.want, ev.Claims); diff != "" {
|
||||||
t.Errorf("case %d: Compare(want, got): %v", i, diff)
|
t.Errorf("case %d: Compare(want, got): %v", i, diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,12 +145,13 @@ func TestPasswordResetParseAndVerify(t *testing.T) {
|
||||||
password := Password("passy")
|
password := Password("passy")
|
||||||
|
|
||||||
goodPR := NewPasswordReset(user, password, *issuer, client, *callback, expires)
|
goodPR := NewPasswordReset(user, password, *issuer, client, *callback, expires)
|
||||||
goodPRNoCB := NewPasswordReset(user, password, *issuer, "", url.URL{}, expires)
|
goodPRNoCB := NewPasswordReset(user, password, *issuer, client, url.URL{}, expires)
|
||||||
expiredPR := NewPasswordReset(user, password, *issuer, client, *callback, -expires)
|
expiredPR := NewPasswordReset(user, password, *issuer, client, *callback, -expires)
|
||||||
wrongIssuerPR := NewPasswordReset(user, password, *otherIssuer, client, *callback, expires)
|
wrongIssuerPR := NewPasswordReset(user, password, *otherIssuer, client, *callback, expires)
|
||||||
noSubPR := NewPasswordReset(User{}, password, *issuer, client, *callback, expires)
|
noSubPR := NewPasswordReset(User{}, password, *issuer, client, *callback, expires)
|
||||||
noPWPR := NewPasswordReset(user, Password(""), *issuer, client, *callback, expires)
|
noPWPR := NewPasswordReset(user, Password(""), *issuer, client, *callback, expires)
|
||||||
noClientPR := NewPasswordReset(user, password, *issuer, "", *callback, expires)
|
noClientPR := NewPasswordReset(user, password, *issuer, "", *callback, expires)
|
||||||
|
noClientNoCBPR := NewPasswordReset(user, password, *issuer, "", url.URL{}, expires)
|
||||||
|
|
||||||
privKey, err := key.GeneratePrivateKey()
|
privKey, err := key.GeneratePrivateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -211,14 +212,22 @@ func TestPasswordResetParseAndVerify(t *testing.T) {
|
||||||
signer: signer,
|
signer: signer,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ev: noClientNoCBPR,
|
||||||
|
signer: signer,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
|
|
||||||
token, err := tt.ev.Token(tt.signer)
|
t.Logf("TODO claims are %v", tt.ev.Claims)
|
||||||
|
|
||||||
|
jwt, err := jose.NewSignedJWT(tt.ev.Claims, tt.signer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("case %d: non-nil error creating token: %v", i, err)
|
t.Fatalf("Failed to generate JWT, error=%v", err)
|
||||||
}
|
}
|
||||||
|
token := jwt.Encode()
|
||||||
|
|
||||||
ev, err := ParseAndVerifyPasswordResetToken(token, *issuer,
|
ev, err := ParseAndVerifyPasswordResetToken(token, *issuer,
|
||||||
[]key.PublicKey{*key.NewPublicKey(privKey.JWK())})
|
[]key.PublicKey{*key.NewPublicKey(privKey.JWK())})
|
||||||
|
@ -236,7 +245,7 @@ func TestPasswordResetParseAndVerify(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if diff := pretty.Compare(tt.ev.claims, ev.claims); diff != "" {
|
if diff := pretty.Compare(tt.ev.Claims, ev.Claims); diff != "" {
|
||||||
t.Errorf("case %d: Compare(want, got): %v", i, diff)
|
t.Errorf("case %d: Compare(want, got): %v", i, diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue