| 1 |
test_name 'C3461 - checkout as a user (ssh protocol)' |
| 2 |
|
| 3 |
# Globals |
| 4 |
repo_name = 'testrepo_user_checkout' |
| 5 |
user = 'myuser' |
| 6 |
|
| 7 |
hosts.each do |host| |
| 8 |
tmpdir = host.tmpdir('vcsrepo') |
| 9 |
step 'setup - create repo' do |
| 10 |
git_pkg = 'git' |
| 11 |
if host['platform'] =~ /ubuntu-10/ |
| 12 |
git_pkg = 'git-core' |
| 13 |
end |
| 14 |
install_package(host, git_pkg) |
| 15 |
my_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..')) |
| 16 |
scp_to(host, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir) |
| 17 |
on(host, "cd #{tmpdir} && ./create_git_repo.sh") |
| 18 |
end |
| 19 |
step 'setup - establish ssh keys' do |
| 20 |
# create ssh keys |
| 21 |
on(host, 'yes | ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""') |
| 22 |
|
| 23 |
# copy public key to authorized_keys |
| 24 |
on(host, 'cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys') |
| 25 |
on(host, 'echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config') |
| 26 |
on(host, 'chown -R root:root /root/.ssh') |
| 27 |
end |
| 28 |
|
| 29 |
step 'setup - create user' do |
| 30 |
apply_manifest_on(host, "user { '#{user}': ensure => present, }", :catch_failures => true) |
| 31 |
end |
| 32 |
|
| 33 |
teardown do |
| 34 |
on(host, "rm -fr #{tmpdir}") |
| 35 |
apply_manifest_on(host, "file{'/root/.ssh/id_rsa': ensure => absent, force => true }", :catch_failures => true) |
| 36 |
apply_manifest_on(host, "file{'/root/.ssh/id_rsa.pub': ensure => absent, force => true }", :catch_failures => true) |
| 37 |
apply_manifest_on(host, "user { '#{user}': ensure => absent, }", :catch_failures => true) |
| 38 |
end |
| 39 |
|
| 40 |
step 'checkout as a user with puppet' do |
| 41 |
pp = <<-EOS |
| 42 |
vcsrepo { "#{tmpdir}/#{repo_name}": |
| 43 |
ensure => present, |
| 44 |
source => "ssh://root@#{host}#{tmpdir}/testrepo.git", |
| 45 |
provider => git, |
| 46 |
owner => '#{user}', |
| 47 |
} |
| 48 |
EOS |
| 49 |
|
| 50 |
apply_manifest_on(host, pp, :catch_failures => true) |
| 51 |
apply_manifest_on(host, pp, :catch_changes => true) |
| 52 |
end |
| 53 |
|
| 54 |
step "verify git checkout is owned by user #{user}" do |
| 55 |
on(host, "ls #{tmpdir}/#{repo_name}/.git/") do |res| |
| 56 |
fail_test('checkout not found') unless res.stdout.include? "HEAD" |
| 57 |
end |
| 58 |
|
| 59 |
on(host, "stat --format '%U:%G' #{tmpdir}/#{repo_name}/.git/HEAD") do |res| |
| 60 |
fail_test('checkout not owned by user') unless res.stdout.include? "#{user}:" |
| 61 |
end |
| 62 |
end |
| 63 |
|
| 64 |
end |