From 322c867e945c5255d29d6c232ad708f48ba44fc1 Mon Sep 17 00:00:00 2001 From: Dietrich Date: Sun, 18 Apr 2021 10:29:09 +0200 Subject: [PATCH] Fix: real secret instead of censored in .env --- src/lib.rs | 2 +- tests/integration-tests.rs | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7402241..5044571 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -208,7 +208,7 @@ impl ServerConfig { "# If it is changed all existing passwords are invalid.\n" ) .to_owned(), - format!("PSLINK_SECRET=\"{}\"\n", self.secret), + format!("PSLINK_SECRET=\"{}\"\n", self.secret.secret), ] } } diff --git a/tests/integration-tests.rs b/tests/integration-tests.rs index d9ee3f6..e6d226f 100644 --- a/tests/integration-tests.rs +++ b/tests/integration-tests.rs @@ -55,10 +55,25 @@ fn test_generate_env() { assert!(dbfile.exists(), "No database-file was created!"); let envfile = std::fs::File::open(envfile).unwrap(); - let mut envcontent = std::io::BufReader::new(envfile).lines(); + let envcontent: Vec> = std::io::BufReader::new(envfile).lines().collect(); assert!( - envcontent.any(|s| s.as_ref().unwrap().starts_with("PSLINK_PORT=")), - "Failed to find DATABASE_URL in the generated .env file." + envcontent + .iter() + .any(|s| s.as_ref().unwrap().starts_with("PSLINK_PORT=")), + "Failed to find PSLINK_PORT in the generated .env file." + ); + assert!( + envcontent + .iter() + .any(|s| s.as_ref().unwrap().starts_with("PSLINK_SECRET=")), + "Failed to find PSLINK_SECRET in the generated .env file." + ); + assert!( + !envcontent.iter().any(|s| { + let r = s.as_ref().unwrap().contains("***SECRET***"); + r + }), + "It seems that a censored secret was used in the .env file." ); let output = test_bin::get_test_bin("pslink") .args(&["generate-env"])