2023-05-24 21:58:00 +00:00
|
|
|
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()
|
|
|
|
|
2023-01-26 02:23:47 +00:00
|
|
|
builder.WithEndpointConfig(schema.ServerEndpointsAuthz{
|
2023-05-24 21:58:00 +00:00
|
|
|
Implementation: "ExtAuthz",
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.Equal(t, AuthzImplExtAuthz, builder.implementation)
|
|
|
|
|
2023-01-26 02:23:47 +00:00
|
|
|
builder.WithEndpointConfig(schema.ServerEndpointsAuthz{
|
2023-05-24 21:58:00 +00:00
|
|
|
Implementation: "ForwardAuth",
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.Equal(t, AuthzImplForwardAuth, builder.implementation)
|
|
|
|
|
2023-01-26 02:23:47 +00:00
|
|
|
builder.WithEndpointConfig(schema.ServerEndpointsAuthz{
|
2023-05-24 21:58:00 +00:00
|
|
|
Implementation: "AuthRequest",
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.Equal(t, AuthzImplAuthRequest, builder.implementation)
|
|
|
|
|
2023-01-26 02:23:47 +00:00
|
|
|
builder.WithEndpointConfig(schema.ServerEndpointsAuthz{
|
2023-05-24 21:58:00 +00:00
|
|
|
Implementation: "Legacy",
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.Equal(t, AuthzImplLegacy, builder.implementation)
|
|
|
|
|
2023-01-26 02:23:47 +00:00
|
|
|
builder.WithEndpointConfig(schema.ServerEndpointsAuthz{
|
2023-05-24 21:58:00 +00:00
|
|
|
Implementation: "ExtAuthz",
|
2023-01-26 02:23:47 +00:00
|
|
|
AuthnStrategies: []schema.ServerEndpointsAuthzAuthnStrategy{
|
2023-05-24 21:58:00 +00:00
|
|
|
{Name: "HeaderProxyAuthorization"},
|
|
|
|
{Name: "CookieSession"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.Len(t, builder.strategies, 2)
|
|
|
|
|
2023-01-26 02:23:47 +00:00
|
|
|
builder.WithEndpointConfig(schema.ServerEndpointsAuthz{
|
2023-05-24 21:58:00 +00:00
|
|
|
Implementation: "ExtAuthz",
|
2023-01-26 02:23:47 +00:00
|
|
|
AuthnStrategies: []schema.ServerEndpointsAuthzAuthnStrategy{
|
2023-05-24 21:58:00 +00:00
|
|
|
{Name: "HeaderAuthorization"},
|
|
|
|
{Name: "HeaderProxyAuthorization"},
|
|
|
|
{Name: "HeaderAuthRequestProxyAuthorization"},
|
|
|
|
{Name: "HeaderLegacy"},
|
|
|
|
{Name: "CookieSession"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.Len(t, builder.strategies, 5)
|
|
|
|
}
|