Merge branch 'stable' into devel
[tails.git] / features / step_definitions / snapshots.rb
blob92eb243f58454ee07e240e8a1d7d496ba7f805b3
1 # Redefining CHECKPOINTS is probably not a good idea, so let's guard against it
2 unless defined? CHECKPOINTS
3   CHECKPOINTS =
4     {
5       'tails-greeter'                                     => {
6         description:       "I have started Tails from DVD without network and stopped at Tails Greeter's login screen",
7         parent_checkpoint: nil,
8         steps:             [
9           'I start the computer',
10           'the computer boots Tails',
11         ],
12       },
14       'no-network-logged-in'                              => {
15         description:       'I have started Tails from DVD without network and logged in',
16         parent_checkpoint: 'tails-greeter',
17         steps:             [
18           'I log in to a new session',
19           'all notifications have disappeared',
20         ],
21       },
23       'with-network-logged-in'                            => {
24         description:       'I have started Tails from DVD and logged in and the network is connected',
25         parent_checkpoint: 'no-network-logged-in',
26         steps:             [
27           'the network is plugged',
28           'Tor is ready',
29           'all notifications have disappeared',
30           'available upgrades have been checked',
31         ],
32       },
34       'no-network-logged-in-sudo-passwd'                  => {
35         temporary:         true,
36         description:       'I have started Tails from DVD without network and logged in with an administration password',
37         parent_checkpoint: 'tails-greeter',
38         steps:             [
39           'I set an administration password',
40           'I log in to a new session',
41           'all notifications have disappeared',
42         ],
43       },
45       'with-network-logged-in-sudo-passwd'                => {
46         temporary:         true,
47         description:       'I have started Tails from DVD and logged in with an administration password and the network is connected',
48         parent_checkpoint: 'no-network-logged-in-sudo-passwd',
49         steps:             [
50           'the network is plugged',
51           'Tor is ready',
52           'all notifications have disappeared',
53           'available upgrades have been checked',
54         ],
55       },
57       'usb-install-tails-greeter'                         => {
58         description:       "I have started Tails without network from a USB drive without a persistent partition and stopped at Tails Greeter's login screen",
59         parent_checkpoint: nil,
60         steps:             [
61           'I create a 7200 MiB disk named "__internal"',
62           'I plug USB drive "__internal"',
63           'I write the Tails USB image to disk "__internal"',
64           'I start Tails from USB drive "__internal" with network unplugged',
65           'the boot device has safe access rights',
66           'the USB drive "__internal" has a valid partition table',
67           'Tails is running from USB drive "__internal"',
68           'there is no persistence partition on USB drive "__internal"',
69           'process "udev-watchdog" is running',
70           'udev-watchdog is monitoring the correct device',
71         ],
72       },
74       'usb-install-logged-in'                             => {
75         description:       'I have started Tails without network from a USB drive without a persistent partition and logged in',
76         parent_checkpoint: 'usb-install-tails-greeter',
77         steps:             [
78           'I log in to a new session',
79           'all notifications have disappeared',
80         ],
81       },
83       'usb-install-with-persistence-tails-greeter'        => {
84         description:       "I have started Tails without network from a USB drive with a persistent partition and stopped at Tails Greeter's login screen",
85         parent_checkpoint: 'usb-install-logged-in',
86         steps:             [
87           'I create a persistent partition',
88           'a Tails persistence partition exists on USB drive "__internal"',
89           'I cold reboot the computer',
90           'the computer reboots Tails',
91           'the boot device has safe access rights',
92           'Tails is running from USB drive "__internal"',
93           'process "udev-watchdog" is running',
94           'udev-watchdog is monitoring the correct device',
95         ],
96       },
98       'usb-install-with-persistence-logged-in'            => {
99         description:       'I have started Tails without network from a USB drive with a persistent partition enabled and logged in',
100         parent_checkpoint: 'usb-install-with-persistence-tails-greeter',
101         steps:             [
102           'I enable persistence',
103           'I log in to a new session',
104           'all tps features are active',
105           'all persistent filesystems have safe access rights',
106           'all persistence configuration files have safe access rights',
107           'all persistent directories have safe access rights',
108           'all notifications have disappeared',
109         ],
110       },
112       'usb-install-with-persistence-luks-1-tails-greeter' => {
113         description:       "I have started Tails without network from a USB drive with a LUKS 1 persistent partition and stopped at Tails Greeter's login screen",
114         parent_checkpoint: 'usb-install-with-persistence-tails-greeter',
115         steps:             [
116           'the persistence partition on USB drive "__internal" uses LUKS version 1',
117           'I reload tails-persistent-storage.service',
118         ],
119       },
121     }.freeze
123   def reach_checkpoint(name, num_try = 0)
124     step 'a computer'
125     if VM.snapshot_exists?(name)
126       $vm.restore_snapshot(name)
127     else
128       checkpoint = CHECKPOINTS[name]
129       checkpoint_description = checkpoint[:description]
130       parent_checkpoint = checkpoint[:parent_checkpoint]
131       steps = checkpoint[:steps]
132       # rubocop:disable Metrics/BlockNesting
133       if parent_checkpoint
134         if VM.snapshot_exists?(parent_checkpoint)
135           $vm.restore_snapshot(parent_checkpoint)
136         else
137           reach_checkpoint(parent_checkpoint)
138         end
139         post_snapshot_restore_hook(parent_checkpoint, num_try)
140       end
141       # rubocop:enable Metrics/BlockNesting
142       log_scenario("Checkpoint: #{checkpoint_description}")
143       step_action = 'Given'
144       if parent_checkpoint
145         parent_description = CHECKPOINTS[parent_checkpoint][:description]
146         step_name = "#{step_action} #{parent_description}"
147         log_step_succeeded(step_name)
148         step_action = 'And'
149       end
150       steps.each do |s|
151         step_name = "#{step_action} #{s}"
152         begin
153           step(s)
154         rescue StandardError => e
155           log_step_failed(step_name)
156           raise e
157         end
158         log_step_succeeded(step_name)
159         step_action = 'And'
160       end
161       $vm.save_snapshot(name)
162     end
163     # VM#save_snapshot restores the RAM-only snapshot immediately
164     # after saving it, in which case post_snapshot_restore_hook is
165     # useful to ensure we've reached a good starting point, so we run
166     # it in all cases, including even when've just saved a new snapshot.
167     post_snapshot_restore_hook(name, num_try)
168   end
169   # For each checkpoint we generate a step to reach it.
170   CHECKPOINTS.each do |name, desc|
171     step_regex = Regexp.new("^#{Regexp.escape(desc[:description])}$")
172     Given step_regex do
173       reach_checkpoint(name)
174     rescue StandardError => e
175       debug_log("    Generated snapshot step failed with exception:\n" \
176                 "      #{e.class}: #{e}\n", color: :red, timestamp: false)
177       raise e
178     end
179   end