mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 21:33:18 +01:00
2
Makefile
2
Makefile
@@ -1,7 +1,7 @@
|
|||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
@rm -rf static
|
@rm -rf static
|
||||||
@go clean
|
@go clean -i
|
||||||
|
|
||||||
.PHONY: static
|
.PHONY: static
|
||||||
static:
|
static:
|
||||||
|
|||||||
@@ -23,6 +23,15 @@ Location: /foobar/
|
|||||||
|
|
||||||
<a href="/foobar/">Moved Permanently</a>.
|
<a href="/foobar/">Moved Permanently</a>.
|
||||||
|
|
||||||
|
/* snapshot: Test_createRoutes_redirect_with_auth */
|
||||||
|
HTTP/1.1 307 Temporary Redirect
|
||||||
|
Connection: close
|
||||||
|
Content-Security-Policy: default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self'; manifest-src 'self'; connect-src 'self' api.github.com; require-trusted-types-for 'script'
|
||||||
|
Content-Type: text/html; charset=utf-8
|
||||||
|
Location: /foobar/login
|
||||||
|
|
||||||
|
<a href="/foobar/login">Temporary Redirect</a>.
|
||||||
|
|
||||||
/* snapshot: Test_createRoutes_username_password */
|
/* snapshot: Test_createRoutes_username_password */
|
||||||
HTTP/1.1 307 Temporary Redirect
|
HTTP/1.1 307 Temporary Redirect
|
||||||
Connection: close
|
Connection: close
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const authorityKey = "AUTH_TIMESTAMP"
|
|||||||
const sessionName = "session"
|
const sessionName = "session"
|
||||||
|
|
||||||
func initializeAuth(h *handler) {
|
func initializeAuth(h *handler) {
|
||||||
|
secured = false
|
||||||
if h.config.Username != "" && h.config.Password != "" {
|
if h.config.Username != "" && h.config.Password != "" {
|
||||||
store = sessions.NewCookieStore([]byte(h.config.Key))
|
store = sessions.NewCookieStore([]byte(h.config.Key))
|
||||||
store.Options.HttpOnly = true
|
store.Options.HttpOnly = true
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/amir20/dozzle/docker"
|
"github.com/amir20/dozzle/docker"
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ func (h *handler) index(w http.ResponseWriter, req *http.Request) {
|
|||||||
fileServer.ServeHTTP(w, req)
|
fileServer.ServeHTTP(w, req)
|
||||||
} else {
|
} else {
|
||||||
if !isAuthorized(req) && req.URL.Path != "login" {
|
if !isAuthorized(req) && req.URL.Path != "login" {
|
||||||
http.Redirect(w, req, h.config.Base+"login", http.StatusTemporaryRedirect)
|
http.Redirect(w, req, path.Clean(h.config.Base+"/login"), http.StatusTemporaryRedirect)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.executeTemplate(w, req)
|
h.executeTemplate(w, req)
|
||||||
|
|||||||
@@ -267,6 +267,19 @@ func Test_createRoutes_redirect(t *testing.T) {
|
|||||||
abide.AssertHTTPResponse(t, t.Name(), rr.Result())
|
abide.AssertHTTPResponse(t, t.Name(), rr.Result())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_createRoutes_redirect_with_auth(t *testing.T) {
|
||||||
|
fs := afero.NewMemMapFs()
|
||||||
|
require.NoError(t, afero.WriteFile(fs, "index.html", []byte("index page"), 0644), "WriteFile should have no error.")
|
||||||
|
|
||||||
|
handler := createHandler(nil, afero.NewIOFS(fs), Config{Base: "/foobar", Username: "amir", Password: "password", Key: "key"})
|
||||||
|
req, err := http.NewRequest("GET", "/foobar/", nil)
|
||||||
|
require.NoError(t, err, "NewRequest should not return an error.")
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
|
handler.ServeHTTP(rr, req)
|
||||||
|
abide.AssertHTTPResponse(t, t.Name(), rr.Result())
|
||||||
|
}
|
||||||
|
|
||||||
func Test_createRoutes_foobar(t *testing.T) {
|
func Test_createRoutes_foobar(t *testing.T) {
|
||||||
fs := afero.NewMemMapFs()
|
fs := afero.NewMemMapFs()
|
||||||
require.NoError(t, afero.WriteFile(fs, "index.html", []byte("foo page"), 0644), "WriteFile should have no error.")
|
require.NoError(t, afero.WriteFile(fs, "index.html", []byte("foo page"), 0644), "WriteFile should have no error.")
|
||||||
|
|||||||
Reference in New Issue
Block a user