Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add valudate tests
  • Loading branch information
f0ssel committed Apr 5, 2024
commit e8d0fae650cda0c32ed878cf7f425e7f847c8da8
6 changes: 1 addition & 5 deletions coderd/workspaceapps/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (r Request) getDatabase(ctx context.Context, db database.Store) (*databaseR
}

// If the app slug is a port number, then route to the port as an
// "anonymous app". We only support HTTP for port-based URLs.
// "anonymous app".
//
// This is only supported for subdomain-based applications.
appURL = fmt.Sprintf("%s://127.0.0.1:%d", protocol, portUint)
Expand Down Expand Up @@ -353,10 +353,6 @@ func (r Request) getDatabase(ctx context.Context, db database.Store) (*databaseR
}
// No port share found, so we keep default to owner.
} else {
if ps.Protocol == database.PortShareProtocolHttps {
// Apply HTTPS protocol if specified.
appURL = fmt.Sprintf("https://127.0.0.1:%d", portUint)
}
appSharingLevel = ps.ShareLevel
}
} else {
Expand Down
20 changes: 20 additions & 0 deletions coderd/workspaceapps/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ func Test_RequestValidate(t *testing.T) {
AppSlugOrPort: "baz",
},
},
{
name: "OK5",
req: workspaceapps.Request{
AccessMethod: workspaceapps.AccessMethodSubdomain,
BasePath: "/",
UsernameOrID: "foo",
WorkspaceNameOrID: "bar",
AppSlugOrPort: "8080",
},
},
{
name: "OK6",
req: workspaceapps.Request{
AccessMethod: workspaceapps.AccessMethodSubdomain,
BasePath: "/",
UsernameOrID: "foo",
WorkspaceNameOrID: "bar",
AppSlugOrPort: "8080s",
},
},
{
name: "NoAccessMethod",
req: workspaceapps.Request{
Expand Down
48 changes: 48 additions & 0 deletions coderd/workspaceapps/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,54 @@ func Test_TokenMatchesRequest(t *testing.T) {
},
want: false,
},
{
name: "PortPortocolHTTP",
req: workspaceapps.Request{
AccessMethod: workspaceapps.AccessMethodSubdomain,
Prefix: "yolo--",
BasePath: "/",
UsernameOrID: "foo",
WorkspaceNameOrID: "bar",
AgentNameOrID: "baz",
AppSlugOrPort: "8080",
},
token: workspaceapps.SignedToken{
Request: workspaceapps.Request{
AccessMethod: workspaceapps.AccessMethodSubdomain,
Prefix: "yolo--",
BasePath: "/",
UsernameOrID: "foo",
WorkspaceNameOrID: "bar",
AgentNameOrID: "baz",
AppSlugOrPort: "8080",
},
},
want: true,
},
{
name: "PortPortocolHTTPS",
req: workspaceapps.Request{
AccessMethod: workspaceapps.AccessMethodSubdomain,
Prefix: "yolo--",
BasePath: "/",
UsernameOrID: "foo",
WorkspaceNameOrID: "bar",
AgentNameOrID: "baz",
AppSlugOrPort: "8080s",
},
token: workspaceapps.SignedToken{
Request: workspaceapps.Request{
AccessMethod: workspaceapps.AccessMethodSubdomain,
Prefix: "yolo--",
BasePath: "/",
UsernameOrID: "foo",
WorkspaceNameOrID: "bar",
AgentNameOrID: "baz",
AppSlugOrPort: "8080",
},
},
want: true,
},
}

for _, c := range cases {
Expand Down