mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-17 23:42:52 +00:00
fix: disallow basic authorization when security keys are enrolled
- This unifies the security behavior of enrolling security keys with enrolling TOTP as a 2FA method. When TOTP is enrolled, you cannot use basic authorization (user:password) to make API request on behalf of the user, this is now also the case when you enroll security keys. - The usage of access tokens are the only method to make API requests on behalf of the user when a 2FA method is enrolled for the user. - Integration test added.
This commit is contained in:
parent
b70196653f
commit
e6bbecb02d
2 changed files with 33 additions and 0 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/pquerna/otp/totp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -58,3 +59,24 @@ func TestAPITwoFactor(t *testing.T) {
|
|||
req.Header.Set("X-Forgejo-OTP", passcode)
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
}
|
||||
|
||||
func TestAPIWebAuthn(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 32})
|
||||
unittest.AssertExistsAndLoadBean(t, &auth_model.WebAuthnCredential{UserID: user.ID})
|
||||
|
||||
req := NewRequest(t, "GET", "/api/v1/user")
|
||||
req.SetBasicAuth(user.Name, "notpassword")
|
||||
|
||||
resp := MakeRequest(t, req, http.StatusUnauthorized)
|
||||
|
||||
type userResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
var userParsed userResponse
|
||||
|
||||
DecodeJSON(t, resp, &userParsed)
|
||||
|
||||
assert.EqualValues(t, "Basic authorization is not allowed while having security keys enrolled", userParsed.Message)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue