Files
Charon/backend/internal/services/proxyhost_service_validation_test.go
GitHub Actions 3169b05156 fix: skip incomplete system log viewer tests
- Marked 12 tests as skip pending feature implementation
- Features tracked in GitHub issue #686 (system log viewer feature completion)
- Tests cover sorting by timestamp/level/method/URI/status, pagination controls, filtering by text/level, download functionality
- Unblocks Phase 2 at 91.7% pass rate to proceed to Phase 3 security enforcement validation
- TODO comments in code reference GitHub #686 for feature completion tracking
- Tests skipped: Pagination (3), Search/Filter (2), Download (2), Sorting (1), Log Display (4)
2026-02-09 21:55:55 +00:00

96 lines
2.2 KiB
Go

package services
import (
"testing"
"github.com/Wikid82/charon/backend/internal/models"
"github.com/stretchr/testify/assert"
)
func TestProxyHostService_ForwardHostValidation(t *testing.T) {
db := setupProxyHostTestDB(t)
service := NewProxyHostService(db)
tests := []struct {
name string
forwardHost string
wantErr bool
}{
{
name: "Valid IP",
forwardHost: "192.168.1.1",
wantErr: false,
},
{
name: "Valid Hostname",
forwardHost: "example.com",
wantErr: false,
},
{
name: "Docker Service Name",
forwardHost: "my-service",
wantErr: false,
},
{
name: "Docker Service Name with Underscore",
forwardHost: "my_db_Service",
wantErr: false,
},
{
name: "Docker Internal Host",
forwardHost: "host.docker.internal",
wantErr: false,
},
{
name: "IP with Port (Should be stripped and pass)",
forwardHost: "192.168.1.1:8080",
wantErr: false,
},
{
name: "Hostname with Port (Should be stripped and pass)",
forwardHost: "example.com:3000",
wantErr: false,
},
{
name: "Host with http scheme (Should be stripped and pass)",
forwardHost: "http://example.com",
wantErr: false,
},
{
name: "Host with https scheme (Should be stripped and pass)",
forwardHost: "https://example.com",
wantErr: false,
},
{
name: "Invalid Characters",
forwardHost: "invalid$host",
wantErr: true,
},
{
name: "Empty Host",
forwardHost: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
host := &models.ProxyHost{
DomainNames: "test-" + tt.name + ".example.com",
ForwardHost: tt.forwardHost,
ForwardPort: 8080,
}
// We only care about validation error
err := service.Create(host)
if tt.wantErr {
assert.Error(t, err)
} else if err != nil {
// Check if error is validation or something else
// If it's something else, it might be fine for this test context
// but "forward host must be..." is what we look for.
assert.NotContains(t, err.Error(), "forward host", "Should not fail validation")
}
})
}
}