Skip to content

Commit edf0154

Browse files
committed
Merge remote-tracking branch 'origin/main' into rbac-global-cache
2 parents fbc940e + 52d2bc9 commit edf0154

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

enterprise/coderd/templates.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ func (api *API) moonsEnabledMW(next http.Handler) http.Handler {
293293
proxy := api.entitlements.Features[codersdk.FeatureWorkspaceProxy].Enabled
294294
api.entitlementsMu.RUnlock()
295295
if !proxy {
296-
httpapi.RouteNotFound(rw)
296+
httpapi.Write(r.Context(), rw, http.StatusForbidden, codersdk.Response{
297+
Message: "External workspace proxies is an Enterprise feature. Contact sales!",
298+
})
297299
return
298300
}
299301

enterprise/wsproxy/wsproxy.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
235235
r.Get("/healthz-report", s.healthReport)
236236
r.NotFound(func(rw http.ResponseWriter, r *http.Request) {
237237
site.RenderStaticErrorPage(rw, r, site.ErrorPageData{
238-
Status: 404,
239-
Title: "Route Not Found",
240-
Description: "The route you requested does not exist on this workspace proxy. Maybe you intended to make this request to the primary dashboard? Click below to be redirected to the primary site.",
238+
Title: "Head to the Dashboard",
239+
Status: http.StatusBadRequest,
240+
HideStatus: true,
241+
Description: "Workspace Proxies route traffic in terminals and apps directly to your workspace. " +
242+
"This page must be loaded from the dashboard. Click to be redirected!",
241243
RetryEnabled: false,
242244
DashboardURL: opts.DashboardURL.String(),
243245
})

site/site.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,9 @@ func extractBin(dest string, r io.Reader) (numExtracted int, err error) {
606606
// ErrorPageData contains the variables that are found in
607607
// site/static/error.html.
608608
type ErrorPageData struct {
609-
Status int
609+
Status int
610+
// HideStatus will remove the status code from the page.
611+
HideStatus bool
610612
Title string
611613
Description string
612614
RetryEnabled bool

site/site_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,34 @@ func TestRenderStaticErrorPage(t *testing.T) {
517517
require.Contains(t, bodyStr, "Retry")
518518
require.Contains(t, bodyStr, d.DashboardURL)
519519
}
520+
521+
func TestRenderStaticErrorPageNoStatus(t *testing.T) {
522+
t.Parallel()
523+
524+
d := site.ErrorPageData{
525+
HideStatus: true,
526+
Status: http.StatusBadGateway,
527+
Title: "Bad Gateway 1234",
528+
Description: "shout out colin",
529+
RetryEnabled: true,
530+
DashboardURL: "https://example.com",
531+
}
532+
533+
rw := httptest.NewRecorder()
534+
r := httptest.NewRequest("GET", "/", nil)
535+
site.RenderStaticErrorPage(rw, r, d)
536+
537+
resp := rw.Result()
538+
defer resp.Body.Close()
539+
require.Equal(t, d.Status, resp.StatusCode)
540+
require.Contains(t, resp.Header.Get("Content-Type"), "text/html")
541+
542+
body, err := io.ReadAll(resp.Body)
543+
require.NoError(t, err)
544+
bodyStr := string(body)
545+
require.NotContains(t, bodyStr, strconv.Itoa(d.Status))
546+
require.Contains(t, bodyStr, d.Title)
547+
require.Contains(t, bodyStr, d.Description)
548+
require.Contains(t, bodyStr, "Retry")
549+
require.Contains(t, bodyStr, d.DashboardURL)
550+
}

site/static/error.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
<meta charset="UTF-8" />
88
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
99
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
10-
<title>{{ .Error.Status }} - {{ .Error.Title }}</title>
10+
<title>
11+
{{- if not .Error.HideStatus }}{{ .Error.Status }} - {{end}}{{
12+
.Error.Title }}
13+
</title>
1114
<style>
1215
* {
1316
padding: 0;
@@ -123,7 +126,10 @@
123126
</defs>
124127
</svg>
125128

126-
<h1>{{ .Error.Status }} - {{ .Error.Title }}</h1>
129+
<h1>
130+
{{- if not .Error.HideStatus }}{{ .Error.Status }} - {{end}}{{
131+
.Error.Title }}
132+
</h1>
127133
<p>{{ .Error.Description }}</p>
128134
<div class="button-group">
129135
{{- if .Error.RetryEnabled }}

0 commit comments

Comments
 (0)