Skip to content

Commit a4f205e

Browse files
committed
comments
1 parent b72ef2f commit a4f205e

File tree

22 files changed

+161
-162
lines changed

22 files changed

+161
-162
lines changed

coderd/apidoc/docs.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func New(options *Options) *API {
399399
//
400400
// Workspace apps do their own auth and must be BEFORE the auth
401401
// middleware.
402-
api.workspaceAppServer.SubdomainAppMW(apiRateLimiter),
402+
api.workspaceAppServer.HandleSubdomain(apiRateLimiter),
403403
// Build-Version is helpful for debugging.
404404
func(next http.Handler) http.Handler {
405405
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

coderd/deployment.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ func (api *API) deploymentStats(rw http.ResponseWriter, r *http.Request) {
7171
func buildInfo(accessURL *url.URL) http.HandlerFunc {
7272
return func(rw http.ResponseWriter, r *http.Request) {
7373
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.BuildInfoResponse{
74-
ExternalURL: buildinfo.ExternalURL(),
75-
Version: buildinfo.Version(),
76-
DashboardURL: accessURL.String(),
77-
IsWorkspaceProxy: false,
74+
ExternalURL: buildinfo.ExternalURL(),
75+
Version: buildinfo.Version(),
76+
DashboardURL: accessURL.String(),
77+
WorkspaceProxy: false,
7878
})
7979
}
8080
}

coderd/httpmw/apikey.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ type ExtractAPIKeyConfig struct {
101101
// cookie-based request, the request will be rejected with a 401.
102102
Optional bool
103103

104-
// TokenFunc is a custom function that can be used to extract the API key.
105-
// If nil, the default behavior is used.
106-
TokenFunc func(r *http.Request) string
104+
// SessionTokenFunc is a custom function that can be used to extract the API
105+
// key. If nil, the default behavior is used.
106+
SessionTokenFunc func(r *http.Request) string
107107
}
108108

109109
// ExtractAPIKeyMW calls ExtractAPIKey with the given config on each request,
@@ -173,8 +173,8 @@ func ExtractAPIKey(rw http.ResponseWriter, r *http.Request, cfg ExtractAPIKeyCon
173173
}
174174

175175
tokenFunc := APITokenFromRequest
176-
if cfg.TokenFunc != nil {
177-
tokenFunc = cfg.TokenFunc
176+
if cfg.SessionTokenFunc != nil {
177+
tokenFunc = cfg.SessionTokenFunc
178178
}
179179
token := tokenFunc(r)
180180
if token == "" {

coderd/workspaceapps/apptest/apptest.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
115115
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
116116
defer cancel()
117117

118-
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, appDetails.PathAppURL(appDetails.OwnerApp).String(), nil)
118+
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, appDetails.PathAppURL(appDetails.Apps.Owner).String(), nil)
119119
require.NoError(t, err)
120120
defer resp.Body.Close()
121121
require.Equal(t, http.StatusUnauthorized, resp.StatusCode)
@@ -127,7 +127,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
127127
t.Run("LoginWithoutAuthOnPrimary", func(t *testing.T) {
128128
t.Parallel()
129129

130-
if !appDetails.AppHostServesAPI {
130+
if !appDetails.AppHostIsPrimary {
131131
t.Skip("This test only applies when testing apps on the primary.")
132132
}
133133

@@ -137,7 +137,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
137137
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
138138
defer cancel()
139139

140-
u := appDetails.PathAppURL(appDetails.OwnerApp).String()
140+
u := appDetails.PathAppURL(appDetails.Apps.Owner).String()
141141
resp, err := requestWithRetries(ctx, t, unauthedClient, http.MethodGet, u, nil)
142142
require.NoError(t, err)
143143
defer resp.Body.Close()
@@ -152,7 +152,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
152152
t.Run("LoginWithoutAuthOnProxy", func(t *testing.T) {
153153
t.Parallel()
154154

155-
if appDetails.AppHostServesAPI {
155+
if appDetails.AppHostIsPrimary {
156156
t.Skip("This test only applies when testing apps on workspace proxies.")
157157
}
158158

@@ -162,7 +162,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
162162
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
163163
defer cancel()
164164

165-
u := appDetails.PathAppURL(appDetails.OwnerApp)
165+
u := appDetails.PathAppURL(appDetails.Apps.Owner)
166166
resp, err := requestWithRetries(ctx, t, unauthedClient, http.MethodGet, u.String(), nil)
167167
require.NoError(t, err)
168168
defer resp.Body.Close()
@@ -196,7 +196,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
196196
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
197197
defer cancel()
198198

199-
resp, err := requestWithRetries(ctx, t, userAppClient, http.MethodGet, appDetails.PathAppURL(appDetails.OwnerApp).String(), nil)
199+
resp, err := requestWithRetries(ctx, t, userAppClient, http.MethodGet, appDetails.PathAppURL(appDetails.Apps.Owner).String(), nil)
200200
require.NoError(t, err)
201201
defer resp.Body.Close()
202202
require.Equal(t, http.StatusNotFound, resp.StatusCode)
@@ -208,7 +208,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
208208
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
209209
defer cancel()
210210

211-
u := appDetails.PathAppURL(appDetails.OwnerApp)
211+
u := appDetails.PathAppURL(appDetails.Apps.Owner)
212212
u.Path = strings.TrimSuffix(u.Path, "/")
213213
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, u.String(), nil)
214214
require.NoError(t, err)
@@ -222,7 +222,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
222222
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
223223
defer cancel()
224224

225-
u := appDetails.PathAppURL(appDetails.OwnerApp)
225+
u := appDetails.PathAppURL(appDetails.Apps.Owner)
226226
u.RawQuery = ""
227227
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, u.String(), nil)
228228
require.NoError(t, err)
@@ -239,7 +239,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
239239
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
240240
defer cancel()
241241

242-
u := appDetails.PathAppURL(appDetails.OwnerApp)
242+
u := appDetails.PathAppURL(appDetails.Apps.Owner)
243243
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, u.String(), nil)
244244
require.NoError(t, err)
245245
defer resp.Body.Close()
@@ -280,7 +280,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
280280
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
281281
defer cancel()
282282

283-
app := appDetails.OwnerApp
283+
app := appDetails.Apps.Owner
284284
app.Username = codersdk.Me
285285

286286
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, appDetails.PathAppURL(app).String(), nil)
@@ -299,7 +299,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
299299
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
300300
defer cancel()
301301

302-
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, appDetails.PathAppURL(appDetails.OwnerApp).String(), nil, func(r *http.Request) {
302+
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, appDetails.PathAppURL(appDetails.Apps.Owner).String(), nil, func(r *http.Request) {
303303
r.Header.Set("Cf-Connecting-IP", "1.1.1.1")
304304
})
305305
require.NoError(t, err)
@@ -317,7 +317,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
317317
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
318318
defer cancel()
319319

320-
resp, err := appDetails.AppClient(t).Request(ctx, http.MethodGet, appDetails.PathAppURL(appDetails.FakeApp).String(), nil)
320+
resp, err := appDetails.AppClient(t).Request(ctx, http.MethodGet, appDetails.PathAppURL(appDetails.Apps.Fake).String(), nil)
321321
require.NoError(t, err)
322322
defer resp.Body.Close()
323323
require.Equal(t, http.StatusBadGateway, resp.StatusCode)
@@ -329,7 +329,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
329329
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
330330
defer cancel()
331331

332-
resp, err := appDetails.AppClient(t).Request(ctx, http.MethodGet, appDetails.PathAppURL(appDetails.PortApp).String(), nil)
332+
resp, err := appDetails.AppClient(t).Request(ctx, http.MethodGet, appDetails.PathAppURL(appDetails.Apps.Port).String(), nil)
333333
require.NoError(t, err)
334334
defer resp.Body.Close()
335335
// TODO(@deansheather): This should be 400. There's a todo in the
@@ -354,7 +354,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
354354
}{
355355
{
356356
name: "Subdomain",
357-
appURL: appDetails.SubdomainAppURL(appDetails.OwnerApp),
357+
appURL: appDetails.SubdomainAppURL(appDetails.Apps.Owner),
358358
verifyCookie: func(t *testing.T, c *http.Cookie) {
359359
// TODO(@dean): fix these asserts, they don't seem to
360360
// work. I wonder if Go strips the domain from the
@@ -365,7 +365,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
365365
},
366366
{
367367
name: "Path",
368-
appURL: appDetails.PathAppURL(appDetails.OwnerApp),
368+
appURL: appDetails.PathAppURL(appDetails.Apps.Owner),
369369
verifyCookie: func(t *testing.T, c *http.Cookie) {
370370
// TODO(@dean): fix these asserts, they don't seem to
371371
// work. I wonder if Go strips the domain from the
@@ -378,7 +378,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
378378
for _, c := range cases {
379379
c := c
380380

381-
if c.name == "Path" && appDetails.AppHostServesAPI {
381+
if c.name == "Path" && appDetails.AppHostIsPrimary {
382382
// Workspace application auth does not apply to path apps
383383
// served from the primary access URL as no smuggling needs
384384
// to take place (they're already logged in with a session
@@ -536,7 +536,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
536536
DisableSubdomainApps: true,
537537
noWorkspace: true,
538538
})
539-
if !appDetails.AppHostServesAPI {
539+
if !appDetails.AppHostIsPrimary {
540540
t.Skip("app hostname does not serve API")
541541
}
542542

@@ -604,7 +604,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
604604
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
605605
defer cancel()
606606

607-
resp, err := requestWithRetries(ctx, t, userAppClient, http.MethodGet, appDetails.SubdomainAppURL(appDetails.OwnerApp).String(), nil)
607+
resp, err := requestWithRetries(ctx, t, userAppClient, http.MethodGet, appDetails.SubdomainAppURL(appDetails.Apps.Owner).String(), nil)
608608
require.NoError(t, err)
609609
defer resp.Body.Close()
610610
require.Equal(t, http.StatusNotFound, resp.StatusCode)
@@ -616,7 +616,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
616616
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
617617
defer cancel()
618618

619-
u := appDetails.SubdomainAppURL(appDetails.OwnerApp)
619+
u := appDetails.SubdomainAppURL(appDetails.Apps.Owner)
620620
u.Path = ""
621621
u.RawQuery = ""
622622
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, u.String(), nil)
@@ -626,7 +626,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
626626

627627
loc, err := resp.Location()
628628
require.NoError(t, err)
629-
require.Equal(t, appDetails.SubdomainAppURL(appDetails.OwnerApp).Path, loc.Path)
629+
require.Equal(t, appDetails.SubdomainAppURL(appDetails.Apps.Owner).Path, loc.Path)
630630
})
631631

632632
t.Run("RedirectsWithQuery", func(t *testing.T) {
@@ -635,7 +635,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
635635
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
636636
defer cancel()
637637

638-
u := appDetails.SubdomainAppURL(appDetails.OwnerApp)
638+
u := appDetails.SubdomainAppURL(appDetails.Apps.Owner)
639639
u.RawQuery = ""
640640
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, u.String(), nil)
641641
require.NoError(t, err)
@@ -644,7 +644,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
644644

645645
loc, err := resp.Location()
646646
require.NoError(t, err)
647-
require.Equal(t, appDetails.SubdomainAppURL(appDetails.OwnerApp).RawQuery, loc.RawQuery)
647+
require.Equal(t, appDetails.SubdomainAppURL(appDetails.Apps.Owner).RawQuery, loc.RawQuery)
648648
})
649649

650650
t.Run("Proxies", func(t *testing.T) {
@@ -653,7 +653,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
653653
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
654654
defer cancel()
655655

656-
u := appDetails.SubdomainAppURL(appDetails.OwnerApp)
656+
u := appDetails.SubdomainAppURL(appDetails.Apps.Owner)
657657
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, u.String(), nil)
658658
require.NoError(t, err)
659659
defer resp.Body.Close()
@@ -694,7 +694,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
694694
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
695695
defer cancel()
696696

697-
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, appDetails.SubdomainAppURL(appDetails.PortApp).String(), nil)
697+
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, appDetails.SubdomainAppURL(appDetails.Apps.Port).String(), nil)
698698
require.NoError(t, err)
699699
defer resp.Body.Close()
700700
body, err := io.ReadAll(resp.Body)
@@ -709,7 +709,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
709709
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
710710
defer cancel()
711711

712-
resp, err := appDetails.AppClient(t).Request(ctx, http.MethodGet, appDetails.SubdomainAppURL(appDetails.FakeApp).String(), nil)
712+
resp, err := appDetails.AppClient(t).Request(ctx, http.MethodGet, appDetails.SubdomainAppURL(appDetails.Apps.Fake).String(), nil)
713713
require.NoError(t, err)
714714
defer resp.Body.Close()
715715
require.Equal(t, http.StatusBadGateway, resp.StatusCode)
@@ -721,7 +721,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
721721
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
722722
defer cancel()
723723

724-
app := appDetails.PortApp
724+
app := appDetails.Apps.Port
725725
app.AppSlugOrPort = strconv.Itoa(codersdk.WorkspaceAgentMinimumListeningPort - 1)
726726
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, appDetails.SubdomainAppURL(app).String(), nil)
727727
require.NoError(t, err)
@@ -745,7 +745,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
745745
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
746746
defer cancel()
747747

748-
u := appDetails.SubdomainAppURL(appDetails.OwnerApp)
748+
u := appDetails.SubdomainAppURL(appDetails.Apps.Owner)
749749
t.Logf("url: %s", u)
750750

751751
resp, err := requestWithRetries(ctx, t, appDetails.AppClient(t), http.MethodGet, u.String(), nil)
@@ -768,7 +768,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
768768
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
769769
defer cancel()
770770

771-
u := appDetails.SubdomainAppURL(appDetails.OwnerApp)
771+
u := appDetails.SubdomainAppURL(appDetails.Apps.Owner)
772772
// Replace the -suffix with nothing.
773773
u.Host = strings.Replace(u.Host, "-suffix", "", 1)
774774
t.Logf("url: %s", u)
@@ -790,7 +790,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
790790
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
791791
defer cancel()
792792

793-
u := appDetails.SubdomainAppURL(appDetails.OwnerApp)
793+
u := appDetails.SubdomainAppURL(appDetails.Apps.Owner)
794794
// Replace the -suffix with something else.
795795
u.Host = strings.Replace(u.Host, "-suffix", "-not-suffix", 1)
796796
t.Logf("url: %s", u)
@@ -961,7 +961,7 @@ func Run(t *testing.T, factory DeploymentFactory) {
961961
require.NoError(t, err, msg)
962962

963963
expectedPath := "/login"
964-
if !isPathApp || !appDetails.AppHostServesAPI {
964+
if !isPathApp || !appDetails.AppHostIsPrimary {
965965
expectedPath = "/api/v2/applications/auth-redirect"
966966
}
967967
assert.Equal(t, expectedPath, location.Path, "should not have access, expected redirect to applicable login endpoint. "+msg)
@@ -1141,11 +1141,11 @@ func Run(t *testing.T, factory DeploymentFactory) {
11411141
}{
11421142
{
11431143
name: "ProxyPath",
1144-
u: appDetails.PathAppURL(appDetails.OwnerApp),
1144+
u: appDetails.PathAppURL(appDetails.Apps.Owner),
11451145
},
11461146
{
11471147
name: "ProxySubdomain",
1148-
u: appDetails.SubdomainAppURL(appDetails.OwnerApp),
1148+
u: appDetails.SubdomainAppURL(appDetails.Apps.Owner),
11491149
},
11501150
}
11511151

0 commit comments

Comments
 (0)