|
159 | 159 | end
|
160 | 160 | end
|
161 | 161 |
|
162 |
| - it "handles no such file or directory errors by issuing a warning" do |
| 162 | + it "backward compatibly handles no such file or directory errors by issuing a warning when resource_ensure not set" do |
163 | 163 | without_partial_double_verification do
|
164 | 164 | allow(self).to receive(:selinux_support?).and_return(true)
|
165 | 165 | allow(self).to receive(:selinux_label_support?).and_return(true)
|
|
170 | 170 | end
|
171 | 171 | end
|
172 | 172 |
|
| 173 | + it "should determine mode based on resource ensure when set to file" do |
| 174 | + without_partial_double_verification do |
| 175 | + allow(self).to receive(:selinux_support?).and_return(true) |
| 176 | + allow(self).to receive(:selinux_label_support?).and_return(true) |
| 177 | + allow(Selinux).to receive(:matchpathcon).with("/root/chuj", 32768).and_return(-1) |
| 178 | + allow(self).to receive(:file_lstat).with("/root/chuj").and_raise(Errno::ENOENT, "/root/chuj") |
| 179 | + |
| 180 | + expect(get_selinux_default_context("/root/chuj", :present)).to be_nil |
| 181 | + expect(get_selinux_default_context("/root/chuj", :file)).to be_nil |
| 182 | + end |
| 183 | + end |
| 184 | + |
| 185 | + it "should determine mode based on resource ensure when set to dir" do |
| 186 | + without_partial_double_verification do |
| 187 | + allow(self).to receive(:selinux_support?).and_return(true) |
| 188 | + allow(self).to receive(:selinux_label_support?).and_return(true) |
| 189 | + allow(Selinux).to receive(:matchpathcon).with("/root/chuj", 16384).and_return(-1) |
| 190 | + allow(self).to receive(:file_lstat).with("/root/chuj").and_raise(Errno::ENOENT, "/root/chuj") |
| 191 | + |
| 192 | + expect(get_selinux_default_context("/root/chuj", :directory)).to be_nil |
| 193 | + end |
| 194 | + end |
| 195 | + |
| 196 | + it "should determine mode based on resource ensure when set to link" do |
| 197 | + without_partial_double_verification do |
| 198 | + allow(self).to receive(:selinux_support?).and_return(true) |
| 199 | + allow(self).to receive(:selinux_label_support?).and_return(true) |
| 200 | + allow(Selinux).to receive(:matchpathcon).with("/root/chuj", 40960).and_return(-1) |
| 201 | + allow(self).to receive(:file_lstat).with("/root/chuj").and_raise(Errno::ENOENT, "/root/chuj") |
| 202 | + |
| 203 | + expect(get_selinux_default_context("/root/chuj", :link)).to be_nil |
| 204 | + end |
| 205 | + end |
| 206 | + |
| 207 | + it "should determine mode based on resource ensure when set to unknown" do |
| 208 | + without_partial_double_verification do |
| 209 | + allow(self).to receive(:selinux_support?).and_return(true) |
| 210 | + allow(self).to receive(:selinux_label_support?).and_return(true) |
| 211 | + allow(Selinux).to receive(:matchpathcon).with("/root/chuj", 0).and_return(-1) |
| 212 | + allow(self).to receive(:file_lstat).with("/root/chuj").and_raise(Errno::ENOENT, "/root/chuj") |
| 213 | + |
| 214 | + expect(get_selinux_default_context("/root/chuj", "unknown")).to be_nil |
| 215 | + end |
| 216 | + end |
| 217 | + |
173 | 218 | it "should return nil if matchpathcon returns failure" do
|
174 | 219 | without_partial_double_verification do
|
175 | 220 | expect(self).to receive(:selinux_support?).and_return(true)
|
|
329 | 374 | end
|
330 | 375 |
|
331 | 376 | it "should return nil if no default context exists" do
|
332 |
| - expect(self).to receive(:get_selinux_default_context).with("/foo").and_return(nil) |
| 377 | + expect(self).to receive(:get_selinux_default_context).with("/foo", nil).and_return(nil) |
333 | 378 | expect(set_selinux_default_context("/foo")).to be_nil
|
334 | 379 | end
|
335 | 380 |
|
336 | 381 | it "should do nothing and return nil if the current context matches the default context" do
|
337 |
| - expect(self).to receive(:get_selinux_default_context).with("/foo").and_return("user_u:role_r:type_t") |
| 382 | + expect(self).to receive(:get_selinux_default_context).with("/foo", nil).and_return("user_u:role_r:type_t") |
338 | 383 | expect(self).to receive(:get_selinux_current_context).with("/foo").and_return("user_u:role_r:type_t")
|
339 | 384 | expect(set_selinux_default_context("/foo")).to be_nil
|
340 | 385 | end
|
341 | 386 |
|
342 | 387 | it "should set and return the default context if current and default do not match" do
|
343 |
| - expect(self).to receive(:get_selinux_default_context).with("/foo").and_return("user_u:role_r:type_t") |
| 388 | + expect(self).to receive(:get_selinux_default_context).with("/foo", nil).and_return("user_u:role_r:type_t") |
344 | 389 | expect(self).to receive(:get_selinux_current_context).with("/foo").and_return("olduser_u:role_r:type_t")
|
345 | 390 | expect(self).to receive(:set_selinux_context).with("/foo", "user_u:role_r:type_t").and_return(true)
|
346 | 391 | expect(set_selinux_default_context("/foo")).to eq("user_u:role_r:type_t")
|
347 | 392 | end
|
348 | 393 | end
|
| 394 | + |
| 395 | + describe "get_create_mode" do |
| 396 | + it "should return 0 if the resource is absent" do |
| 397 | + expect(get_create_mode(:absent)).to eq(0) |
| 398 | + end |
| 399 | + |
| 400 | + it "should return mode with file type set to S_IFREG when resource is file" do |
| 401 | + expect(get_create_mode(:present)).to eq(32768) |
| 402 | + expect(get_create_mode(:file)).to eq(32768) |
| 403 | + end |
| 404 | + |
| 405 | + it "should return mode with file type set to S_IFDIR when resource is dir" do |
| 406 | + expect(get_create_mode(:directory)).to eq(16384) |
| 407 | + end |
| 408 | + |
| 409 | + it "should return mode with file type set to S_IFLNK when resource is link" do |
| 410 | + expect(get_create_mode(:link)).to eq(40960) |
| 411 | + end |
| 412 | + |
| 413 | + it "should return 0 for everything else" do |
| 414 | + expect(get_create_mode("unknown")).to eq(0) |
| 415 | + end |
| 416 | + end |
349 | 417 | end
|
0 commit comments