2021-05-04 22:06:05 +00:00
|
|
|
package oidc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/authorization"
|
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
2021-05-04 22:06:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestOpenIDConnectStore_GetClientPolicy(t *testing.T) {
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
s, err := NewOpenIDConnectStore(&schema.OpenIDConnectConfiguration{
|
2021-05-04 22:06:05 +00:00
|
|
|
IssuerPrivateKey: exampleIssuerPrivateKey,
|
|
|
|
Clients: []schema.OpenIDConnectClientConfiguration{
|
|
|
|
{
|
|
|
|
ID: "myclient",
|
|
|
|
Description: "myclient desc",
|
|
|
|
Policy: "one_factor",
|
|
|
|
Scopes: []string{"openid", "profile"},
|
|
|
|
Secret: "mysecret",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "myotherclient",
|
|
|
|
Description: "myclient desc",
|
|
|
|
Policy: "two_factor",
|
|
|
|
Scopes: []string{"openid", "profile"},
|
|
|
|
Secret: "mysecret",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-05-04 22:06:05 +00:00
|
|
|
policyOne := s.GetClientPolicy("myclient")
|
|
|
|
assert.Equal(t, authorization.OneFactor, policyOne)
|
|
|
|
|
|
|
|
policyTwo := s.GetClientPolicy("myotherclient")
|
|
|
|
assert.Equal(t, authorization.TwoFactor, policyTwo)
|
|
|
|
|
|
|
|
policyInvalid := s.GetClientPolicy("invalidclient")
|
|
|
|
assert.Equal(t, authorization.TwoFactor, policyInvalid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOpenIDConnectStore_GetInternalClient(t *testing.T) {
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
s, err := NewOpenIDConnectStore(&schema.OpenIDConnectConfiguration{
|
2021-05-04 22:06:05 +00:00
|
|
|
IssuerPrivateKey: exampleIssuerPrivateKey,
|
|
|
|
Clients: []schema.OpenIDConnectClientConfiguration{
|
|
|
|
{
|
|
|
|
ID: "myclient",
|
|
|
|
Description: "myclient desc",
|
|
|
|
Policy: "one_factor",
|
|
|
|
Scopes: []string{"openid", "profile"},
|
|
|
|
Secret: "mysecret",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-05-04 22:06:05 +00:00
|
|
|
client, err := s.GetClient(context.Background(), "myinvalidclient")
|
|
|
|
assert.EqualError(t, err, "not_found")
|
|
|
|
assert.Nil(t, client)
|
|
|
|
|
|
|
|
client, err = s.GetClient(context.Background(), "myclient")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, client)
|
|
|
|
assert.Equal(t, "myclient", client.GetID())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOpenIDConnectStore_GetInternalClient_ValidClient(t *testing.T) {
|
|
|
|
c1 := schema.OpenIDConnectClientConfiguration{
|
|
|
|
ID: "myclient",
|
|
|
|
Description: "myclient desc",
|
|
|
|
Policy: "one_factor",
|
|
|
|
Scopes: []string{"openid", "profile"},
|
|
|
|
Secret: "mysecret",
|
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
s, err := NewOpenIDConnectStore(&schema.OpenIDConnectConfiguration{
|
2021-05-04 22:06:05 +00:00
|
|
|
IssuerPrivateKey: exampleIssuerPrivateKey,
|
|
|
|
Clients: []schema.OpenIDConnectClientConfiguration{c1},
|
|
|
|
})
|
|
|
|
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-05-04 22:06:05 +00:00
|
|
|
client, err := s.GetInternalClient(c1.ID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, client)
|
|
|
|
assert.Equal(t, client.ID, c1.ID)
|
|
|
|
assert.Equal(t, client.Description, c1.Description)
|
|
|
|
assert.Equal(t, client.Scopes, c1.Scopes)
|
|
|
|
assert.Equal(t, client.GrantTypes, c1.GrantTypes)
|
|
|
|
assert.Equal(t, client.ResponseTypes, c1.ResponseTypes)
|
|
|
|
assert.Equal(t, client.RedirectURIs, c1.RedirectURIs)
|
|
|
|
assert.Equal(t, client.Policy, authorization.OneFactor)
|
|
|
|
assert.Equal(t, client.Secret, []byte(c1.Secret))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOpenIDConnectStore_GetInternalClient_InvalidClient(t *testing.T) {
|
|
|
|
c1 := schema.OpenIDConnectClientConfiguration{
|
|
|
|
ID: "myclient",
|
|
|
|
Description: "myclient desc",
|
|
|
|
Policy: "one_factor",
|
|
|
|
Scopes: []string{"openid", "profile"},
|
|
|
|
Secret: "mysecret",
|
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
s, err := NewOpenIDConnectStore(&schema.OpenIDConnectConfiguration{
|
2021-05-04 22:06:05 +00:00
|
|
|
IssuerPrivateKey: exampleIssuerPrivateKey,
|
|
|
|
Clients: []schema.OpenIDConnectClientConfiguration{c1},
|
|
|
|
})
|
|
|
|
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-05-04 22:06:05 +00:00
|
|
|
client, err := s.GetInternalClient("another-client")
|
|
|
|
assert.Nil(t, client)
|
|
|
|
assert.EqualError(t, err, "not_found")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOpenIDConnectStore_IsValidClientID(t *testing.T) {
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
s, err := NewOpenIDConnectStore(&schema.OpenIDConnectConfiguration{
|
2021-05-04 22:06:05 +00:00
|
|
|
IssuerPrivateKey: exampleIssuerPrivateKey,
|
|
|
|
Clients: []schema.OpenIDConnectClientConfiguration{
|
|
|
|
{
|
|
|
|
ID: "myclient",
|
|
|
|
Description: "myclient desc",
|
|
|
|
Policy: "one_factor",
|
|
|
|
Scopes: []string{"openid", "profile"},
|
|
|
|
Secret: "mysecret",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-05-04 22:06:05 +00:00
|
|
|
validClient := s.IsValidClientID("myclient")
|
|
|
|
invalidClient := s.IsValidClientID("myinvalidclient")
|
|
|
|
|
|
|
|
assert.True(t, validClient)
|
|
|
|
assert.False(t, invalidClient)
|
|
|
|
}
|