summaryrefslogtreecommitdiff
path: root/tests/setup_sshd_test
blob: 23a6f07edc49326c92f7c1ec442b26e396c72b90 (plain)
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
#!/usr/bin/env atf-sh

. $(atf_get_srcdir)/test_env.sh
init_tests \
	setup_sshd_usage \
	setup_sshd_empty \
	setup_sshd_dropbear \
	setup_sshd_openssh \
	setup_sshd_interactive

setup_sshd_usage_body() {
	test_usage setup-sshd
}

setup_sshd_empty_body() {
	init_env
	atf_check -s exit:0 \
		-e empty \
		-o empty \
		setup-sshd none
}

setup_sshd_dropbear_body() {
	init_env
	atf_check -s exit:0 \
		-e empty \
		-o match:"^apk add .* dropbear" \
		-o match:"service dropbear added" \
		-o match:"Starting dropbear" \
		setup-sshd dropbear
}

setup_sshd_openssh_body() {
	init_env
	export WGETCONTENT="ssh-id FOOBAR"
	atf_check -s exit:0 \
		-e empty \
		-o match:"^apk add .* openssh" \
		-o match:"service sshd added" \
		-o match:"Starting sshd" \
		setup-sshd -k 'https://example.com/user.keys' openssh
	grep 'ssh-id FOOBAR' root/.ssh/authorized_keys || atf_fail "failed to wget ssh key"
}

setup_sshd_interactive_body() {
	init_env
	mkdir -p etc/ssh
	echo "PermitRootLogin foobar" > etc/ssh/sshd_config
	(
		echo "openssh"
		echo "no"
	) | atf_check -s exit:0 \
		-e empty \
		-o match:"Which SSH server" \
		-o match:"^apk add .* openssh" \
		-o match:"^rc-update add sshd" \
		-o match:"^rc-service sshd start" \
		setup-sshd
	grep '^PermitRootLogin no$' etc/ssh/sshd_config || atf_fail "did not set PermitRootLogin"
}