File: validatessh

package info (click to toggle)
goss 0.4.9-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,700 kB
  • sloc: sh: 984; makefile: 139
file content (72 lines) | stat: -rw-r--r-- 1,927 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

# Test goss by using it to validate ssh service is online

expected_success_output="Count: 4, Failed: 0, Skipped: 0"
expected_fail_output="Count: 4, Failed: 1, Skipped: 0"


# Start ssh, and set goss acknowledge ssh active is correct
systemctl start ssh

goss add package openssh-server
goss add service ssh


# Confirm that goss validation succeeds with ssh active
initial_valid_output=$(goss validate)
initial_return_code=$?

grep -q "$expected_success_output" <<< "$initial_valid_output"
initial_output_correct=$?

if [[ $initial_output_correct -ne 0 ]]; then
  echo "Initial validation failed, expected:"
  echo $expected_success_output
  echo "found:"
  grep "Count" <<< "$initial_valid_output"
  exit 1
elif [[ $initial_return_code -ne 0 ]]; then
  echo "Initial validation failed: bad return code of $initial_return_code"
  exit 1
fi

# Confirm that goss validation fails with ssh inactive
systemctl stop ssh

invalid_output=$(goss validate)
invalid_return_code=$?

grep -q "$expected_fail_output" <<< "$invalid_output"
invalid_output_correct=$?

if [[ $invalid_output_correct -ne 0 ]]; then
  echo "ssh offline validation failed, expected:"
  echo $expected_fail_output
  echo "found:"
  grep "Count" <<< "$invalid_output"
  exit 1
elif [[ $invalid_return_code -ne 1 ]]; then
  echo "ssh offline validation failed: bad return code of $invalid_return_code"
  exit 1
fi

# Confirm that goss validation succeeds with ssh reactivated
systemctl start ssh

final_valid_output=$(goss validate)
final_return_code=$?

grep -q "$expected_success_output" <<< "$final_valid_output"
final_output_correct=$?

if [[ $final_output_correct -ne 0 ]]; then
  echo "Final validation failed, expected:"
  echo $expected_success_output
  echo "found:"
  grep "Count" <<< "$final_valid_output"
  exit 1
elif [[ $final_return_code -ne 0 ]]; then
  echo "Final validation failed: bad return code of $final_return_code"
  exit 1
fi