Something went wrong. Try again.
An OIDC provider for AT Protocol OAuth. Rust port of apenwarr/atlogin. forked from quilling.dev/ratlogin
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596use crate::support::TestResult;use std::process::{Command, Output};
fn command(args: &[&str]) -> Command { let mut command = Command::new(env!("CARGO_BIN_EXE_ratlogin")); command .args(args) .env_remove("RATLOGIN_CONFIG") .env_remove("RATLOGIN_STATE_DIR") .env_remove("RUST_LOG"); command}
fn ratlogin(args: &[&str]) -> std::io::Result<Output> { command(args).output()}
#[test]fn the_binary_keeps_stdout_for_program_output_and_fails_with_a_message() -> TestResult { let dir = tempfile::tempdir()?; let state_dir = dir.path().to_str().ok_or("utf8 path")?;
let init = ratlogin(&["init", "--state-dir", state_dir])?; assert!(init.status.success(), "{init:?}"); assert!(init.stdout.is_empty(), "{init:?}"); assert!( String::from_utf8(init.stderr)?.contains("state initialized"), "the log goes to stderr" );
let add = ratlogin(&[ "add-client", "--state-dir", state_dir, "--id", "app", "--redirect-uri", "https://app.example/cb", ])?; assert!(add.status.success(), "{add:?}"); let secret = String::from_utf8(add.stdout)?; assert_eq!( secret.trim_end().len(), ratlogin::database::random_token().len(), "only the secret: {secret:?}" ); assert!(secret.ends_with('\n') && !secret.trim_end().contains(char::is_whitespace));
let failed = ratlogin(&[ "serve", "--state-dir", state_dir, "--config", "/nonexistent/config.toml", ])?; assert_eq!(failed.status.code(), Some(1), "{failed:?}"); assert!(failed.stdout.is_empty(), "{failed:?}"); let message = String::from_utf8(failed.stderr)?; assert!( message.contains("ratlogin: cannot read config /nonexistent/config.toml"), "{message}" );
let config = dir.path().join("config.toml"); std::fs::write( &config, format!( "issuer = \"https://ratlogin.test\"\nlisten = \"127.0.0.1:0\"\nclient_name = \"Test\"\n\ [[clients]]\nid = \"app\"\nsecret = \"{}\"\nredirect_uris = [\"https://app.test/cb\"]\n", "s".repeat(32) ), )?; let roots = dir.path().join("roots.pem"); std::fs::write( &roots, "-----BEGIN CERTIFICATE-----\nAAAA\n-----END CERTIFICATE-----\n", )?; let unusable = command(&[ "serve", "--state-dir", state_dir, "--config", config.to_str().ok_or("utf8 path")?, ]) .env("SSL_CERT_FILE", &roots) .env_remove("SSL_CERT_DIR") .output()?; assert_eq!(unusable.status.code(), Some(1), "{unusable:?}"); let message = String::from_utf8(unusable.stderr)?; assert!( message.contains("ratlogin: cannot build the outbound client"), "a root store with no usable certificate stops the provider: {message}" ); Ok(())}