-
Notifications
You must be signed in to change notification settings - Fork 19
/
addon_eula_dialog_test.rb
220 lines (175 loc) · 6.8 KB
/
addon_eula_dialog_test.rb
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env rspec
# ------------------------------------------------------------------------------
# Copyright (c) 2018 SUSE LLC, All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# ------------------------------------------------------------------------------
require_relative "../../spec_helper"
require "registration/ui/addon_eula_dialog"
describe Registration::UI::AddonEulaDialog do
subject(:dialog) { described_class.new(addons) }
let(:params) { { "eula_url" => "http://example.addon-eula.url" } }
let(:addons) { [registered_addon, addon_wo_eula, addon_with_eula] }
let(:addon_wo_eula) { Registration::Addon.new(addon_generator) }
let(:addon_with_eula) { Registration::Addon.new(addon_generator(params)) }
let(:second_addon_with_eula) { Registration::Addon.new(addon_generator(params)) }
let(:registered_addon) { Registration::Addon.new(addon_generator(params)) }
let(:product_license) do
instance_double(Y2Packager::ProductLicense, accepted?: false, accept!: true)
end
describe "#run" do
before do
allow(Yast::Wizard).to receive(:SetContents)
allow(dialog).to receive(:find_license).and_return(product_license)
allow(dialog).to receive(:download_eula).and_return(true)
registered_addon.registered
end
after do
Registration::Addon.reset!
end
context "when there are no EULA acceptances to show" do
let(:addons) { [registered_addon, addon_wo_eula] }
it "does not display the EULA dialog" do
expect(Yast::ProductLicense).to_not receive(:DisplayLicenseDialogWithTitle)
dialog.run
end
it "returns :next" do
expect(dialog.run).to eq(:next)
end
end
context "when there are EULA acceptances pending" do
let(:addons) { [addon_with_eula, second_addon_with_eula] }
let(:first_dialog_response) { :accepted }
let(:second_dialog_response) { :accepted }
before do
allow(Yast::ProductLicense).to receive(:HandleLicenseDialogRet)
.and_return(first_dialog_response, second_dialog_response)
end
context "and the user wants to go back" do
let(:first_dialog_response) { :back }
it "returns :back" do
expect(subject.run).to eq(:back)
end
end
context "and the user wants to abort" do
let(:first_dialog_response) { :abort }
it "returns :abort" do
expect(subject.run).to eq(:abort)
end
end
context "but an EULA cannot be downloaded" do
before do
allow(dialog).to receive(:download_eula).and_return(false)
end
it "does not display the eula dialog" do
expect(Yast::ProductLicense).to_not receive(:DisplayLicenseDialogWithTitle)
dialog.run
end
it "returns :back" do
expect(dialog.run).to eq(:back)
end
end
end
context "when EULA is accepted" do
let(:addons) { [addon_with_eula] }
before do
allow(Yast::ProductLicense).to receive(:HandleLicenseDialogRet)
.and_return(:accepted)
end
it "sets it as accepted" do
expect(product_license).to receive(:accept!)
subject.run
end
it "returns :next" do
expect(dialog.run).to eq(:next)
subject.run
end
end
context "when EULA is refused" do
let(:addons) { [addon_with_eula] }
before do
allow(Yast::ProductLicense).to receive(:HandleLicenseDialogRet)
.and_return(:abort)
end
it "does not set it as accepted" do
expect(product_license).to_not receive(:accept!)
end
it "returns :abort" do
expect(dialog.run).to eq(:abort)
end
end
end
describe "#accept_eula" do
let(:addon) do
addon_generator("name" => "SLES", "eula_url" => "https://suse.com/download/SLES/eula")
end
let(:addons) { [addon] }
let(:eula_downloader) { instance_double(Registration::EulaDownloader, download: true) }
let(:eula_reader) { instance_double(Registration::EulaReader, licenses: licenses_files) }
let(:licenses_files) do
{ Y2Packager::License::DEFAULT_LANG => "license.txt" }
end
let(:accepted?) { true }
let(:product_license) { instance_double(Y2Packager::ProductLicense, accepted?: accepted?) }
let(:license_content) { "content" }
before do
allow(Registration::EulaDownloader).to receive(:new).and_return(eula_downloader)
allow(Registration::EulaReader).to receive(:new).and_return(eula_reader)
allow(Y2Packager::ProductLicense).to receive(:find).and_return(product_license)
allow(Yast::SCR).to receive(:Read).with(Yast::Path.new(".target.string"), "license.txt")
.and_return(license_content)
allow(dialog).to receive(:setup_eula_dialog)
allow(dialog).to receive(:run_eula_dialog)
end
context "when the eula could not be downloaded" do
before do
allow(eula_downloader).to receive(:download).and_raise(StandardError)
end
it "returns :back" do
expect(dialog.send(:accept_eula, addon)).to eq(:back)
end
end
it "reads the license and asks for a already seen license with the same content" do
expect(Y2Packager::ProductLicense).to receive(:find)
.with(addon.identifier, content: "content").and_return(product_license)
dialog.send(:accept_eula, addon)
end
context "when the license file is not defined" do
let(:licenses_files) { {} }
it "does not ask for already seen licenses" do
expect(Y2Packager::ProductLicense).to_not receive(:find)
dialog.send(:accept_eula, addon)
end
end
context "when license file could not be read" do
let(:license_content) { nil }
it "does not ask for already seen licenses" do
expect(Y2Packager::ProductLicense).to_not receive(:find)
dialog.send(:accept_eula, addon)
end
end
context "when the license was previously accepted" do
let(:accepted?) { true }
it "returns :accepted" do
expect(dialog.send(:accept_eula, addon)).to eq(:accepted)
end
it "does not show the eula" do
expect(subject).to_not receive(:run_eula_dialog)
dialog.send(:accept_eula, addon)
end
end
context "when the license was not previously accepted" do
let(:accepted?) { false }
it "shows the eula" do
expect(subject).to receive(:run_eula_dialog)
dialog.send(:accept_eula, addon)
end
end
end
end