- Implemented Issue #9: User Authentication & Authorization - Added User model fields (FailedLoginAttempts, LockedUntil, LastLogin) - Created AuthService with JWT support, bcrypt hashing, and account lockout - Added AuthMiddleware and AuthHandler - Registered auth routes in backend - Created AuthContext and RequireAuth component in frontend - Implemented Login page and integrated with backend - Fixed 'Blank Page' issue in local Docker environment - Added QueryClientProvider to main.tsx - Installed missing lucide-react dependency - Fixed TypeScript linting errors in SetupGuard.tsx - Updated docker-entrypoint.sh to use 127.0.0.1 for reliable Caddy checks - Verified with local Docker build
126 lines
2.3 KiB
Go
126 lines
2.3 KiB
Go
package caddy
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/Wikid82/CaddyProxyManagerPlus/backend/internal/models"
|
|
)
|
|
|
|
func TestValidate_EmptyConfig(t *testing.T) {
|
|
config := &Config{}
|
|
err := Validate(config)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestValidate_ValidConfig(t *testing.T) {
|
|
hosts := []models.ProxyHost{
|
|
{
|
|
UUID: "test",
|
|
DomainNames: "test.example.com",
|
|
ForwardHost: "10.0.1.100",
|
|
ForwardPort: 8080,
|
|
Enabled: true,
|
|
},
|
|
}
|
|
|
|
config, _ := GenerateConfig(hosts, "/tmp/caddy-data", "admin@example.com")
|
|
err := Validate(config)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestValidate_DuplicateHosts(t *testing.T) {
|
|
config := &Config{
|
|
Apps: Apps{
|
|
HTTP: &HTTPApp{
|
|
Servers: map[string]*Server{
|
|
"srv": {
|
|
Listen: []string{":80"},
|
|
Routes: []*Route{
|
|
{
|
|
Match: []Match{{Host: []string{"test.com"}}},
|
|
Handle: []Handler{
|
|
ReverseProxyHandler("app:8080", false),
|
|
},
|
|
},
|
|
{
|
|
Match: []Match{{Host: []string{"test.com"}}},
|
|
Handle: []Handler{
|
|
ReverseProxyHandler("app2:8080", false),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
err := Validate(config)
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "duplicate host")
|
|
}
|
|
|
|
func TestValidate_NoListenAddresses(t *testing.T) {
|
|
config := &Config{
|
|
Apps: Apps{
|
|
HTTP: &HTTPApp{
|
|
Servers: map[string]*Server{
|
|
"srv": {
|
|
Listen: []string{},
|
|
Routes: []*Route{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
err := Validate(config)
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "no listen addresses")
|
|
}
|
|
|
|
func TestValidate_InvalidPort(t *testing.T) {
|
|
config := &Config{
|
|
Apps: Apps{
|
|
HTTP: &HTTPApp{
|
|
Servers: map[string]*Server{
|
|
"srv": {
|
|
Listen: []string{":99999"},
|
|
Routes: []*Route{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
err := Validate(config)
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "out of range")
|
|
}
|
|
|
|
func TestValidate_NoHandlers(t *testing.T) {
|
|
config := &Config{
|
|
Apps: Apps{
|
|
HTTP: &HTTPApp{
|
|
Servers: map[string]*Server{
|
|
"srv": {
|
|
Listen: []string{":80"},
|
|
Routes: []*Route{
|
|
{
|
|
Match: []Match{{Host: []string{"test.com"}}},
|
|
Handle: []Handler{},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
err := Validate(config)
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "no handlers")
|
|
}
|