diff --git a/e2e/domain_routing_test.go b/e2e/domain_routing_test.go index ff9f9d8..864285b 100644 --- a/e2e/domain_routing_test.go +++ b/e2e/domain_routing_test.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "path/filepath" + "strings" "testing" "time" @@ -262,7 +263,7 @@ func TestDomainRouting_SPAFallback(t *testing.T) { } // TestDeployment_DomainFormat verifies that deployment URLs use the correct format: -// - CORRECT: {name}.{baseDomain} (e.g., "myapp.dbrs.space") +// - CORRECT: {name}-{random}.{baseDomain} (e.g., "myapp-f3o4if.dbrs.space") // - WRONG: {name}.node-{shortID}.{baseDomain} (should NOT exist) func TestDeployment_DomainFormat(t *testing.T) { env, err := LoadTestEnv() @@ -293,8 +294,9 @@ func TestDeployment_DomainFormat(t *testing.T) { } } - expectedDomain := env.BuildDeploymentDomain(deploymentName) - t.Logf("Expected domain format: %s", expectedDomain) + // Get the subdomain from deployment response + subdomain, _ := deployment["subdomain"].(string) + t.Logf("Deployment subdomain: %s", subdomain) t.Logf("Deployment URLs: %v", urls) foundCorrectFormat := false @@ -304,28 +306,37 @@ func TestDeployment_DomainFormat(t *testing.T) { continue } - // URL should contain the simple format: {name}.{baseDomain} - if assert.Contains(t, urlStr, expectedDomain, - "URL should contain %s", expectedDomain) { + // URL should start with https://{name}- + expectedPrefix := fmt.Sprintf("https://%s-", deploymentName) + if strings.HasPrefix(urlStr, expectedPrefix) { foundCorrectFormat = true } + // URL should contain base domain + assert.Contains(t, urlStr, env.BaseDomain, + "URL should contain base domain %s", env.BaseDomain) + // URL should NOT contain node identifier pattern assert.NotContains(t, urlStr, ".node-", "URL should NOT have node identifier (got: %s)", urlStr) } if len(urls) > 0 { - assert.True(t, foundCorrectFormat, "Should find URL with correct domain format") + assert.True(t, foundCorrectFormat, "Should find URL with correct domain format (https://{name}-{random}.{baseDomain})") } t.Logf("✓ Domain format verification passed") - t.Logf(" - Expected: %s", expectedDomain) + t.Logf(" - Format: {name}-{random}.{baseDomain}") }) t.Run("Domain resolves via Host header", func(t *testing.T) { - // Test that the simple domain format works - domain := env.BuildDeploymentDomain(deploymentName) + // Get the actual subdomain from the deployment + deployment := GetDeployment(t, env, deploymentID) + subdomain, _ := deployment["subdomain"].(string) + if subdomain == "" { + t.Skip("No subdomain set, skipping host header test") + } + domain := subdomain + "." + env.BaseDomain resp := TestDeploymentWithHostHeader(t, env, domain, "/") defer resp.Body.Close() diff --git a/e2e/namespace_cluster_test.go b/e2e/namespace_cluster_test.go index f1e1348..898fcb2 100644 --- a/e2e/namespace_cluster_test.go +++ b/e2e/namespace_cluster_test.go @@ -69,6 +69,7 @@ func TestNamespaceCluster_StatusPolling(t *testing.T) { t.Run("Status endpoint returns valid response", func(t *testing.T) { // Test with a non-existent cluster ID (should return 404) req, _ := http.NewRequest("GET", env.GatewayURL+"/v1/namespace/status?id=non-existent-id", nil) + req.Header.Set("Authorization", "Bearer "+env.APIKey) resp, err := env.HTTPClient.Do(req) require.NoError(t, err, "Should execute request") @@ -168,8 +169,8 @@ func TestDeployment_RandomSubdomain(t *testing.T) { tarballPath := filepath.Join("../testdata/tarballs/react-vite.tar.gz") - // Create a deployment - deploymentName := "subdomain-test" + // Create a deployment with unique name + deploymentName := fmt.Sprintf("subdomain-test-%d", time.Now().UnixNano()) deploymentID := CreateTestDeployment(t, env, deploymentName, tarballPath) defer func() { if !env.SkipCleanup { diff --git a/pkg/environments/development/topology.go b/pkg/environments/development/topology.go index 607bed7..1bc2f99 100644 --- a/pkg/environments/development/topology.go +++ b/pkg/environments/development/topology.go @@ -54,12 +54,12 @@ func DefaultTopology() *Topology { Name: "node-2", ConfigFilename: "node-2.yaml", DataDir: "node-2", - P2PPort: 4011, - IPFSAPIPort: 4511, - IPFSSwarmPort: 4111, - IPFSGatewayPort: 7511, - RQLiteHTTPPort: 5011, - RQLiteRaftPort: 7011, + P2PPort: 4002, + IPFSAPIPort: 4502, + IPFSSwarmPort: 4102, + IPFSGatewayPort: 7502, + RQLiteHTTPPort: 5002, + RQLiteRaftPort: 7002, ClusterAPIPort: 9104, ClusterPort: 9106, UnifiedGatewayPort: 6002, @@ -70,12 +70,12 @@ func DefaultTopology() *Topology { Name: "node-3", ConfigFilename: "node-3.yaml", DataDir: "node-3", - P2PPort: 4002, - IPFSAPIPort: 4502, - IPFSSwarmPort: 4102, - IPFSGatewayPort: 7502, - RQLiteHTTPPort: 5002, - RQLiteRaftPort: 7002, + P2PPort: 4003, + IPFSAPIPort: 4503, + IPFSSwarmPort: 4103, + IPFSGatewayPort: 7503, + RQLiteHTTPPort: 5003, + RQLiteRaftPort: 7003, ClusterAPIPort: 9114, ClusterPort: 9116, UnifiedGatewayPort: 6003, @@ -86,12 +86,12 @@ func DefaultTopology() *Topology { Name: "node-4", ConfigFilename: "node-4.yaml", DataDir: "node-4", - P2PPort: 4003, - IPFSAPIPort: 4503, - IPFSSwarmPort: 4103, - IPFSGatewayPort: 7503, - RQLiteHTTPPort: 5003, - RQLiteRaftPort: 7003, + P2PPort: 4004, + IPFSAPIPort: 4504, + IPFSSwarmPort: 4104, + IPFSGatewayPort: 7504, + RQLiteHTTPPort: 5004, + RQLiteRaftPort: 7004, ClusterAPIPort: 9124, ClusterPort: 9126, UnifiedGatewayPort: 6004, @@ -102,12 +102,12 @@ func DefaultTopology() *Topology { Name: "node-5", ConfigFilename: "node-5.yaml", DataDir: "node-5", - P2PPort: 4004, - IPFSAPIPort: 4504, - IPFSSwarmPort: 4104, - IPFSGatewayPort: 7504, - RQLiteHTTPPort: 5004, - RQLiteRaftPort: 7004, + P2PPort: 4005, + IPFSAPIPort: 4505, + IPFSSwarmPort: 4105, + IPFSGatewayPort: 7505, + RQLiteHTTPPort: 5005, + RQLiteRaftPort: 7005, ClusterAPIPort: 9134, ClusterPort: 9136, UnifiedGatewayPort: 6005, diff --git a/pkg/gateway/handlers/deployments/service.go b/pkg/gateway/handlers/deployments/service.go index 75406ce..df7b1aa 100644 --- a/pkg/gateway/handlers/deployments/service.go +++ b/pkg/gateway/handlers/deployments/service.go @@ -143,10 +143,10 @@ func (s *DeploymentService) generateSubdomain(ctx context.Context, name, namespa // subdomainExists checks if a subdomain is already registered globally func (s *DeploymentService) subdomainExists(ctx context.Context, subdomain string) (bool, error) { type existsRow struct { - Exists int `db:"exists"` + Found int `db:"found"` } var rows []existsRow - query := `SELECT 1 as exists FROM global_deployment_subdomains WHERE subdomain = ? LIMIT 1` + query := `SELECT 1 as found FROM global_deployment_subdomains WHERE subdomain = ? LIMIT 1` err := s.db.Query(ctx, &rows, query, subdomain) if err != nil { return false, err