mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix: allow sharing ports >9999 (#22273)
Closes https://github.com/coder/coder/issues/22267
This commit is contained in:
@@ -19,7 +19,10 @@ var (
|
||||
appURL = regexp.MustCompile(fmt.Sprintf(
|
||||
`^(?P<AppSlug>%[1]s)(?:--(?P<AgentName>%[1]s))?--(?P<WorkspaceName>%[1]s)--(?P<Username>%[1]s)$`,
|
||||
nameRegex))
|
||||
PortRegex = regexp.MustCompile(`^\d{4}s?$`)
|
||||
// PortRegex should not be able to be greater than 65535. In usage though, if a
|
||||
// user tries to use a greater port, the proxy will just block it and not cause
|
||||
// any issues. This is a good enough regex check.
|
||||
PortRegex = regexp.MustCompile(`^\d{4,5}s?$`)
|
||||
|
||||
validHostnameLabelRegex = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)
|
||||
)
|
||||
|
||||
@@ -193,6 +193,16 @@ func TestParseSubdomainAppURL(t *testing.T) {
|
||||
Username: "user",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Port(5)--Agent--Workspace--User",
|
||||
Subdomain: "12412--agent--workspace--user",
|
||||
Expected: appurl.ApplicationURL{
|
||||
AppSlugOrPort: "12412",
|
||||
AgentName: "agent",
|
||||
WorkspaceName: "workspace",
|
||||
Username: "user",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Port--Agent--Workspace--User",
|
||||
Subdomain: "8080s--agent--workspace--user",
|
||||
@@ -225,11 +235,11 @@ func TestParseSubdomainAppURL(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "5DigitAppSlug--Workspace--User",
|
||||
Subdomain: "30000--workspace--user",
|
||||
Name: "5DigitPort--agent--Workspace--User",
|
||||
Subdomain: "30000--agent--workspace--user",
|
||||
Expected: appurl.ApplicationURL{
|
||||
AppSlugOrPort: "30000",
|
||||
AgentName: "",
|
||||
AgentName: "agent",
|
||||
WorkspaceName: "workspace",
|
||||
Username: "user",
|
||||
},
|
||||
@@ -599,6 +609,14 @@ func TestURLGenerationVsParsing(t *testing.T) {
|
||||
Name: "5DigitAppSlug_AgentOmittedInParsing",
|
||||
AppSlugOrPort: "30000",
|
||||
AgentName: "agent",
|
||||
ExpectedParsed: "agent",
|
||||
},
|
||||
{
|
||||
// 6 digits is not a valid port, so it is treated as an app slug.
|
||||
// App slugs do not require the agent name, so it is dropped
|
||||
Name: "6DigitAppSlug_AgentOmittedInParsing",
|
||||
AppSlugOrPort: "300000",
|
||||
AgentName: "agent",
|
||||
ExpectedParsed: "",
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user