diff options
author | Tuomo Ala-Vannesluoma <tuomoav@gmail.com> | 2018-04-06 18:23:58 +0300 |
---|---|---|
committer | Tuomo Ala-Vannesluoma <tuomoav@gmail.com> | 2018-06-30 22:50:19 +0300 |
commit | 9cf40354085f4b4446f06d4d03926dcaa6ab9565 (patch) | |
tree | eb6ade3a82feec5f9b258417f41a8fecd3e9aec9 /internal/httperrors | |
parent | c4a419ed595281f62977fd47aa30d225c4eddb5d (diff) |
Add support for private projects and authentication with GitLab API
Diffstat (limited to 'internal/httperrors')
-rw-r--r-- | internal/httperrors/httperrors.go | 12 | ||||
-rw-r--r-- | internal/httperrors/httperrors_test.go | 12 |
2 files changed, 24 insertions, 0 deletions
diff --git a/internal/httperrors/httperrors.go b/internal/httperrors/httperrors.go index 92413e07..1ae5224b 100644 --- a/internal/httperrors/httperrors.go +++ b/internal/httperrors/httperrors.go @@ -14,6 +14,13 @@ type content struct { } var ( + content401 = content{ + http.StatusUnauthorized, + "Unauthorized (401)", + "401", + "You don't have permission to access the resource.", + `<p>The resource that you are attempting to access is protected and you don't have the necessary permissions to view it.</p>`, + } content404 = content{ http.StatusNotFound, "The page you're looking for could not be found (404)", @@ -155,6 +162,11 @@ func serveErrorPage(w http.ResponseWriter, c content) { fmt.Fprintln(w, generateErrorHTML(c)) } +// Serve401 returns a 401 error response / HTML page to the http.ResponseWriter +func Serve401(w http.ResponseWriter) { + serveErrorPage(w, content401) +} + // Serve404 returns a 404 error response / HTML page to the http.ResponseWriter func Serve404(w http.ResponseWriter) { serveErrorPage(w, content404) diff --git a/internal/httperrors/httperrors_test.go b/internal/httperrors/httperrors_test.go index 1a79d850..be532dfe 100644 --- a/internal/httperrors/httperrors_test.go +++ b/internal/httperrors/httperrors_test.go @@ -68,6 +68,18 @@ func TestServeErrorPage(t *testing.T) { assert.Equal(t, w.Status(), testingContent.status) } +func TestServe401(t *testing.T) { + w := newTestResponseWriter(httptest.NewRecorder()) + Serve401(w) + assert.Equal(t, w.Header().Get("Content-Type"), "text/html; charset=utf-8") + assert.Equal(t, w.Header().Get("X-Content-Type-Options"), "nosniff") + assert.Equal(t, w.Status(), content401.status) + assert.Contains(t, w.Content(), content401.title) + assert.Contains(t, w.Content(), content401.statusString) + assert.Contains(t, w.Content(), content401.header) + assert.Contains(t, w.Content(), content401.subHeader) +} + func TestServe404(t *testing.T) { w := newTestResponseWriter(httptest.NewRecorder()) Serve404(w) |