summaryrefslogtreecommitdiffstats
path: root/features/step_definitions/snapshots.rb
blob: 83a6e9689c45e4115f337aa797647751fe0c3304 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
def checkpoints
  {
    'tails-greeter' => {
      :description => "I have started Tails from DVD without network and stopped at Tails Greeter's login screen",
      :parent_checkpoint => nil,
      :steps => [
        'the network is unplugged',
        'I start the computer',
        'the computer boots Tails'
      ],
    },

    'no-network-logged-in' => {
      :description => "I have started Tails from DVD without network and logged in",
      :parent_checkpoint => "tails-greeter",
      :steps => [
        'I log in to a new session',
      ],
    },

    'with-network-logged-in' => {
      :description => "I have started Tails from DVD and logged in and the network is connected",
      :parent_checkpoint => "no-network-logged-in",
      :steps => [
        'the network is plugged',
        'Tor is ready',
        'all notifications have disappeared',
        'available upgrades have been checked',
      ],
    },

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

    'no-network-logged-in-sudo-passwd' => {
      :temporary => true,
      :description => "I have started Tails from DVD without network and logged in with an administration password",
      :parent_checkpoint => "tails-greeter",
      :steps => [
        'I set an administration password',
        'I log in to a new session',
      ],
    },

    'with-network-logged-in-sudo-passwd' => {
      :temporary => true,
      :description => "I have started Tails from DVD and logged in with an administration password and the network is connected",
      :parent_checkpoint => "no-network-logged-in-sudo-passwd",
      :steps => [
        'the network is plugged',
        'Tor is ready',
        'all notifications have disappeared',
        'available upgrades have been checked',
      ],
    },

    'usb-install-tails-greeter' => {
      :description => "I have started Tails without network from a USB drive without a persistent partition and stopped at Tails Greeter's login screen",
      :parent_checkpoint => nil,
      :steps => [
        'I create a 7200 MiB disk named "__internal"',
        'I plug USB drive "__internal"',
        'I write the Tails USB image to disk "__internal"',
        'I start Tails from USB drive "__internal" with network unplugged',
        'the boot device has safe access rights',
        'Tails is running from USB drive "__internal"',
        'there is no persistence partition on USB drive "__internal"',
        'process "udev-watchdog" is running',
        'udev-watchdog is monitoring the correct device',
      ],
    },

    'usb-install-logged-in' => {
      :description => "I have started Tails without network from a USB drive without a persistent partition and logged in",
      :parent_checkpoint => 'usb-install-tails-greeter',
      :steps => [
        'I log in to a new session',
      ],
    },

    '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 => [
        'I create a persistent partition',
        'a Tails persistence partition exists on USB drive "__internal"',
        'I shutdown Tails and wait for the computer to power off',
        'I start Tails from USB drive "__internal" with network unplugged',
        'the boot device has safe access rights',
        'Tails is running from USB drive "__internal"',
        'process "udev-watchdog" is running',
        'udev-watchdog is monitoring the correct device',
      ],
    },

    'usb-install-with-persistence-logged-in' => {
      :description => "I have started Tails without network from a USB drive with a persistent partition enabled and logged in",
      :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',
      ],
    },

    'usb-install-with-persistence-logged-in-with-administration-password' => {
      :description => "I have started Tails without network from a USB drive with a persistent partition enabled and logged in with an administration password",
      :parent_checkpoint => 'usb-install-with-persistence-tails-greeter',
      :steps => [
        'I enable persistence',
        'I set an administration password',
        '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',
      ],
    },
  }
end

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

  step "a computer"
  if VM.snapshot_exists?(name)
    $vm.restore_snapshot(name)
    post_snapshot_restore_hook
  else
    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)
      end
      post_snapshot_restore_hook
    end
    debug_log(scenario_indent + "Checkpoint: #{checkpoint_description}",
              color: :white, timestamp: false)
    step_action = "Given"
    if parent_checkpoint
      parent_description = checkpoints[parent_checkpoint][:description]
      debug_log(step_indent + "#{step_action} #{parent_description}",
                color: :green, timestamp: false)
      step_action = "And"
    end
    steps.each do |s|
      begin
        step(s)
      rescue Exception => e
        debug_log(scenario_indent +
                  "Step failed while creating checkpoint: #{s}",
                  color: :red, timestamp: false)
        raise e
      end
      debug_log(step_indent + "#{step_action} #{s}",
                color: :green, timestamp: false)
      step_action = "And"
    end
    $vm.save_snapshot(name)
  end
end

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