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
iv
gitlab-ce
Commits
a2ecfdc5
Commit
a2ecfdc5
authored
Jul 21, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move access-related matchers to their own module
parent
1fee24a3
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
72 additions
and
35 deletions
+72
-35
spec/features/security/dashboard_access_spec.rb
spec/features/security/dashboard_access_spec.rb
+2
-0
spec/features/security/group/group_access_spec.rb
spec/features/security/group/group_access_spec.rb
+2
-0
spec/features/security/group/internal_group_access_spec.rb
spec/features/security/group/internal_group_access_spec.rb
+2
-0
spec/features/security/group/mixed_group_access_spec.rb
spec/features/security/group/mixed_group_access_spec.rb
+2
-0
spec/features/security/group/public_group_access_spec.rb
spec/features/security/group/public_group_access_spec.rb
+2
-0
spec/features/security/profile_access_spec.rb
spec/features/security/profile_access_spec.rb
+2
-0
spec/features/security/project/internal_access_spec.rb
spec/features/security/project/internal_access_spec.rb
+2
-0
spec/features/security/project/private_access_spec.rb
spec/features/security/project/private_access_spec.rb
+2
-0
spec/features/security/project/public_access_spec.rb
spec/features/security/project/public_access_spec.rb
+2
-1
spec/support/matchers.rb
spec/support/matchers.rb
+0
-34
spec/support/matchers/access_matchers.rb
spec/support/matchers/access_matchers.rb
+54
-0
No files found.
spec/features/security/dashboard_access_spec.rb
View file @
a2ecfdc5
require
'spec_helper'
describe
"Dashboard access"
,
feature:
true
do
include
AccessMatchers
describe
"GET /dashboard"
do
subject
{
dashboard_path
}
...
...
spec/features/security/group/group_access_spec.rb
View file @
a2ecfdc5
require
'spec_helper'
describe
"Group access"
,
feature:
true
do
include
AccessMatchers
describe
"GET /projects/new"
do
it
{
expect
(
new_group_path
).
to
be_allowed_for
:admin
}
it
{
expect
(
new_group_path
).
to
be_allowed_for
:user
}
...
...
spec/features/security/group/internal_group_access_spec.rb
View file @
a2ecfdc5
require
'spec_helper'
describe
"Group with internal project access"
,
feature:
true
do
include
AccessMatchers
describe
"Group"
do
let
(
:group
)
{
create
(
:group
)
}
...
...
spec/features/security/group/mixed_group_access_spec.rb
View file @
a2ecfdc5
require
'spec_helper'
describe
"Group access"
,
feature:
true
do
include
AccessMatchers
describe
"Group"
do
let
(
:group
)
{
create
(
:group
)
}
...
...
spec/features/security/group/public_group_access_spec.rb
View file @
a2ecfdc5
require
'spec_helper'
describe
"Group with public project access"
,
feature:
true
do
include
AccessMatchers
describe
"Group"
do
let
(
:group
)
{
create
(
:group
)
}
...
...
spec/features/security/profile_access_spec.rb
View file @
a2ecfdc5
require
'spec_helper'
describe
"Profile access"
,
feature:
true
do
include
AccessMatchers
before
do
@u1
=
create
(
:user
)
end
...
...
spec/features/security/project/internal_access_spec.rb
View file @
a2ecfdc5
require
'spec_helper'
describe
"Internal Project Access"
,
feature:
true
do
include
AccessMatchers
let
(
:project
)
{
create
(
:project
,
:internal
)
}
let
(
:master
)
{
create
(
:user
)
}
...
...
spec/features/security/project/private_access_spec.rb
View file @
a2ecfdc5
require
'spec_helper'
describe
"Private Project Access"
,
feature:
true
do
include
AccessMatchers
let
(
:project
)
{
create
(
:project
)
}
let
(
:master
)
{
create
(
:user
)
}
...
...
spec/features/security/project/public_access_spec.rb
View file @
a2ecfdc5
require
'spec_helper'
describe
"Public Project Access"
,
feature:
true
do
include
AccessMatchers
let
(
:project
)
{
create
(
:project
)
}
let
(
:master
)
{
create
(
:user
)
}
...
...
@@ -17,7 +19,6 @@ describe "Public Project Access", feature: true do
# readonly
project
.
team
<<
[
reporter
,
:reporter
]
end
describe
"Project should be public"
do
...
...
spec/support/matchers.rb
View file @
a2ecfdc5
def
emulate_user
(
user
)
user
=
case
user
when
:user
then
create
(
:user
)
when
:visitor
then
nil
when
:admin
then
create
(
:admin
)
else
user
end
login_with
(
user
)
if
user
end
RSpec
::
Matchers
.
define
:be_allowed_for
do
|
user
|
match
do
|
url
|
emulate_user
(
user
)
visit
url
status_code
!=
404
&&
current_path
!=
new_user_session_path
end
end
RSpec
::
Matchers
.
define
:be_denied_for
do
|
user
|
match
do
|
url
|
emulate_user
(
user
)
visit
url
status_code
==
404
||
current_path
==
new_user_session_path
end
end
RSpec
::
Matchers
.
define
:be_not_found_for
do
|
user
|
match
do
|
url
|
emulate_user
(
user
)
visit
url
status_code
==
404
end
end
RSpec
::
Matchers
.
define
:include_module
do
|
expected
|
match
do
described_class
.
included_modules
.
include?
(
expected
)
...
...
spec/support/matchers/access_matchers.rb
0 → 100644
View file @
a2ecfdc5
# AccessMatchers
#
# The custom matchers contained in this module are used to test a user's access
# to a URL by emulating a specific user or type of user account, visiting the
# URL, and then checking the response status code and resulting path.
module
AccessMatchers
extend
RSpec
::
Matchers
::
DSL
include
Warden
::
Test
::
Helpers
def
emulate_user
(
user
)
case
user
when
:user
login_as
(
create
(
:user
))
when
:visitor
logout
when
:admin
login_as
(
create
(
:admin
))
when
User
login_as
(
user
)
else
raise
ArgumentError
,
"cannot emulate user
#{
user
}
"
end
end
def
description_for
(
user
,
type
)
if
user
.
kind_of?
(
User
)
# User#inspect displays too much information for RSpec's description
# messages
"be
#{
type
}
for supplied User"
else
"be
#{
type
}
for
#{
user
}
"
end
end
matcher
:be_allowed_for
do
|
user
|
match
do
|
url
|
emulate_user
(
user
)
visit
url
status_code
!=
404
&&
current_path
!=
new_user_session_path
end
description
{
description_for
(
user
,
'allowed'
)
}
end
matcher
:be_denied_for
do
|
user
|
match
do
|
url
|
emulate_user
(
user
)
visit
url
status_code
==
404
||
current_path
==
new_user_session_path
end
description
{
description_for
(
user
,
'denied'
)
}
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