Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: revert: use CRC32 to shorten app subdomain #10160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions coderd/httpapi/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package httpapi

import (
"fmt"
"hash/crc32"
"net"
"regexp"
"strings"
Expand All @@ -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.
Expand All @@ -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
Expand Down
10 changes: 0 additions & 10 deletions coderd/httpapi/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion coderd/workspaceapps/apptest/apptest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
8 changes: 4 additions & 4 deletions coderd/workspaceapps/apptest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down