Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
8210b0d5
Commit
8210b0d5
authored
3 years ago
by
Jörn Künsemöller
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-278
: skip test if keycloak is not reachable or admin credentials are not configured
parent
52b166bd
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!634
WIP: COBALT commissioning delta
,
!517
TMSS-278: add endpoints to get friend of project and current user roles in project plus tests
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/TMSS/backend/test/t_permissions_project_roles.py
+20
-10
20 additions, 10 deletions
SAS/TMSS/backend/test/t_permissions_project_roles.py
with
20 additions
and
10 deletions
SAS/TMSS/backend/test/t_permissions_project_roles.py
+
20
−
10
View file @
8210b0d5
...
@@ -54,6 +54,10 @@ from django.test import TestCase
...
@@ -54,6 +54,10 @@ from django.test import TestCase
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth
import
get_user_model
User
=
get_user_model
()
User
=
get_user_model
()
from
django.conf
import
settings
import
json
class
ProjectPermissionTestCase
(
TestCase
):
class
ProjectPermissionTestCase
(
TestCase
):
# This tests that the project permissions are enforced in light of the project roles that are externally provided
# This tests that the project permissions are enforced in light of the project roles that are externally provided
# for the user through the user admin. This test does not rely on the project permissions as defined in the system,
# for the user through the user admin. This test does not rely on the project permissions as defined in the system,
...
@@ -235,29 +239,35 @@ class ProjectPermissionTestCase(TestCase):
...
@@ -235,29 +239,35 @@ class ProjectPermissionTestCase(TestCase):
self
.
assertEqual
(
r
.
status_code
,
403
)
self
.
assertEqual
(
r
.
status_code
,
403
)
self
.
assertNotIn
(
'
Access-Control-Allow-Methods
'
,
r
.
headers
)
self
.
assertNotIn
(
'
Access-Control-Allow-Methods
'
,
r
.
headers
)
# todo: add tests for other models with project permissions
def
test_project_get_friend_returns_correct_user
(
self
):
def
test_project_get_friend_returns_correct_user
(
self
):
"""
"""
Note: This test relies on real data from Keycloak.
Note: This test relies on real data from Keycloak.
"""
"""
r
=
GET_and_assert_equal_expected_code
(
self
,
self
.
project_keycloak_url
+
'
/friend/
'
,
200
)
with
requests
.
Session
()
as
session
:
self
.
assertEqual
(
len
(
r
),
2
)
session
.
verify
=
False
for
friend
in
r
:
session
.
auth
=
(
AUTH
.
username
,
AUTH
.
password
)
r
=
session
.
get
(
self
.
project_keycloak_url
+
'
/friend/
'
)
if
'
Invalid user credentials
'
in
str
(
r
.
content
)
or
\
'
Service Unavailable
'
in
str
(
r
.
content
):
self
.
skipTest
(
'
skipping test_project_get_friend_returns_correct_user because the test environment has
'
'
no valid admin credentials configured, or Keycloak is not working correctly.
'
)
self
.
assertEqual
(
r
.
status_code
,
200
)
content
=
json
.
loads
(
r
.
content
.
decode
(
'
utf-8
'
))
self
.
assertEqual
(
len
(
content
),
2
)
for
friend
in
content
:
# Todo: find a way to mock the Keycloak response so we can assert more strictly.
# Todo: find a way to mock the Keycloak response so we can assert more strictly.
self
.
assertTrue
(
friend
.
endswith
(
'
@astron.nl
'
))
# redacted expected full email due to GDPR
self
.
assertTrue
(
friend
.
endswith
(
'
@astron.nl
'
))
# redacted expected full email due to GDPR
def
test_project_get_friend_returns_403_if_no_permission_for_project
(
self
):
def
test_project_get_friend_returns_403_if_no_permission_for_project
(
self
):
r
=
GET_and_assert_equal_expected_code
(
self
,
self
.
project_forbidden_url
+
'
/
my_roles
/
'
,
403
,
auth
=
self
.
auth
)
r
=
GET_and_assert_equal_expected_code
(
self
,
self
.
project_forbidden_url
+
'
/
friend
/
'
,
403
,
auth
=
self
.
auth
)
self
.
assertIn
(
'
permission
'
,
str
(
r
))
self
.
assertIn
(
'
permission
'
,
str
(
r
))
def
test_project_get_my_roles_returns_correct_roles
(
self
):
def
test_project_get_my_roles_returns_correct_roles
(
self
):
#
r = GET_and_assert_equal_expected_code(self, self.project_shared_support_url + '/my_roles/', 200, auth=self.auth)
r
=
GET_and_assert_equal_expected_code
(
self
,
self
.
project_shared_support_url
+
'
/my_roles/
'
,
200
,
auth
=
self
.
auth
)
#
expected_reply = ['shared_support']
expected_reply
=
[
'
shared_support
'
]
#
self.assertEqual(expected_reply, r)
self
.
assertEqual
(
expected_reply
,
r
)
r
=
GET_and_assert_equal_expected_code
(
self
,
self
.
project_friend_url
+
'
/my_roles/
'
,
200
,
auth
=
self
.
auth
)
r
=
GET_and_assert_equal_expected_code
(
self
,
self
.
project_friend_url
+
'
/my_roles/
'
,
200
,
auth
=
self
.
auth
)
expected_reply
=
[
'
friend_of_project
'
]
expected_reply
=
[
'
friend_of_project
'
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment