Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9816856d
Commit
9816856d
authored
Jun 22, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perform signature update in sidekiq worker
parent
9d30a80d
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
7 deletions
+67
-7
app/models/gpg_key.rb
app/models/gpg_key.rb
+6
-2
app/models/user.rb
app/models/user.rb
+2
-1
app/workers/invalid_gpg_signature_update_worker.rb
app/workers/invalid_gpg_signature_update_worker.rb
+12
-0
config/sidekiq_queues.yml
config/sidekiq_queues.yml
+1
-0
spec/features/commits_spec.rb
spec/features/commits_spec.rb
+10
-4
spec/workers/invalid_gpg_signature_update_worker_spec.rb
spec/workers/invalid_gpg_signature_update_worker_spec.rb
+36
-0
No files found.
app/models/gpg_key.rb
View file @
9816856d
...
@@ -28,7 +28,7 @@ class GpgKey < ActiveRecord::Base
...
@@ -28,7 +28,7 @@ class GpgKey < ActiveRecord::Base
unless:
->
{
errors
.
has_key?
(
:key
)
}
unless:
->
{
errors
.
has_key?
(
:key
)
}
before_validation
:extract_fingerprint
,
:extract_primary_keyid
before_validation
:extract_fingerprint
,
:extract_primary_keyid
after_create
:update_invalid_gpg_signatures
after_create
:update_invalid_gpg_signatures
_after_create
after_create
:notify_user
after_create
:notify_user
def
key
=
(
value
)
def
key
=
(
value
)
...
@@ -54,7 +54,7 @@ class GpgKey < ActiveRecord::Base
...
@@ -54,7 +54,7 @@ class GpgKey < ActiveRecord::Base
end
end
def
update_invalid_gpg_signatures
def
update_invalid_gpg_signatures
Gitlab
::
Gpg
::
InvalidGpgSignatureUpdater
.
new
(
self
).
run
InvalidGpgSignatureUpdateWorker
.
perform_async
(
self
.
id
)
end
end
private
private
...
@@ -74,4 +74,8 @@ class GpgKey < ActiveRecord::Base
...
@@ -74,4 +74,8 @@ class GpgKey < ActiveRecord::Base
def
notify_user
def
notify_user
run_after_commit
{
NotificationService
.
new
.
new_gpg_key
(
self
)
}
run_after_commit
{
NotificationService
.
new
.
new_gpg_key
(
self
)
}
end
end
def
update_invalid_gpg_signatures_after_create
run_after_commit
{
update_invalid_gpg_signatures
}
end
end
end
app/models/user.rb
View file @
9816856d
...
@@ -13,6 +13,7 @@ class User < ActiveRecord::Base
...
@@ -13,6 +13,7 @@ class User < ActiveRecord::Base
include
IgnorableColumn
include
IgnorableColumn
include
FeatureGate
include
FeatureGate
include
CreatedAtFilterable
include
CreatedAtFilterable
include
AfterCommitQueue
DEFAULT_NOTIFICATION_LEVEL
=
:participating
DEFAULT_NOTIFICATION_LEVEL
=
:participating
...
@@ -515,7 +516,7 @@ class User < ActiveRecord::Base
...
@@ -515,7 +516,7 @@ class User < ActiveRecord::Base
end
end
def
update_invalid_gpg_signatures
def
update_invalid_gpg_signatures
gpg_keys
.
each
(
&
:update_invalid_gpg_signatures
)
run_after_commit
{
gpg_keys
.
each
(
&
:update_invalid_gpg_signatures
)
}
end
end
# Returns the groups a user has access to
# Returns the groups a user has access to
...
...
app/workers/invalid_gpg_signature_update_worker.rb
0 → 100644
View file @
9816856d
class
InvalidGpgSignatureUpdateWorker
include
Sidekiq
::
Worker
include
DedicatedSidekiqQueue
def
perform
(
gpg_key_id
)
if
gpg_key
=
GpgKey
.
find_by
(
id:
gpg_key_id
)
Gitlab
::
Gpg
::
InvalidGpgSignatureUpdater
.
new
(
gpg_key
).
run
else
Rails
.
logger
.
error
(
"InvalidGpgSignatureUpdateWorker: couldn't find gpg_key with ID=
#{
gpg_key_id
}
, skipping job"
)
end
end
end
config/sidekiq_queues.yml
View file @
9816856d
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
- [email_receiver, 2]
- [email_receiver, 2]
- [emails_on_push, 2]
- [emails_on_push, 2]
- [mailers, 2]
- [mailers, 2]
- [invalid_gpg_signature_update, 2]
- [upload_checksum, 1]
- [upload_checksum, 1]
- [use_key, 1]
- [use_key, 1]
- [repository_fork, 1]
- [repository_fork, 1]
...
...
spec/features/commits_spec.rb
View file @
9816856d
...
@@ -223,7 +223,9 @@ describe 'Commits' do
...
@@ -223,7 +223,9 @@ describe 'Commits' do
user
=
create
:user
,
email:
'unrelated.user@example.org'
user
=
create
:user
,
email:
'unrelated.user@example.org'
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
Sidekiq
::
Testing
.
inline!
do
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
end
login_with
(
user
)
login_with
(
user
)
...
@@ -235,8 +237,10 @@ describe 'Commits' do
...
@@ -235,8 +237,10 @@ describe 'Commits' do
end
end
# user changes his email which makes the gpg key verified
# user changes his email which makes the gpg key verified
Sidekiq
::
Testing
.
inline!
do
user
.
skip_reconfirmation!
user
.
skip_reconfirmation!
user
.
update_attributes!
(
email:
GpgHelpers
::
User1
.
emails
.
first
)
user
.
update_attributes!
(
email:
GpgHelpers
::
User1
.
emails
.
first
)
end
visit
namespace_project_commits_path
(
project
.
namespace
,
project
,
:master
)
visit
namespace_project_commits_path
(
project
.
namespace
,
project
,
:master
)
...
@@ -260,7 +264,9 @@ describe 'Commits' do
...
@@ -260,7 +264,9 @@ describe 'Commits' do
end
end
# user adds the gpg key which makes the signature valid
# user adds the gpg key which makes the signature valid
Sidekiq
::
Testing
.
inline!
do
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
end
visit
namespace_project_commits_path
(
project
.
namespace
,
project
,
:master
)
visit
namespace_project_commits_path
(
project
.
namespace
,
project
,
:master
)
...
...
spec/workers/invalid_gpg_signature_update_worker_spec.rb
0 → 100644
View file @
9816856d
require
'spec_helper'
describe
InvalidGpgSignatureUpdateWorker
do
context
'when GpgKey is found'
do
it
'calls NotificationService.new.run'
do
gpg_key
=
create
(
:gpg_key
)
invalid_signature_updater
=
double
(
:invalid_signature_updater
)
expect
(
Gitlab
::
Gpg
::
InvalidGpgSignatureUpdater
).
to
receive
(
:new
).
with
(
gpg_key
).
and_return
(
invalid_signature_updater
)
expect
(
invalid_signature_updater
).
to
receive
(
:run
)
described_class
.
new
.
perform
(
gpg_key
.
id
)
end
end
context
'when GpgKey is not found'
do
let
(
:nonexisting_gpg_key_id
)
{
-
1
}
it
'logs InvalidGpgSignatureUpdateWorker process skipping'
do
expect
(
Rails
.
logger
).
to
receive
(
:error
)
.
with
(
"InvalidGpgSignatureUpdateWorker: couldn't find gpg_key with ID=-1, skipping job"
)
described_class
.
new
.
perform
(
nonexisting_gpg_key_id
)
end
it
'does not raise errors'
do
expect
{
described_class
.
new
.
perform
(
nonexisting_gpg_key_id
)
}.
not_to
raise_error
end
it
'does not call NotificationService.new.run'
do
expect
(
Gitlab
::
Gpg
::
InvalidGpgSignatureUpdater
).
not_to
receive
(
:new
)
described_class
.
new
.
perform
(
nonexisting_gpg_key_id
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment