test(handlers): add missing tests (#5480)
Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>pull/5482/head
parent
1f2672e379
commit
f1b3fc7b31
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/valyala/fasthttp"
|
||||
|
||||
"github.com/authelia/authelia/v4/internal/authentication"
|
||||
"github.com/authelia/authelia/v4/internal/mocks"
|
||||
"github.com/authelia/authelia/v4/internal/session"
|
||||
)
|
||||
|
||||
func TestAuthzImplementation(t *testing.T) {
|
||||
assert.Equal(t, "Legacy", AuthzImplLegacy.String())
|
||||
assert.Equal(t, "", AuthzImplementation(-1).String())
|
||||
}
|
||||
|
||||
func TestFriendlyMethod(t *testing.T) {
|
||||
assert.Equal(t, "unknown", friendlyMethod(""))
|
||||
assert.Equal(t, "GET", friendlyMethod(fasthttp.MethodGet))
|
||||
}
|
||||
|
||||
func TestGenerateVerifySessionHasUpToDateProfileTraceLogs(t *testing.T) {
|
||||
mock := mocks.NewMockAutheliaCtx(t)
|
||||
|
||||
generateVerifySessionHasUpToDateProfileTraceLogs(mock.Ctx, &session.UserSession{Username: "john", DisplayName: "example", Groups: []string{"abc"}, Emails: []string{"user@example.com", "test@example.com"}}, &authentication.UserDetails{Username: "john", Groups: []string{"123"}, DisplayName: "notexample", Emails: []string{"notuser@example.com"}})
|
||||
generateVerifySessionHasUpToDateProfileTraceLogs(mock.Ctx, &session.UserSession{Username: "john", DisplayName: "example"}, &authentication.UserDetails{Username: "john", DisplayName: "example"})
|
||||
generateVerifySessionHasUpToDateProfileTraceLogs(mock.Ctx, &session.UserSession{Username: "john", DisplayName: "example", Emails: []string{"abc@example.com"}}, &authentication.UserDetails{Username: "john", DisplayName: "example"})
|
||||
generateVerifySessionHasUpToDateProfileTraceLogs(mock.Ctx, &session.UserSession{Username: "john", DisplayName: "example"}, &authentication.UserDetails{Username: "john", DisplayName: "example", Emails: []string{"abc@example.com"}})
|
||||
}
|
Loading…
Reference in New Issue