Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab FOSS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab FOSS
Commits
3091d196
Commit
3091d196
authored
7 years ago
by
Alexis Reigel
Browse files
Options
Downloads
Patches
Plain Diff
also update gpg_signatures when gpg_key is null
parent
8f73b392
Loading
Loading
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/gitlab/gpg/invalid_gpg_signature_updater.rb
+1
-1
1 addition, 1 deletion
lib/gitlab/gpg/invalid_gpg_signature_updater.rb
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
+55
-15
55 additions, 15 deletions
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
with
56 additions
and
16 deletions
lib/gitlab/gpg/invalid_gpg_signature_updater.rb
+
1
−
1
View file @
3091d196
...
...
@@ -7,7 +7,7 @@ def initialize(gpg_key)
def
run
GpgSignature
.
where
(
valid_signature
:
false
)
.
where
(
'gpg_key_id IS NULL OR
valid_signature
= ?'
,
false
)
.
where
(
gpg_key_primary_keyid:
@gpg_key
.
primary_keyid
)
.
find_each
do
|
gpg_signature
|
Gitlab
::
Gpg
::
Commit
.
new
(
gpg_signature
.
commit
).
update_signature!
(
gpg_signature
)
...
...
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
+
55
−
15
View file @
3091d196
...
...
@@ -19,29 +19,60 @@
create
:commit
,
git_commit:
raw_commit
,
project:
project
end
let!
(
:gpg_signature
)
do
create
:gpg_signature
,
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
nil
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
false
end
before
do
allow_any_instance_of
(
GpgSignature
).
to
receive
(
:commit
).
and_return
(
commit
)
end
context
'gpg signature did have an associated gpg key which was removed later'
do
let!
(
:user
)
{
create
:user
,
email:
GpgHelpers
::
User1
.
emails
.
first
}
let!
(
:valid_gpg_signature
)
do
create
:gpg_signature
,
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
nil
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
true
end
it
'assigns the gpg key to the signature when the missing gpg key is added'
do
# InvalidGpgSignatureUpdater is called by the after_create hook
gpg_key
=
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
expect
(
valid_gpg_signature
.
reload
.
gpg_key
).
to
eq
gpg_key
end
it
'does not assign the gpg key when an unrelated gpg key is added'
do
# InvalidGpgSignatureUpdater is called by the after_create hook
create
:gpg_key
,
key:
GpgHelpers
::
User2
.
public_key
,
user:
user
expect
(
valid_gpg_signature
.
reload
.
gpg_key
).
to
be_nil
end
end
context
'gpg signature did not have an associated gpg key'
do
let!
(
:user
)
{
create
:user
,
email:
GpgHelpers
::
User1
.
emails
.
first
}
let!
(
:invalid_gpg_signature
)
do
create
:gpg_signature
,
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
nil
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
false
end
it
'updates the signature to being valid when the missing gpg key is added'
do
# InvalidGpgSignatureUpdater is called by the after_create hook
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_truthy
expect
(
invalid_
gpg_signature
.
reload
.
valid_signature
).
to
be_truthy
end
it
'keeps the signature at being invalid when an unrelated gpg key is added'
do
...
...
@@ -50,7 +81,7 @@
key:
GpgHelpers
::
User2
.
public_key
,
user:
user
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
expect
(
invalid_
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
end
end
...
...
@@ -61,17 +92,26 @@
end
end
let!
(
:invalid_gpg_signature
)
do
create
:gpg_signature
,
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
nil
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
false
end
it
'updates the signature to being valid when the user updates the email address'
do
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
expect
(
invalid_
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
# InvalidGpgSignatureUpdater is called by the after_update hook
user
.
update_attributes!
(
email:
GpgHelpers
::
User1
.
emails
.
first
)
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_truthy
expect
(
invalid_
gpg_signature
.
reload
.
valid_signature
).
to
be_truthy
end
it
'keeps the signature at being invalid when the changed email address is still unrelated'
do
...
...
@@ -79,12 +119,12 @@
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
expect
(
invalid_
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
# InvalidGpgSignatureUpdater is called by the after_update hook
user
.
update_attributes!
(
email:
'still.unrelated@example.com'
)
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
expect
(
invalid_
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment