Calendar: add FT sprint
[tails/test.git] / features / step_definitions / snapshots.rb
blobd262cb7b37e3dfa7d53e543b58515cba72ac3fa4
1 CHECKPOINTS =
2   {
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         'the network is unplugged',
8         'I start the computer',
9         'the computer boots Tails',
10       ],
11     },
13     'no-network-logged-in'                       => {
14       description:       'I have started Tails from DVD without network and logged in',
15       parent_checkpoint: 'tails-greeter',
16       steps:             [
17         'I log in to a new session',
18         'all notifications have disappeared',
19       ],
20     },
22     'with-network-logged-in'                     => {
23       description:       'I have started Tails from DVD and logged in and the network is connected',
24       parent_checkpoint: 'no-network-logged-in',
25       steps:             [
26         'the network is plugged',
27         'Tor is ready',
28         'all notifications have disappeared',
29         'available upgrades have been checked',
30       ],
31     },
33     'no-network-bridge-mode'                     => {
34       temporary:         true,
35       description:       'I have started Tails from DVD without network and logged in with bridge mode enabled',
36       parent_checkpoint: 'tails-greeter',
37       steps:             [
38         'I enable the specific Tor configuration option',
39         'I log in to a new session',
40         'all notifications have disappeared',
41       ],
42     },
44     'no-network-logged-in-sudo-passwd'           => {
45       temporary:         true,
46       description:       'I have started Tails from DVD without network and logged in with an administration password',
47       parent_checkpoint: 'tails-greeter',
48       steps:             [
49         'I set an administration password',
50         'I log in to a new session',
51         'all notifications have disappeared',
52       ],
53     },
55     'with-network-logged-in-sudo-passwd'         => {
56       temporary:         true,
57       description:       'I have started Tails from DVD and logged in with an administration password and the network is connected',
58       parent_checkpoint: 'no-network-logged-in-sudo-passwd',
59       steps:             [
60         'the network is plugged',
61         'Tor is ready',
62         'all notifications have disappeared',
63         'available upgrades have been checked',
64       ],
65     },
67     'no-network-logged-in-unsafe-browser'        => {
68       temporary:         true,
69       description:       'I have started Tails from DVD without network and logged in with the Unsafe Browser enabled',
70       parent_checkpoint: 'tails-greeter',
71       steps:             [
72         'I allow the Unsafe Browser to be started',
73         'I log in to a new session',
74         'all notifications have disappeared',
75       ],
76     },
78     'with-network-logged-in-unsafe-browser'      => {
79       temporary:         true,
80       description:       'I have started Tails from DVD and logged in with the Unsafe Browser enabled and the network is connected',
81       parent_checkpoint: 'no-network-logged-in-unsafe-browser',
82       steps:             [
83         'the network is plugged',
84         'Tor is ready',
85         'all notifications have disappeared',
86         'available upgrades have been checked',
87       ],
88     },
90     'usb-install-tails-greeter'                  => {
91       description:       "I have started Tails without network from a USB drive without a persistent partition and stopped at Tails Greeter's login screen",
92       parent_checkpoint: nil,
93       steps:             [
94         'I create a 7200 MiB disk named "__internal"',
95         'I plug USB drive "__internal"',
96         'I write the Tails USB image to disk "__internal"',
97         'I start Tails from USB drive "__internal" with network unplugged',
98         'the boot device has safe access rights',
99         'Tails is running from USB drive "__internal"',
100         'there is no persistence partition on USB drive "__internal"',
101         'process "udev-watchdog" is running',
102         'udev-watchdog is monitoring the correct device',
103       ],
104     },
106     'usb-install-logged-in'                      => {
107       description:       'I have started Tails without network from a USB drive without a persistent partition and logged in',
108       parent_checkpoint: 'usb-install-tails-greeter',
109       steps:             [
110         'I log in to a new session',
111         'all notifications have disappeared',
112       ],
113     },
115     'usb-install-with-persistence-tails-greeter' => {
116       description:       "I have started Tails without network from a USB drive with a persistent partition and stopped at Tails Greeter's login screen",
117       parent_checkpoint: 'usb-install-logged-in',
118       steps:             [
119         'I create a persistent partition',
120         'a Tails persistence partition exists on USB drive "__internal"',
121         'I cold reboot the computer',
122         'the computer reboots Tails',
123         'the boot device has safe access rights',
124         'Tails is running from USB drive "__internal"',
125         'process "udev-watchdog" is running',
126         'udev-watchdog is monitoring the correct device',
127       ],
128     },
130     'usb-install-with-persistence-logged-in'     => {
131       description:       'I have started Tails without network from a USB drive with a persistent partition enabled and logged in',
132       parent_checkpoint: 'usb-install-with-persistence-tails-greeter',
133       steps:             [
134         'I enable persistence',
135         'I log in to a new session',
136         'all persistence presets are enabled',
137         'all persistent filesystems have safe access rights',
138         'all persistence configuration files have safe access rights',
139         'all persistent directories have safe access rights',
140         'all notifications have disappeared',
141       ],
142     },
144   }.freeze
146 # XXX: giving up on a few worst offenders for now
147 # rubocop:disable Metrics/AbcSize
148 # rubocop:disable Metrics/MethodLength
149 def reach_checkpoint(name)
150   scenario_indent = ' ' * 4
151   step_indent = ' ' * 6
153   step 'a computer'
154   if VM.snapshot_exists?(name)
155     $vm.restore_snapshot(name)
156   else
157     checkpoint = CHECKPOINTS[name]
158     checkpoint_description = checkpoint[:description]
159     parent_checkpoint = checkpoint[:parent_checkpoint]
160     steps = checkpoint[:steps]
161     if parent_checkpoint
162       if VM.snapshot_exists?(parent_checkpoint)
163         $vm.restore_snapshot(parent_checkpoint)
164       else
165         reach_checkpoint(parent_checkpoint)
166       end
167       post_snapshot_restore_hook(parent_checkpoint)
168     end
169     debug_log(scenario_indent + "Checkpoint: #{checkpoint_description}",
170               color: :white, timestamp: false)
171     step_action = 'Given'
172     if parent_checkpoint
173       parent_description = CHECKPOINTS[parent_checkpoint][:description]
174       debug_log(step_indent + "#{step_action} #{parent_description}",
175                 color: :green, timestamp: false)
176       step_action = 'And'
177     end
178     steps.each do |s|
179       begin
180         step(s)
181       rescue StandardError => e
182         debug_log(scenario_indent +
183                   "Step failed while creating checkpoint: #{s}",
184                   color: :red, timestamp: false)
185         raise e
186       end
187       debug_log(step_indent + "#{step_action} #{s}",
188                 color: :green, timestamp: false)
189       step_action = 'And'
190     end
191     $vm.save_snapshot(name)
192   end
193   # VM#save_snapshot restores the RAM-only snapshot immediately
194   # after saving it, in which case post_snapshot_restore_hook is
195   # useful to ensure we've reached a good starting point, so we run
196   # it in all cases, including even when've just saved a new snapshot.
197   post_snapshot_restore_hook(name)
199 # rubocop:enable Metrics/AbcSize
200 # rubocop:enable Metrics/MethodLength
202 # For each checkpoint we generate a step to reach it.
203 CHECKPOINTS.each do |name, desc|
204   step_regex = Regexp.new("^#{Regexp.escape(desc[:description])}$")
205   Given step_regex do
206     begin
207       reach_checkpoint(name)
208     rescue StandardError => e
209       debug_log("    Generated snapshot step failed with exception:\n" \
210                 "      #{e.class}: #{e}\n", color: :red, timestamp: false)
211       raise e
212     end
213   end