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
502e31be
Commit
502e31be
authored
Jun 15, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
memoize verified_signature call
parent
5d5fd4ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
14 deletions
+23
-14
lib/gitlab/gpg/commit.rb
lib/gitlab/gpg/commit.rb
+17
-8
spec/lib/gitlab/gpg/commit_spec.rb
spec/lib/gitlab/gpg/commit_spec.rb
+6
-6
No files found.
lib/gitlab/gpg/commit.rb
View file @
502e31be
...
...
@@ -19,6 +19,19 @@ module Gitlab
cached_signature
=
GpgSignature
.
find_by
(
commit_sha:
commit
.
sha
)
return
cached_signature
if
cached_signature
.
present?
using_keychain
do
|
gpg_key
|
if
gpg_key
Gitlab
::
Gpg
::
CurrentKeyChain
.
add
(
gpg_key
.
key
)
@verified_signature
=
nil
end
create_cached_signature!
(
gpg_key
)
end
end
private
def
using_keychain
Gitlab
::
Gpg
.
using_tmp_keychain
do
# first we need to get the keyid from the signature to query the gpg
# key belonging to the keyid.
...
...
@@ -30,27 +43,23 @@ module Gitlab
Gitlab
::
Gpg
::
CurrentKeyChain
.
add
(
gpg_key
.
key
)
end
create_cached_signature!
(
gpg_key
)
yield
gpg_key
end
end
private
def
verified_signature
GPGME
::
Crypto
.
new
.
verify
(
@signature_text
,
signed_text:
@signed_text
)
do
|
verified_signature
|
@verified_signature
||=
GPGME
::
Crypto
.
new
.
verify
(
@signature_text
,
signed_text:
@signed_text
)
do
|
verified_signature
|
return
verified_signature
end
end
def
create_cached_signature!
(
gpg_key
)
verified_signature_result
=
verified_signature
GpgSignature
.
create!
(
commit_sha:
commit
.
sha
,
project:
commit
.
project
,
gpg_key:
gpg_key
,
gpg_key_primary_keyid:
gpg_key
&
.
primary_keyid
||
verified_signature
_result
.
fingerprint
,
valid_signature:
!!
(
gpg_key
&&
gpg_key
.
verified?
&&
verified_signature
_result
.
valid?
)
gpg_key_primary_keyid:
gpg_key
&
.
primary_keyid
||
verified_signature
.
fingerprint
,
valid_signature:
!!
(
gpg_key
&&
gpg_key
.
verified?
&&
verified_signature
.
valid?
)
)
end
end
...
...
spec/lib/gitlab/gpg/commit_spec.rb
View file @
502e31be
...
...
@@ -38,11 +38,11 @@ RSpec.describe Gitlab::Gpg::Commit do
it
'returns the cached signature on second call'
do
gpg_commit
=
described_class
.
new
(
commit
)
expect
(
gpg_commit
).
to
receive
(
:
verified_signature
).
twice
.
and_call_original
expect
(
gpg_commit
).
to
receive
(
:
using_keychain
)
.
and_call_original
gpg_commit
.
signature
# consecutive call
expect
(
gpg_commit
).
not_to
receive
(
:
verified_signature
).
and_call_original
expect
(
gpg_commit
).
not_to
receive
(
:
using_keychain
).
and_call_original
gpg_commit
.
signature
end
end
...
...
@@ -73,11 +73,11 @@ RSpec.describe Gitlab::Gpg::Commit do
it
'returns the cached signature on second call'
do
gpg_commit
=
described_class
.
new
(
commit
)
expect
(
gpg_commit
).
to
receive
(
:
verified_signature
).
and_call_original
expect
(
gpg_commit
).
to
receive
(
:
using_keychain
).
and_call_original
gpg_commit
.
signature
# consecutive call
expect
(
gpg_commit
).
not_to
receive
(
:
verified_signature
).
and_call_original
expect
(
gpg_commit
).
not_to
receive
(
:
using_keychain
).
and_call_original
gpg_commit
.
signature
end
end
...
...
@@ -108,11 +108,11 @@ RSpec.describe Gitlab::Gpg::Commit do
it
'returns the cached signature on second call'
do
gpg_commit
=
described_class
.
new
(
commit
)
expect
(
gpg_commit
).
to
receive
(
:
verified_signature
).
and_call_original
expect
(
gpg_commit
).
to
receive
(
:
using_keychain
).
and_call_original
gpg_commit
.
signature
# consecutive call
expect
(
gpg_commit
).
not_to
receive
(
:
verified_signature
).
and_call_original
expect
(
gpg_commit
).
not_to
receive
(
:
using_keychain
).
and_call_original
gpg_commit
.
signature
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