From 2f9d345795abccd43a659539f0cf72aaa43d36b8 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Tue, 10 Oct 2023 09:39:19 +0200 Subject: [PATCH] Revert "fix: use CRC32 to shorten app subdomain (#9645)" This reverts commit 0e28397c82afe478bee2131bf8ea605f3de8e553. --- coderd/httpapi/url.go | 10 +--------- coderd/httpapi/url_test.go | 10 ---------- coderd/workspaceapps/apptest/apptest.go | 2 +- coderd/workspaceapps/apptest/setup.go | 8 ++++---- 4 files changed, 6 insertions(+), 24 deletions(-) diff --git a/coderd/httpapi/url.go b/coderd/httpapi/url.go index 1085281a8fb6f..b23d28bfd3990 100644 --- a/coderd/httpapi/url.go +++ b/coderd/httpapi/url.go @@ -2,7 +2,6 @@ package httpapi import ( "fmt" - "hash/crc32" "net" "regexp" "strings" @@ -19,8 +18,6 @@ var ( nameRegex)) validHostnameLabelRegex = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`) - - crcTable = crc32.MakeTable(crc32.IEEE) ) // ApplicationURL is a parsed application URL hostname. @@ -42,12 +39,7 @@ func (a ApplicationURL) String() string { _, _ = appURL.WriteString(a.WorkspaceName) _, _ = appURL.WriteString("--") _, _ = appURL.WriteString(a.Username) - hostname := appURL.String() - - if len(hostname) < 64 { // max length for the subdomain level - return hostname - } - return fmt.Sprintf("app-%08x", crc32.Checksum([]byte(hostname), crcTable)) + return appURL.String() } // ParseSubdomainAppURL parses an ApplicationURL from the given subdomain. If diff --git a/coderd/httpapi/url_test.go b/coderd/httpapi/url_test.go index 2372fe23b52ac..8c1dfd8995b94 100644 --- a/coderd/httpapi/url_test.go +++ b/coderd/httpapi/url_test.go @@ -42,16 +42,6 @@ func TestApplicationURLString(t *testing.T) { }, Expected: "8080--agent--workspace--user", }, - { - Name: "LongAppName", - URL: httpapi.ApplicationURL{ - AppSlugOrPort: "0123456789012345678901234567890123456789", - AgentName: "agent", - WorkspaceName: "workspace", - Username: "user", - }, - Expected: "app-90667f72", - }, } for _, c := range testCases { diff --git a/coderd/workspaceapps/apptest/apptest.go b/coderd/workspaceapps/apptest/apptest.go index f8d593885a1cf..7339743d1ad71 100644 --- a/coderd/workspaceapps/apptest/apptest.go +++ b/coderd/workspaceapps/apptest/apptest.go @@ -1353,7 +1353,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { }, testutil.WaitLong, testutil.IntervalFast, "stats not reported") assert.Equal(t, workspaceapps.AccessMethodPath, stats[0].AccessMethod) - assert.Equal(t, proxyTestAppNameOwner, stats[0].SlugOrPort) + assert.Equal(t, "test-app-owner", stats[0].SlugOrPort) assert.Equal(t, 1, stats[0].Requests) }) } diff --git a/coderd/workspaceapps/apptest/setup.go b/coderd/workspaceapps/apptest/setup.go index a8e8be2d40de5..43bada0083f54 100644 --- a/coderd/workspaceapps/apptest/setup.go +++ b/coderd/workspaceapps/apptest/setup.go @@ -32,10 +32,10 @@ import ( const ( proxyTestAgentName = "agent-name" - proxyTestAppNameFake = "taf" - proxyTestAppNameOwner = "tao" - proxyTestAppNameAuthenticated = "taa" - proxyTestAppNamePublic = "tap" + proxyTestAppNameFake = "test-app-fake" + proxyTestAppNameOwner = "test-app-owner" + proxyTestAppNameAuthenticated = "test-app-authenticated" + proxyTestAppNamePublic = "test-app-public" proxyTestAppQuery = "query=true" proxyTestAppBody = "hello world from apps test"