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
28bb5e3d
Commit
28bb5e3d
authored
Feb 16, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit signature with spec
parent
817d9558
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
281 additions
and
2 deletions
+281
-2
app/models/commit.rb
app/models/commit.rb
+1
-1
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+6
-1
spec/models/commit_spec.rb
spec/models/commit_spec.rb
+40
-0
spec/spec_helper.rb
spec/spec_helper.rb
+12
-0
spec/support/gpg_helpers.rb
spec/support/gpg_helpers.rb
+222
-0
No files found.
app/models/commit.rb
View file @
28bb5e3d
...
...
@@ -237,7 +237,7 @@ class Commit
def
signature
return
@signature
if
defined?
(
@signature
)
sig
,
signed
=
@raw
.
extract_signature
(
project
.
repository
.
raw_
repository
)
sig
,
signed
=
@raw
.
signature
(
project
.
repository
)
if
sig
&&
signed
GPGME
::
Crypto
.
new
.
verify
(
sig
,
signed_text:
signed
)
do
|
sign
|
@signature
=
sign
...
...
lib/gitlab/git/commit.rb
View file @
28bb5e3d
...
...
@@ -319,7 +319,12 @@ module Gitlab
end
end
def
extract_signature
(
repo
)
# Get the gpg signature of this commit.
#
# Ex.
# commit.signature(repo)
#
def
signature
(
repo
)
Rugged
::
Commit
.
extract_signature
(
repo
.
rugged
,
sha
)
end
...
...
spec/models/commit_spec.rb
View file @
28bb5e3d
...
...
@@ -414,4 +414,44 @@ eos
expect
(
described_class
.
valid_hash?
(
'a'
*
41
)).
to
be
false
end
end
describe
'#signature'
do
it
'returns nil if the commit is not signed'
do
expect
(
commit
.
signature
).
to
be_nil
end
context
'signed commit'
,
:gpg
do
it
'returns a valid signature if the public key is known'
do
GPGME
::
Key
.
import
(
GpgHelpers
.
public_key
)
raw_commit
=
double
(
:raw_commit
,
signature:
[
GpgHelpers
.
signed_commit_signature
,
GpgHelpers
.
signed_commit_base_data
])
allow
(
raw_commit
).
to
receive
:save!
commit
=
create
:commit
,
git_commit:
raw_commit
,
project:
project
expect
(
commit
.
signature
).
to
be_a
GPGME
::
Signature
expect
(
commit
.
signature
.
valid?
).
to
be_truthy
end
it
'returns an invalid signature if the public commit is unknown'
,
:gpg
do
raw_commit
=
double
(
:raw_commit
,
signature:
[
GpgHelpers
.
signed_commit_signature
,
GpgHelpers
.
signed_commit_base_data
])
allow
(
raw_commit
).
to
receive
:save!
commit
=
create
:commit
,
git_commit:
raw_commit
,
project:
project
expect
(
commit
.
signature
).
to
be_a
GPGME
::
Signature
expect
(
commit
.
signature
.
valid?
).
to
be_falsey
end
end
end
end
spec/spec_helper.rb
View file @
28bb5e3d
...
...
@@ -141,6 +141,18 @@ RSpec.configure do |config|
config
.
around
(
:each
,
:postgresql
)
do
|
example
|
example
.
run
if
Gitlab
::
Database
.
postgresql?
end
config
.
around
(
:each
,
:gpg
)
do
|
example
|
Dir
.
mktmpdir
do
|
dir
|
original_dir
=
GPGME
::
Engine
.
dirinfo
(
'homedir'
)
GPGME
::
Engine
.
home_dir
=
dir
example
.
run
GPGME
::
Engine
.
home_dir
=
original_dir
end
end
end
FactoryGirl
::
SyntaxRunner
.
class_eval
do
...
...
spec/support/gpg_helpers.rb
0 → 100644
View file @
28bb5e3d
This diff is collapsed.
Click to expand it.
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