|
5 | 5 |
|
6 | 6 | describe 'gitlab_ci_runner::register_to_file' do |
7 | 7 | let(:url) { 'https://gitlab.example.org' } |
8 | | - let(:regtoken) { 'registration-token' } |
| 8 | + let(:token) do |
| 9 | + { |
| 10 | + reg_token: 'registration-token', |
| 11 | + auth_token: 'glrt-authentication-token' |
| 12 | + } |
| 13 | + end |
9 | 14 | let(:runner_name) { 'testrunner' } |
10 | 15 | let(:filename) { "/etc/gitlab-runner/auth-token-#{runner_name}" } |
11 | 16 | let(:return_hash) do |
|
30 | 35 | allow(File).to receive(:read).with(filename).and_return(return_hash['token']) |
31 | 36 | end |
32 | 37 |
|
33 | | - it { is_expected.to run.with_params(url, regtoken, runner_name).and_return(return_hash['token']) } |
| 38 | + it { is_expected.to run.with_params(url, token[:reg_token], runner_name).and_return(return_hash['token']) } |
| 39 | + it { is_expected.to run.with_params(url, token[:auth_token], runner_name).and_return(return_hash['token']) } |
34 | 40 | end |
35 | 41 |
|
36 | | - context "retrieves from Gitlab and writes auth token to file if it doesn't exist" do |
| 42 | + context 'retrieves from Gitlab and writes auth token to file if it doesn\'t exist' do |
37 | 43 | before do |
38 | | - allow(PuppetX::Gitlab::Runner).to receive(:register).with(url, { 'token' => regtoken }, nil, nil).and_return(return_hash) |
39 | 44 | allow(File).to receive(:exist?).and_call_original |
40 | 45 | allow(File).to receive(:exist?).with(File.dirname(filename)).and_return(true) |
41 | | - allow(File).to receive(:write).with(filename, return_hash['token']) |
42 | 46 | allow(File).to receive(:chmod).with(0o400, filename) |
43 | 47 | end |
44 | 48 |
|
45 | | - it { is_expected.to run.with_params(url, regtoken, runner_name).and_return(return_hash['token']) } |
46 | | - |
47 | | - context 'with existing file ca_file option' do |
| 49 | + context 'with registration token' do |
48 | 50 | before do |
49 | | - allow(PuppetX::Gitlab::Runner).to receive(:register).with(url, { 'token' => regtoken }, nil, '/tmp').and_return(return_hash) |
| 51 | + allow(PuppetX::Gitlab::Runner).to receive(:register).with(url, { 'registration-token' => token[:reg_token] }, nil, nil).and_return(return_hash) |
| 52 | + allow(File).to receive(:write).with(filename, return_hash['token']) |
50 | 53 | end |
51 | 54 |
|
52 | | - it { is_expected.to run.with_params(url, regtoken, runner_name, {}, nil, '/tmp').and_return(return_hash['token']) } |
53 | | - end |
| 55 | + it { is_expected.to run.with_params(url, token[:reg_token], runner_name).and_return(return_hash['token']) } |
54 | 56 |
|
55 | | - context 'with non existent ca_file option' do |
56 | | - before do |
57 | | - allow(PuppetX::Gitlab::Runner).to receive(:register).with(url, { 'token' => regtoken }, nil, '/path/to/ca_file').and_return(return_hash) |
| 57 | + context 'with existing file ca_file option' do |
| 58 | + before do |
| 59 | + allow(PuppetX::Gitlab::Runner).to receive(:register).with(url, { 'registration-token' => token[:reg_token] }, nil, '/tmp').and_return(return_hash) |
| 60 | + end |
| 61 | + |
| 62 | + it { is_expected.to run.with_params(url, token[:reg_token], runner_name, {}, nil, '/tmp').and_return(return_hash['token']) } |
58 | 63 | end |
59 | 64 |
|
60 | | - it { is_expected.to run.with_params(url, regtoken, runner_name, {}, nil, '/path/to/ca_file').and_return('Specified CA file doesn\'t exist, not attempting to create authtoken') } |
| 65 | + context 'with non existent ca_file option' do |
| 66 | + before do |
| 67 | + allow(PuppetX::Gitlab::Runner).to receive(:register).with(url, { 'registration-token' => token[:reg_token] }, nil, '/path/to/ca_file').and_return(return_hash) |
| 68 | + end |
| 69 | + |
| 70 | + it { is_expected.to run.with_params(url, token[:reg_token], runner_name, {}, nil, '/path/to/ca_file').and_return('Specified CA file doesn\'t exist, not attempting to create authtoken') } |
| 71 | + end |
| 72 | + |
| 73 | + context 'with sensitive token value' do |
| 74 | + before do |
| 75 | + allow(PuppetX::Gitlab::Runner).to receive(:register).with(url, { 'registration-token' => token[:reg_token] }, nil, '/tmp').and_return(return_hash) |
| 76 | + end |
| 77 | + |
| 78 | + it { is_expected.to run.with_params(url, sensitive(token[:reg_token]), runner_name, {}, nil, '/tmp').and_return(return_hash['token']) } |
| 79 | + end |
61 | 80 | end |
62 | 81 |
|
63 | | - context 'with sensitive token value' do |
| 82 | + context 'with authentication token' do |
64 | 83 | before do |
65 | | - allow(PuppetX::Gitlab::Runner).to receive(:register).with(url, { 'token' => regtoken }, nil, '/tmp').and_return(return_hash) |
| 84 | + allow(PuppetX::Gitlab::Runner).to receive(:verify).with(url, token[:auth_token], nil, nil).and_return(return_hash.merge('token' => token[:auth_token])) |
| 85 | + allow(File).to receive(:write).with(filename, token[:auth_token]) |
| 86 | + end |
| 87 | + |
| 88 | + it { is_expected.to run.with_params(url, token[:auth_token], runner_name).and_return(token[:auth_token]) } |
| 89 | + |
| 90 | + context 'with existing file ca_file option' do |
| 91 | + before do |
| 92 | + allow(PuppetX::Gitlab::Runner).to receive(:verify).with(url, token[:auth_token], nil, '/tmp').and_return(return_hash.merge('token' => token[:auth_token])) |
| 93 | + end |
| 94 | + |
| 95 | + it { is_expected.to run.with_params(url, token[:auth_token], runner_name, {}, nil, '/tmp').and_return(token[:auth_token]) } |
66 | 96 | end |
67 | 97 |
|
68 | | - it { is_expected.to run.with_params(url, sensitive(regtoken), runner_name, {}, nil, '/tmp').and_return(return_hash['token']) } |
| 98 | + context 'with non existent ca_file option' do |
| 99 | + before do |
| 100 | + allow(PuppetX::Gitlab::Runner).to receive(:verify).with(url, token[:auth_token], nil, '/path/to/ca_file').and_return(return_hash.merge('token' => token[:auth_token])) |
| 101 | + end |
| 102 | + |
| 103 | + it { is_expected.to run.with_params(url, token[:auth_token], runner_name, {}, nil, '/path/to/ca_file').and_return('Specified CA file doesn\'t exist, not attempting to create authtoken') } |
| 104 | + end |
| 105 | + |
| 106 | + context 'with sensitive token value' do |
| 107 | + before do |
| 108 | + allow(PuppetX::Gitlab::Runner).to receive(:verify).with(url, token[:auth_token], nil, '/tmp').and_return(return_hash.merge('token' => token[:auth_token])) |
| 109 | + end |
| 110 | + |
| 111 | + it { is_expected.to run.with_params(url, sensitive(token[:auth_token]), runner_name, {}, nil, '/tmp').and_return(token[:auth_token]) } |
| 112 | + end |
69 | 113 | end |
70 | 114 | end |
71 | 115 |
|
|
75 | 119 | allow(Puppet.settings).to receive(:[]).with(:noop).and_return(true) |
76 | 120 | end |
77 | 121 |
|
78 | | - it { is_expected.to run.with_params(url, regtoken, runner_name).and_return('DUMMY-NOOP-TOKEN') } |
| 122 | + it { is_expected.to run.with_params(url, token[:reg_token], runner_name).and_return('DUMMY-NOOP-TOKEN') } |
| 123 | + it { is_expected.to run.with_params(url, token[:auth_token], runner_name).and_return('DUMMY-NOOP-TOKEN') } |
79 | 124 | end |
80 | 125 | end |
0 commit comments