-
Notifications
You must be signed in to change notification settings - Fork 8
/
proposal_settings_test.rb
executable file
·215 lines (172 loc) · 6.26 KB
/
proposal_settings_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
#!/usr/bin/env rspec
# ------------------------------------------------------------------------------
# Copyright (c) 2017 SUSE LLC
#
#
# 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.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact SUSE.
#
# To contact SUSE about this file by physical or electronic mail, you may find
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------
require_relative "../../test_helper.rb"
require "y2firewall/proposal_settings"
Yast.import "Linuxrc"
Yast.import "ProductFeatures"
describe Y2Firewall::ProposalSettings do
subject { described_class.create_instance }
let(:global_section) do
{
"enable_firewall" => false,
"enable_sshd" => false,
"firewall_enable_ssh" => false
}
end
let(:use_vnc) { false }
let(:use_ssh) { false }
let(:root_password) { "secret" }
before do
allow(Yast::Linuxrc).to receive(:vnc).and_return(use_vnc)
allow(Yast::Linuxrc).to receive(:usessh).and_return(use_ssh)
allow(Yast::UsersSimple).to receive(:GetRootPassword).and_return(root_password)
allow(Yast::ProductFeatures).to receive("GetSection")
.with("globals").and_return(global_section)
end
describe "#initialize" do
it "loads the default values from the control file" do
expect_any_instance_of(described_class).to receive(:load_features)
described_class.create_instance
end
context "when firewall has been enabled in the control file" do
let(:global_section) { { "enable_firewall" => true, "enable_sshd" => false } }
it "sets firewalld service to be enabled" do
expect_any_instance_of(described_class).to receive(:enable_firewall!)
described_class.create_instance
end
end
context "when ssh has been enable by Linuxrc" do
let(:use_ssh) { true }
it "sets ssh service to be enabled" do
expect_any_instance_of(described_class).to receive(:enable_sshd!)
described_class.create_instance
end
it "sets the ssh port to be opened" do
expect_any_instance_of(described_class).to receive(:open_ssh!)
described_class.create_instance
end
end
context "when vnc has been enable by Linuxrc" do
let(:use_vnc) { true }
it "sets the vnc port to be opened" do
expect_any_instance_of(described_class).to receive(:open_vnc!)
described_class.create_instance
end
end
context "when no root password was set" do
before do
allow(Yast::Linuxrc).to receive(:usessh).and_return(false)
allow(Yast::UsersSimple).to receive(:GetRootPassword)
.and_return("")
end
it "opens SSH to allow public key authentication" do
expect_any_instance_of(described_class).to receive(:enable_sshd!)
expect_any_instance_of(described_class).to receive(:open_ssh!)
described_class.create_instance
end
end
end
describe "#selinux_config" do
it "returns a Y2Security::Selinux instance" do
expect(subject.selinux_config).to be_a(Y2Security::Selinux)
end
end
describe "#enable_firewall!" do
it "sets firewalld service to be enabled" do
allow(Yast::PackagesProposal).to receive("AddResolvables")
.with("firewall", :package, ["firewalld"])
expect(subject.enable_firewall).to be(false)
subject.enable_firewall!
expect(subject.enable_firewall).to be(true)
end
it "adds the firewalld package to be installed" do
expect(Yast::PackagesProposal).to receive("AddResolvables")
.with("firewall", :package, ["firewalld"])
subject.enable_firewall!
end
end
describe "#disable_firewall!" do
it "sets firewalld service to be disabled" do
allow(Yast::PackagesProposal).to receive("RemoveResolvables")
.with("firewall", :package, ["firewalld"])
subject.disable_firewall!
expect(subject.enable_firewall).to be(false)
end
it "removes the firewalld package for current selection" do
expect(Yast::PackagesProposal).to receive("RemoveResolvables")
.with("firewall", :package, ["firewalld"])
subject.disable_firewall!
end
end
describe "#enable_sshd!" do
it "sets sshd service to be enabled" do
allow(Yast::PackagesProposal).to receive("AddResolvables")
.with("firewall", :package, ["openssh"])
subject.enable_sshd!
expect(subject.enable_sshd).to be(true)
end
it "adds the openssh package to be installed" do
expect(Yast::PackagesProposal).to receive("AddResolvables")
.with("firewall", :package, ["openssh"])
subject.enable_sshd!
end
end
describe "#disable_sshd!" do
it "sets sshd service to be disabled" do
allow(Yast::PackagesProposal).to receive("RemoveResolvables")
.with("firewall", :package, ["openssh"])
subject.disable_sshd!
expect(subject.enable_sshd).to be(false)
end
it "removes the openssh package for current selection" do
expect(Yast::PackagesProposal).to receive("RemoveResolvables")
.with("firewall", :package, ["openssh"])
subject.disable_sshd!
end
end
describe "#open_ssh!" do
it "sets the ssh port to be opened" do
subject.open_ssh = false
subject.open_ssh!
expect(subject.open_ssh).to be(true)
end
end
describe "#close_ssh!" do
it "sets the ssh port to be closed" do
subject.open_ssh = true
subject.close_ssh!
expect(subject.open_ssh).to be(false)
end
end
describe "#open_vnc!" do
it "sets the vnc port to be opened" do
subject.open_vnc = false
subject.open_vnc!
expect(subject.open_vnc).to be(true)
end
end
describe "#close_vnc!" do
it "sets the vnc port to be closed" do
subject.open_vnc = true
subject.close_vnc!
expect(subject.open_vnc).to be(false)
end
end
end