Skip to content

Commit b3d60a4

Browse files
committed
add tests
1 parent 0ab922a commit b3d60a4

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

coderd/workspaceapps/db_test.go

+63
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func Test_ResolveRequest(t *testing.T) {
4040
// Users can access unhealthy and initializing apps (as of 2024-02).
4141
appNameUnhealthy = "app-unhealthy"
4242
appNameInitializing = "app-initializing"
43+
appNameEndsInS = "app-ends-in-s"
4344

4445
// This agent will never connect, so it will never become "connected".
4546
// Users cannot access unhealthy agents.
@@ -166,6 +167,12 @@ func Test_ResolveRequest(t *testing.T) {
166167
Threshold: 1000,
167168
},
168169
},
170+
{
171+
Slug: appNameEndsInS,
172+
DisplayName: appNameEndsInS,
173+
SharingLevel: proto.AppSharingLevel_OWNER,
174+
Url: appURL,
175+
},
169176
},
170177
},
171178
{
@@ -644,6 +651,62 @@ func Test_ResolveRequest(t *testing.T) {
644651
require.Equal(t, "http://127.0.0.1:9090", token.AppURL)
645652
})
646653

654+
t.Run("PortSubdomainHTTPSS", func(t *testing.T) {
655+
t.Parallel()
656+
657+
req := (workspaceapps.Request{
658+
AccessMethod: workspaceapps.AccessMethodSubdomain,
659+
BasePath: "/",
660+
UsernameOrID: me.Username,
661+
WorkspaceNameOrID: workspace.Name,
662+
AgentNameOrID: agentName,
663+
AppSlugOrPort: "9090ss",
664+
}).Normalize()
665+
666+
rw := httptest.NewRecorder()
667+
r := httptest.NewRequest("GET", "/", nil)
668+
r.Header.Set(codersdk.SessionTokenHeader, client.SessionToken())
669+
670+
_, ok := workspaceapps.ResolveRequest(rw, r, workspaceapps.ResolveRequestOptions{
671+
Logger: api.Logger,
672+
SignedTokenProvider: api.WorkspaceAppsProvider,
673+
DashboardURL: api.AccessURL,
674+
PathAppBaseURL: api.AccessURL,
675+
AppHostname: api.AppHostname,
676+
AppRequest: req,
677+
})
678+
// should parse as app and fail to find app "9090ss"
679+
require.False(t, ok)
680+
})
681+
682+
t.Run("SubdomainEndsInS", func(t *testing.T) {
683+
t.Parallel()
684+
685+
req := (workspaceapps.Request{
686+
AccessMethod: workspaceapps.AccessMethodSubdomain,
687+
BasePath: "/",
688+
UsernameOrID: me.Username,
689+
WorkspaceNameOrID: workspace.Name,
690+
AgentNameOrID: agentName,
691+
AppSlugOrPort: appNameEndsInS,
692+
}).Normalize()
693+
694+
rw := httptest.NewRecorder()
695+
r := httptest.NewRequest("GET", "/", nil)
696+
r.Header.Set(codersdk.SessionTokenHeader, client.SessionToken())
697+
698+
token, ok := workspaceapps.ResolveRequest(rw, r, workspaceapps.ResolveRequestOptions{
699+
Logger: api.Logger,
700+
SignedTokenProvider: api.WorkspaceAppsProvider,
701+
DashboardURL: api.AccessURL,
702+
PathAppBaseURL: api.AccessURL,
703+
AppHostname: api.AppHostname,
704+
AppRequest: req,
705+
})
706+
require.True(t, ok)
707+
require.Equal(t, req.AppSlugOrPort, token.AppSlugOrPort)
708+
})
709+
647710
t.Run("Terminal", func(t *testing.T) {
648711
t.Parallel()
649712

0 commit comments

Comments
 (0)