feat: generate PASSWORD_HASH on the fly
* remove PASSWORD environment variable in favor of PASSWORD_HASH * enhance password validity check server function * update Dockerfile to include building a binary for generating hashed password * update README with comprehensive Docker usage instructions hash generation
This commit is contained in:
39
wg-password/src/main.rs
Normal file
39
wg-password/src/main.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
fn main() {
|
||||
let args = std::env::args();
|
||||
let collect = args.collect::<Vec<String>>();
|
||||
match collect.get(1) {
|
||||
None => panic!("Your password was missing !"),
|
||||
Some(password) => match bcrypt::hash(password, bcrypt::DEFAULT_COST) {
|
||||
Err(err) => eprintln!("{}", err.to_string()),
|
||||
Ok(hash) => println!("PASSWORD_HASH='{hash}'"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use assert_cmd::Command;
|
||||
use predicates::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn test_missing_password() {
|
||||
// Test when no password is provided
|
||||
let mut cmd = Command::cargo_bin("wgpw").unwrap();
|
||||
cmd.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains("Your password was missing !"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_generate_password() {
|
||||
// Test with a valid password
|
||||
let mut cmd = Command::cargo_bin("wgpw").unwrap();
|
||||
cmd.arg("my_password")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("PASSWORD_HASH='"));
|
||||
}
|
||||
|
||||
// fn test_invalid_password() {
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user