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
ed5a02c9
Commit
ed5a02c9
authored
Oct 19, 2017
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make reject_unsigned_commits rule work for Silver and Gold plans.
Also fix some broken specs
parent
58126159
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
144 additions
and
5 deletions
+144
-5
app/models/license.rb
app/models/license.rb
+0
-1
app/models/push_rule.rb
app/models/push_rule.rb
+9
-1
app/views/shared/push_rules/_reject_unsigned_commits_setting.html.haml
...red/push_rules/_reject_unsigned_commits_setting.html.haml
+1
-1
spec/features/projects/push_rules_spec.rb
spec/features/projects/push_rules_spec.rb
+66
-0
spec/lib/gitlab/checks/change_access_spec.rb
spec/lib/gitlab/checks/change_access_spec.rb
+4
-0
spec/models/push_rule_spec.rb
spec/models/push_rule_spec.rb
+62
-0
spec/support/db_cleaner.rb
spec/support/db_cleaner.rb
+2
-2
No files found.
app/models/license.rb
View file @
ed5a02c9
...
...
@@ -116,7 +116,6 @@ class License < ActiveRecord::Base
multiple_ldap_servers
object_storage
repository_size_limit
reject_unsigned_commits
]
.
freeze
validate
:valid_license
...
...
app/models/push_rule.rb
View file @
ed5a02c9
...
...
@@ -22,7 +22,7 @@ class PushRule < ActiveRecord::Base
end
def
commit_signature_allowed?
(
commit
)
return
true
unless
License
.
feature_
available?
(
:reject_unsigned_commits
)
return
true
unless
available?
(
:reject_unsigned_commits
)
return
true
unless
reject_unsigned_commits
commit
.
has_signature?
...
...
@@ -75,6 +75,14 @@ class PushRule < ActiveRecord::Base
is_sample?
end
def
available?
(
feature_sym
)
if
global?
License
.
feature_available?
(
feature_sym
)
else
project
&
.
feature_available?
(
feature_sym
)
end
end
private
def
data_match?
(
data
,
regex
)
...
...
app/views/shared/push_rules/_reject_unsigned_commits_setting.html.haml
View file @
ed5a02c9
-
return
unless
License
.
feature_
available?
(
:reject_unsigned_commits
)
-
return
unless
push_rule
.
available?
(
:reject_unsigned_commits
)
-
form
=
local_assigns
.
fetch
(
:form
)
-
push_rule
=
local_assigns
.
fetch
(
:push_rule
)
...
...
spec/features/projects/push_rules_spec.rb
0 → 100644
View file @
ed5a02c9
require
'spec_helper'
feature
'Projects > Push Rules'
,
:js
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
namespace:
user
.
namespace
)
}
before
do
project
.
team
<<
[
user
,
:master
]
sign_in
(
user
)
end
describe
'Reject unsigned commits rule'
do
context
'unlicensed'
do
before
do
stub_licensed_features
(
reject_unsigned_commits:
false
)
end
it
'does not render the setting checkbox'
do
visit
project_settings_repository_path
(
project
)
expect
(
page
).
not_to
have_content
(
'Reject unsigned commits'
)
end
end
context
'licensed'
do
let
(
:bronze_plan
)
{
Plan
.
find_by!
(
name:
'bronze'
)
}
let
(
:gold_plan
)
{
Plan
.
find_by!
(
name:
'gold'
)
}
before
do
stub_licensed_features
(
reject_unsigned_commits:
true
)
end
it
'renders the setting checkbox'
do
visit
project_settings_repository_path
(
project
)
expect
(
page
).
to
have_content
(
'Reject unsigned commits'
)
end
describe
'with GL.com plans'
do
before
do
stub_application_setting
(
check_namespace_plan:
true
)
end
context
'when disabled'
do
it
'does not render the setting checkbox'
do
project
.
namespace
.
update!
(
plan_id:
bronze_plan
.
id
)
visit
project_settings_repository_path
(
project
)
expect
(
page
).
not_to
have_content
(
'Reject unsigned commits'
)
end
end
context
'when enabled'
do
it
'renders the setting checkbox'
do
project
.
namespace
.
update!
(
plan_id:
gold_plan
.
id
)
visit
project_settings_repository_path
(
project
)
expect
(
page
).
to
have_content
(
'Reject unsigned commits'
)
end
end
end
end
end
end
spec/lib/gitlab/checks/change_access_spec.rb
View file @
ed5a02c9
...
...
@@ -371,6 +371,10 @@ describe Gitlab::Checks::ChangeAccess do
end
context
'GPG sign rules'
do
before
do
stub_licensed_features
(
reject_unsigned_commits:
true
)
end
let
(
:push_rule
)
{
create
(
:push_rule
,
reject_unsigned_commits:
true
)
}
it_behaves_like
'check ignored when push rule unlicensed'
...
...
spec/models/push_rule_spec.rb
View file @
ed5a02c9
...
...
@@ -49,6 +49,7 @@ describe PushRule do
end
describe
'#commit_signature_allowed?'
do
let!
(
:premium_license
)
{
create
(
:license
,
plan:
License
::
PREMIUM_PLAN
)
}
let
(
:signed_commit
)
{
double
(
has_signature?:
true
)
}
let
(
:unsigned_commit
)
{
double
(
has_signature?:
false
)
}
...
...
@@ -135,4 +136,65 @@ describe PushRule do
end
end
end
describe
'#available?'
do
shared_examples
'an unavailable push_rule'
do
it
'is not available'
do
expect
(
push_rule
.
available?
(
:reject_unsigned_commits
)).
to
eq
(
false
)
end
end
shared_examples
'an available push_rule'
do
it
'is available'
do
expect
(
push_rule
.
available?
(
:reject_unsigned_commits
)).
to
eq
(
true
)
end
end
describe
'reject_unsigned_commits'
do
context
'with the global push_rule'
do
let
(
:push_rule
)
{
create
(
:push_rule_sample
)
}
context
'with a EE starter license'
do
let!
(
:license
)
{
create
(
:license
,
plan:
License
::
STARTER_PLAN
)
}
it_behaves_like
'an unavailable push_rule'
end
context
'with a EE premium license'
do
let!
(
:license
)
{
create
(
:license
,
plan:
License
::
PREMIUM_PLAN
)
}
it_behaves_like
'an available push_rule'
end
end
context
'with GL.com plans'
do
let
(
:group
)
{
create
(
:group
,
plan:
Plan
.
find_by!
(
name:
gl_plan
))
}
let
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
let
(
:push_rule
)
{
create
(
:push_rule
,
project:
project
)
}
before
do
create
(
:license
,
plan:
License
::
PREMIUM_PLAN
)
stub_application_setting
(
check_namespace_plan:
true
)
end
context
'with a Bronze plan'
do
let
(
:gl_plan
)
{
::
EE
::
Namespace
::
BRONZE_PLAN
}
it_behaves_like
'an unavailable push_rule'
end
context
'with a Silver plan'
do
let
(
:gl_plan
)
{
::
EE
::
Namespace
::
SILVER_PLAN
}
it_behaves_like
'an available push_rule'
end
context
'with a Gold plan'
do
let
(
:gl_plan
)
{
::
EE
::
Namespace
::
GOLD_PLAN
}
it_behaves_like
'an available push_rule'
end
end
end
end
end
spec/support/db_cleaner.rb
View file @
ed5a02c9
...
...
@@ -14,11 +14,11 @@ RSpec.configure do |config|
end
config
.
before
(
:each
,
:js
)
do
DatabaseCleaner
.
strategy
=
:truncation
,
{
except:
[
'licenses'
]
}
DatabaseCleaner
.
strategy
=
:truncation
,
{
except:
%w[licenses plans
]
}
end
config
.
before
(
:each
,
:truncate
)
do
DatabaseCleaner
.
strategy
=
:truncation
,
{
except:
[
'licenses'
]
}
DatabaseCleaner
.
strategy
=
:truncation
,
{
except:
%w[licenses plans
]
}
end
config
.
before
(
:each
,
:migration
)
do
...
...
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