Skip to content

Commit e8d0fae

Browse files
committed
add valudate tests
1 parent 87ae0be commit e8d0fae

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

coderd/workspaceapps/request.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func (r Request) getDatabase(ctx context.Context, db database.Store) (*databaseR
320320
}
321321

322322
// If the app slug is a port number, then route to the port as an
323-
// "anonymous app". We only support HTTP for port-based URLs.
323+
// "anonymous app".
324324
//
325325
// This is only supported for subdomain-based applications.
326326
appURL = fmt.Sprintf("%s://127.0.0.1:%d", protocol, portUint)
@@ -353,10 +353,6 @@ func (r Request) getDatabase(ctx context.Context, db database.Store) (*databaseR
353353
}
354354
// No port share found, so we keep default to owner.
355355
} else {
356-
if ps.Protocol == database.PortShareProtocolHttps {
357-
// Apply HTTPS protocol if specified.
358-
appURL = fmt.Sprintf("https://127.0.0.1:%d", portUint)
359-
}
360356
appSharingLevel = ps.ShareLevel
361357
}
362358
} else {

coderd/workspaceapps/request_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ func Test_RequestValidate(t *testing.T) {
5757
AppSlugOrPort: "baz",
5858
},
5959
},
60+
{
61+
name: "OK5",
62+
req: workspaceapps.Request{
63+
AccessMethod: workspaceapps.AccessMethodSubdomain,
64+
BasePath: "/",
65+
UsernameOrID: "foo",
66+
WorkspaceNameOrID: "bar",
67+
AppSlugOrPort: "8080",
68+
},
69+
},
70+
{
71+
name: "OK6",
72+
req: workspaceapps.Request{
73+
AccessMethod: workspaceapps.AccessMethodSubdomain,
74+
BasePath: "/",
75+
UsernameOrID: "foo",
76+
WorkspaceNameOrID: "bar",
77+
AppSlugOrPort: "8080s",
78+
},
79+
},
6080
{
6181
name: "NoAccessMethod",
6282
req: workspaceapps.Request{

coderd/workspaceapps/token_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,54 @@ func Test_TokenMatchesRequest(t *testing.T) {
222222
},
223223
want: false,
224224
},
225+
{
226+
name: "PortPortocolHTTP",
227+
req: workspaceapps.Request{
228+
AccessMethod: workspaceapps.AccessMethodSubdomain,
229+
Prefix: "yolo--",
230+
BasePath: "/",
231+
UsernameOrID: "foo",
232+
WorkspaceNameOrID: "bar",
233+
AgentNameOrID: "baz",
234+
AppSlugOrPort: "8080",
235+
},
236+
token: workspaceapps.SignedToken{
237+
Request: workspaceapps.Request{
238+
AccessMethod: workspaceapps.AccessMethodSubdomain,
239+
Prefix: "yolo--",
240+
BasePath: "/",
241+
UsernameOrID: "foo",
242+
WorkspaceNameOrID: "bar",
243+
AgentNameOrID: "baz",
244+
AppSlugOrPort: "8080",
245+
},
246+
},
247+
want: true,
248+
},
249+
{
250+
name: "PortPortocolHTTPS",
251+
req: workspaceapps.Request{
252+
AccessMethod: workspaceapps.AccessMethodSubdomain,
253+
Prefix: "yolo--",
254+
BasePath: "/",
255+
UsernameOrID: "foo",
256+
WorkspaceNameOrID: "bar",
257+
AgentNameOrID: "baz",
258+
AppSlugOrPort: "8080s",
259+
},
260+
token: workspaceapps.SignedToken{
261+
Request: workspaceapps.Request{
262+
AccessMethod: workspaceapps.AccessMethodSubdomain,
263+
Prefix: "yolo--",
264+
BasePath: "/",
265+
UsernameOrID: "foo",
266+
WorkspaceNameOrID: "bar",
267+
AgentNameOrID: "baz",
268+
AppSlugOrPort: "8080",
269+
},
270+
},
271+
want: true,
272+
},
225273
}
226274

227275
for _, c := range cases {

0 commit comments

Comments
 (0)