File: deluser_files.t

package info (click to toggle)
adduser 3.154
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,584 kB
  • sloc: perl: 9,508; sh: 189; makefile: 22
file content (154 lines) | stat: -rwxr-xr-x 6,031 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#! /usr/bin/perl -Idebian/tests/lib


use diagnostics;
use strict;
use warnings;

use AdduserTestsCommon;

sub create_files_in_homedir{
    my ($acct, $uid, $gid, $acct2, $uid2, $gid2) = @_;
    mkdir ("/home/$acct", 0777);
    mkdir ("/home/$acct/mnt", 0777);
    mkdir ("/home/$acct/dir", 0777);
    mkdir ("/tmp/$acct", 0777);
    unlink("/tmp/deluserfiles.txt");
    for ("/home/$acct/extra.txt", "/tmp/$acct/extra2.txt", "/tmp/deluserfiles.txt", "/home/$acct2/not-utf-8-but-possible-\x7F", "/home/$acct/not-utf-8-but-possible-\x7F", "/home/$acct2/still-not-utf-8-but-possible-\x7F") {
        open (XTRA, '>', $_) || die ("could not open file $_: $!");
        print XTRA "extra file";
        close (XTRA) || die ('could not close file!');
    }
    system ('mkfifo', "/home/$acct/pipe");
    chown ($uid, $gid, 
        "/home/$acct", 
        "/home/$acct/extra.txt",
        "/tmp/$acct/extra2.txt",
        "/home/$acct/mnt",
        "/home/$acct/dir",
        "/tmp/deluserfiles.txt",
        "/home/$acct/pipe",
        "/home/$acct/not-utf-8-but-possible-\x7F",
        "/home/$acct2/still-not-utf-8-but-possible-\x7F");
    chown ($uid2, $gid2, "/home/$acct2/not-utf-8-but-possible-\x7F");
    assert_command_success('mount','-o','bind',"/tmp/$acct","/home/$acct/mnt");
}

END {
    # remove_tree('/home/deluserfiles');
    # remove_tree('/var/mail/deluserfiles');
    system("umount /home/deluserfiles-extra/mnt >/dev/null 2>/dev/null");
    remove_tree('/home/deluserfiles-extra');
    remove_tree('/tmp/deluserfiles-extra');
    unlink('/tmp/deluserfiles.tar.gz'); 
    unlink('/tmp/deluserfiles.txt');
    assert_user_exists('deluserfiles2');
    assert_command_success('/usr/sbin/deluser',
        '--stdoutmsglevel=error', '--stderrmsglevel=error',
        'deluserfiles2');
    assert_user_does_not_exist('deluserfiles2');
    remove_tree('/home/deluserfiles2');
}

assert_user_does_not_exist('deluserfiles2');
assert_command_success('/usr/sbin/adduser',
    '--stdoutmsglevel=error', '--stderrmsglevel=error',
    '--home', '/home/deluserfiles2',
    '--comment', '',
    '--disabled-password',
    'deluserfiles2');
assert_user_exists('deluserfiles2');

assert_user_does_not_exist('deluserfiles');
assert_command_success('/usr/sbin/adduser',
    '--stdoutmsglevel=error', '--stderrmsglevel=error',
    '--system', 
    '--home', '/home/deluserfiles',
    'deluserfiles');
assert_user_exists('deluserfiles');

my ($login, $pass, $uid, $gid) = getpwnam('deluserfiles');
my ($login2, $pass2, $uid2, $gid2) = getpwnam('deluserfiles2');
create_files_in_homedir("deluserfiles-extra", $uid, $gid, "deluserfiles2", $uid2, $gid2);

assert_command_success('/usr/sbin/deluser',
    '--stdoutmsglevel=error', '--stderrmsglevel=error',
    '--system',
    '--backup-suffix', 'gz',
    '--remove-all-files',
    '--backup-to', '/tmp',
    'deluserfiles');
system("umount /home/deluserfiles-extra/mnt >/dev/null 2>/dev/null");
assert_user_does_not_exist('deluserfiles');
assert_path_does_not_exist('/home/deluserfiles');
assert_path_does_not_exist('/home/deluserfiles-extra/extra.txt');
assert_path_does_not_exist('/home/deluserfiles-extra/pipe');
#FIXME
#assert_path_does_not_exist('/tmp/deluserfiles-extra/extra2.txt');
assert_path_exists('/tmp/deluserfiles.txt');
assert_path_exists('/home/deluserfiles-extra/mnt');
assert_path_does_not_exist('/home/deluserfiles-extra/dir');

# check backup archive
assert_path_exists('/tmp/deluserfiles.tar.gz');
my $tar_files = `tar tf /tmp/deluserfiles.tar.gz`;
is($? >> 8, 0, 'successfully listed backup files');
like($tar_files, qr{home/deluserfiles-extra/extra.txt}, 'archive contains expected file: extra.txt');

# create new user and delete again, backing up to /nonexistent
# this succeeds when there are no files to back up
assert_command_success('/usr/sbin/adduser',
    '--stdoutmsglevel=error', '--stderrmsglevel=error',
    '--system', 
    '--home', '/home/deluserfiles',
    'deluserfiles');
assert_user_exists('deluserfiles', $uid, $gid);
assert_command_success('/usr/sbin/deluser',
    '--stdoutmsglevel=error', '--stderrmsglevel=error',
    '--system',
    '--remove-all-files',
    '--backup-to', '/nonexistent',
    'deluserfiles');
# create new user, put files in and delete again, backing up to /nonexistent
# this must fail
assert_command_success('/usr/sbin/adduser',
    '--stdoutmsglevel=error', '--stderrmsglevel=error',
    '--system', 
    '--home', '/home/deluserfiles',
    'deluserfiles');
assert_user_exists('deluserfiles', $uid, $gid);
($login, $pass, $uid, $gid) = getpwnam('deluserfiles');
create_files_in_homedir("deluserfiles-extra", $uid, $gid, "deluserfiles2", $uid2, $gid2);
assert_command_failure_silent('/usr/sbin/deluser',
    '--stdoutmsglevel=error', '--stderrmsglevel=error',
    '--system',
    '--remove-all-files',
    '--backup-to', '/nonexistent',
    'deluserfiles');
assert_user_exists('deluserfiles');
assert_path_exists('/home/deluserfiles');
assert_path_exists('/home/deluserfiles-extra/extra.txt');
assert_path_exists('/home/deluserfiles-extra/pipe');
#FIXME
#assert_path_does_not_exist('/tmp/deluserfiles-extra/extra2.txt');
assert_path_exists('/tmp/deluserfiles.txt');
assert_path_exists('/home/deluserfiles-extra/mnt');
assert_path_exists('/home/deluserfiles-extra/dir');
assert_command_success('/usr/sbin/deluser',
    '--stdoutmsglevel=error', '--stderrmsglevel=error',
    '--system',
    '--remove-all-files',
    '--backup-to', '/tmp',
    'deluserfiles');
system("umount /home/deluserfiles-extra/mnt >/dev/null 2>/dev/null");
assert_user_does_not_exist('deluserfiles');
assert_path_does_not_exist('/home/deluserfiles');
assert_path_does_not_exist('/home/deluserfiles-extra/extra.txt');
assert_path_does_not_exist('/home/deluserfiles-extra/pipe');
#FIXME
#assert_path_does_not_exist('/tmp/deluserfiles-extra/extra2.txt');
assert_path_exists('/tmp/deluserfiles.txt');
assert_path_exists('/home/deluserfiles-extra/mnt');
assert_path_does_not_exist('/home/deluserfiles-extra/dir');

# vim: tabstop=4 shiftwidth=4 expandtab