补齐安全码与已验证邮箱二选一授权回归覆盖

This commit is contained in:
xuans committed 2026-10-02 18:36:39 +08:00
1 parent 96656d9b21
commit f965affcaa
8 files changed
+203 -53

No files matched your search

+24
View File
@@ -8,10 +8,34 @@ import (
"path/filepath"
"testing"
"git.pcux.cn/xuans/Smail/services/access"
appcontext "git.pcux.cn/xuans/Smail/utils/context"
log "github.com/sirupsen/logrus"
)
func TestConfigAuthorizationAcceptsEitherRecoveryOption(t *testing.T) {
actor := AuditActor{UserID: "2", Role: string(access.RoleAdmin), RecentAuth: true, ExternalEmailConfigured: true}
if err := DefaultConfigAuthorization(stdcontext.Background(), actor, ConfigOperationUpdate, SectionPlugins); err != nil {
t.Fatalf("email-only admin rejected: %v", err)
}
actor.RecentAuth = false
if err := DefaultConfigAuthorization(stdcontext.Background(), actor, ConfigOperationUpdate, SectionPlugins); !access.IsDenied(err, access.CodeRecentAuthRequired) {
t.Fatalf("email bypassed recent auth: %v", err)
}
actor.RecentAuth = true
if err := DefaultConfigAuthorization(stdcontext.Background(), actor, ConfigOperationRollback, SectionRoot); !access.IsDenied(err, access.CodeAccessDenied) {
t.Fatalf("email granted rollback: %v", err)
}
actor.ExternalEmailConfigured = false
if err := DefaultConfigAuthorization(stdcontext.Background(), actor, ConfigOperationUpdate, SectionPlugins); !access.IsDenied(err, access.CodeRecoveryCodeRequired) {
t.Fatalf("missing recovery option accepted: %v", err)
}
actor.RecoveryCodeConfigured = true
if err := DefaultConfigAuthorization(stdcontext.Background(), actor, ConfigOperationUpdate, SectionPlugins); err != nil {
t.Fatalf("code-only admin rejected: %v", err)
}
}
func TestLogFormatterHandlesMissingLogID(t *testing.T) {
entry := &log.Entry{
Context: &appcontext.Context{Context: stdcontext.Background()},