|
6 | 6 | describe Puppet::Util::SELinux do
|
7 | 7 | include Puppet::Util::SELinux
|
8 | 8 |
|
9 |
| - let(:selinux) { double('selinux', is_selinux_enabled: false) } |
| 9 | + let(:selinux) { double('selinux', is_selinux_enabled: 0) } |
10 | 10 |
|
11 | 11 | before :each do
|
12 | 12 | stub_const('Selinux', selinux)
|
|
252 | 252 | end
|
253 | 253 | end
|
254 | 254 |
|
| 255 | + it "should return nil when permission denied errors are encountered" do |
| 256 | + without_partial_double_verification do |
| 257 | + expect(self).to receive(:selinux_support?).and_return(true) |
| 258 | + expect(self).to receive(:selinux_label_support?).and_return(true) |
| 259 | + hnd = double("SWIG::TYPE_p_selabel_handle") |
| 260 | + expect(Selinux).to receive(:selabel_lookup).with(hnd, "/root/chuj", 0).and_return(-1) |
| 261 | + expect(self).to receive(:file_lstat).with("/root/chuj").and_raise(Errno::EACCES, "/root/chuj") |
| 262 | + |
| 263 | + expect(get_selinux_default_context_with_handle("/root/chuj", hnd)).to be_nil |
| 264 | + end |
| 265 | + end |
| 266 | + |
| 267 | + it "should return nil when no such file or directory errors are encountered and resource_ensure is unset" do |
| 268 | + without_partial_double_verification do |
| 269 | + expect(self).to receive(:selinux_support?).and_return(true) |
| 270 | + expect(self).to receive(:selinux_label_support?).and_return(true) |
| 271 | + hnd = double("SWIG::TYPE_p_selabel_handle") |
| 272 | + expect(Selinux).to receive(:selabel_lookup).with(hnd, "/root/chuj", 0).and_return(-1) |
| 273 | + expect(self).to receive(:file_lstat).with("/root/chuj").and_raise(Errno::ENOENT, "/root/chuj") |
| 274 | + |
| 275 | + expect(get_selinux_default_context_with_handle("/root/chuj", hnd)).to be_nil |
| 276 | + end |
| 277 | + end |
| 278 | + |
| 279 | + it "should pass through lstat mode when file exists" do |
| 280 | + without_partial_double_verification do |
| 281 | + expect(self).to receive(:selinux_support?).and_return(true).twice |
| 282 | + expect(self).to receive(:selinux_label_support?).and_return(true).twice |
| 283 | + hnd = double("SWIG::TYPE_p_selabel_handle") |
| 284 | + fstat = double("File::Stat", :mode => 16384) |
| 285 | + expect(Selinux).to receive(:selabel_lookup).with(hnd, "/root/chuj", fstat.mode).and_return([0, "user_u:role_r:type_t:s0"]).twice |
| 286 | + expect(self).to receive(:file_lstat).with("/root/chuj").and_return(fstat).twice |
| 287 | + |
| 288 | + expect(get_selinux_default_context_with_handle("/root/chuj", hnd)).to eq("user_u:role_r:type_t:s0") |
| 289 | + expect(get_selinux_default_context_with_handle("/root/chuj", hnd, :file)).to eq("user_u:role_r:type_t:s0") |
| 290 | + end |
| 291 | + end |
| 292 | + |
| 293 | + it "should determine mode based on resource ensure when set to file" do |
| 294 | + without_partial_double_verification do |
| 295 | + expect(self).to receive(:selinux_support?).and_return(true).twice |
| 296 | + expect(self).to receive(:selinux_label_support?).and_return(true).twice |
| 297 | + hnd = double("SWIG::TYPE_p_selabel_handle") |
| 298 | + expect(Selinux).to receive(:selabel_lookup).with(hnd, "/root/chuj", 32768).and_return(-1).twice |
| 299 | + expect(self).to receive(:file_lstat).with("/root/chuj").and_raise(Errno::ENOENT, "/root/chuj").twice |
| 300 | + |
| 301 | + expect(get_selinux_default_context_with_handle("/root/chuj", hnd, :present)).to be_nil |
| 302 | + expect(get_selinux_default_context_with_handle("/root/chuj", hnd, :file)).to be_nil |
| 303 | + end |
| 304 | + end |
| 305 | + |
| 306 | + it "should determine mode based on resource ensure when set to dir" do |
| 307 | + without_partial_double_verification do |
| 308 | + expect(self).to receive(:selinux_support?).and_return(true) |
| 309 | + expect(self).to receive(:selinux_label_support?).and_return(true) |
| 310 | + hnd = double("SWIG::TYPE_p_selabel_handle") |
| 311 | + expect(Selinux).to receive(:selabel_lookup).with(hnd, "/root/chuj", 16384).and_return(-1) |
| 312 | + expect(self).to receive(:file_lstat).with("/root/chuj").and_raise(Errno::ENOENT, "/root/chuj") |
| 313 | + |
| 314 | + expect(get_selinux_default_context_with_handle("/root/chuj", hnd, :directory)).to be_nil |
| 315 | + end |
| 316 | + end |
| 317 | + |
| 318 | + it "should determine mode based on resource ensure when set to link" do |
| 319 | + without_partial_double_verification do |
| 320 | + expect(self).to receive(:selinux_support?).and_return(true) |
| 321 | + expect(self).to receive(:selinux_label_support?).and_return(true) |
| 322 | + hnd = double("SWIG::TYPE_p_selabel_handle") |
| 323 | + expect(Selinux).to receive(:selabel_lookup).with(hnd, "/root/chuj", 40960).and_return(-1) |
| 324 | + expect(self).to receive(:file_lstat).with("/root/chuj").and_raise(Errno::ENOENT, "/root/chuj") |
| 325 | + |
| 326 | + expect(get_selinux_default_context_with_handle("/root/chuj", hnd, :link)).to be_nil |
| 327 | + end |
| 328 | + end |
| 329 | + |
| 330 | + it "should determine mode based on resource ensure when set to unknown" do |
| 331 | + without_partial_double_verification do |
| 332 | + expect(self).to receive(:selinux_support?).and_return(true) |
| 333 | + expect(self).to receive(:selinux_label_support?).and_return(true) |
| 334 | + hnd = double("SWIG::TYPE_p_selabel_handle") |
| 335 | + expect(Selinux).to receive(:selabel_lookup).with(hnd, "/root/chuj", 0).and_return(-1) |
| 336 | + expect(self).to receive(:file_lstat).with("/root/chuj").and_raise(Errno::ENOENT, "/root/chuj") |
| 337 | + |
| 338 | + expect(get_selinux_default_context_with_handle("/root/chuj", hnd, "unknown")).to be_nil |
| 339 | + end |
| 340 | + end |
| 341 | + |
255 | 342 | it "should raise an ArgumentError when handle is nil" do
|
256 | 343 | allow(self).to receive(:selinux_support?).and_return(true)
|
257 | 344 | allow(self).to receive(:selinux_label_support?).and_return(true)
|
|
0 commit comments