补齐安全码与已验证邮箱二选一授权回归覆盖
This commit is contained in:
1 parent
96656d9b21
commit
f965affcaa
8 files changed
+203
-53
No files matched your search
@@ -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()},
|
||||
|
||||
@@ -55,12 +55,12 @@ type UpdateRequest struct {
|
||||
}
|
||||
|
||||
type AuditActor struct {
|
||||
UserID string
|
||||
Name string
|
||||
Role string
|
||||
SessionID string
|
||||
RecentAuth bool
|
||||
RecoveryCodeConfigured bool
|
||||
UserID string
|
||||
Name string
|
||||
Role string
|
||||
SessionID string
|
||||
RecentAuth bool
|
||||
RecoveryCodeConfigured bool
|
||||
ExternalEmailConfigured bool
|
||||
}
|
||||
|
||||
|
||||
@@ -162,10 +162,10 @@ func DefaultConfigAuthorization(_ context.Context, actor AuditActor, operation C
|
||||
capability = access.CapabilityDatabaseMigrate
|
||||
}
|
||||
request := access.Request{
|
||||
ActorRole: access.Role(actor.Role),
|
||||
Capability: capability,
|
||||
RecentAuth: actor.RecentAuth,
|
||||
RecoveryCodeConfigured: actor.RecoveryCodeConfigured,
|
||||
ActorRole: access.Role(actor.Role),
|
||||
Capability: capability,
|
||||
RecentAuth: actor.RecentAuth,
|
||||
RecoveryCodeConfigured: actor.RecoveryCodeConfigured,
|
||||
ExternalEmailConfigured: actor.ExternalEmailConfigured,
|
||||
}
|
||||
if operation == ConfigOperationRollback && request.ActorRole == access.RoleSuperAdmin {
|
||||
|
||||
Reference in new issue
Block a user