1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-24 14:31:44 +01:00

feat: collects all stats like cpu and mem in background for up to 5 minutes (#2740)

This commit is contained in:
Amir Raminfar
2024-02-01 12:43:44 -08:00
committed by GitHub
parent 2c398cc227
commit 8677a34087
30 changed files with 518 additions and 254 deletions

View File

@@ -0,0 +1,54 @@
package web
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/amir20/dozzle/internal/auth"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/spf13/afero"
)
func Test_createRoutes_proxy_missing_headers(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: "/",
Authorization: Authorization{
Provider: FORWARD_PROXY,
Authorizer: auth.NewForwardProxyAuth("Remote-User", "Remote-Email", "Remote-Name"),
},
})
req, err := http.NewRequest("GET", "/", nil)
require.NoError(t, err, "NewRequest should not return an error.")
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
assert.Equal(t, 401, rr.Code, "Response code should be 401.")
}
func Test_createRoutes_proxy_happy(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: "/",
Authorization: Authorization{
Provider: FORWARD_PROXY,
Authorizer: auth.NewForwardProxyAuth("Remote-User", "Remote-Email", "Remote-Name"),
},
})
req, err := http.NewRequest("GET", "/", nil)
req.Header.Set("Remote-Email", "amir@test.com")
req.Header.Set("Remote-Name", "Amir")
req.Header.Set("Remote-User", "amir")
require.NoError(t, err, "NewRequest should not return an error.")
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
assert.Equal(t, 200, rr.Code, "Response code should be 200.")
}