Files
zeekayandHanzo Dev 21170e3418 Remove the OTP request header that nothing reads
X-Gitea-OTP was declared as an API security scheme and allowed through CORS,
but identity here is Hanzo IAM's: basic auth accepts a token, and no handler
has read a passcode header since local password auth left. TestAPITwoFactor
went with it — it signed in with a username and password to exercise the
header, so it could not pass either.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-10 18:14:39 -07:00

68 lines
2.3 KiB
Go

// Copyright 2026 Hanzo AI, Inc. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"net/http"
"testing"
auth_model "github.com/hanzoai/git/models/auth"
"github.com/hanzoai/git/models/unittest"
user_model "github.com/hanzoai/git/models/user"
"github.com/hanzoai/git/tests"
"github.com/stretchr/testify/assert"
)
func TestBasicAuthWithWebAuthn(t *testing.T) {
defer tests.PrepareTestEnv(t)()
// user1 has no webauthn enrolled, he can request API with basic auth
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
unittest.AssertNotExistsBean(t, &auth_model.WebAuthnCredential{UserID: user1.ID})
req := NewRequest(t, "GET", "/v1/user")
req.SetBasicAuth(user1.Name, "password")
MakeRequest(t, req, http.StatusOK)
// user1 has no webauthn enrolled, he can request git protocol with basic auth
req = NewRequest(t, "GET", "/user2/repo1/info/refs")
req.SetBasicAuth(user1.Name, "password")
MakeRequest(t, req, http.StatusOK)
// user1 has no webauthn enrolled, he can request container package with basic auth
req = NewRequest(t, "GET", "/v2/token")
req.SetBasicAuth(user1.Name, "password")
resp := MakeRequest(t, req, http.StatusOK)
type tokenResponse struct {
Token string `json:"token"`
}
tokenParsed := DecodeJSON(t, resp, &tokenResponse{})
assert.NotEmpty(t, tokenParsed.Token)
// user32 has webauthn enrolled, he can't request API with basic auth
user32 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 32})
unittest.AssertExistsAndLoadBean(t, &auth_model.WebAuthnCredential{UserID: user32.ID})
req = NewRequest(t, "GET", "/v1/user")
req.SetBasicAuth(user32.Name, "notpassword")
resp = MakeRequest(t, req, http.StatusUnauthorized)
type userResponse struct {
Message string `json:"message"`
}
userParsed := DecodeJSON(t, resp, &userResponse{})
assert.Equal(t, "basic authorization is not allowed while WebAuthn enrolled", userParsed.Message)
// user32 has webauthn enrolled, he can't request git protocol with basic auth
req = NewRequest(t, "GET", "/user2/repo1/info/refs")
req.SetBasicAuth(user32.Name, "notpassword")
MakeRequest(t, req, http.StatusUnauthorized)
// user32 has webauthn enrolled, he can't request container package with basic auth
req = NewRequest(t, "GET", "/v2/token")
req.SetBasicAuth(user1.Name, "notpassword")
MakeRequest(t, req, http.StatusUnauthorized)
}