additional_software_packages.rb 6.46 KB
Newer Older
1
ASP_STATE_DIR = '/run/live-additional-software'.freeze
2
ASP_CONF = '/live/persistence/TailsData_unlocked/live-additional-software.conf'
3
           .freeze
4

5
Then /^the Additional Software (upgrade|installation) service has started$/ do |service|
intrigeri's avatar
intrigeri committed
6
  if $vm.file_exist?(ASP_CONF) && !$vm.file_empty?(ASP_CONF)
7
    case service
8
9
    when 'installation'
      service = 'tails-additional-software-install'
10
      seconds_to_wait = 600
11
12
    when 'upgrade'
      service = 'tails-additional-software-upgrade'
13
      seconds_to_wait = 900
14
    end
15
    try_for(seconds_to_wait, delay: 10) do
16
      $vm.execute("systemctl status #{service}.service").success?
17
    end
18
19
    if service == 'installation'
      step 'I am notified that the installation succeeded'
20
    end
21
  end
22
end
23

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

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

34
Then /^I am proposed to add the "([^"]*)" package to my Additional Software$/ do |package|
35
  title = "Add #{package} to your additional software?"
36
  step "I see the \"#{title}\" notification after at most 300 seconds"
37
38
end

39
Then /^I create a persistent storage and activate the Additional Software feature$/ do
40
41
  gnome_shell = Dogtail::Application.new('gnome-shell')
  gnome_shell.child('Create Persistent Storage', roleName: 'push button').click
42
43
  step 'I create a persistent partition for Additional Software'
  step 'The Additional Software persistence option is enabled'
44
  save_and_exit_the_persistence_wizard
45
46
end

47
Then /^The Additional Software persistence option is enabled$/ do
48
49
50
51
52
53
54
55
  @screen.wait('PersistenceWizardPresets.png', 60)
  begin
    @screen.find('ASPPersistenceSetupOptionEnabled.png')
  rescue FindFailed
    # We might have to scroll down to find it
    @screen.press('Page_Down')
    @screen.wait('ASPPersistenceSetupOptionEnabled.png', 10)
  end
56
57
end

intrigeri's avatar
intrigeri committed
58
Then /^Additional Software is correctly configured for package "([^"]*)"$/ do |package|
59
  try_for(30) do
60
    assert($vm.file_exist?(ASP_CONF), 'ASP configuration file not found')
61
    step 'all persistence configuration files have safe access rights'
62
63
64
65
    assert_not_empty(
      $vm.file_glob(
        "/live/persistence/TailsData_unlocked/apt/cache/#{package}_*.deb"
      )
66
    )
67
68
    assert_not_empty(
      $vm.file_glob('/live/persistence/TailsData_unlocked/apt/lists/*_Packages')
69
70
71
72
    )
    $vm.execute(
      "grep --line-regexp --fixed-strings #{package} #{ASP_CONF}"
    ).success?
73
  end
74
75
end

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

84
When /^I (refuse|accept) (adding|removing) "([^"]*)" (?:to|from) Additional Software$/ do |decision, action, package|
85
  case action
86
  when 'adding'
87
    notification_title = "Add #{package} to your additional software?"
88
    case decision
89
    when 'accept'
90
      button_title = 'Install Every Time'
91
    when 'refuse'
92
      button_title = 'Install Only Once'
93
    end
94
  when 'removing'
95
    notification_title = "Remove #{package} from your additional software?"
96
    case decision
97
    when 'accept'
98
      button_title = 'Remove'
99
    when 'refuse'
100
      button_title = 'Cancel'
101
102
    end
  end
103
104
  try_for(300) do
    notification =
intrigeri's avatar
Linting    
intrigeri committed
105
106
      Dogtail::Application
      .new('gnome-shell')
107
      .children('', roleName: 'notification')
intrigeri's avatar
Linting    
intrigeri committed
108
      .find { |notif| notif.child?(notification_title, roleName: 'label') }
109
110
111
    assert_not_nil(notification)
    notification.child(button_title, roleName: 'push button').click
  end
112
113
end

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

122
When /^I prepare the Additional Software upgrade process to fail$/ do
123
  # Remove the newest cowsay package from the APT cache with a DPKG hook
124
  # before it gets upgraded so that we simulate a failing upgrade.
125
  failing_dpkg_hook = <<~HOOK
126
127
128
    DPkg::Pre-Invoke {
      "ls -1 -v /var/cache/apt/archives/cowsay*.deb | tail -n 1 | xargs rm";
    };
129
  HOOK
130
131
  $vm.file_overwrite('/etc/apt/apt.conf.d/00failingDPKGhook', failing_dpkg_hook)
  # Tell the upgrade service check step not to run
132
  $vm.execute_successfully("touch #{ASP_STATE_DIR}/doomed_to_fail")
133
134
end

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

141
Then /^I can open the Additional Software documentation from the notification$/ do
142
143
  gnome_shell = Dogtail::Application.new('gnome-shell')
  gnome_shell.child('Documentation', roleName: 'push button').click
144
  try_for(60) { @torbrowser = Dogtail::Application.new('Firefox') }
145
  step '"Tails - Install from another Tails" has loaded in the Tor Browser'
146
end
147

148
Then /^the Additional Software dpkg hook has been run for package "([^"]*)" and notices the persistence is locked$/ do |package|
149
  asp_logs = "#{ASP_STATE_DIR}/log"
150
  assert(!$vm.file_empty?(asp_logs))
151
  try_for(180, delay: 2) do
152
153
154
155
156
157
158
159
160
    $vm.execute(
      "grep -E '^.*New\spackages\smanually\sinstalled:\s.*#{package}.*$' " \
      "#{asp_logs}"
    ).success?
  end
  try_for(60) do
    $vm.file_content(asp_logs)
       .include?('Warning: persistence storage is locked')
  end
161
end
162

bertagaz's avatar
bertagaz committed
163
When /^I can open the Additional Software configuration window from the notification$/ do
164
165
  gnome_shell = Dogtail::Application.new('gnome-shell')
  gnome_shell.child('Configure', roleName: 'push button').click
166
  Dogtail::Application.new('tails-additional-software-config')
167
168
end

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