Prevent starting up if the JWT secret is not given
Similarly, don't create the admin if the password is not given
This commit is contained in:
committed by
nitnelave
parent
1f26262e13
commit
f417427635
@@ -3,6 +3,8 @@ use std::env::var;
|
||||
|
||||
pub const DB_KEY: &str = "LLDAP_DATABASE_URL";
|
||||
pub const PRIVATE_KEY_SEED: &str = "LLDAP_KEY_SEED";
|
||||
pub const JWT_SECRET: &str = "LLDAP_JWT_SECRET";
|
||||
pub const LDAP_USER_PASSWORD: &str = "LLDAP_LDAP_USER_PASS";
|
||||
|
||||
pub fn database_url() -> String {
|
||||
let url = var(DB_KEY).ok();
|
||||
|
||||
@@ -43,14 +43,13 @@ const MAX_HEALTHCHECK_ATTEMPS: u8 = 10;
|
||||
|
||||
impl LLDAPFixture {
|
||||
pub fn new() -> Self {
|
||||
let mut cmd = create_lldap_command();
|
||||
cmd.arg("run");
|
||||
cmd.arg("--verbose");
|
||||
let child = cmd.spawn().expect("Unable to start server");
|
||||
let child = create_lldap_command("run")
|
||||
.arg("--verbose")
|
||||
.spawn()
|
||||
.expect("Unable to start server");
|
||||
let mut started = false;
|
||||
for _ in 0..MAX_HEALTHCHECK_ATTEMPS {
|
||||
let status = create_lldap_command()
|
||||
.arg("healthcheck")
|
||||
let status = create_lldap_command("healthcheck")
|
||||
.status()
|
||||
.expect("healthcheck fail");
|
||||
if status.success() {
|
||||
@@ -229,7 +228,7 @@ pub fn new_id(prefix: Option<&str>) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_lldap_command() -> Command {
|
||||
fn create_lldap_command(subcommand: &str) -> Command {
|
||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("cargo bin not found");
|
||||
// This gives us the absolute path of the repo base instead of running it in server/
|
||||
let path = canonicalize("..").expect("canonical path");
|
||||
@@ -237,5 +236,10 @@ fn create_lldap_command() -> Command {
|
||||
cmd.current_dir(path);
|
||||
cmd.env(env::DB_KEY, db_url);
|
||||
cmd.env(env::PRIVATE_KEY_SEED, "Random value");
|
||||
cmd.env(env::JWT_SECRET, "Random value");
|
||||
cmd.env(env::LDAP_USER_PASSWORD, "password");
|
||||
cmd.arg(subcommand);
|
||||
cmd.arg("--config-file=/dev/null");
|
||||
cmd.arg("--server-key-file=''");
|
||||
cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user