Serverspec: test file owned only by root

27 Views Asked by At

I'm running some tests using serverspec/rspec and I want to test that this file owned only by root exists and it's content:

require 'spec_helper'

describe port(9252) do
  it { should be_listening }
end

describe file('/etc/gitlab-runner/config.toml') do
  it { should exist }
  it { should be_owned_by 'root' }
  it { should contain 'listen_address = "localhost:9252"' }
end

I'm running this test using 'ec2-user', however, the file I'm testing is owned only by root:

[root@ip-10-1-10-91 ~]# ls -lad /etc/gitlab-runner
drwx------. 2 root root 50 Jun  7 09:13 /etc/gitlab-runner

[root@ip-10-1-10-91 ~]# ls -la /etc/gitlab-runner/config.toml
-rw-------. 1 root root 1123 Jun  6 19:20 /etc/gitlab-runner/config.toml

As such, when running the test it fails because the test runs under user 'ec2-user' that can't access the file/directory I'm testing.

I tried running the test script using 'sudo' but no luck.

0

There are 0 best solutions below