fix(metrics): write system metrics on start (#3641)
* fix(metrics): write system metrics on start * add broken basic auth test * refactor: simplify Prometheus instantiation Signed-off-by: Deluan <deluan@navidrome.org> * fix: basic authentication Signed-off-by: Deluan <deluan@navidrome.org> * refactor: move magic strings to constants Signed-off-by: Deluan <deluan@navidrome.org> * refactor: simplify prometheus http handler Signed-off-by: Deluan <deluan@navidrome.org> * add artist metadata to aggregrate sql --------- Signed-off-by: Deluan <deluan@navidrome.org> Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
+28
-10
@@ -219,18 +219,36 @@ var _ = Describe("Auth", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Describe("authHeaderMapper", func() {
|
||||
It("maps the custom header to Authorization header", func() {
|
||||
r := httptest.NewRequest("GET", "/index.html", nil)
|
||||
r.Header.Set(consts.UIAuthorizationHeader, "test authorization bearer")
|
||||
w := httptest.NewRecorder()
|
||||
Describe("tokenFromHeader", func() {
|
||||
It("returns the token when the Authorization header is set correctly", func() {
|
||||
req := httptest.NewRequest("GET", "/", nil)
|
||||
req.Header.Set(consts.UIAuthorizationHeader, "Bearer testtoken")
|
||||
|
||||
authHeaderMapper(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
Expect(r.Header.Get("Authorization")).To(Equal("test authorization bearer"))
|
||||
w.WriteHeader(200)
|
||||
})).ServeHTTP(w, r)
|
||||
token := tokenFromHeader(req)
|
||||
Expect(token).To(Equal("testtoken"))
|
||||
})
|
||||
|
||||
Expect(w.Code).To(Equal(200))
|
||||
It("returns an empty string when the Authorization header is not set", func() {
|
||||
req := httptest.NewRequest("GET", "/", nil)
|
||||
|
||||
token := tokenFromHeader(req)
|
||||
Expect(token).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("returns an empty string when the Authorization header is not a Bearer token", func() {
|
||||
req := httptest.NewRequest("GET", "/", nil)
|
||||
req.Header.Set(consts.UIAuthorizationHeader, "Basic testtoken")
|
||||
|
||||
token := tokenFromHeader(req)
|
||||
Expect(token).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("returns an empty string when the Bearer token is too short", func() {
|
||||
req := httptest.NewRequest("GET", "/", nil)
|
||||
req.Header.Set(consts.UIAuthorizationHeader, "Bearer")
|
||||
|
||||
token := tokenFromHeader(req)
|
||||
Expect(token).To(BeEmpty())
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user