Adding a first integrationtest for delete_user
This commit is contained in:
parent
732893b5d4
commit
647881f022
@ -155,7 +155,7 @@ impl UserDBLocal {
|
||||
}
|
||||
}
|
||||
|
||||
use crate::api::{DeleteHome, DeletePrimaryGroup, NewUserArgs, UserDBRead, UserDBWrite};
|
||||
use crate::api::{DeleteHome, NewUserArgs, UserDBRead, UserDBWrite};
|
||||
impl UserDBWrite for UserDBLocal {
|
||||
fn delete_user(&mut self, args: NewUserArgs) -> Result<crate::User, UserLibError> {
|
||||
// try to get the user from the database
|
||||
@ -190,10 +190,10 @@ impl UserDBWrite for UserDBLocal {
|
||||
error!("The source files have changed. Deleting the user could corrupt the userdatabase. Aborting!");
|
||||
Err(format!("The userdatabase has been changed {}", args.username).into())
|
||||
} else {
|
||||
UserDBLocal::delete_from_passwd(user, passwd_file_content, &mut locked_p)?;
|
||||
UserDBLocal::delete_from_shadow(user, shadow_file_content, &mut locked_s)?;
|
||||
Self::delete_from_passwd(user, passwd_file_content, &mut locked_p)?;
|
||||
Self::delete_from_shadow(user, shadow_file_content, &mut locked_s)?;
|
||||
if args.delete_home == DeleteHome::Delete {
|
||||
UserDBLocal::delete_home(user)?;
|
||||
Self::delete_home(user)?;
|
||||
}
|
||||
let group = self.get_group_pos_by_id(user.get_gid());
|
||||
match group {
|
||||
|
@ -3,5 +3,43 @@ mod testfiles;
|
||||
|
||||
#[test]
|
||||
fn test_test() {
|
||||
assert_eq!(1, 1);
|
||||
use testfiles::Fixture;
|
||||
|
||||
use adduser::api::UserDBWrite;
|
||||
use adduser::api::UserRead;
|
||||
use std::fs;
|
||||
|
||||
let p = Fixture::copy("passwd");
|
||||
let s = Fixture::copy("shadow");
|
||||
let g = Fixture::copy("group");
|
||||
|
||||
let pf = fs::read_to_string(&p.path).unwrap();
|
||||
|
||||
let mf = adduser::Files {
|
||||
passwd: Some(p.path.clone()),
|
||||
shadow: Some(s.path.clone()),
|
||||
group: Some(g.path.clone()),
|
||||
};
|
||||
|
||||
let mut db = adduser::UserDBLocal::load_files(mf).unwrap();
|
||||
|
||||
let user_res: Result<adduser::User, adduser::UserLibError> = db.delete_user(
|
||||
adduser::api::NewUserArgs::builder()
|
||||
.username("teste")
|
||||
// .delete_home(adduser::api::DeleteHome::Delete)
|
||||
.build()
|
||||
.unwrap(),
|
||||
);
|
||||
let pf2 = fs::read_to_string(&p.path).unwrap();
|
||||
assert_eq!(user_res.unwrap().get_username().unwrap(), "teste");
|
||||
let pfl = pf.lines();
|
||||
let pfl2 = pf2.lines();
|
||||
for (l1, l2) in pfl.zip(pfl2) {
|
||||
if l1 != l2 {
|
||||
dbg!(l1, l2);
|
||||
assert!(l1.starts_with("teste"));
|
||||
assert!(l2.starts_with("bergfried"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
93
tests/fixtures/group
vendored
Normal file
93
tests/fixtures/group
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
root:x:0:
|
||||
bin:x:1:
|
||||
daemon:x:2:
|
||||
sys:x:3:
|
||||
adm:x:4:
|
||||
tty:x:5:
|
||||
disk:x:6:
|
||||
lp:x:7:
|
||||
mem:x:8:
|
||||
kmem:x:9:
|
||||
wheel:x:10:dietrich
|
||||
cdrom:x:11:
|
||||
mail:x:12:
|
||||
man:x:15:
|
||||
dialout:x:18:dietrich
|
||||
floppy:x:19:
|
||||
games:x:20:
|
||||
tape:x:33:
|
||||
video:x:39:
|
||||
ftp:x:50:
|
||||
lock:x:54:dietrich
|
||||
audio:x:63:
|
||||
users:x:100:
|
||||
nobody:x:65534:
|
||||
utmp:x:22:
|
||||
utempter:x:35:
|
||||
input:x:999:
|
||||
kvm:x:36:qemu
|
||||
render:x:998:
|
||||
systemd-journal:x:190:
|
||||
systemd-coredump:x:997:
|
||||
systemd-network:x:192:
|
||||
systemd-resolve:x:193:
|
||||
dbus:x:81:
|
||||
systemd-timesync:x:996:
|
||||
tss:x:59:clevis
|
||||
dip:x:40:
|
||||
printadmin:x:995:
|
||||
gluster:x:994:
|
||||
qemu:x:107:
|
||||
nm-openconnect:x:993:
|
||||
usbmuxd:x:113:
|
||||
geoclue:x:992:
|
||||
polkitd:x:991:
|
||||
rtkit:x:172:
|
||||
pulse-access:x:990:
|
||||
pulse-rt:x:989:
|
||||
pulse:x:171:
|
||||
chrony:x:988:
|
||||
avahi:x:70:
|
||||
pipewire:x:987:
|
||||
dnsmasq:x:986:
|
||||
saslauth:x:76:
|
||||
radvd:x:75:
|
||||
rpc:x:32:
|
||||
ssh_keys:x:985:
|
||||
openvpn:x:984:
|
||||
nm-openvpn:x:983:
|
||||
libvirt:x:982:dietrich
|
||||
unbound:x:981:
|
||||
brlapi:x:980:
|
||||
apache:x:48:
|
||||
colord:x:979:
|
||||
rpcuser:x:29:
|
||||
abrt:x:173:
|
||||
flatpak:x:978:
|
||||
gdm:x:42:
|
||||
gnome-initial-setup:x:977:
|
||||
sshd:x:74:
|
||||
slocate:x:21:
|
||||
vboxsf:x:976:
|
||||
tcpdump:x:72:
|
||||
wbpriv:x:88:
|
||||
clevis:x:975:
|
||||
cockpit-ws:x:974:
|
||||
libvirtdbus:x:973:
|
||||
setroubleshoot:x:972:
|
||||
mysql:x:27:
|
||||
firebird:x:971:
|
||||
cockpit-wsinstance:x:970:
|
||||
pbuilder:x:969:
|
||||
teste:x:1002:test,teste
|
||||
testnewgroup:x:1015:teste
|
||||
hausle:x:1018:dietrich
|
||||
bergfried:x:1009:
|
||||
t1:x:1019:
|
||||
t2:x:1020:
|
||||
docker:x:968:
|
||||
jackuser:x:967:
|
||||
akmods:x:966:
|
||||
mock:x:135:
|
||||
rtlsdr:x:965:
|
||||
Debian-exim:x:128:
|
60
tests/fixtures/passwd
vendored
Normal file
60
tests/fixtures/passwd
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
root:x:0:0:root:/root:/bin/bash
|
||||
bin:x:1:1:bin:/bin:/sbin/nologin
|
||||
daemon:x:2:2:daemon:/sbin:/sbin/nologin
|
||||
adm:x:3:4:adm:/var/adm:/sbin/nologin
|
||||
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
|
||||
sync:x:5:0:sync:/sbin:/bin/sync
|
||||
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
|
||||
halt:x:7:0:halt:/sbin:/sbin/halt
|
||||
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
|
||||
operator:x:11:0:operator:/root:/sbin/nologin
|
||||
games:x:12:100:games:/usr/games:/sbin/nologin
|
||||
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
|
||||
nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin
|
||||
systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin
|
||||
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
|
||||
systemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin
|
||||
dbus:x:81:81:System message bus:/:/sbin/nologin
|
||||
systemd-timesync:x:998:996:systemd Time Synchronization:/:/sbin/nologin
|
||||
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
|
||||
gluster:x:997:994:GlusterFS daemons:/run/gluster:/sbin/nologin
|
||||
qemu:x:107:107:qemu user:/:/sbin/nologin
|
||||
nm-openconnect:x:996:993:NetworkManager user for OpenConnect:/:/sbin/nologin
|
||||
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
|
||||
geoclue:x:995:992:User for geoclue:/var/lib/geoclue:/sbin/nologin
|
||||
polkitd:x:994:991:User for polkitd:/:/sbin/nologin
|
||||
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
|
||||
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
|
||||
chrony:x:993:988::/var/lib/chrony:/sbin/nologin
|
||||
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
|
||||
pipewire:x:992:987:PipeWire System Daemon:/var/run/pipewire:/sbin/nologin
|
||||
dnsmasq:x:986:986:Dnsmasq DHCP and DNS server:/var/lib/dnsmasq:/sbin/nologin
|
||||
saslauth:x:985:76:Saslauthd user:/run/saslauthd:/sbin/nologin
|
||||
radvd:x:75:75:radvd user:/:/sbin/nologin
|
||||
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
|
||||
openvpn:x:984:984:OpenVPN:/etc/openvpn:/sbin/nologin
|
||||
nm-openvpn:x:983:983:Default user for running openvpn spawned by NetworkManager:/:/sbin/nologin
|
||||
unbound:x:982:981:Unbound DNS resolver:/etc/unbound:/sbin/nologin
|
||||
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
|
||||
colord:x:981:979:User for colord:/var/lib/colord:/sbin/nologin
|
||||
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
|
||||
abrt:x:173:173::/etc/abrt:/sbin/nologin
|
||||
flatpak:x:980:978:User for flatpak system helper:/:/sbin/nologin
|
||||
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
|
||||
gnome-initial-setup:x:979:977::/run/gnome-initial-setup/:/sbin/nologin
|
||||
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
|
||||
vboxadd:x:978:1::/var/run/vboxadd:/sbin/nologin
|
||||
tcpdump:x:72:72::/:/sbin/nologin
|
||||
clevis:x:977:975:Clevis Decryption Framework unprivileged user:/var/cache/clevis:/sbin/nologin
|
||||
cockpit-ws:x:976:974:User for cockpit-ws:/nonexisting:/sbin/nologin
|
||||
libvirtdbus:x:975:973:Libvirt D-Bus bridge:/:/sbin/nologin
|
||||
setroubleshoot:x:974:972::/var/lib/setroubleshoot:/sbin/nologin
|
||||
mysql:x:27:27:MySQL Server:/var/lib/mysql:/sbin/nologin
|
||||
firebird:x:973:971::/:/bin/nologin
|
||||
cockpit-wsinstance:x:972:970:User for cockpit-ws instances:/nonexisting:/sbin/nologin
|
||||
pbuilder:x:971:969:pbuilder:/var/run/pbuilder:/sbin/nologin
|
||||
test:x:1001:1015:Long,007,1499990,1999201,AKK:/home/test:/bin/bash
|
||||
teste:x:1002:1002::/home/teste:/bin/bash
|
||||
bergfried:x:1009:1009:Bergfried Freiberg,,,,:/home/bergfried:/bin/bash
|
||||
akmods:x:970:966:User is used by akmods to build akmod packages:/var/cache/akmods/:/sbin/nologin
|
||||
Debian-exim:x:123:128::/var/spool/exim4:/usr/sbin/nologin
|
60
tests/fixtures/shadow
vendored
Normal file
60
tests/fixtures/shadow
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
root:$6$I4MRB1rzlIft7qiw$2i0OBungWyGBxXbcxbHNKfeaXKRQBEksxK8o3Zvb8VQKuDOSCaLjh1p6C1yfY.z/BCX0dzozj6l3F67QW1X8b.:18260:0:99999:7:::
|
||||
bin:*:17995:0:99999:7:::
|
||||
daemon:*:17995:0:99999:7:::
|
||||
adm:*:17995:0:99999:7:::
|
||||
lp:*:17995:0:99999:7:::
|
||||
sync:*:17995:0:99999:7:::
|
||||
shutdown:*:17995:0:99999:7:::
|
||||
halt:*:17995:0:99999:7:::
|
||||
mail:*:17995:0:99999:7:::
|
||||
operator:*:17995:0:99999:7:::
|
||||
games:*:17995:0:99999:7:::
|
||||
ftp:*:17995:0:99999:7:::
|
||||
nobody:*:17995:0:99999:7:::
|
||||
systemd-coredump:!!:18107::::::
|
||||
systemd-network:!!:18107::::::
|
||||
systemd-resolve:!!:18107::::::
|
||||
dbus:!!:18107::::::
|
||||
systemd-timesync:!!:18107::::::
|
||||
tss:!!:18107::::::
|
||||
gluster:!!:18107::::::
|
||||
qemu:!!:18107::::::
|
||||
nm-openconnect:!!:18107::::::
|
||||
usbmuxd:!!:18107::::::
|
||||
geoclue:!!:18107::::::
|
||||
polkitd:!!:18107::::::
|
||||
rtkit:!!:18107::::::
|
||||
pulse:!!:18107::::::
|
||||
chrony:!!:18107::::::
|
||||
avahi:!!:18107::::::
|
||||
pipewire:!!:18107::::::
|
||||
dnsmasq:!!:18107::::::
|
||||
saslauth:!!:18107::::::
|
||||
radvd:!!:18107::::::
|
||||
rpc:!!:18107:0:99999:7:::
|
||||
openvpn:!!:18107::::::
|
||||
nm-openvpn:!!:18107::::::
|
||||
unbound:!!:18107::::::
|
||||
apache:!!:18107::::::
|
||||
colord:!!:18107::::::
|
||||
rpcuser:!!:18107::::::
|
||||
abrt:!!:18107::::::
|
||||
flatpak:!!:18107::::::
|
||||
gdm:!!:18107::::::
|
||||
gnome-initial-setup:!!:18107::::::
|
||||
sshd:!!:18107::::::
|
||||
vboxadd:!!:18107::::::
|
||||
tcpdump:!!:18107::::::
|
||||
clevis:!!:18113::::::
|
||||
cockpit-ws:!!:18113::::::
|
||||
libvirtdbus:!!:18113::::::
|
||||
setroubleshoot:!!:18113::::::
|
||||
mysql:!!:18137::::::
|
||||
firebird:!!:18140::::::
|
||||
cockpit-wsinstance:!!:18196::::::
|
||||
pbuilder:!!:18198::::::
|
||||
test:$6$K3iBIIJwfJjolbIV$AaDjW1kvaeYl8KAqAkvXMTWloQV2VsB8a33PHYItRPdETtYGKP2T2n6HjUUuXUZFPxLdnJyB8cWlpPCl1x/VP0:18574:0:99999:7:::
|
||||
teste:$6$u0Hh.9WKRF1Aeu4g$XqoDyL6Re/4ZLNQCGAXlNacxCxbdigexEqzFzkOVPV5Z1H23hlenjW8ZLgq6GQtFURYwenIFpo1c.r4aW9l5S/:18574:0:99999:7:::
|
||||
bergfried:$6$dzc1lAZo7XaWwFx9$MpUJtzD9WFJhgt.5zVtgP6mGjFldNCZ02Pp9S9Y4XTV16fMUuN/0vi5Xs4BH2T0G6EL2gS/gAHRnsyvY4aVi31:18574:0:99999:7:::
|
||||
akmods:!!:18395::::::
|
||||
Debian-exim:!:18574:0:99999:7:::
|
@ -5,14 +5,14 @@ use tempfile::TempDir;
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
struct Fixture {
|
||||
path: PathBuf,
|
||||
source: PathBuf,
|
||||
pub struct Fixture {
|
||||
pub path: PathBuf,
|
||||
pub source: PathBuf,
|
||||
_tempdir: TempDir,
|
||||
}
|
||||
|
||||
impl Fixture {
|
||||
fn blank(fixture_filename: &str) -> Self {
|
||||
pub fn blank(fixture_filename: &str) -> Self {
|
||||
// First, figure out the right file in `tests/fixtures/`:
|
||||
let root_dir = &env::var("CARGO_MANIFEST_DIR").expect("$CARGO_MANIFEST_DIR");
|
||||
let mut source = PathBuf::from(root_dir);
|
||||
@ -30,7 +30,7 @@ impl Fixture {
|
||||
path,
|
||||
}
|
||||
}
|
||||
fn copy(fixture_filename: &str) -> Self {
|
||||
pub fn copy(fixture_filename: &str) -> Self {
|
||||
let fixture = Fixture::blank(fixture_filename);
|
||||
fs::copy(&fixture.source, &fixture.path).unwrap();
|
||||
fixture
|
||||
|
Loading…
Reference in New Issue
Block a user