torrust-tracker icon indicating copy to clipboard operation
torrust-tracker copied to clipboard

Enable test `should_fail_with_ssl_enabled_and_bad_ssl_config`

Open josecelano opened this issue 2 years ago • 2 comments

THe following test was ignored by @da2ce7 but it seems to pass.

#[tokio::test]
#[ignore]
#[should_panic = "Could not receive bind_address."]
async fn should_fail_with_ssl_enabled_and_bad_ssl_config() {
    let mut test_env = stopped_test_environment(configuration::ephemeral());

    let cfg = test_env.config_mut();

    cfg.ssl_enabled = true;
    cfg.ssl_key_path = Some("bad key path".to_string());
    cfg.ssl_cert_path = Some("bad cert path".to_string());

    test_env.start().await;
}

josecelano avatar Nov 24 '23 10:11 josecelano

The test was ignored because it's failing on the GitHub runner:

failures:

---- servers::api::v1::contract::configuration::should_fail_with_ssl_enabled_and_bad_ssl_config stdout ----
---- servers::api::v1::contract::configuration::should_fail_with_ssl_enabled_and_bad_ssl_config stderr ----
panic did not contain expected string
      panic message: `"`spawn_local` called from outside of a `task::LocalSet`"`,
 expected substring: `"Could not receive bind_address."`
thread 'main' panicked at /home/runner/work/torrust-tracker/torrust-tracker/src/servers/apis/server.rs:216:9:
`spawn_local` called from outside of a `task::LocalSet`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Anyway, I don't like the final panic message: Could not receive bind_address. I think the Launcher should catch the error and return the exact reason why the service could not be launched.

This is part of the ApiServer<Stopped>::start function:

        let task = tokio::spawn(async move {
            let (bind_addr, server) = Launcher::start(&configuration, tracker, shutdown_signal(shutdown_receiver));

            addr_sender.send(bind_addr).expect("Could not return SocketAddr.");

            server.await;
        });

What is happening is Launcher::start is panicking here:

            let tls_config = RustlsConfig::from_pem_file(ssl_cert_path, ssl_key_path)
                .await
                .expect("Could not read tls cert.");

So the line addr_sender.send(bind_addr).expect("Could not return SocketAddr."); is never reached. Maybe the channel could send something like Resultt<SocketAddr, LaunchingError>. In the case that tls config cannot be initialized we could return that error.

enum LaunchingError {
  InvalidCertOrKeyPath
}

josecelano avatar Dec 22 '23 17:12 josecelano

Hi @da2ce7 after merging https://github.com/torrust/torrust-tracker/pull/553 now it's also failing locally.

josecelano avatar Dec 26 '23 16:12 josecelano