|
19 | 19 | end |
20 | 20 | end |
21 | 21 |
|
22 | | - let(:gitaly_check_access) { GitAccessStatus.new(true, 'ok', gl_repository, repo_path, { 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default'} , 'address' => 'unix:gitaly.socket' }) } |
| 22 | + let(:gitaly_check_access) { GitAccessStatus.new( |
| 23 | + true, |
| 24 | + 'ok', |
| 25 | + gl_repository: gl_repository, |
| 26 | + gl_username: gl_username, |
| 27 | + repository_path: repo_path, |
| 28 | + gitaly: { 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default'} , 'address' => 'unix:gitaly.socket' }, |
| 29 | + geo_node: false |
| 30 | + ) |
| 31 | + } |
23 | 32 |
|
24 | 33 | let(:api) do |
25 | 34 | double(GitlabNet).tap do |api| |
26 | 35 | api.stub(discover: { 'name' => 'John Doe' }) |
27 | | - api.stub(check_access: GitAccessStatus.new(true, 'ok', gl_repository, repo_path, nil)) |
| 36 | + api.stub(check_access: GitAccessStatus.new( |
| 37 | + true, |
| 38 | + 'ok', |
| 39 | + gl_repository: gl_repository, |
| 40 | + gl_username: gl_username, |
| 41 | + repository_path: repo_path, |
| 42 | + gitaly: nil, |
| 43 | + geo_node: nil)) |
28 | 44 | api.stub(two_factor_recovery_codes: { |
29 | 45 | 'success' => true, |
30 | 46 | 'recovery_codes' => ['f67c514de60c4953', '41278385fc00c1e0'] |
|
39 | 55 | let(:repo_name) { 'gitlab-ci.git' } |
40 | 56 | let(:repo_path) { File.join(tmp_repos_path, repo_name) } |
41 | 57 | let(:gl_repository) { 'project-1' } |
| 58 | + let(:gl_username) { 'testuser' } |
42 | 59 |
|
43 | 60 | before do |
44 | 61 | GitlabConfig.any_instance.stub(audit_usernames: false) |
|
130 | 147 | end |
131 | 148 |
|
132 | 149 | describe :exec do |
133 | | - let(:gitaly_message) { JSON.dump({ 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default' }, 'gl_repository' => gl_repository , 'gl_id' => key_id}) } |
| 150 | + let(:gitaly_message) { JSON.dump({ 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default' }, 'gl_repository' => gl_repository, 'gl_id' => key_id, 'gl_username' => gl_username}) } |
134 | 151 |
|
135 | 152 | shared_examples_for 'upload-pack' do |command| |
136 | 153 | let(:ssh_cmd) { "#{command} gitlab-ci.git" } |
|
167 | 184 |
|
168 | 185 | context 'gitaly-upload-pack with GeoNode' do |
169 | 186 | let(:ssh_cmd) { "git-upload-pack gitlab-ci.git" } |
170 | | - let(:gitaly_check_access_with_geo) { GitAccessStatus.new(true, 'ok', gl_repository, repo_path, { 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default'} , 'address' => 'unix:gitaly.socket' }, true) } |
171 | | - let(:gitaly_message_with_all_refs) { JSON.dump({ 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default' }, 'gl_repository' => gl_repository , 'gl_id' => key_id, 'git_config_options' => [GitlabShell::GIT_CONFIG_SHOW_ALL_REFS]}) } |
| 187 | + let(:gitaly_check_access_with_geo) { GitAccessStatus.new( |
| 188 | + true, |
| 189 | + 'ok', |
| 190 | + gl_repository: gl_repository, |
| 191 | + gl_username: gl_username, |
| 192 | + repository_path: repo_path, |
| 193 | + gitaly: { 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default'} , 'address' => 'unix:gitaly.socket' }, |
| 194 | + geo_node: true) } |
| 195 | + let(:gitaly_message_with_all_refs) { JSON.dump({ 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default' }, 'gl_repository' => gl_repository , 'gl_id' => key_id, 'gl_username' => gl_username, 'git_config_options' => [GitlabShell::GIT_CONFIG_SHOW_ALL_REFS]}) } |
172 | 196 | before { api.stub(check_access: gitaly_check_access_with_geo) } |
173 | 197 | after { subject.exec(ssh_cmd) } |
174 | 198 |
|
|
346 | 370 | end |
347 | 371 |
|
348 | 372 | it "should disallow access and log the attempt if check_access returns false status" do |
349 | | - api.stub(check_access: GitAccessStatus.new(false, 'denied', nil, nil, nil)) |
| 373 | + api.stub(check_access: GitAccessStatus.new( |
| 374 | + false, |
| 375 | + 'denied', |
| 376 | + gl_repository: nil, |
| 377 | + gl_username: nil, |
| 378 | + repository_path: nil, |
| 379 | + gitaly: nil, |
| 380 | + geo_node: nil)) |
350 | 381 | message = "gitlab-shell: Access denied for git command <git-upload-pack gitlab-ci.git> " |
351 | 382 | message << "by user with key #{key_id}." |
352 | 383 | $logger.should_receive(:warn).with(message) |
|
383 | 414 | 'LANG' => ENV['LANG'], |
384 | 415 | 'GL_ID' => key_id, |
385 | 416 | 'GL_PROTOCOL' => 'ssh', |
386 | | - 'GL_REPOSITORY' => gl_repository |
| 417 | + 'GL_REPOSITORY' => gl_repository, |
| 418 | + 'GL_USERNAME' => 'testuser' |
387 | 419 | } |
388 | 420 | end |
389 | 421 | let(:exec_options) { { unsetenv_others: true, chdir: ROOT_PATH } } |
390 | 422 | before do |
391 | 423 | Kernel.stub(:exec) |
392 | 424 | shell.gl_repository = gl_repository |
| 425 | + shell.username = gl_username |
393 | 426 | end |
394 | 427 |
|
395 | 428 | it "uses Kernel::exec method" do |
|
0 commit comments