Added test cases
This commit is contained in:
parent
16cfb49fc1
commit
9bd6a1306a
|
|
@ -22,6 +22,7 @@ import (
|
||||||
const (
|
const (
|
||||||
// This is not exported as it's not currently user configurable
|
// This is not exported as it's not currently user configurable
|
||||||
oidcUserClaim = "sub"
|
oidcUserClaim = "sub"
|
||||||
|
oidcAcrClaim = "acr"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProviderData contains information required to configure all implementations
|
// ProviderData contains information required to configure all implementations
|
||||||
|
|
@ -267,7 +268,7 @@ func (p *ProviderData) buildSessionFromClaims(rawIDToken, accessToken string) (*
|
||||||
{p.UserClaim, &ss.User},
|
{p.UserClaim, &ss.User},
|
||||||
{p.EmailClaim, &ss.Email},
|
{p.EmailClaim, &ss.Email},
|
||||||
{p.GroupsClaim, &ss.Groups},
|
{p.GroupsClaim, &ss.Groups},
|
||||||
{"acr", &ss.Acr},
|
{oidcAcrClaim, &ss.Acr},
|
||||||
// TODO (@NickMeves) Deprecate for dynamic claim to session mapping
|
// TODO (@NickMeves) Deprecate for dynamic claim to session mapping
|
||||||
{"preferred_username", &ss.PreferredUsername},
|
{"preferred_username", &ss.PreferredUsername},
|
||||||
} {
|
} {
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,8 @@ func TestProviderDataAuthorize(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
allowedGroups []string
|
allowedGroups []string
|
||||||
groups []string
|
groups []string
|
||||||
|
acr string
|
||||||
|
userAcr string
|
||||||
expectedAuthZ bool
|
expectedAuthZ bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
|
@ -101,6 +103,23 @@ func TestProviderDataAuthorize(t *testing.T) {
|
||||||
groups: []string{"baz", "foo"},
|
groups: []string{"baz", "foo"},
|
||||||
expectedAuthZ: false,
|
expectedAuthZ: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "UserNotAllowedForACRLevel",
|
||||||
|
acr: "1",
|
||||||
|
expectedAuthZ: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "UserNotAllowedForACRLevel",
|
||||||
|
acr: "1",
|
||||||
|
userAcr: "1",
|
||||||
|
expectedAuthZ: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "UserNotAllowedForACRLevel",
|
||||||
|
acr: "2",
|
||||||
|
userAcr: "somethingElse",
|
||||||
|
expectedAuthZ: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
@ -109,9 +128,11 @@ func TestProviderDataAuthorize(t *testing.T) {
|
||||||
|
|
||||||
session := &sessions.SessionState{
|
session := &sessions.SessionState{
|
||||||
Groups: tc.groups,
|
Groups: tc.groups,
|
||||||
|
Acr: tc.userAcr,
|
||||||
}
|
}
|
||||||
p := &ProviderData{}
|
p := &ProviderData{}
|
||||||
p.setAllowedGroups(tc.allowedGroups)
|
p.setAllowedGroups(tc.allowedGroups)
|
||||||
|
p.setAllowedACR(tc.acr)
|
||||||
|
|
||||||
authorized, err := p.Authorize(context.Background(), session)
|
authorized, err := p.Authorize(context.Background(), session)
|
||||||
g.Expect(err).ToNot(HaveOccurred())
|
g.Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue