Commit 9bdd60c5 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'fix-nil-user-update-mirror-service' into 'master'

Fix nil user handling in UpdateMirrorService

Previously an exception was hit quite frequently:

```
NoMethodError: undefined method `can?' for nil:NilClass
  app/services/projects/update_mirror_service.rb:9:in `execute'
    unless current_user.can?(:push_code_to_protected_branches, project)
  lib/gitlab/metrics/instrumentation.rb:153:in `execute'
    retval   = super
  app/workers/repository_update_mirror_worker.rb:13:in `perform'
    result = Projects::UpdateMirrorService.new(@project, @current_user).execute
  lib/gitlab/sidekiq_middleware/memory_killer.rb:17:in `call'
    yield
  lib/gitlab/sidekiq_middleware/arguments_logger.rb:6:in `call'
    yield
...
(26 additional frame(s) were not displayed)
```

Closes #605

See merge request !434
parents 2a8a78f7 39c215be
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.9.0 (unreleased) v 8.9.0 (unreleased)
- Fix nil user handling in UpdateMirrorService
v 8.8.3 v 8.8.3
- Add standard web hook headers to Jenkins CI post. !374 - Add standard web hook headers to Jenkins CI post. !374
......
...@@ -6,7 +6,7 @@ module Projects ...@@ -6,7 +6,7 @@ module Projects
def execute def execute
return false unless project.mirror? return false unless project.mirror?
unless current_user.can?(:push_code_to_protected_branches, project) unless can?(current_user, :push_code_to_protected_branches, project)
return error("The mirror user is not allowed to push code to all branches on this project.") return error("The mirror user is not allowed to push code to all branches on this project.")
end end
......
...@@ -75,6 +75,16 @@ describe Projects::UpdateMirrorService do ...@@ -75,6 +75,16 @@ describe Projects::UpdateMirrorService do
expect(result[:status]).to eq(:error) expect(result[:status]).to eq(:error)
end end
end end
describe "when no user is present" do
let(:mirror_user) { }
it "fails" do
result = subject.execute
expect(result[:status]).to eq(:error)
end
end
end end
def fetch_mirror(repository) def fetch_mirror(repository)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment