mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-27 13:37:14 +00:00
fix(settings): require re-2FA confirmation for sensitive setting changes (#5610)
* fix(settings): require server-side 2fa for sensitive changes * fix(lint): group third-party imports separately from local (goimports) golangci-lint goimports flagged setting.go and setting_security_test.go because xlzd/gotp and gorm.io/gorm were mixed into the github.com/mhsanaei/3x-ui local-prefix group. Move them into the third-party group so the local imports stand alone.
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/xlzd/gotp"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
||||
)
|
||||
@@ -100,3 +102,22 @@ func TestSanitizePublicHTTPURLBlocksPrivateAddressUnlessAllowed(t *testing.T) {
|
||||
t.Fatalf("allowPrivate result = %q, %v", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifyTwoFactorCode(t *testing.T) {
|
||||
setupSettingTestDB(t)
|
||||
s := &SettingService{}
|
||||
if err := s.saveSetting("twoFactorEnable", "true"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const token = "JBSWY3DPEHPK3PXP"
|
||||
if err := s.saveSetting("twoFactorToken", token); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := s.VerifyTwoFactorCode(gotp.NewDefaultTOTP(token).Now()); err != nil {
|
||||
t.Fatalf("valid code rejected: %v", err)
|
||||
}
|
||||
if err := s.VerifyTwoFactorCode("000000"); err == nil {
|
||||
t.Fatal("invalid code accepted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user