This commit is contained in:
Firstyear 2021-10-10 08:44:58 +10:00 committed by GitHub
parent c62b39c338
commit a09c1bc169
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 34 deletions

View file

@ -14,24 +14,39 @@ fn main() {
Some(outdir) => outdir,
};
let comp_dir = PathBuf::from(outdir)
.ancestors()
.skip(2)
.next()
.map(|p| p.join("completions"))
.expect("Unable to process completions path");
if !comp_dir.exists() {
std::fs::create_dir(&comp_dir).expect("Unable to create completions dir");
}
SshAuthorizedOpt::clap().gen_completions(
"kanidm_ssh_authorizedkeys_direct",
Shell::Bash,
outdir.clone(),
comp_dir.clone(),
);
SshAuthorizedOpt::clap().gen_completions(
"kanidm_ssh_authorizedkeys_direct",
Shell::Zsh,
outdir.clone(),
comp_dir.clone(),
);
BadlistProcOpt::clap().gen_completions(
"kanidm_badlist_preprocess",
Shell::Bash,
outdir.clone(),
comp_dir.clone(),
);
BadlistProcOpt::clap().gen_completions(
"kanidm_badlist_preprocess",
Shell::Zsh,
comp_dir.clone(),
);
BadlistProcOpt::clap().gen_completions("kanidm_badlist_preprocess", Shell::Zsh, outdir.clone());
KanidmClientOpt::clap().gen_completions("kanidm", Shell::Bash, outdir.clone());
KanidmClientOpt::clap().gen_completions("kanidm", Shell::Zsh, outdir);
KanidmClientOpt::clap().gen_completions("kanidm", Shell::Bash, comp_dir.clone());
KanidmClientOpt::clap().gen_completions("kanidm", Shell::Zsh, comp_dir);
}

View file

@ -375,7 +375,7 @@ impl AccountOpt {
}
AccountPosix::SetPassword(aopt) => {
let client = aopt.copt.to_client();
let password = match password_prompt("Enter new unit (sudo) password: ") {
let password = match password_prompt("Enter new posix (sudo) password: ") {
Some(v) => v,
None => {
println!("Passwords do not match");

View file

@ -23,33 +23,44 @@ fn main() {
Some(outdir) => outdir,
};
let comp_dir = PathBuf::from(outdir)
.ancestors()
.skip(2)
.next()
.map(|p| p.join("completions"))
.expect("Unable to process completions path");
if !comp_dir.exists() {
std::fs::create_dir(&comp_dir).expect("Unable to create completions dir");
}
SshAuthorizedOpt::clap().gen_completions(
"kanidm_ssh_authorizedkeys",
Shell::Bash,
outdir.clone(),
comp_dir.clone(),
);
SshAuthorizedOpt::clap().gen_completions(
"kanidm_ssh_authorizedkeys",
Shell::Zsh,
outdir.clone(),
comp_dir.clone(),
);
CacheInvalidateOpt::clap().gen_completions(
"kanidm_cache_invalidate",
Shell::Bash,
outdir.clone(),
comp_dir.clone(),
);
CacheInvalidateOpt::clap().gen_completions(
"kanidm_cache_invalidate",
Shell::Zsh,
outdir.clone(),
comp_dir.clone(),
);
CacheClearOpt::clap().gen_completions("kanidm_cache_clear", Shell::Bash, outdir.clone());
CacheClearOpt::clap().gen_completions("kanidm_cache_clear", Shell::Zsh, outdir.clone());
CacheClearOpt::clap().gen_completions("kanidm_cache_clear", Shell::Bash, comp_dir.clone());
CacheClearOpt::clap().gen_completions("kanidm_cache_clear", Shell::Zsh, comp_dir.clone());
UnixdStatusOpt::clap().gen_completions("kanidm_unixd_status", Shell::Bash, outdir.clone());
UnixdStatusOpt::clap().gen_completions("kanidm_unixd_status", Shell::Zsh, outdir);
UnixdStatusOpt::clap().gen_completions("kanidm_unixd_status", Shell::Bash, comp_dir.clone());
UnixdStatusOpt::clap().gen_completions("kanidm_unixd_status", Shell::Zsh, comp_dir);
println!("cargo:rerun-if-env-changed=KANIDM_BUILD_PROFILE");
let profile = env::var("KANIDM_BUILD_PROFILE").unwrap_or_else(|_| "developer".to_string());

View file

@ -18,11 +18,6 @@ include!("src/server/opt.rs");
include!("../profiles/syntax.rs");
fn main() {
let outdir = match env::var_os("OUT_DIR") {
None => return,
Some(outdir) => outdir,
};
// check to see if the rust version matches the rust minimum version we require for this build
let rust_minver = match read_to_string("../RUST_MSRV") {
Ok(value) => value,
@ -35,8 +30,26 @@ fn main() {
panic!("This crate requires rustc >= {}, quitting.", rust_minver);
}
KanidmdOpt::clap().gen_completions("kanidmd", Shell::Bash, outdir.clone());
KanidmdOpt::clap().gen_completions("kanidmd", Shell::Zsh, outdir);
let outdir = match env::var_os("OUT_DIR") {
None => return,
Some(outdir) => outdir,
};
// Will be the form /Volumes/ramdisk/rs/debug/build/kanidm-8aadc4b0821e9fe7/out
// We want to get to /Volumes/ramdisk/rs/debug/completions
let comp_dir = PathBuf::from(outdir)
.ancestors()
.skip(2)
.next()
.map(|p| p.join("completions"))
.expect("Unable to process completions path");
if !comp_dir.exists() {
std::fs::create_dir(&comp_dir).expect("Unable to create completions dir");
}
KanidmdOpt::clap().gen_completions("kanidmd", Shell::Bash, comp_dir.clone());
KanidmdOpt::clap().gen_completions("kanidmd", Shell::Zsh, comp_dir);
// transform any requested paths for our server. We do this by reading
// our profile that we have been provided.

View file

@ -1873,10 +1873,13 @@ mod tests {
});
}
pub const DB_BACKUP_FILE_NAME: &'static str = "./.backup_test.json";
#[test]
fn test_be_backup_restore() {
let db_backup_file_name = format!(
"{}/.backup_test.json",
option_env!("OUT_DIR").unwrap_or("/tmp")
);
eprintln!(" ⚠️ {}", db_backup_file_name);
run_test!(|be: &mut BackendWriteTransaction| {
// First create some entries (3?)
let mut e1: Entry<EntryInit, EntryNew> = Entry::new();
@ -1900,7 +1903,7 @@ mod tests {
assert!(entry_exists!(be, e2));
assert!(entry_exists!(be, e3));
let result = fs::remove_file(DB_BACKUP_FILE_NAME);
let result = fs::remove_file(&db_backup_file_name);
match result {
Err(e) => {
@ -1914,17 +1917,20 @@ mod tests {
_ => (),
}
be.backup(DB_BACKUP_FILE_NAME).expect("Backup failed!");
be.restore(DB_BACKUP_FILE_NAME).expect("Restore failed!");
be.backup(&db_backup_file_name).expect("Backup failed!");
be.restore(&db_backup_file_name).expect("Restore failed!");
assert!(be.verify().len() == 0);
});
}
pub const DB_BACKUP2_FILE_NAME: &'static str = "./.backup2_test.json";
#[test]
fn test_be_backup_restore_tampered() {
let db_backup_file_name = format!(
"{}/.backup2_test.json",
option_env!("OUT_DIR").unwrap_or("/tmp")
);
eprintln!(" ⚠️ {}", db_backup_file_name);
run_test!(|be: &mut BackendWriteTransaction| {
// First create some entries (3?)
let mut e1: Entry<EntryInit, EntryNew> = Entry::new();
@ -1948,7 +1954,7 @@ mod tests {
assert!(entry_exists!(be, e2));
assert!(entry_exists!(be, e3));
let result = fs::remove_file(DB_BACKUP2_FILE_NAME);
let result = fs::remove_file(&db_backup_file_name);
match result {
Err(e) => {
@ -1962,17 +1968,17 @@ mod tests {
_ => (),
}
be.backup(DB_BACKUP2_FILE_NAME).expect("Backup failed!");
be.backup(&db_backup_file_name).expect("Backup failed!");
// Now here, we need to tamper with the file.
let serialized_string = fs::read_to_string(DB_BACKUP2_FILE_NAME).unwrap();
let serialized_string = fs::read_to_string(&db_backup_file_name).unwrap();
let mut dbentries: Vec<DbEntry> = serde_json::from_str(&serialized_string).unwrap();
let _ = dbentries.pop();
let serialized_entries_str = serde_json::to_string_pretty(&dbentries).unwrap();
fs::write(DB_BACKUP2_FILE_NAME, serialized_entries_str).unwrap();
fs::write(&db_backup_file_name, serialized_entries_str).unwrap();
be.restore(DB_BACKUP2_FILE_NAME).expect("Restore failed!");
be.restore(&db_backup_file_name).expect("Restore failed!");
assert!(be.verify().len() == 0);
});