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
7b616d39
Commit
7b616d39
authored
Jun 15, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gpg signature is only valid when key is verified
parent
8c4b6a32
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
3 deletions
+47
-3
app/models/gpg_key.rb
app/models/gpg_key.rb
+4
-0
lib/gitlab/gpg/commit.rb
lib/gitlab/gpg/commit.rb
+1
-1
spec/lib/gitlab/gpg/commit_spec.rb
spec/lib/gitlab/gpg/commit_spec.rb
+26
-2
spec/models/gpg_key_spec.rb
spec/models/gpg_key_spec.rb
+16
-0
No files found.
app/models/gpg_key.rb
View file @
7b616d39
...
@@ -48,6 +48,10 @@ class GpgKey < ActiveRecord::Base
...
@@ -48,6 +48,10 @@ class GpgKey < ActiveRecord::Base
end
end
end
end
def
verified?
emails_with_verified_status
.
any?
{
|
_email
,
verified
|
verified
}
end
private
private
def
extract_fingerprint
def
extract_fingerprint
...
...
lib/gitlab/gpg/commit.rb
View file @
7b616d39
...
@@ -45,7 +45,7 @@ module Gitlab
...
@@ -45,7 +45,7 @@ module Gitlab
project:
commit
.
project
,
project:
commit
.
project
,
gpg_key:
gpg_key
,
gpg_key:
gpg_key
,
gpg_key_primary_keyid:
gpg_key
&
.
primary_keyid
,
gpg_key_primary_keyid:
gpg_key
&
.
primary_keyid
,
valid_signature:
!!
(
gpg_key
&&
verified_signature
.
valid?
)
valid_signature:
!!
(
gpg_key
&&
gpg_key
.
verified?
&&
verified_signature
.
valid?
)
)
)
end
end
end
end
...
...
spec/lib/gitlab/gpg/commit_spec.rb
View file @
7b616d39
...
@@ -10,9 +10,9 @@ RSpec.describe Gitlab::Gpg::Commit do
...
@@ -10,9 +10,9 @@ RSpec.describe Gitlab::Gpg::Commit do
end
end
end
end
context
'known public key'
do
context
'known
and verified
public key'
do
it
'returns a valid signature'
do
it
'returns a valid signature'
do
gpg_key
=
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
gpg_key
=
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
,
user:
create
(
:user
,
email:
GpgHelpers
::
User1
.
emails
.
first
)
raw_commit
=
double
(
:raw_commit
,
signature:
[
raw_commit
=
double
(
:raw_commit
,
signature:
[
GpgHelpers
::
User1
.
signed_commit_signature
,
GpgHelpers
::
User1
.
signed_commit_signature
,
...
@@ -34,6 +34,30 @@ RSpec.describe Gitlab::Gpg::Commit do
...
@@ -34,6 +34,30 @@ RSpec.describe Gitlab::Gpg::Commit do
end
end
end
end
context
'known but unverified public key'
do
it
'returns an invalid signature'
do
gpg_key
=
create
:gpg_key
,
key:
GpgHelpers
::
User1
.
public_key
raw_commit
=
double
(
:raw_commit
,
signature:
[
GpgHelpers
::
User1
.
signed_commit_signature
,
GpgHelpers
::
User1
.
signed_commit_base_data
],
sha:
'0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
)
allow
(
raw_commit
).
to
receive
:save!
commit
=
create
:commit
,
git_commit:
raw_commit
,
project:
project
expect
(
described_class
.
new
(
commit
).
signature
).
to
have_attributes
(
commit_sha:
'0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
,
project:
project
,
gpg_key:
gpg_key
,
gpg_key_primary_keyid:
GpgHelpers
::
User1
.
primary_keyid
,
valid_signature:
false
)
end
end
context
'unknown public key'
do
context
'unknown public key'
do
it
'returns an invalid signature'
,
:gpg
do
it
'returns an invalid signature'
,
:gpg
do
raw_commit
=
double
(
:raw_commit
,
signature:
[
raw_commit
=
double
(
:raw_commit
,
signature:
[
...
...
spec/models/gpg_key_spec.rb
View file @
7b616d39
...
@@ -65,6 +65,22 @@ describe GpgKey do
...
@@ -65,6 +65,22 @@ describe GpgKey do
end
end
end
end
describe
'#verified?'
do
it
'returns true one of the email addresses in the key belongs to the user'
do
user
=
create
:user
,
email:
'bette.cartwright@example.com'
gpg_key
=
create
:gpg_key
,
key:
GpgHelpers
::
User2
.
public_key
,
user:
user
expect
(
gpg_key
.
verified?
).
to
be_truthy
end
it
'returns false if one of the email addresses in the key does not belong to the user'
do
user
=
create
:user
,
email:
'someone.else@example.com'
gpg_key
=
create
:gpg_key
,
key:
GpgHelpers
::
User2
.
public_key
,
user:
user
expect
(
gpg_key
.
verified?
).
to
be_falsey
end
end
describe
'notification'
do
describe
'notification'
do
include
EmailHelpers
include
EmailHelpers
...
...
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