0.38.3
This commit is contained in:
1 parent
8bdec5c757
commit
9e81cce271
23 files changed
+671
-20
No files matched your search
@@ -1054,4 +1054,94 @@ mod tests {
|
||||
assert_eq!(found.len(), 1);
|
||||
assert_eq!(found[0].message.as_deref(), Some("restarting"));
|
||||
}
|
||||
|
||||
fn security_agent(assignment: Assignment) -> Agent {
|
||||
Agent {
|
||||
id: "node1".into(),
|
||||
name: "Node 1".into(),
|
||||
endpoint: "http://10.0.0.2:9876".into(),
|
||||
token: "012345678901234567890123".into(),
|
||||
base_domain: "docker1.lab.local".into(),
|
||||
listener_ids: vec!["http".into()],
|
||||
assignments: vec![assignment],
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn docker_assignment_carries_diagnostics_methods_rate_limit_and_security_headers() {
|
||||
let mut desired = crate::config::demo_config("127.0.0.1:9000".parse().unwrap());
|
||||
let assignment: Assignment = serde_json::from_value(serde_json::json!({
|
||||
"service_key": "container:app:8080/tcp",
|
||||
"hostname": "app",
|
||||
"timing_headers": true,
|
||||
"backend_header": true,
|
||||
"backend_timing_header": true,
|
||||
"cloudflare_client_ip": true,
|
||||
"method_policy": {"mode": "allow", "methods": ["GET", "HEAD", "POST"]},
|
||||
"rate_limit": {"enabled": true, "requests": 50, "window_seconds": 10, "burst": 5,
|
||||
"country_access": {"mode": "block", "countries": ["RU"]}},
|
||||
"security_headers": {"hsts": {"enabled": true, "max_age_seconds": 600}, "nosniff": true, "frame_options": "deny"}
|
||||
}))
|
||||
.unwrap();
|
||||
desired.docker_agents.agents.push(security_agent(assignment));
|
||||
let effective = effective_config(desired, &observation(service(), vec![])).unwrap();
|
||||
let host = effective.vhosts.last().unwrap();
|
||||
assert!(host.timing_headers && host.backend_header && host.backend_timing_header);
|
||||
assert!(host.cloudflare_client_ip);
|
||||
assert_eq!(host.method_policy.methods, ["GET", "HEAD", "POST"]);
|
||||
assert!(host.rate_limit.enabled);
|
||||
assert_eq!(host.rate_limit.requests, 50);
|
||||
assert_eq!(host.rate_limit.country_access.countries, ["RU"]);
|
||||
assert!(host.security_headers.hsts.enabled && host.security_headers.nosniff);
|
||||
assert!(!host.transient_unavailable);
|
||||
let plain = serde_json::to_value(Assignment::default()).unwrap();
|
||||
for key in ["timing_headers", "method_policy", "rate_limit", "security_headers"] {
|
||||
assert!(plain.get(key).is_none(), "{key} must not be stored when unused");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assignment_from_the_removed_login_option_still_loads_and_drops_it() {
|
||||
let assignment: Assignment = serde_json::from_value(serde_json::json!({
|
||||
"service_key": "container:app:8080/tcp",
|
||||
"hostname": "app",
|
||||
"login_vhost_id": "sso"
|
||||
}))
|
||||
.unwrap();
|
||||
assert!(serde_json::to_value(&assignment).unwrap().get("login_vhost_id").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn docker_assignment_basic_auth_protects_the_generated_vhost() {
|
||||
let mut desired = crate::config::demo_config("127.0.0.1:9000".parse().unwrap());
|
||||
let hash = crate::auth::hash_sync("Correct-Horse-12345").unwrap();
|
||||
let assignment: Assignment = serde_json::from_value(serde_json::json!({
|
||||
"service_key": "container:app:8080/tcp",
|
||||
"hostname": "app",
|
||||
"basic_auth": {"enabled": true, "realm": "Ops", "require_tls": false,
|
||||
"users": [{"username": "ops", "password_hash": hash}]}
|
||||
}))
|
||||
.unwrap();
|
||||
desired.docker_agents.agents.push(security_agent(assignment.clone()));
|
||||
let effective = effective_config(desired.clone(), &observation(service(), vec![])).unwrap();
|
||||
let host = effective.vhosts.last().unwrap();
|
||||
assert!(host.basic_auth.enabled && !host.basic_auth.require_tls);
|
||||
assert_eq!(host.basic_auth.users[0].username, "ops");
|
||||
assert_eq!(
|
||||
host.authentication.map(|choice| choice.provider),
|
||||
Some(crate::auth_provider::IdentityProvider::Basic)
|
||||
);
|
||||
let mut settings = desired.docker_agents.clone();
|
||||
settings.validate(&desired.listeners).unwrap();
|
||||
settings.agents[0].assignments[0].basic_auth.as_mut().unwrap().users.clear();
|
||||
let error = settings.validate(&desired.listeners).unwrap_err();
|
||||
assert!(format!("{error:#}").contains("basic.users_required"), "{error:#}");
|
||||
let mut off = assignment;
|
||||
off.basic_auth.as_mut().unwrap().enabled = false;
|
||||
desired.docker_agents.agents[0].assignments[0] = off;
|
||||
let effective = effective_config(desired, &observation(service(), vec![])).unwrap();
|
||||
let host = effective.vhosts.last().unwrap();
|
||||
assert!(!host.basic_auth.enabled && host.authentication.is_none());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user