Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,41 @@ bind = "127.0.0.1"
assert_eq!(config.api.bind, "[::]");
}

#[test]
fn test_docker_deployment_forces_api_bind_from_toml() {
let _lock = env_test_lock().lock();
let _env = EnvGuard::new();

unsafe {
std::env::set_var("SPACEBOT_DEPLOYMENT", "docker");
}

let toml = r#"
[api]
bind = "127.0.0.1"
"#;

let parsed: TomlConfig = toml::from_str(toml).expect("failed to parse test TOML");
let config = Config::from_toml(parsed, PathBuf::from(".")).expect("failed to build Config");

assert_eq!(config.api.bind, "0.0.0.0");
}

#[test]
fn test_docker_deployment_forces_api_bind_from_env_defaults() {
let _lock = env_test_lock().lock();
let _env = EnvGuard::new();

unsafe {
std::env::set_var("SPACEBOT_DEPLOYMENT", "docker");
}

let config = Config::load_from_env(&Config::default_instance_dir())
.expect("failed to load config from env");

assert_eq!(config.api.bind, "0.0.0.0");
}

/// Helper to build a minimal `SlackConfig` for permission tests.
fn slack_config_with_dm_users(dm_allowed_users: Vec<String>) -> SlackConfig {
SlackConfig {
Expand Down
1 change: 1 addition & 0 deletions src/config/toml_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub(super) fn default_api_bind() -> String {
pub(super) fn hosted_api_bind(bind: String) -> String {
match std::env::var("SPACEBOT_DEPLOYMENT") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For docker, do we want 0.0.0.0 (matches docs/docker.md + avoids IPv6-disabled hosts) instead of [::]? Something like:

Suggested change
match std::env::var("SPACEBOT_DEPLOYMENT") {
match std::env::var("SPACEBOT_DEPLOYMENT") {
Ok(deployment) if deployment.eq_ignore_ascii_case("hosted") => "[::]".into(),
Ok(deployment) if deployment.eq_ignore_ascii_case("docker") => "0.0.0.0".into(),
_ => bind,
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decision to use 0.0.0.0 is, like you said, because not every Cloud host offers IPv6. If the user wants IPv6 they can override the deployment ourselves. I can't make any assumptions about the hosted infrastructure, but I do know a lot about Docker.

Ok(deployment) if deployment.eq_ignore_ascii_case("hosted") => "[::]".into(),
Ok(deployment) if deployment.eq_ignore_ascii_case("docker") => "0.0.0.0".into(),
_ => bind,
}
}
Expand Down