fix(api): relax account password validation
This commit is contained in:
@@ -60,7 +60,7 @@ func InitPlatformRoot(database *gorm.DB) error {
|
||||
|
||||
// platformRootPassword 优先读取部署环境传入的 root 初始密码。
|
||||
func platformRootPassword() string {
|
||||
if password := os.Getenv("HEQI_PLATFORM_ROOT_PASSWORD"); len(password) >= 12 {
|
||||
if password := os.Getenv("HEQI_PLATFORM_ROOT_PASSWORD"); common.IsValidAccountPassword(password) {
|
||||
return password
|
||||
}
|
||||
return PlatformRootPassword
|
||||
|
||||
@@ -32,3 +32,19 @@ func TestInitPlatformAccessSeedsRootRole(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlatformRootPassword(t *testing.T) {
|
||||
t.Run("accepts six character environment password", func(t *testing.T) {
|
||||
t.Setenv("HEQI_PLATFORM_ROOT_PASSWORD", "123456")
|
||||
if got := platformRootPassword(); got != "123456" {
|
||||
t.Fatalf("platformRootPassword() = %q, want environment password", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("falls back when environment password is too short", func(t *testing.T) {
|
||||
t.Setenv("HEQI_PLATFORM_ROOT_PASSWORD", "12345")
|
||||
if got := platformRootPassword(); got != PlatformRootPassword {
|
||||
t.Fatalf("platformRootPassword() = %q, want default password", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user