http: local-login rejects auth_source='oidc' users

This commit is contained in:
2026-05-05 13:37:07 +01:00
parent 86598d6357
commit c62d7d3ac3
2 changed files with 32 additions and 0 deletions
+3
View File
@@ -56,6 +56,9 @@ func (s *Server) authenticateAndSession(w stdhttp.ResponseWriter, r *stdhttp.Req
// existence to a probing attacker. // existence to a probing attacker.
return nil, errInvalidCredentials return nil, errInvalidCredentials
} }
if u.AuthSource == "oidc" {
return nil, errInvalidCredentials
}
if err := auth.VerifyPassword(u.PasswordHash, password); err != nil { if err := auth.VerifyPassword(u.PasswordHash, password); err != nil {
return nil, errInvalidCredentials return nil, errInvalidCredentials
} }
@@ -1,7 +1,9 @@
package http package http
import ( import (
"bytes"
"context" "context"
"encoding/json"
stdhttp "net/http" stdhttp "net/http"
"net/http/cookiejar" "net/http/cookiejar"
"net/http/httptest" "net/http/httptest"
@@ -262,3 +264,30 @@ func TestOIDCLogoutRedirectsToEndSession(t *testing.T) {
t.Errorf("location missing post_logout_redirect_uri: %q", loc) t.Errorf("location missing post_logout_redirect_uri: %q", loc)
} }
} }
func TestLocalLoginRejectsOIDCUser(t *testing.T) {
t.Parallel()
srv, urlBase := newTestServer(t, false)
uid := "u-oidc"
sub := "sub-x"
if err := srv.deps.Store.CreateUser(t.Context(), store.User{
ID: uid, Username: "ouser", PasswordHash: "",
Role: store.RoleOperator, CreatedAt: time.Now().UTC(),
AuthSource: "oidc", OIDCSubject: &sub,
}); err != nil {
t.Fatalf("create: %v", err)
}
body, _ := json.Marshal(map[string]string{
"username": "ouser", "password": "anything",
})
res, err := stdhttp.Post(urlBase+"/api/auth/login",
"application/json", bytes.NewReader(body))
if err != nil {
t.Fatalf("post: %v", err)
}
defer res.Body.Close()
if res.StatusCode != stdhttp.StatusUnauthorized {
t.Errorf("status: got %d want 401", res.StatusCode)
}
}