Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
strideynet authored and github-actions committed Jun 20, 2024
1 parent 5281130 commit ee6423e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/authz/permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ func TestGetDisconnectExpiredCertFromIdentity(t *testing.T) {
name string
expires time.Time
previousIdentityExpires time.Time
checker services.AccessChecker
mfaVerified bool
disconnectExpiredCert bool
expected time.Time
}{
{
name: "mfa overrides expires when set",
checker: &fakeCtxChecker{},
expires: now,
previousIdentityExpires: inAnHour,
mfaVerified: true,
Expand All @@ -76,18 +78,36 @@ func TestGetDisconnectExpiredCertFromIdentity(t *testing.T) {
},
{
name: "expires returned when mfa unset",
checker: &fakeCtxChecker{},
expires: now,
mfaVerified: false,
disconnectExpiredCert: true,
expected: now,
},
{
name: "unset when disconnectExpiredCert is false",
checker: &fakeCtxChecker{},
expires: now,
previousIdentityExpires: inAnHour,
mfaVerified: true,
disconnectExpiredCert: false,
},
{
name: "no expiry returned when checker nil and disconnectExpiredCert false",
checker: nil,
expires: now,
mfaVerified: false,
disconnectExpiredCert: false,
expected: time.Time{},
},
{
name: "expiry returned when checker nil and disconnectExpiredCert true",
checker: nil,
expires: now,
mfaVerified: false,
disconnectExpiredCert: true,
expected: now,
},
} {
t.Run(test.name, func(t *testing.T) {
var mfaVerified string
Expand All @@ -103,7 +123,7 @@ func TestGetDisconnectExpiredCertFromIdentity(t *testing.T) {
authPref := types.DefaultAuthPreference()
authPref.SetDisconnectExpiredCert(test.disconnectExpiredCert)

ctx := Context{Checker: &fakeCtxChecker{}, Identity: WrapIdentity(identity)}
ctx := Context{Checker: test.checker, Identity: WrapIdentity(identity)}

got := ctx.GetDisconnectCertExpiry(authPref)
require.Equal(t, test.expected, got)
Expand Down

0 comments on commit ee6423e

Please sign in to comment.