diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2023-05-25 07:58:00 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-25 07:58:00 +1000 |
| commit | f1b3fc7b31249bc38b2795c694022036c58e89af (patch) | |
| tree | 14af8896fd8d1a7738f7f9abad95c87f4ce24aeb /internal/handlers/handler_authz_builder_test.go | |
| parent | 1f2672e37979391e439a9a8644381b353ee7aa84 (diff) | |
test(handlers): add missing tests (#5480)
Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
Diffstat (limited to 'internal/handlers/handler_authz_builder_test.go')
| -rw-r--r-- | internal/handlers/handler_authz_builder_test.go | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/internal/handlers/handler_authz_builder_test.go b/internal/handlers/handler_authz_builder_test.go new file mode 100644 index 000000000..dc4bff1fd --- /dev/null +++ b/internal/handlers/handler_authz_builder_test.go @@ -0,0 +1,93 @@ +package handlers + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + + "github.com/authelia/authelia/v4/internal/configuration/schema" +) + +func TestAuthzBuilder_WithConfig(t *testing.T) { + builder := NewAuthzBuilder() + + builder.WithConfig(&schema.Configuration{ + AuthenticationBackend: schema.AuthenticationBackend{ + RefreshInterval: "always", + }, + }) + + assert.Equal(t, time.Second*0, builder.config.RefreshInterval) + + builder.WithConfig(&schema.Configuration{ + AuthenticationBackend: schema.AuthenticationBackend{ + RefreshInterval: "disable", + }, + }) + + assert.Equal(t, time.Second*-1, builder.config.RefreshInterval) + + builder.WithConfig(&schema.Configuration{ + AuthenticationBackend: schema.AuthenticationBackend{ + RefreshInterval: "1m", + }, + }) + + assert.Equal(t, time.Minute, builder.config.RefreshInterval) + + builder.WithConfig(nil) + + assert.Equal(t, time.Minute, builder.config.RefreshInterval) +} + +func TestAuthzBuilder_WithEndpointConfig(t *testing.T) { + builder := NewAuthzBuilder() + + builder.WithEndpointConfig(schema.ServerAuthzEndpoint{ + Implementation: "ExtAuthz", + }) + + assert.Equal(t, AuthzImplExtAuthz, builder.implementation) + + builder.WithEndpointConfig(schema.ServerAuthzEndpoint{ + Implementation: "ForwardAuth", + }) + + assert.Equal(t, AuthzImplForwardAuth, builder.implementation) + + builder.WithEndpointConfig(schema.ServerAuthzEndpoint{ + Implementation: "AuthRequest", + }) + + assert.Equal(t, AuthzImplAuthRequest, builder.implementation) + + builder.WithEndpointConfig(schema.ServerAuthzEndpoint{ + Implementation: "Legacy", + }) + + assert.Equal(t, AuthzImplLegacy, builder.implementation) + + builder.WithEndpointConfig(schema.ServerAuthzEndpoint{ + Implementation: "ExtAuthz", + AuthnStrategies: []schema.ServerAuthzEndpointAuthnStrategy{ + {Name: "HeaderProxyAuthorization"}, + {Name: "CookieSession"}, + }, + }) + + assert.Len(t, builder.strategies, 2) + + builder.WithEndpointConfig(schema.ServerAuthzEndpoint{ + Implementation: "ExtAuthz", + AuthnStrategies: []schema.ServerAuthzEndpointAuthnStrategy{ + {Name: "HeaderAuthorization"}, + {Name: "HeaderProxyAuthorization"}, + {Name: "HeaderAuthRequestProxyAuthorization"}, + {Name: "HeaderLegacy"}, + {Name: "CookieSession"}, + }, + }) + + assert.Len(t, builder.strategies, 5) +} |
