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
42fcd388
Commit
42fcd388
authored
Mar 10, 2016
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
External Users
The user has the rights of a public user execpt it can never create a project, group, or team. Also it cant view internal projects.
parent
065de4ab
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
171 additions
and
60 deletions
+171
-60
users_controller.rb
app/controllers/admin/users_controller.rb
+1
-1
projects_finder.rb
app/finders/projects_finder.rb
+5
-6
ability.rb
app/models/ability.rb
+17
-17
user.rb
app/models/user.rb
+12
-0
_form.html.haml
app/views/admin/users/_form.html.haml
+5
-0
show.html.haml
app/views/admin/users/show.html.haml
+4
-0
20160310185910_add_external_flag_to_users.rb
db/migrate/20160310185910_add_external_flag_to_users.rb
+5
-0
schema.rb
db/schema.rb
+2
-1
users.rb
lib/api/users.rb
+3
-2
internal_access_spec.rb
spec/features/security/project/internal_access_spec.rb
+26
-11
private_access_spec.rb
spec/features/security/project/private_access_spec.rb
+23
-11
public_access_spec.rb
spec/features/security/project/public_access_spec.rb
+30
-11
user_spec.rb
spec/models/user_spec.rb
+16
-0
users_spec.rb
spec/requests/api/users_spec.rb
+20
-0
access_matchers.rb
spec/support/matchers/access_matchers.rb
+2
-0
No files found.
app/controllers/admin/users_controller.rb
View file @
42fcd388
...
...
@@ -150,7 +150,7 @@ class Admin::UsersController < Admin::ApplicationController
:email
,
:remember_me
,
:bio
,
:name
,
:username
,
:skype
,
:linkedin
,
:twitter
,
:website_url
,
:color_scheme_id
,
:theme_id
,
:force_random_password
,
:extern_uid
,
:provider
,
:password_expires_at
,
:avatar
,
:hide_no_ssh_key
,
:hide_no_password
,
:projects_limit
,
:can_create_group
,
:admin
,
:key_id
:projects_limit
,
:can_create_group
,
:admin
,
:key_id
,
:external
)
end
...
...
app/finders/projects_finder.rb
View file @
42fcd388
...
...
@@ -51,13 +51,12 @@ class ProjectsFinder
end
def
all_projects
(
current_user
)
if
current_user
[
current_user
.
authorized_projects
,
public_and_internal_projects
]
return
[
Project
.
public_only
]
unless
current_user
if
current_user
.
external?
[
current_user
.
authorized_projects
,
public_projects
]
else
[
Project
.
public_only
]
[
current_user
.
authorized_projects
,
public_and_internal_projects
]
end
end
...
...
app/models/ability.rb
View file @
42fcd388
...
...
@@ -109,23 +109,10 @@ class Ability
key
=
"/user/
#{
user
.
id
}
/project/
#{
project
.
id
}
"
RequestStore
.
store
[
key
]
||=
begin
team
=
project
.
team
# Push abilities on the users team role
rules
.
push
(
*
project_team_rules
(
project
.
team
,
user
))
# Rules based on role in project
if
team
.
master?
(
user
)
rules
.
push
(
*
project_master_rules
)
elsif
team
.
developer?
(
user
)
rules
.
push
(
*
project_dev_rules
)
elsif
team
.
reporter?
(
user
)
rules
.
push
(
*
project_report_rules
)
elsif
team
.
guest?
(
user
)
rules
.
push
(
*
project_guest_rules
)
end
if
project
.
public?
||
project
.
internal?
if
project
.
public?
||
(
project
.
internal?
&&
!
user
.
external?
)
rules
.
push
(
*
public_project_rules
)
# Allow to read builds for internal projects
...
...
@@ -148,6 +135,19 @@ class Ability
end
end
def
project_team_rules
(
team
,
user
)
# Rules based on role in project
if
team
.
master?
(
user
)
project_master_rules
elsif
team
.
developer?
(
user
)
project_dev_rules
elsif
team
.
reporter?
(
user
)
project_report_rules
elsif
team
.
guest?
(
user
)
project_guest_rules
end
end
def
public_project_rules
@public_project_rules
||=
project_guest_rules
+
[
:download_code
,
...
...
@@ -356,7 +356,7 @@ class Ability
]
end
if
snippet
.
public?
||
snippet
.
internal?
if
snippet
.
public?
||
(
snippet
.
internal?
&&
!
user
.
external?
)
rules
<<
:read_personal_snippet
end
...
...
app/models/user.rb
View file @
42fcd388
...
...
@@ -59,6 +59,7 @@
# hide_project_limit :boolean default(FALSE)
# unlock_token :string
# otp_grace_period_started_at :datetime
# external :boolean default(FALSE)
#
require
'carrierwave/orm/activerecord'
...
...
@@ -77,6 +78,7 @@ class User < ActiveRecord::Base
add_authentication_token_field
:authentication_token
default_value_for
:admin
,
false
default_value_for
:external
,
false
default_value_for
:can_create_group
,
gitlab_config
.
default_can_create_group
default_value_for
:can_create_team
,
false
default_value_for
:hide_no_ssh_key
,
false
...
...
@@ -179,6 +181,7 @@ class User < ActiveRecord::Base
after_update
:update_emails_with_primary_email
,
if:
->
(
user
)
{
user
.
email_changed?
}
before_save
:ensure_authentication_token
before_save
:ensure_external_user_rights
after_save
:ensure_namespace_correct
after_initialize
:set_projects_limit
after_create
:post_create_hook
...
...
@@ -848,4 +851,13 @@ class User < ActiveRecord::Base
def
send_devise_notification
(
notification
,
*
args
)
devise_mailer
.
send
(
notification
,
self
,
*
args
).
deliver_later
end
def
ensure_external_user_rights
return
unless
self
.
external?
self
.
can_create_team
=
false
self
.
can_create_group
=
false
self
.
projects_limit
=
0
self
.
hide_project_limit
=
true
end
end
app/views/admin/users/_form.html.haml
View file @
42fcd388
...
...
@@ -61,6 +61,11 @@
.col-sm-10
You cannot remove your own admin rights
-
else
.col-sm-10
=
f
.
check_box
:admin
.form-group
=
f
.
label
:external
,
class:
'control-label'
.col-sm-10
=
f
.
check_box
:external
%fieldset
%legend
Profile
.form-group
...
...
app/views/admin/users/show.html.haml
View file @
42fcd388
...
...
@@ -48,6 +48,10 @@
Disabled
%li
%span
.light
External User:
%strong
=
@user
.
external?
?
"Yes"
:
"No"
%li
%span
.light
Can create groups:
%strong
=
@user
.
can_create_group
?
"Yes"
:
"No"
...
...
db/migrate/20160310185910_add_external_flag_to_users.rb
0 → 100644
View file @
42fcd388
class
AddExternalFlagToUsers
<
ActiveRecord
::
Migration
def
change
add_column
:users
,
:external
,
:boolean
,
default:
false
end
end
db/schema.rb
View file @
42fcd388
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201603
09140734
)
do
ActiveRecord
::
Schema
.
define
(
version:
201603
10185910
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -929,6 +929,7 @@ ActiveRecord::Schema.define(version: 20160309140734) do
t
.
string
"unlock_token"
t
.
datetime
"otp_grace_period_started_at"
t
.
boolean
"ldap_email"
,
default:
false
,
null:
false
t
.
boolean
"external"
,
default:
false
end
add_index
"users"
,
[
"admin"
],
name:
"index_users_on_admin"
,
using: :btree
...
...
lib/api/users.rb
View file @
42fcd388
...
...
@@ -61,19 +61,20 @@ module API
# admin - User is admin - true or false (default)
# can_create_group - User can create groups - true or false
# confirm - Require user confirmation - true (default) or false
# external - Is user an external user - true or false(default)
# Example Request:
# POST /users
post
do
authenticated_as_admin!
required_attributes!
[
:email
,
:password
,
:name
,
:username
]
attrs
=
attributes_for_keys
[
:email
,
:name
,
:password
,
:skype
,
:linkedin
,
:twitter
,
:projects_limit
,
:username
,
:bio
,
:can_create_group
,
:admin
,
:confirm
]
attrs
=
attributes_for_keys
[
:email
,
:name
,
:password
,
:skype
,
:linkedin
,
:twitter
,
:projects_limit
,
:username
,
:bio
,
:can_create_group
,
:admin
,
:confirm
,
:external
]
admin
=
attrs
.
delete
(
:admin
)
confirm
=
!
(
attrs
.
delete
(
:confirm
)
=~
(
/(false|f|no|0)$/i
))
user
=
User
.
build_user
(
attrs
)
user
.
admin
=
admin
unless
admin
.
nil?
user
.
skip_confirmation!
unless
confirm
identity_attrs
=
attributes_for_keys
[
:provider
,
:extern_uid
]
if
identity_attrs
.
any?
user
.
identities
.
build
(
identity_attrs
)
end
...
...
spec/features/security/project/internal_access_spec.rb
View file @
42fcd388
...
...
@@ -34,6 +34,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -45,6 +46,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -56,6 +58,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -67,6 +70,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -78,6 +82,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -89,22 +94,21 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
describe
"GET /:project_path/blob"
do
before
do
commit
=
project
.
repository
.
commit
path
=
'.gitignore'
@blob_path
=
namespace_project_blob_path
(
project
.
namespace
,
project
,
File
.
join
(
commit
.
id
,
path
))
end
let
(
:commit
)
{
project
.
repository
.
commit
}
subject
{
namespace_project_blob_path
(
project
.
namespace
,
project
,
File
.
join
(
commit
.
id
,
'.gitignore'
))
}
it
{
expect
(
@blob_path
).
to
be_allowed_for
master
}
it
{
expect
(
@blob_path
).
to
be_allowed_for
reporter
}
it
{
expect
(
@blob_path
).
to
be_allowed_for
:admin
}
it
{
expect
(
@blob_path
).
to
be_allowed_for
guest
}
it
{
expect
(
@blob_path
).
to
be_allowed_for
:user
}
it
{
expect
(
@blob_path
).
to
be_denied_for
:visitor
}
it
{
is_expected
.
to
be_allowed_for
master
}
it
{
is_expected
.
to
be_allowed_for
reporter
}
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
describe
"GET /:project_path/edit"
do
...
...
@@ -115,6 +119,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -126,6 +131,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -137,6 +143,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -149,6 +156,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -160,6 +168,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -171,6 +180,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -182,6 +192,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -193,6 +204,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -209,6 +221,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -225,6 +238,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -236,6 +250,7 @@ describe "Internal Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
end
spec/features/security/project/private_access_spec.rb
View file @
42fcd388
...
...
@@ -34,6 +34,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -45,6 +46,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -56,6 +58,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -78,6 +81,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -89,22 +93,21 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
describe
"GET /:project_path/blob"
do
before
do
commit
=
project
.
repository
.
commit
path
=
'.gitignore'
@blob_path
=
namespace_project_blob_path
(
project
.
namespace
,
project
,
File
.
join
(
commit
.
id
,
path
))
end
let
(
:commit
)
{
project
.
repository
.
commit
}
subject
{
namespace_project_blob_path
(
project
.
namespace
,
project
,
File
.
join
(
commit
.
id
,
'.gitignore'
))}
it
{
expect
(
@blob_path
).
to
be_allowed_for
master
}
it
{
expect
(
@blob_path
).
to
be_allowed_for
reporter
}
it
{
expect
(
@blob_path
).
to
be_allowed_for
:admin
}
it
{
expect
(
@blob_path
).
to
be_denied_for
guest
}
it
{
expect
(
@blob_path
).
to
be_denied_for
:user
}
it
{
expect
(
@blob_path
).
to
be_denied_for
:visitor
}
it
{
is_expected
.
to
be_allowed_for
master
}
it
{
is_expected
.
to
be_allowed_for
reporter
}
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
describe
"GET /:project_path/edit"
do
...
...
@@ -115,6 +118,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -126,6 +130,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -137,6 +142,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -149,6 +155,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -160,6 +167,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -171,6 +179,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -187,6 +196,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -203,6 +213,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -214,6 +225,7 @@ describe "Private Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
end
spec/features/security/project/public_access_spec.rb
View file @
42fcd388
...
...
@@ -38,6 +38,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -49,6 +50,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -60,6 +62,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -71,6 +74,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -82,6 +86,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -93,6 +98,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -107,6 +113,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -118,6 +125,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
end
...
...
@@ -135,6 +143,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -146,23 +155,22 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
end
describe
"GET /:project_path/blob"
do
before
do
commit
=
project
.
repository
.
commit
path
=
'.gitignore'
@blob_path
=
namespace_project_blob_path
(
project
.
namespace
,
project
,
File
.
join
(
commit
.
id
,
path
))
end
let
(
:commit
)
{
project
.
repository
.
commit
}
subject
{
namespace_project_blob_path
(
project
.
namespace
,
project
,
File
.
join
(
commit
.
id
,
'.gitignore'
))
}
it
{
expect
(
@blob_path
)
.
to
be_allowed_for
master
}
it
{
expect
(
@blob_path
)
.
to
be_allowed_for
reporter
}
it
{
expect
(
@blob_path
)
.
to
be_allowed_for
:admin
}
it
{
expect
(
@blob_path
)
.
to
be_allowed_for
guest
}
it
{
expect
(
@blob_path
)
.
to
be_allowed_for
:user
}
it
{
expect
(
@blob_path
)
.
to
be_allowed_for
:visitor
}
it
{
is_expected
.
to
be_allowed_for
master
}
it
{
is_expected
.
to
be_allowed_for
reporter
}
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
describe
"GET /:project_path/edit"
do
...
...
@@ -173,6 +181,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -184,6 +193,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -195,6 +205,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -207,6 +218,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -218,6 +230,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -229,6 +242,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -240,6 +254,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -251,6 +266,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
...
...
@@ -267,6 +283,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -283,6 +300,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_allowed_for
guest
}
it
{
is_expected
.
to
be_allowed_for
:user
}
it
{
is_expected
.
to
be_allowed_for
:external
}
it
{
is_expected
.
to
be_allowed_for
:visitor
}
end
...
...
@@ -294,6 +312,7 @@ describe "Public Project Access", feature: true do
it
{
is_expected
.
to
be_allowed_for
:admin
}
it
{
is_expected
.
to
be_denied_for
guest
}
it
{
is_expected
.
to
be_denied_for
:user
}
it
{
is_expected
.
to
be_denied_for
:external
}
it
{
is_expected
.
to
be_denied_for
:visitor
}
end
end
spec/models/user_spec.rb
View file @
42fcd388
...
...
@@ -206,6 +206,21 @@ describe User, models: true do
it
{
is_expected
.
to
respond_to
(
:is_admin?
)
}
it
{
is_expected
.
to
respond_to
(
:name
)
}
it
{
is_expected
.
to
respond_to
(
:private_token
)
}
it
{
is_expected
.
to
respond_to
(
:external?
)
}
end
describe
'before save hook'
do
context
'when saving an external user'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:external_user
)
{
create
(
:user
,
external:
true
)
}
it
"sets other properties aswell"
do
expect
(
external_user
.
can_create_team
).
to
be_falsey
expect
(
external_user
.
can_create_group
).
to
be_falsey
expect
(
external_user
.
hide_project_limit
).
to
be_truthy
expect
(
external_user
.
projects_limit
).
to
be
0
end
end
end
describe
'#confirm'
do
...
...
@@ -430,6 +445,7 @@ describe User, models: true do
expect
(
user
.
projects_limit
).
to
eq
(
Gitlab
.
config
.
gitlab
.
default_projects_limit
)
expect
(
user
.
can_create_group
).
to
eq
(
Gitlab
.
config
.
gitlab
.
default_can_create_group
)
expect
(
user
.
theme_id
).
to
eq
(
Gitlab
.
config
.
gitlab
.
default_theme
)
expect
(
user
.
external
).
to
be_falsey
end
end
...
...
spec/requests/api/users_spec.rb
View file @
42fcd388
...
...
@@ -120,6 +120,26 @@ describe API::API, api: true do
expect
(
response
.
status
).
to
eq
(
201
)
end
it
'creates non-external users by default'
do
post
api
(
"/users"
,
admin
),
attributes_for
(
:user
)
expect
(
response
.
status
).
to
eq
(
201
)
user_id
=
json_response
[
'id'
]
new_user
=
User
.
find
(
user_id
)
expect
(
new_user
).
not_to
eq
nil
expect
(
new_user
.
external
).
to
be_falsy
end
it
'should allow an external user to be created'
do
post
api
(
"/users"
,
admin
),
attributes_for
(
:user
,
external:
true
)
expect
(
response
.
status
).
to
eq
(
201
)
user_id
=
json_response
[
'id'
]
new_user
=
User
.
find
(
user_id
)
expect
(
new_user
).
not_to
eq
nil
expect
(
new_user
.
external
).
to
be_truthy
end
it
"should not create user with invalid email"
do
post
api
(
'/users'
,
admin
),
email:
'invalid email'
,
...
...
spec/support/matchers/access_matchers.rb
View file @
42fcd388
...
...
@@ -15,6 +15,8 @@ module AccessMatchers
logout
when
:admin
login_as
(
create
(
:admin
))
when
:external
login_as
(
create
(
:user
,
external:
true
))
when
User
login_as
(
user
)
else
...
...
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