summaryrefslogtreecommitdiffstats
path: root/features/step_definitions/additional_software_packages.rb
blob: 4ffdec0f2ee5d76bc6b69ce32454b6e6205ce071 (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
ASP_STATE_DIR = "/run/live-additional-software"
ASP_CONF = '/live/persistence/TailsData_unlocked/live-additional-software.conf'

Then /^the Additional Software (upgrade|installation) service has started$/ do |service|
  if $vm.file_exist?(ASP_CONF) and !$vm.file_empty?(ASP_CONF)
    case service
    when "installation"
      service = "tails-additional-software-install"
      seconds_to_wait = 600
    when "upgrade"
      service = "tails-additional-software-upgrade"
      seconds_to_wait = 900
    end
    try_for(seconds_to_wait, :delay => 10) do
      $vm.execute("systemctl status #{service}.service").success?
    end
    if service == "installation"
      step "I am notified that the installation succeeded"
    end
  end
end

Then /^I am notified I can not use Additional Software for "([^"]*)"$/  do |package|
  title = "You could install #{package} automatically when starting Tails"
  step "I see the \"#{title}\" notification after at most 300 seconds"
end

Then /^I am notified that the installation succeeded$/  do
  title = "Additional software installed successfully"
  step "I see the \"#{title}\" notification after at most 300 seconds"
end

Then /^I am proposed to create an Additional Software persistence for the "([^"]*)" package$/  do |package|
  title = "Add #{package} to your additional software?"
  step "I see the \"#{title}\" notification after at most 300 seconds"
end

Then /^I create the Additional Software persistence$/  do
  gnome_shell = Dogtail::Application.new('gnome-shell')
  gnome_shell.child('Create Persistent Storage', roleName: 'push button').click
  step 'I create a persistent partition for Additional Software'
  step 'The Additional Software persistence option is enabled'
  save_and_exit_the_persistence_wizard
end

Then /^The Additional Software persistence option is enabled$/  do
  @screen.wait('ASPPersistenceSetupOptionEnabled.png', 60)
end

Then /^Additional Software is correctly configured for package "([^"]*)"$/ do |package|
  assert($vm.file_exist?(ASP_CONF), "ASP configuration file not found")
  step 'all persistence configuration files have safe access rights'
  $vm.execute("ls /live/persistence/TailsData_unlocked/apt/cache/#{package}_*.deb").success?
  $vm.execute("ls /live/persistence/TailsData_unlocked/apt/lists/*_Packages").success?
  try_for(30) do
    $vm.execute("grep --line-regexp --fixed-strings #{package} #{ASP_CONF}").success?
  end
end

Then /^"([^"]*)" is not in the list of Additional Software$/ do |package|
  assert($vm.file_exist?(ASP_CONF), "ASP configuration file not found")
  step 'all persistence configuration files have safe access rights'
  try_for(30) do
    $vm.execute("grep \"#{package}\" #{ASP_CONF}").stdout.empty?
  end
end

When /^I (refuse|accept) (adding|removing) "([^"]*)" (?:to|from) Additional Software$/  do |decision, action, package|
  gnome_shell = Dogtail::Application.new('gnome-shell')
  case action
  when "adding"
    title = "Add #{package} to your additional software?"
    step "I see the \"#{title}\" notification after at most 300 seconds"
    case decision
    when "accept"
      gnome_shell.child('Install Every Time', roleName: 'push button').click
    when "refuse"
      gnome_shell.child('Install Only Once', roleName: 'push button').click
    end
  when "removing"
    title = "Remove #{package} from your additional software?"
    step "I see the \"#{title}\" notification after at most 300 seconds"
    case decision
    when "accept"
      gnome_shell.child('Remove', roleName: 'push button').click
    when "refuse"
      gnome_shell.child('Cancel', roleName: 'push button').click
    end
  end
end

Given /^I remove "([^"]*)" from the list of Additional Software using Additional Software GUI$/  do |package|
  asp_gui = Dogtail::Application.new('tails-additional-software-config')
  installed_package = asp_gui.child(package, roleName: 'label')
  installed_package.parent.parent.child('Close', roleName: 'push button').click
  asp_gui.child('Question', roleName: 'alert').button('Remove').click
  deal_with_polkit_prompt(@sudo_password)
end

When /^I prepare the Additional Software upgrade process to fail$/  do
  # Remove the newest cowsay package from the APT cache with a DPKG hook
  # before it gets upgraded so that we simulate a failing upgrade.
  failing_dpkg_hook = <<-EOF
DPkg::Pre-Invoke {
  "ls -tr1 /var/cache/apt/archives/cowsay*.deb | head -n 1 | xargs rm";
};
EOF
  $vm.file_overwrite('/etc/apt/apt.conf.d/00failingDPKGhook', failing_dpkg_hook)
  # Tell the upgrade service check step not to run
  $vm.execute("touch #{ASP_STATE_DIR}/doomed_to_fail")
end

When /^I remove the "([^"]*)" deb files from the APT cache$/  do |package|
  $vm.execute_successfully("rm /live/persistence/TailsData_unlocked/apt/cache/#{package}_*.deb")
end

Then /^I can open the Additional Software documentation from the notification$/  do
  gnome_shell = Dogtail::Application.new('gnome-shell')
  gnome_shell.child('Documentation', roleName: 'push button').click
  # For some reason the below two steps fail. Dogtail can not find the Firefox
  # application.
  #try_for(60) { @torbrowser = Dogtail::Application.new('Firefox') }
  #step '"Install from another Tails" has loaded in the Tor Browser'
  # So instead let's try to find the title of the page with Sikuli.
  @screen.wait('ASPDocumentationInstallCloning.png', 120)
end

Then /^the Additional Software dpkg hook has been run for package "([^"]*)" and notices the persistence is locked$/ do |package|
  asp_logs = "#{ASP_STATE_DIR}/log"
  assert(!$vm.file_empty?(asp_logs))
  try_for(60) { $vm.execute("grep -E '^.*New\spackages\smanually\sinstalled:\s.*#{package}.*$' #{asp_logs}").success? }
  try_for(60) { $vm.file_content(asp_logs).include?('Warning: persistence storage is locked') }
end

When /^I can open the Additional Software configuration window from the notification$/ do
  gnome_shell = Dogtail::Application.new('gnome-shell')
  gnome_shell.child('Configure', roleName: 'push button').click
  asp = Dogtail::Application.new('tails-additional-software-config')
end

Then /^I can open the Additional Software log file from the notification$/ do
  gnome_shell = Dogtail::Application.new('gnome-shell')
  gnome_shell.child('Show Log', roleName: 'push button').click
  try_for(60) { gedit = Dogtail::Application.new('gedit').child("log [Read-Only] (#{ASP_STATE_DIR}) - gedit", roleName: 'frame') }
end