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
Boxiang Sun
gitlab-ce
Commits
9488b778
Commit
9488b778
authored
Jul 26, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize query, only select relevant db columns
parent
4e53131f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
11 deletions
+54
-11
lib/gitlab/gpg/invalid_gpg_signature_updater.rb
lib/gitlab/gpg/invalid_gpg_signature_updater.rb
+1
-0
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
+53
-11
No files found.
lib/gitlab/gpg/invalid_gpg_signature_updater.rb
View file @
9488b778
...
@@ -7,6 +7,7 @@ module Gitlab
...
@@ -7,6 +7,7 @@ module Gitlab
def
run
def
run
GpgSignature
GpgSignature
.
select
(
:id
,
:commit_sha
,
:project_id
)
.
where
(
'gpg_key_id IS NULL OR 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
|
...
...
spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb
View file @
9488b778
...
@@ -20,7 +20,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
...
@@ -20,7 +20,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
end
end
before
do
before
do
allow_any_instance_of
(
GpgSignature
).
to
receive
(
:commit
).
and_return
(
commit
)
allow_any_instance_of
(
Project
).
to
receive
(
:commit
).
and_return
(
commit
)
end
end
context
'gpg signature did have an associated gpg key which was removed later'
do
context
'gpg signature did have an associated gpg key which was removed later'
do
...
@@ -41,7 +41,13 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
...
@@ -41,7 +41,13 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
key:
GpgHelpers
::
User1
.
public_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
user:
user
expect
(
valid_gpg_signature
.
reload
.
gpg_key
).
to
eq
gpg_key
expect
(
valid_gpg_signature
.
reload
).
to
have_attributes
(
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
gpg_key
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
true
)
end
end
it
'does not assign the gpg key when an unrelated gpg key is added'
do
it
'does not assign the gpg key when an unrelated gpg key is added'
do
...
@@ -50,7 +56,13 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
...
@@ -50,7 +56,13 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
key:
GpgHelpers
::
User2
.
public_key
,
key:
GpgHelpers
::
User2
.
public_key
,
user:
user
user:
user
expect
(
valid_gpg_signature
.
reload
.
gpg_key
).
to
be_nil
expect
(
valid_gpg_signature
.
reload
).
to
have_attributes
(
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
nil
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
true
)
end
end
end
end
...
@@ -68,11 +80,17 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
...
@@ -68,11 +80,17 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
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
,
gpg_key
=
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
user:
user
expect
(
invalid_gpg_signature
.
reload
.
valid_signature
).
to
be_truthy
expect
(
invalid_gpg_signature
.
reload
).
to
have_attributes
(
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
gpg_key
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
true
)
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
...
@@ -81,7 +99,13 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
...
@@ -81,7 +99,13 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
key:
GpgHelpers
::
User2
.
public_key
,
key:
GpgHelpers
::
User2
.
public_key
,
user:
user
user:
user
expect
(
invalid_gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
expect
(
invalid_gpg_signature
.
reload
).
to
have_attributes
(
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
nil
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
false
)
end
end
end
end
...
@@ -102,7 +126,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
...
@@ -102,7 +126,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
end
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
,
gpg_key
=
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
user:
user
...
@@ -111,20 +135,38 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
...
@@ -111,20 +135,38 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
# 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
(
invalid_gpg_signature
.
reload
.
valid_signature
).
to
be_truthy
expect
(
invalid_gpg_signature
.
reload
).
to
have_attributes
(
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
gpg_key
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
true
)
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
create
:gpg_key
,
gpg_key
=
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
user
user:
user
expect
(
invalid_gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
expect
(
invalid_gpg_signature
.
reload
).
to
have_attributes
(
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
gpg_key
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
false
)
# 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
(
invalid_gpg_signature
.
reload
.
valid_signature
).
to
be_falsey
expect
(
invalid_gpg_signature
.
reload
).
to
have_attributes
(
project:
project
,
commit_sha:
commit_sha
,
gpg_key:
gpg_key
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
false
)
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