nixosTests.ecryptfs: Port to Python
This commit is contained in:
parent
4a7ba2cdfe
commit
46fab2e289
|
@ -1,4 +1,4 @@
|
||||||
import ./make-test.nix ({ ... }:
|
import ./make-test-python.nix ({ ... }:
|
||||||
{
|
{
|
||||||
name = "ecryptfs";
|
name = "ecryptfs";
|
||||||
|
|
||||||
|
@ -10,75 +10,76 @@ import ./make-test.nix ({ ... }:
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
$machine->waitForUnit("default.target");
|
def login_as_alice():
|
||||||
|
machine.wait_until_tty_matches(1, "login: ")
|
||||||
|
machine.send_chars("alice\n")
|
||||||
|
machine.wait_until_tty_matches(1, "Password: ")
|
||||||
|
machine.send_chars("foobar\n")
|
||||||
|
machine.wait_until_tty_matches(1, "alice\@machine")
|
||||||
|
|
||||||
# Set alice up with a password and a home
|
|
||||||
$machine->succeed("(echo foobar; echo foobar) | passwd alice");
|
|
||||||
$machine->succeed("chown -R alice.users ~alice");
|
|
||||||
|
|
||||||
# Migrate alice's home
|
def logout():
|
||||||
my $out = $machine->succeed("echo foobar | ecryptfs-migrate-home -u alice");
|
machine.send_chars("logout\n")
|
||||||
$machine->log("ecryptfs-migrate-home said: $out");
|
machine.wait_until_tty_matches(1, "login: ")
|
||||||
|
|
||||||
# Log alice in (ecryptfs passwhrase is wrapped during first login)
|
|
||||||
$machine->waitUntilTTYMatches(1, "login: ");
|
machine.wait_for_unit("default.target")
|
||||||
$machine->sendChars("alice\n");
|
|
||||||
$machine->waitUntilTTYMatches(1, "Password: ");
|
with subtest("Set alice up with a password and a home"):
|
||||||
$machine->sendChars("foobar\n");
|
machine.succeed("(echo foobar; echo foobar) | passwd alice")
|
||||||
$machine->waitUntilTTYMatches(1, "alice\@machine");
|
machine.succeed("chown -R alice.users ~alice")
|
||||||
$machine->sendChars("logout\n");
|
|
||||||
$machine->waitUntilTTYMatches(1, "login: ");
|
with subtest("Migrate alice's home"):
|
||||||
|
out = machine.succeed("echo foobar | ecryptfs-migrate-home -u alice")
|
||||||
|
machine.log(f"ecryptfs-migrate-home said: {out}")
|
||||||
|
|
||||||
|
with subtest("Log alice in (ecryptfs passwhrase is wrapped during first login)"):
|
||||||
|
login_as_alice()
|
||||||
|
machine.send_chars("logout\n")
|
||||||
|
machine.wait_until_tty_matches(1, "login: ")
|
||||||
|
|
||||||
# Why do I need to do this??
|
# Why do I need to do this??
|
||||||
$machine->succeed("su alice -c ecryptfs-umount-private || true");
|
machine.succeed("su alice -c ecryptfs-umount-private || true")
|
||||||
$machine->sleep(1);
|
machine.sleep(1)
|
||||||
$machine->fail("mount | grep ecryptfs"); # check that encrypted home is not mounted
|
|
||||||
|
|
||||||
# Show contents of the user keyring
|
with subtest("check that encrypted home is not mounted"):
|
||||||
my $out = $machine->succeed("su - alice -c 'keyctl list \@u'");
|
machine.fail("mount | grep ecryptfs")
|
||||||
$machine->log("keyctl unlink said: " . $out);
|
|
||||||
|
|
||||||
# Log alice again
|
with subtest("Show contents of the user keyring"):
|
||||||
$machine->waitUntilTTYMatches(1, "login: ");
|
out = machine.succeed("su - alice -c 'keyctl list \@u'")
|
||||||
$machine->sendChars("alice\n");
|
machine.log(f"keyctl unlink said: {out}")
|
||||||
$machine->waitUntilTTYMatches(1, "Password: ");
|
|
||||||
$machine->sendChars("foobar\n");
|
|
||||||
$machine->waitUntilTTYMatches(1, "alice\@machine");
|
|
||||||
|
|
||||||
# Create some files in encrypted home
|
with subtest("Log alice again"):
|
||||||
$machine->succeed("su alice -c 'touch ~alice/a'");
|
login_as_alice()
|
||||||
$machine->succeed("su alice -c 'echo c > ~alice/b'");
|
|
||||||
|
|
||||||
# Logout
|
with subtest("Create some files in encrypted home"):
|
||||||
$machine->sendChars("logout\n");
|
machine.succeed("su alice -c 'touch ~alice/a'")
|
||||||
$machine->waitUntilTTYMatches(1, "login: ");
|
machine.succeed("su alice -c 'echo c > ~alice/b'")
|
||||||
|
|
||||||
|
with subtest("Logout"):
|
||||||
|
logout()
|
||||||
|
|
||||||
# Why do I need to do this??
|
# Why do I need to do this??
|
||||||
$machine->succeed("su alice -c ecryptfs-umount-private || true");
|
machine.succeed("su alice -c ecryptfs-umount-private || true")
|
||||||
$machine->sleep(1);
|
machine.sleep(1)
|
||||||
|
|
||||||
# Check that the filesystem is not accessible
|
with subtest("Check that the filesystem is not accessible"):
|
||||||
$machine->fail("mount | grep ecryptfs");
|
machine.fail("mount | grep ecryptfs")
|
||||||
$machine->succeed("su alice -c 'test \! -f ~alice/a'");
|
machine.succeed("su alice -c 'test \! -f ~alice/a'")
|
||||||
$machine->succeed("su alice -c 'test \! -f ~alice/b'");
|
machine.succeed("su alice -c 'test \! -f ~alice/b'")
|
||||||
|
|
||||||
# Log alice once more
|
with subtest("Log alice once more"):
|
||||||
$machine->waitUntilTTYMatches(1, "login: ");
|
login_as_alice()
|
||||||
$machine->sendChars("alice\n");
|
|
||||||
$machine->waitUntilTTYMatches(1, "Password: ");
|
|
||||||
$machine->sendChars("foobar\n");
|
|
||||||
$machine->waitUntilTTYMatches(1, "alice\@machine");
|
|
||||||
|
|
||||||
# Check that the files are there
|
with subtest("Check that the files are there"):
|
||||||
$machine->sleep(1);
|
machine.sleep(1)
|
||||||
$machine->succeed("su alice -c 'test -f ~alice/a'");
|
machine.succeed("su alice -c 'test -f ~alice/a'")
|
||||||
$machine->succeed("su alice -c 'test -f ~alice/b'");
|
machine.succeed("su alice -c 'test -f ~alice/b'")
|
||||||
$machine->succeed(qq%test "\$(cat ~alice/b)" = "c"%);
|
machine.succeed('test "$(cat ~alice/b)" = "c"')
|
||||||
|
|
||||||
# Catch https://github.com/NixOS/nixpkgs/issues/16766
|
with subtest("Catch https://github.com/NixOS/nixpkgs/issues/16766"):
|
||||||
$machine->succeed("su alice -c 'ls -lh ~alice/'");
|
machine.succeed("su alice -c 'ls -lh ~alice/'")
|
||||||
|
|
||||||
$machine->sendChars("logout\n");
|
logout()
|
||||||
$machine->waitUntilTTYMatches(1, "login: ");
|
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue