fix: remove minimum length requirement for bootstrap admin password
This commit is contained in:
1 parent
386d15cde2
commit
f5ba6cb255
3 files changed
+34
-2
No files matched your search
@@ -86,7 +86,9 @@ def validate_config(config, mode):
|
||||
value = str(api.get(key, ""))
|
||||
if not value or any(marker in value.upper() for marker in ("CHANGE_ME", "GENERATE_", "REPLACE-WITH")):
|
||||
fail("Missing/placeholder setting: " + key)
|
||||
for key, minimum in (("AUTH_PASSWORD_PEPPER", 32), ("CREDENTIAL_ENCRYPTION_KEY", 32), ("ADMIN_PASSWORD", 16)):
|
||||
if not str(api["ADMIN_PASSWORD"]).strip():
|
||||
fail("ADMIN_PASSWORD must not be blank.")
|
||||
for key, minimum in (("AUTH_PASSWORD_PEPPER", 32), ("CREDENTIAL_ENCRYPTION_KEY", 32)):
|
||||
if len(str(api[key])) < minimum:
|
||||
fail(key + " is too short (minimum " + str(minimum) + " characters).")
|
||||
if api["AUTH_PASSWORD_PEPPER"] == api["CREDENTIAL_ENCRYPTION_KEY"]:
|
||||
|
||||
@@ -74,6 +74,34 @@ class DeploymentTests(unittest.TestCase):
|
||||
def test_tunnel_config(self):
|
||||
deploy.validate_config(configuration(), "tunnel")
|
||||
|
||||
def test_admin_password_has_no_minimum_length(self):
|
||||
for mode in ("tunnel", "https"):
|
||||
for password in ("x", "Test7!", "Qa-Test42!"):
|
||||
with self.subTest(mode=mode, length=len(password)):
|
||||
cfg = configuration()
|
||||
api = cfg["services"]["moyi-api"]["environment"]
|
||||
api["ADMIN_PASSWORD"] = password
|
||||
api["AUTH_SECURE_COOKIE"] = "true" if mode == "https" else "false"
|
||||
deploy.validate_config(cfg, mode)
|
||||
|
||||
def test_admin_password_still_rejects_empty_blank_and_placeholder(self):
|
||||
for password in ("", " ", "\t\r\n", "GENERATE_ADMIN_PASSWORD"):
|
||||
with self.subTest(password=password):
|
||||
cfg = configuration()
|
||||
cfg["services"]["moyi-api"]["environment"]["ADMIN_PASSWORD"] = password
|
||||
with self.assertRaisesRegex(ValueError, "ADMIN_PASSWORD"):
|
||||
deploy.validate_config(cfg, "tunnel")
|
||||
|
||||
def test_cryptographic_secrets_keep_minimum_length(self):
|
||||
for key in ("AUTH_PASSWORD_PEPPER", "CREDENTIAL_ENCRYPTION_KEY"):
|
||||
with self.subTest(key=key):
|
||||
cfg = configuration()
|
||||
cfg["services"]["moyi-api"]["environment"][key] = "s" * 31
|
||||
with self.assertRaisesRegex(ValueError, key + " is too short"):
|
||||
deploy.validate_config(cfg, "tunnel")
|
||||
cfg["services"]["moyi-api"]["environment"][key] = "s" * 32
|
||||
deploy.validate_config(cfg, "tunnel")
|
||||
|
||||
def test_reject_placeholder(self):
|
||||
cfg = configuration()
|
||||
cfg["services"]["moyi-api"]["environment"]["MOYI_REDIS_HOST"] = "CHANGE_ME_TAIR_HOST"
|
||||
@@ -146,7 +174,7 @@ class DeploymentTests(unittest.TestCase):
|
||||
"CHANGE_ME_RDS_HOST": "rds.internal", "CHANGE_ME_RDS_PASSWORD": "test-db-$value#literal",
|
||||
"CHANGE_ME_TAIR_HOST": "redis.internal", "CHANGE_ME_TAIR_PASSWORD": "test-cache-$value#literal",
|
||||
"GENERATE_AUTH_PEPPER": "p" * 64, "GENERATE_CREDENTIAL_KEY": "k" * 64,
|
||||
"GENERATE_ADMIN_PASSWORD": "test-only-admin-password",
|
||||
"GENERATE_ADMIN_PASSWORD": "Qa-Test42!",
|
||||
}
|
||||
for before, after in replacements.items():
|
||||
content = content.replace(before, after)
|
||||
@@ -160,6 +188,7 @@ class DeploymentTests(unittest.TestCase):
|
||||
api = cfg["services"]["moyi-api"]["environment"]
|
||||
self.assertEqual(api["MOYI_REDIS_PASSWORD"], "test-cache-$value#literal")
|
||||
self.assertEqual(api["SPRING_DATASOURCE_PASSWORD"], "test-db-$value#literal")
|
||||
self.assertEqual(api["ADMIN_PASSWORD"], "Qa-Test42!")
|
||||
self.assertNotIn("MOYI_REDIS_PASSWORD", cfg["services"]["frontend"].get("environment", {}))
|
||||
self.assertNotIn("OSS_ACCESS_KEY_SECRET", api)
|
||||
if mode == "https":
|
||||
|
||||
Reference in new issue
Block a user