0

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.

  • This is more of a permissions issue. If you can modify the directory and file to be `0704` and `0604` respectively, then that would fix the issue. Alternatively you can setup a local account with more access. If you execute `serverspec` tests remotely with rake+net/ssh then local sudo would not help. You would need to modify the `Rakefile`. If you want that path forward, then we need to see the `Rakefile`. – Matthew Schuchard Jun 07 '23 at 18:43

0 Answers0