mirror of
https://github.com/traefik/traefik.git
synced 2026-06-09 00:32:27 -04:00
Remove map lookup making the basic auth notFoundSecret empty
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Build and Publish Documentation / Doc Process (push) Has been cancelled
Build experimental image on branch / build-webui (push) Has been cancelled
Build experimental image on branch / Build experimental image on branch (push) Has been cancelled
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Build and Publish Documentation / Doc Process (push) Has been cancelled
Build experimental image on branch / build-webui (push) Has been cancelled
Build experimental image on branch / Build experimental image on branch (push) Has been cancelled
This commit is contained in:
parent
e4b2c648bf
commit
8c4fc89579
2 changed files with 12 additions and 1 deletions
|
|
@ -44,7 +44,7 @@ func NewBasic(ctx context.Context, next http.Handler, authConfig dynamic.BasicAu
|
|||
// To prevent timing attacks, we need to compute a hash even if the user is not found.
|
||||
// We assume it to be safe only when the users hashes are all from the same algorithm,
|
||||
// so we can pick the first one as a random hash to compute.
|
||||
notFoundSecret := users[slices.Collect(maps.Values(users))[0]]
|
||||
notFoundSecret := slices.Collect(maps.Values(users))[0]
|
||||
|
||||
ba := &basicAuth{
|
||||
next: next,
|
||||
|
|
|
|||
|
|
@ -14,6 +14,17 @@ import (
|
|||
"github.com/traefik/traefik/v2/pkg/testhelpers"
|
||||
)
|
||||
|
||||
func TestNewBasicNotFoundSecretIsSet(t *testing.T) {
|
||||
auth := dynamic.BasicAuth{
|
||||
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
||||
}
|
||||
middleware, err := NewBasic(t.Context(), nil, auth, "authName")
|
||||
require.NoError(t, err)
|
||||
|
||||
ba := middleware.(*basicAuth)
|
||||
assert.Equal(t, "$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", ba.notFoundSecret)
|
||||
}
|
||||
|
||||
func TestBasicAuthFail(t *testing.T) {
|
||||
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "traefik")
|
||||
|
|
|
|||
Loading…
Reference in a new issue