feat: complete Epic 1 production foundation
This commit is contained in:
@@ -5,9 +5,11 @@ use crank_config::{
|
||||
parse_migrator, parse_process,
|
||||
};
|
||||
|
||||
const TEST_MASTER_KEY: &str = "test-master-key-00000000000000000000000000000000";
|
||||
|
||||
fn required_admin() -> BTreeMap<String, String> {
|
||||
[
|
||||
("CRANK_MASTER_KEY", "master"),
|
||||
("CRANK_MASTER_KEY", TEST_MASTER_KEY),
|
||||
("CRANK_SESSION_SECRET", "session"),
|
||||
("CRANK_PASSWORD_PEPPER", "pepper"),
|
||||
("CRANK_BOOTSTRAP_ADMIN_EMAIL", "owner@example.test"),
|
||||
@@ -19,7 +21,7 @@ fn required_admin() -> BTreeMap<String, String> {
|
||||
}
|
||||
|
||||
fn required_mcp() -> BTreeMap<String, String> {
|
||||
[("CRANK_MASTER_KEY", "master")]
|
||||
[("CRANK_MASTER_KEY", TEST_MASTER_KEY)]
|
||||
.into_iter()
|
||||
.map(|(key, value)| (key.to_owned(), value.to_owned()))
|
||||
.collect()
|
||||
@@ -106,9 +108,9 @@ fn source_for(
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn registry_covers_exactly_the_57_observed_runtime_names() {
|
||||
fn registry_covers_exactly_the_59_observed_runtime_names() {
|
||||
let registry = field_registry();
|
||||
assert_eq!(registry.len(), 57);
|
||||
assert_eq!(registry.len(), 59);
|
||||
let unique = registry
|
||||
.iter()
|
||||
.map(|field| field.env_name)
|
||||
@@ -148,9 +150,10 @@ fn defaults_are_preserved_and_invalid_values_never_fall_back() {
|
||||
|
||||
for (name, value) in [
|
||||
("POSTGRES_PORT", "bad"),
|
||||
("CRANK_MASTER_KEY", "too-short"),
|
||||
("CRANK_SESSION_TTL_HOURS", "bad"),
|
||||
("CRANK_ADMIN_RATE_LIMIT_RPS", "bad"),
|
||||
("CRANK_TRUST_FORWARDED_HEADERS", "tru"),
|
||||
("CRANK_TRUSTED_PROXY_IPS", "not-an-ip"),
|
||||
] {
|
||||
let mut vars = required_admin();
|
||||
vars.insert(name.to_owned(), value.to_owned());
|
||||
@@ -309,6 +312,24 @@ fn process_specific_fields_and_zero_ports_fail_closed() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn production_admin_non_loopback_requires_https_base_url() {
|
||||
let mut vars = required_admin();
|
||||
vars.insert("CRANK_ENVIRONMENT".into(), "production".into());
|
||||
vars.insert("CRANK_ADMIN_BIND".into(), "0.0.0.0:3001".into());
|
||||
vars.insert("CRANK_BASE_URL".into(), "http://crank.example.test".into());
|
||||
let error = parse_process(ProcessKind::AdminApi, ConfigSource::from_utf8(vars)).unwrap_err();
|
||||
assert!(error.diagnostics().iter().any(|item| {
|
||||
item.code == DiagnosticCode::UnsafeCombination && item.field == "admin.exposure.tls"
|
||||
}));
|
||||
|
||||
let mut safe = required_admin();
|
||||
safe.insert("CRANK_ENVIRONMENT".into(), "production".into());
|
||||
safe.insert("CRANK_ADMIN_BIND".into(), "0.0.0.0:3001".into());
|
||||
safe.insert("CRANK_BASE_URL".into(), "https://crank.example.test".into());
|
||||
parse_process(ProcessKind::AdminApi, ConfigSource::from_utf8(safe)).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn whitespace_secrets_and_consumer_invalid_values_fail_in_the_leaf_parser() {
|
||||
for name in [
|
||||
@@ -355,6 +376,7 @@ fn cross_field_and_typed_boundaries_fail_closed() {
|
||||
("POSTGRES_MAX_CONNECTIONS", "1025"),
|
||||
("CRANK_ADMIN_RATE_LIMIT_RPS", "100001"),
|
||||
("CRANK_ADMIN_RATE_LIMIT_BURST", "0"),
|
||||
("CRANK_OUTBOUND_MAX_REQUEST_BYTES", "67108865"),
|
||||
("CRANK_OUTBOUND_MAX_RESPONSE_BYTES", "67108865"),
|
||||
("OTEL_BSP_SCHEDULE_DELAY", "bad"),
|
||||
("OTEL_BSP_EXPORT_TIMEOUT", "300001"),
|
||||
@@ -406,11 +428,12 @@ fn inclusive_edges_and_legacy_boolean_spellings_are_explicit() {
|
||||
("POSTGRES_MAX_CONNECTIONS".into(), "1024".into()),
|
||||
("POSTGRES_MIN_CONNECTIONS".into(), "0".into()),
|
||||
("CRANK_RUNTIME_MAX_CONCURRENT_UNARY".into(), "1".into()),
|
||||
("CRANK_OUTBOUND_MAX_REQUEST_BYTES".into(), "67108864".into()),
|
||||
(
|
||||
"CRANK_OUTBOUND_MAX_RESPONSE_BYTES".into(),
|
||||
"67108864".into(),
|
||||
),
|
||||
("CRANK_TRUST_FORWARDED_HEADERS".into(), "yes".into()),
|
||||
("CRANK_TRUSTED_PROXY_IPS".into(), "127.0.0.1,::1".into()),
|
||||
("CRANK_DEMO_SEED".into(), "off".into()),
|
||||
]);
|
||||
let config = parse_process(ProcessKind::AdminApi, ConfigSource::from_utf8(vars)).unwrap();
|
||||
@@ -419,7 +442,7 @@ fn inclusive_edges_and_legacy_boolean_spellings_are_explicit() {
|
||||
assert_eq!(admin.database.pool.max_connections, 1024);
|
||||
assert_eq!(admin.database.pool.min_connections, 0);
|
||||
assert_eq!(admin.runtime.max_concurrent_unary, 1);
|
||||
assert!(admin.trust_forwarded_headers);
|
||||
assert_eq!(admin.trusted_proxy_ips.len(), 2);
|
||||
assert!(!admin.demo_seed);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user