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
857d0391
Commit
857d0391
authored
May 31, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lint our factories creation in addition to their build
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
19ee16a0
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
93 additions
and
47 deletions
+93
-47
app/models/commit.rb
app/models/commit.rb
+1
-1
spec/controllers/profiles/keys_controller_spec.rb
spec/controllers/profiles/keys_controller_spec.rb
+1
-1
spec/factories/ci/pipelines.rb
spec/factories/ci/pipelines.rb
+9
-12
spec/factories/ci/stages.rb
spec/factories/ci/stages.rb
+2
-0
spec/factories/ci/trigger_requests.rb
spec/factories/ci/trigger_requests.rb
+2
-2
spec/factories/commits.rb
spec/factories/commits.rb
+2
-7
spec/factories/file_uploaders.rb
spec/factories/file_uploaders.rb
+2
-0
spec/factories/keys.rb
spec/factories/keys.rb
+5
-14
spec/factories/project_statistics.rb
spec/factories/project_statistics.rb
+6
-2
spec/factories/project_wikis.rb
spec/factories/project_wikis.rb
+2
-0
spec/factories/projects.rb
spec/factories/projects.rb
+2
-0
spec/factories/wiki_directories.rb
spec/factories/wiki_directories.rb
+2
-0
spec/factories_spec.rb
spec/factories_spec.rb
+10
-4
spec/models/key_spec.rb
spec/models/key_spec.rb
+6
-4
spec/support/helpers/key_generator_helper.rb
spec/support/helpers/key_generator_helper.rb
+41
-0
No files found.
app/models/commit.rb
View file @
857d0391
...
@@ -14,7 +14,7 @@ class Commit
...
@@ -14,7 +14,7 @@ class Commit
participant
:committer
participant
:committer
participant
:notes_with_associations
participant
:notes_with_associations
attr_accessor
:project
attr_accessor
:project
,
:author
DIFF_SAFE_LINES
=
Gitlab
::
Git
::
DiffCollection
::
DEFAULT_LIMITS
[
:max_lines
]
DIFF_SAFE_LINES
=
Gitlab
::
Git
::
DiffCollection
::
DEFAULT_LIMITS
[
:max_lines
]
...
...
spec/controllers/profiles/keys_controller_spec.rb
View file @
857d0391
...
@@ -49,7 +49,7 @@ describe Profiles::KeysController do
...
@@ -49,7 +49,7 @@ describe Profiles::KeysController do
expect
(
response
.
body
).
to
eq
(
user
.
all_ssh_keys
.
join
(
"
\n
"
))
expect
(
response
.
body
).
to
eq
(
user
.
all_ssh_keys
.
join
(
"
\n
"
))
expect
(
response
.
body
).
to
include
(
key
.
key
.
sub
(
' dummy@gitlab.com'
,
''
))
expect
(
response
.
body
).
to
include
(
key
.
key
.
sub
(
' dummy@gitlab.com'
,
''
))
expect
(
response
.
body
).
to
include
(
another_key
.
key
)
expect
(
response
.
body
).
to
include
(
another_key
.
key
.
sub
(
' dummy@gitlab.com'
,
''
)
)
expect
(
response
.
body
).
not_to
include
(
deploy_key
.
key
)
expect
(
response
.
body
).
not_to
include
(
deploy_key
.
key
)
end
end
...
...
spec/factories/ci/pipelines.rb
View file @
857d0391
...
@@ -8,14 +8,14 @@ FactoryGirl.define do
...
@@ -8,14 +8,14 @@ FactoryGirl.define do
factory
:ci_pipeline_without_jobs
do
factory
:ci_pipeline_without_jobs
do
after
(
:build
)
do
|
pipeline
|
after
(
:build
)
do
|
pipeline
|
allow
(
pipeline
).
to
receive
(
:ci_yaml_file
)
{
YAML
.
dump
({})
}
pipeline
.
instance_variable_set
(
:@ci_yaml_file
,
YAML
.
dump
({}))
end
end
end
end
factory
:ci_pipeline_with_one_job
do
factory
:ci_pipeline_with_one_job
do
after
(
:build
)
do
|
pipeline
|
after
(
:build
)
do
|
pipeline
|
allow
(
pipeline
).
to
receive
(
:ci_yaml_file
)
do
allow
(
pipeline
).
to
receive
(
:ci_yaml_file
)
do
YAML
.
dump
({
rspec:
{
script:
"ls"
}
}
)
pipeline
.
instance_variable_set
(
:@ci_yaml_file
,
YAML
.
dump
({
rspec:
{
script:
"ls"
}
})
)
end
end
end
end
end
end
...
@@ -33,17 +33,14 @@ FactoryGirl.define do
...
@@ -33,17 +33,14 @@ FactoryGirl.define do
transient
{
config
nil
}
transient
{
config
nil
}
after
(
:build
)
do
|
pipeline
,
evaluator
|
after
(
:build
)
do
|
pipeline
,
evaluator
|
allow
(
pipeline
).
to
receive
(
:ci_yaml_file
)
do
if
evaluator
.
config
if
evaluator
.
config
pipeline
.
instance_variable_set
(
:@ci_yaml_file
,
YAML
.
dump
(
evaluator
.
config
))
YAML
.
dump
(
evaluator
.
config
)
else
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
end
end
# Populates pipeline with errors
# Populates pipeline with errors
#
pipeline
.
config_processor
if
evaluator
.
config
pipeline
.
config_processor
if
evaluator
.
config
else
pipeline
.
instance_variable_set
(
:@ci_yaml_file
,
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
)))
end
end
end
trait
:invalid
do
trait
:invalid
do
...
...
spec/factories/ci/stages.rb
View file @
857d0391
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:ci_stage
,
class:
Ci
::
Stage
do
factory
:ci_stage
,
class:
Ci
::
Stage
do
skip_create
transient
do
transient
do
name
'test'
name
'test'
status
nil
status
nil
...
...
spec/factories/ci/trigger_requests.rb
View file @
857d0391
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:ci_trigger_request
,
class:
Ci
::
TriggerRequest
do
factory
:ci_trigger_request
,
class:
Ci
::
TriggerRequest
do
factory
:ci_trigger_request_with_variables
do
trigger
factory: :ci_trigger
trigger
factory: :ci_trigger
factory
:ci_trigger_request_with_variables
do
variables
do
variables
do
{
{
TRIGGER_KEY_1
:
'TRIGGER_VALUE_1'
,
TRIGGER_KEY_1
:
'TRIGGER_VALUE_1'
,
...
...
spec/factories/commits.rb
View file @
857d0391
...
@@ -4,19 +4,14 @@ FactoryGirl.define do
...
@@ -4,19 +4,14 @@ FactoryGirl.define do
factory
:commit
do
factory
:commit
do
git_commit
RepoHelpers
.
sample_commit
git_commit
RepoHelpers
.
sample_commit
project
factory: :empty_project
project
factory: :empty_project
author
{
build
(
:author
)
}
initialize_with
do
initialize_with
do
new
(
git_commit
,
project
)
new
(
git_commit
,
project
)
end
end
after
(
:build
)
do
|
commit
|
allow
(
commit
).
to
receive
(
:author
).
and_return
build
(
:author
)
end
trait
:without_author
do
trait
:without_author
do
after
(
:build
)
do
|
commit
|
author
nil
allow
(
commit
).
to
receive
(
:author
).
and_return
nil
end
end
end
end
end
end
end
spec/factories/file_uploader.rb
→
spec/factories/file_uploader
s
.rb
View file @
857d0391
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:file_uploader
do
factory
:file_uploader
do
skip_create
project
factory: :empty_project
project
factory: :empty_project
secret
nil
secret
nil
...
...
spec/factories/keys.rb
View file @
857d0391
require_relative
'../support/helpers/key_generator_helper'
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:key
do
factory
:key
do
title
title
key
do
key
{
Spec
::
Support
::
Helpers
::
KeyGeneratorHelper
.
new
(
1024
).
generate
+
' dummy@gitlab.com'
}
'ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= dummy@gitlab.com'
end
factory
:deploy_key
,
class:
'DeployKey'
do
factory
:deploy_key
,
class:
'DeployKey'
key
do
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFf6RYK3qu/RKF/3ndJmL5xgMLp3O96x8lTay+QGZ0+9FnnAXMdUqBq/ZU6d/gyMB4IaW3nHzM1w049++yAB6UPCzMB8Uo27K5/jyZCtj7Vm9PFNjF/8am1kp46c/SeYicQgQaSBdzIW3UDEa1Ef68qroOlvpi9PYZ/tA7M0YP0K5PXX+E36zaIRnJVMPT3f2k+GnrxtjafZrwFdpOP/Fol5BQLBgcsyiU+LM1SuaCrzd8c9vyaTA1CxrkxaZh+buAi0PmdDtaDrHd42gqZkXCKavyvgM5o2CkQ5LJHCgzpXy05qNFzmThBSkb+XtoxbyagBiGbVZtSVow6Xa7qewz'
end
end
factory
:personal_key
do
factory
:personal_key
do
user
user
end
end
factory
:another_key
do
factory
:another_key
do
key
do
factory
:another_deploy_key
,
class:
'DeployKey'
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmTillFzNTrrGgwaCKaSj+QCz81E6jBc/s9av0+3b1Hwfxgkqjl4nAK/OD2NjgyrONDTDfR8cRN4eAAy6nY8GLkOyYBDyuc5nTMqs5z3yVuTwf3koGm/YQQCmo91psZ2BgDFTor8SVEE5Mm1D1k3JDMhDFxzzrOtRYFPci9lskTJaBjpqWZ4E9rDTD2q/QZntCqbC3wE9uSemRQB5f8kik7vD/AD8VQXuzKladrZKkzkONCPWsXDspUitjM8HkQdOf0PsYn1CMUC1xKYbCxkg5TkEosIwGv6CoEArUrdu/4+10LVslq494mAvEItywzrluCLCnwELfW+h/m8UHoVhZ'
end
factory
:another_deploy_key
,
class:
'DeployKey'
do
end
end
end
factory
:write_access_key
,
class:
'DeployKey'
do
factory
:write_access_key
,
class:
'DeployKey'
do
...
...
spec/factories/project_statistics.rb
View file @
857d0391
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:project_statistics
do
factory
:project_statistics
do
project
{
create
:project
}
project
namespace
{
project
.
namespace
}
initialize_with
do
# statistics are automatically created when a project is created
project
&
.
statistics
||
new
end
end
end
end
end
spec/factories/project_wikis.rb
View file @
857d0391
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:project_wiki
do
factory
:project_wiki
do
skip_create
project
factory: :empty_project
project
factory: :empty_project
user
factory: :user
user
factory: :user
initialize_with
{
new
(
project
,
user
)
}
initialize_with
{
new
(
project
,
user
)
}
...
...
spec/factories/projects.rb
View file @
857d0391
require_relative
'../support/test_env'
FactoryGirl
.
define
do
FactoryGirl
.
define
do
# Project without repository
# Project without repository
#
#
...
...
spec/factories/wiki_directories.rb
View file @
857d0391
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:wiki_directory
do
factory
:wiki_directory
do
skip_create
slug
'/path_up_to/dir'
slug
'/path_up_to/dir'
initialize_with
{
new
(
slug
)
}
initialize_with
{
new
(
slug
)
}
end
end
...
...
spec/factories_spec.rb
View file @
857d0391
...
@@ -3,14 +3,20 @@ require 'spec_helper'
...
@@ -3,14 +3,20 @@ require 'spec_helper'
describe
'factories'
do
describe
'factories'
do
FactoryGirl
.
factories
.
each
do
|
factory
|
FactoryGirl
.
factories
.
each
do
|
factory
|
describe
"
#{
factory
.
name
}
factory"
do
describe
"
#{
factory
.
name
}
factory"
do
let
(
:entity
)
{
build
(
factory
.
name
)
}
it
'does not raise error when built'
do
expect
{
build
(
factory
.
name
)
}.
not_to
raise_error
end
it
'does not raise error when created'
do
it
'does not raise error when created'
do
expect
{
entity
}.
not_to
raise_error
expect
{
create
(
factory
.
name
)
}.
not_to
raise_error
end
end
it
'is valid'
,
if:
factory
.
build_class
<
ActiveRecord
::
Base
do
factory
.
definition
.
defined_traits
.
map
(
&
:name
).
each
do
|
trait_name
|
expect
(
entity
).
to
be_valid
describe
"linting
#{
trait_name
}
trait"
do
skip
'does not raise error when created'
do
expect
{
create
(
factory
.
name
,
trait_name
)
}.
not_to
raise_error
end
end
end
end
end
end
end
end
...
...
spec/models/key_spec.rb
View file @
857d0391
...
@@ -66,14 +66,16 @@ describe Key, models: true do
...
@@ -66,14 +66,16 @@ describe Key, models: true do
end
end
it
"does not accept the exact same key twice"
do
it
"does not accept the exact same key twice"
do
create
(
:key
,
user:
user
)
first_key
=
create
(
:key
,
user:
user
)
expect
(
build
(
:key
,
user:
user
)).
not_to
be_valid
expect
(
build
(
:key
,
user:
user
,
key:
first_key
.
key
)).
not_to
be_valid
end
end
it
"does not accept a duplicate key with a different comment"
do
it
"does not accept a duplicate key with a different comment"
do
create
(
:key
,
user:
user
)
first_key
=
create
(
:key
,
user:
user
)
duplicate
=
build
(
:key
,
user:
user
)
duplicate
=
build
(
:key
,
user:
user
,
key:
first_key
.
key
)
duplicate
.
key
<<
' extra comment'
duplicate
.
key
<<
' extra comment'
expect
(
duplicate
).
not_to
be_valid
expect
(
duplicate
).
not_to
be_valid
end
end
end
end
...
...
spec/support/helpers/key_generator_helper.rb
0 → 100644
View file @
857d0391
module
Spec
module
Support
module
Helpers
class
KeyGeneratorHelper
# The components in a openssh .pub / known_host RSA public key.
RSA_COMPONENTS
=
[
'ssh-rsa'
,
:e
,
:n
].
freeze
attr_reader
:size
def
initialize
(
size
=
2048
)
@size
=
size
end
def
generate
key
=
OpenSSL
::
PKey
::
RSA
.
generate
(
size
)
components
=
RSA_COMPONENTS
.
map
do
|
component
|
key
.
respond_to?
(
component
)
?
encode_mpi
(
key
.
public_send
(
component
))
:
component
end
# Ruby tries to be helpful and adds new lines every 60 bytes :(
'ssh-rsa '
+
[
pack_pubkey_components
(
components
)].
pack
(
'm'
).
delete
(
"
\n
"
)
end
private
# Encodes an openssh-mpi-encoded integer.
def
encode_mpi
(
n
)
chars
,
n
=
[],
n
.
to_i
chars
<<
(
n
&
0xff
)
&&
n
>>=
8
while
n
!=
0
chars
<<
0
if
chars
.
empty?
||
chars
.
last
>=
0x80
chars
.
reverse
.
pack
(
'C*'
)
end
# Packs string components into an openssh-encoded pubkey.
def
pack_pubkey_components
(
strings
)
(
strings
.
map
{
|
s
|
[
s
.
length
].
pack
(
'N'
)
}).
zip
(
strings
).
flatten
.
join
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