snapshots.rb 6.27 KB
Newer Older
1
2
def checkpoints
  {
anonym's avatar
anonym committed
3
    'tails-greeter' => {
4
      :description => "I have started Tails from DVD without network and stopped at Tails Greeter's login screen",
5
      :parent_checkpoint => nil,
6
      :steps => [
7
8
9
        'the network is unplugged',
        'I start the computer',
        'the computer boots Tails'
10
11
      ],
    },
anonym's avatar
anonym committed
12

13
    'no-network-logged-in' => {
14
      :description => "I have started Tails from DVD without network and logged in",
anonym's avatar
anonym committed
15
      :parent_checkpoint => "tails-greeter",
16
17
18
19
      :steps => [
        'I log in to a new session',
      ],
    },
kytv's avatar
kytv committed
20

21
    'with-network-logged-in' => {
22
      :description => "I have started Tails from DVD and logged in and the network is connected",
anonym's avatar
anonym committed
23
      :parent_checkpoint => "no-network-logged-in",
24
25
      :steps => [
        'the network is plugged',
anonym's avatar
anonym committed
26
27
28
29
30
31
        'Tor is ready',
        'all notifications have disappeared',
        'available upgrades have been checked',
      ],
    },

32
33
    'no-network-bridge-mode' => {
      :temporary => true,
34
      :description => "I have started Tails from DVD without network and logged in with bridge mode enabled",
35
36
37
38
39
40
41
42
      :parent_checkpoint => "tails-greeter",
      :steps => [
        'I enable the specific Tor configuration option',
        'I log in to a new session',
        'all notifications have disappeared',
      ],
    },

anonym's avatar
anonym committed
43
    'no-network-logged-in-sudo-passwd' => {
anonym's avatar
anonym committed
44
      :temporary => true,
45
      :description => "I have started Tails from DVD without network and logged in with an administration password",
anonym's avatar
anonym committed
46
47
      :parent_checkpoint => "tails-greeter",
      :steps => [
48
        'I set an administration password',
49
        'I log in to a new session',
anonym's avatar
anonym committed
50
51
52
53
      ],
    },

    'with-network-logged-in-sudo-passwd' => {
anonym's avatar
anonym committed
54
      :temporary => true,
55
      :description => "I have started Tails from DVD and logged in with an administration password and the network is connected",
anonym's avatar
anonym committed
56
57
58
      :parent_checkpoint => "no-network-logged-in-sudo-passwd",
      :steps => [
        'the network is plugged',
59
60
61
62
63
        'Tor is ready',
        'all notifications have disappeared',
        'available upgrades have been checked',
      ],
    },
anonym's avatar
anonym committed
64

65
    'usb-install-tails-greeter' => {
anonym's avatar
anonym committed
66
      :description => "I have started Tails without network from a USB drive without a persistent partition and stopped at Tails Greeter's login screen",
67
      :parent_checkpoint => 'no-network-logged-in',
68
      :steps => [
69
70
        'I create a 4 GiB disk named "__internal"',
        'I plug USB drive "__internal"',
71
        'I "Install by cloning" Tails to USB drive "__internal"',
72
73
        'the running Tails is installed on USB drive "__internal"',
        'there is no persistence partition on USB drive "__internal"',
74
        'I shutdown Tails and wait for the computer to power off',
75
        'I start Tails from USB drive "__internal" with network unplugged',
76
        'the boot device has safe access rights',
77
78
        'Tails is running from USB drive "__internal"',
        'there is no persistence partition on USB drive "__internal"',
79
80
        'process "udev-watchdog" is running',
        'udev-watchdog is monitoring the correct device',
81
82
      ],
    },
anonym's avatar
anonym committed
83

anonym's avatar
anonym committed
84
85
    'usb-install-logged-in' => {
      :description => "I have started Tails without network from a USB drive without a persistent partition and logged in",
86
      :parent_checkpoint => 'usb-install-tails-greeter',
87
88
      :steps => [
        'I log in to a new session',
anonym's avatar
anonym committed
89
90
91
92
93
94
95
      ],
    },

    'usb-install-with-persistence-tails-greeter' => {
      :description => "I have started Tails without network from a USB drive with a persistent partition and stopped at Tails Greeter's login screen",
      :parent_checkpoint => 'usb-install-logged-in',
      :steps => [
96
        'I create a persistent partition',
97
        'a Tails persistence partition exists on USB drive "__internal"',
98
        'I shutdown Tails and wait for the computer to power off',
99
        'I start Tails from USB drive "__internal" with network unplugged',
100
        'the boot device has safe access rights',
101
        'Tails is running from USB drive "__internal"',
102
103
        'process "udev-watchdog" is running',
        'udev-watchdog is monitoring the correct device',
104
105
      ],
    },
106
107

    'usb-install-with-persistence-logged-in' => {
108
      :description => "I have started Tails without network from a USB drive with a persistent partition enabled and logged in",
109
110
111
112
113
114
115
116
117
118
      :parent_checkpoint => 'usb-install-with-persistence-tails-greeter',
      :steps => [
        'I enable persistence',
        'I log in to a new session',
        'all persistence presets are enabled',
        'all persistent filesystems have safe access rights',
        'all persistence configuration files have safe access rights',
        'all persistent directories have safe access rights',
      ],
    },
119
  }
120
121
122
123
124
125
end

def reach_checkpoint(name)
  scenario_indent = " "*4
  step_indent = " "*6

126
  step "a computer"
127
128
  if VM.snapshot_exists?(name)
    $vm.restore_snapshot(name)
129
130
    post_snapshot_restore_hook
  else
131
132
133
134
135
136
137
138
139
    checkpoint = checkpoints[name]
    checkpoint_description = checkpoint[:description]
    parent_checkpoint = checkpoint[:parent_checkpoint]
    steps = checkpoint[:steps]
    if parent_checkpoint
      if VM.snapshot_exists?(parent_checkpoint)
        $vm.restore_snapshot(parent_checkpoint)
      else
        reach_checkpoint(parent_checkpoint)
140
141
142
      end
      post_snapshot_restore_hook
    end
143
    debug_log(scenario_indent + "Checkpoint: #{checkpoint_description}",
144
              color: :white, timestamp: false)
145
146
147
    step_action = "Given"
    if parent_checkpoint
      parent_description = checkpoints[parent_checkpoint][:description]
148
      debug_log(step_indent + "#{step_action} #{parent_description}",
149
                color: :green, timestamp: false)
150
      step_action = "And"
151
152
153
154
155
    end
    steps.each do |s|
      begin
        step(s)
      rescue Exception => e
156
157
        debug_log(scenario_indent +
                  "Step failed while creating checkpoint: #{s}",
158
                  color: :red, timestamp: false)
159
160
        raise e
      end
161
162
      debug_log(step_indent + "#{step_action} #{s}",
                color: :green, timestamp: false)
163
      step_action = "And"
164
    end
165
    $vm.save_snapshot(name)
166
167
168
  end
end

169
170
# For each checkpoint we generate a step to reach it.
checkpoints.each do |name, desc|
171
  step_regex = Regexp.new("^#{Regexp.escape(desc[:description])}$")
172
173
174
  Given step_regex do
    reach_checkpoint(name)
  end
175
end