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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
b66e3726
Commit
b66e3726
authored
Jul 06, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
also update gpg_signatures when gpg_key is null
parent
7f03282f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
16 deletions
+56
-16
lib/gitlab/gpg/invalid_gpg_signature_updater.rb
lib/gitlab/gpg/invalid_gpg_signature_updater.rb
+1
-1
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
+55
-15
No files found.
lib/gitlab/gpg/invalid_gpg_signature_updater.rb
View file @
b66e3726
...
@@ -7,7 +7,7 @@ module Gitlab
...
@@ -7,7 +7,7 @@ module Gitlab
def
run
def
run
GpgSignature
GpgSignature
.
where
(
valid_signature:
false
)
.
where
(
'gpg_key_id IS NULL OR valid_signature = ?'
,
false
)
.
where
(
gpg_key_primary_keyid:
@gpg_key
.
primary_keyid
)
.
where
(
gpg_key_primary_keyid:
@gpg_key
.
primary_keyid
)
.
find_each
do
|
gpg_signature
|
.
find_each
do
|
gpg_signature
|
Gitlab
::
Gpg
::
Commit
.
new
(
gpg_signature
.
commit
).
update_signature!
(
gpg_signature
)
Gitlab
::
Gpg
::
Commit
.
new
(
gpg_signature
.
commit
).
update_signature!
(
gpg_signature
)
...
...
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
View file @
b66e3726
...
@@ -19,29 +19,60 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
...
@@ -19,29 +19,60 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
create
:commit
,
git_commit:
raw_commit
,
project:
project
create
:commit
,
git_commit:
raw_commit
,
project:
project
end
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
before
do
allow_any_instance_of
(
GpgSignature
).
to
receive
(
:commit
).
and_return
(
commit
)
allow_any_instance_of
(
GpgSignature
).
to
receive
(
:commit
).
and_return
(
commit
)
end
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
context
'gpg signature did not have an associated gpg key'
do
let!
(
:user
)
{
create
:user
,
email:
GpgHelpers
::
User1
.
emails
.
first
}
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
it
'updates the signature to being valid when the missing gpg key is added'
do
# InvalidGpgSignatureUpdater is called by the after_create hook
# InvalidGpgSignatureUpdater is called by the after_create hook
create
:gpg_key
,
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
user:
user
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_truthy
expect
(
invalid_
gpg_signature
.
reload
.
valid_signature
).
to
be_truthy
end
end
it
'keeps the signature at being invalid when an unrelated gpg key is added'
do
it
'keeps the signature at being invalid when an unrelated gpg key is added'
do
...
@@ -50,7 +81,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
...
@@ -50,7 +81,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
key:
GpgHelpers
::
User2
.
public_key
,
key:
GpgHelpers
::
User2
.
public_key
,
user:
user
user:
user
expect
(
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
expect
(
invalid_
gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
end
end
end
end
...
@@ -61,17 +92,26 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
...
@@ -61,17 +92,26 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
end
end
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
it
'updates the signature to being valid when the user updates the email address'
do
create
:gpg_key
,
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
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
# InvalidGpgSignatureUpdater is called by the after_update hook
user
.
update_attributes!
(
email:
GpgHelpers
::
User1
.
emails
.
first
)
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
end
it
'keeps the signature at being invalid when the changed email address is still unrelated'
do
it
'keeps the signature at being invalid when the changed email address is still unrelated'
do
...
@@ -79,12 +119,12 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
...
@@ -79,12 +119,12 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
key:
GpgHelpers
::
User1
.
public_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
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
# InvalidGpgSignatureUpdater is called by the after_update hook
user
.
update_attributes!
(
email:
'still.unrelated@example.com'
)
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
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