mirror of
https://github.com/uutils/shadow.git
synced 2026-06-10 16:14:57 -07:00
Merge pull request #92 from shadow-utils-rs/fix/78-86-88-final
fix: binary <1MB, test helpers, completions
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// This file is part of the shadow-rs package.
|
||||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
//! Shared test helpers for shadow-rs integration tests.
|
||||
//!
|
||||
//! Import with `#[path = "../common/mod.rs"] mod common;` in test files.
|
||||
|
||||
/// Skip the test when not running as root (euid != 0).
|
||||
///
|
||||
/// Returns `true` if the test should be skipped.
|
||||
pub fn skip_unless_root() -> bool {
|
||||
!nix::unistd::geteuid().is_root()
|
||||
}
|
||||
|
||||
/// Create a temp directory with synthetic `/etc/` files for testing.
|
||||
///
|
||||
/// Returns a `TempDir` — the directory and files are cleaned up on drop.
|
||||
pub fn setup_prefix(shadow_content: &str) -> tempfile::TempDir {
|
||||
let dir = tempfile::tempdir().expect("failed to create temp dir");
|
||||
let etc = dir.path().join("etc");
|
||||
std::fs::create_dir_all(&etc).expect("failed to create etc dir");
|
||||
std::fs::write(etc.join("shadow"), shadow_content).expect("failed to write shadow");
|
||||
dir
|
||||
}
|
||||
|
||||
/// Create a temp directory with passwd, shadow, and group files.
|
||||
pub fn setup_full_prefix(
|
||||
passwd_content: &str,
|
||||
shadow_content: &str,
|
||||
group_content: &str,
|
||||
) -> tempfile::TempDir {
|
||||
let dir = tempfile::tempdir().expect("failed to create temp dir");
|
||||
let etc = dir.path().join("etc");
|
||||
std::fs::create_dir_all(&etc).expect("failed to create etc dir");
|
||||
std::fs::write(etc.join("passwd"), passwd_content).expect("failed to write passwd");
|
||||
std::fs::write(etc.join("shadow"), shadow_content).expect("failed to write shadow");
|
||||
std::fs::write(etc.join("group"), group_content).expect("failed to write group");
|
||||
dir
|
||||
}
|
||||
|
||||
/// Read a file from a temp prefix directory.
|
||||
pub fn read_file(dir: &tempfile::TempDir, relative: &str) -> String {
|
||||
std::fs::read_to_string(dir.path().join(relative)).expect("failed to read file")
|
||||
}
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generate shell completions for all shadow-rs tools.
|
||||
#
|
||||
# Usage:
|
||||
# ./util/generate-completions.sh bash
|
||||
# ./util/generate-completions.sh zsh
|
||||
# ./util/generate-completions.sh fish
|
||||
#
|
||||
# For proper clap-based completions, build with clap_complete.
|
||||
# This is a minimal placeholder until clap_complete is integrated.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SHELL_TYPE="${1:-bash}"
|
||||
TOOLS="passwd pwck useradd userdel usermod chpasswd chage groupadd groupdel groupmod grpck chfn chsh newgrp"
|
||||
|
||||
case "$SHELL_TYPE" in
|
||||
bash)
|
||||
for tool in $TOOLS; do
|
||||
echo "complete -W '--help' $tool"
|
||||
done
|
||||
;;
|
||||
zsh)
|
||||
echo "#compdef shadow-rs"
|
||||
for tool in $TOOLS; do
|
||||
echo "complete -c $tool -s h -l help -d 'Show help'"
|
||||
done
|
||||
;;
|
||||
fish)
|
||||
for tool in $TOOLS; do
|
||||
echo "complete -c $tool -s h -l help -d 'Show help'"
|
||||
done
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {bash|zsh|fish}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user