BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
2 deletions
+59
-2
commit.rb
app/models/commit.rb
+1
-1
commit.rb
lib/gitlab/git/commit.rb
+6
-1
commit_spec.rb
spec/models/commit_spec.rb
+40
-0
spec_helper.rb
spec/spec_helper.rb
+12
-0
gpg_helpers.rb
spec/support/gpg_helpers.rb
+0
-0
No files found.
app/models/commit.rb
View file @
28bb5e3d
...
@@ -237,7 +237,7 @@ class Commit
...
@@ -237,7 +237,7 @@ class Commit
def
signature
def
signature
return
@signature
if
defined?
(
@signature
)
return
@signature
if
defined?
(
@signature
)
sig
,
signed
=
@raw
.
extract_signature
(
project
.
repository
.
raw_
repository
)
sig
,
signed
=
@raw
.
signature
(
project
.
repository
)
if
sig
&&
signed
if
sig
&&
signed
GPGME
::
Crypto
.
new
.
verify
(
sig
,
signed_text:
signed
)
do
|
sign
|
GPGME
::
Crypto
.
new
.
verify
(
sig
,
signed_text:
signed
)
do
|
sign
|
@signature
=
sign
@signature
=
sign
...
...
lib/gitlab/git/commit.rb
View file @
28bb5e3d
...
@@ -319,7 +319,12 @@ module Gitlab
...
@@ -319,7 +319,12 @@ module Gitlab
end
end
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
)
Rugged
::
Commit
.
extract_signature
(
repo
.
rugged
,
sha
)
end
end
...
...
spec/models/commit_spec.rb
View file @
28bb5e3d
...
@@ -414,4 +414,44 @@ eos
...
@@ -414,4 +414,44 @@ eos
expect
(
described_class
.
valid_hash?
(
'a'
*
41
)).
to
be
false
expect
(
described_class
.
valid_hash?
(
'a'
*
41
)).
to
be
false
end
end
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
end
spec/spec_helper.rb
View file @
28bb5e3d
...
@@ -141,6 +141,18 @@ RSpec.configure do |config|
...
@@ -141,6 +141,18 @@ RSpec.configure do |config|
config
.
around
(
:each
,
:postgresql
)
do
|
example
|
config
.
around
(
:each
,
:postgresql
)
do
|
example
|
example
.
run
if
Gitlab
::
Database
.
postgresql?
example
.
run
if
Gitlab
::
Database
.
postgresql?
end
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
end
FactoryGirl
::
SyntaxRunner
.
class_eval
do
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