Skip to content
GitLab
Explore
Sign in
Register
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
f3749ef3
Commit
f3749ef3
authored
3 years ago
by
Jörn Künsemöller
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-453
: fix test for TMSSsession to work when test env is hosted on 127.0.0.1
parent
84255891
No related branches found
No related tags found
3 merge requests
!634
WIP: COBALT commissioning delta
,
!481
Draft: SW-971 SW-973 SW-975: Various fixes to build LOFAR correctly.
,
!476
Resolve TMSS-453
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/TMSS/backend/test/t_tmssapp_authorization_REST_API.py
+9
-8
9 additions, 8 deletions
SAS/TMSS/backend/test/t_tmssapp_authorization_REST_API.py
with
9 additions
and
8 deletions
SAS/TMSS/backend/test/t_tmssapp_authorization_REST_API.py
+
9
−
8
View file @
f3749ef3
...
...
@@ -85,18 +85,23 @@ class OIDCSession(unittest.TestCase):
if
"
OIDC_RP_CLIENT_ID
"
not
in
os
.
environ
.
keys
():
raise
unittest
.
SkipTest
(
"
Cannot run OIDCSession-test when OIDC_RP_CLIENT_ID is not set in the environment to configure django settings
"
)
# Fix the base url if required, since our test Keycloak expects localhost and not 127.0.0.1
self
.
BASE_URL_fixed
=
BASE_URL
.
replace
(
'
127.0.0.1
'
,
'
localhost
'
)
self
.
hostname
=
urllib
.
parse
.
urlparse
(
self
.
BASE_URL_fixed
).
hostname
self
.
port
=
urllib
.
parse
.
urlparse
(
self
.
BASE_URL_fixed
).
port
@integration_test
def
test_failure_without_authentication
(
self
):
with
requests
.
Session
()
as
session
:
session
.
verify
=
False
r
=
session
.
get
(
BASE_URL
+
'
/task_draft/?format=api
'
)
r
=
session
.
get
(
self
.
BASE_URL
_fixed
+
'
/task_draft/?format=api
'
)
self
.
assertEqual
(
r
.
status_code
,
401
)
self
.
assertIn
(
"
Authentication credentials were not provided
"
,
r
.
content
.
decode
(
'
utf8
'
))
@integration_test
def
test_failure_using_wrong_credentials
(
self
):
with
self
.
assertRaises
(
ValueError
)
as
err
:
with
TMSSsession
(
'
nouser
'
,
'
wrongpassword
'
,
urllib
.
parse
.
urlparse
(
BASE_URL
).
hostname
,
urllib
.
parse
.
urlparse
(
BASE_URL
)
.
port
):
with
TMSSsession
(
'
nouser
'
,
'
wrongpassword
'
,
self
.
hostname
,
self
.
port
):
pass
self
.
assertIn
(
'
The username and/or password you specified are not correct
'
,
str
(
err
.
exception
))
...
...
@@ -106,15 +111,11 @@ class OIDCSession(unittest.TestCase):
'''
Note: This test expects the test env AUTH credentials to work against the OpenID provider in use.
If that is not the case, set working credentials via OIDC_USERNAME and OIDC_PASSWORD env vars.
todo: fix this test for Keycloak. We can login and get redirected back to TMSS as expected,
but unexpectedly get a 401 then, i.e. the session is not authenticated even though it should be.
The callback looks the same as when the credentials are posted with the browser, and there we end up with
an authenticated session. (Not sure if this is somehow cookie-related or so, but Keycloak seems happy...)
'''
username
=
os
.
environ
.
get
(
'
OIDC_USERNAME
'
,
AUTH
.
username
)
password
=
os
.
environ
.
get
(
'
OIDC_PASSWORD
'
,
AUTH
.
password
)
with
TMSSsession
(
username
,
password
,
urllib
.
parse
.
urlparse
(
BASE_URL
).
hostname
,
urllib
.
parse
.
urlparse
(
BASE_URL
)
.
port
)
as
tmss_session
:
r
=
tmss_session
.
session
.
get
(
BASE_URL
+
'
/task_draft/
'
)
with
TMSSsession
(
username
,
password
,
self
.
hostname
,
self
.
port
)
as
tmss_session
:
r
=
tmss_session
.
session
.
get
(
self
.
BASE_URL
_fixed
+
'
/task_draft/
'
)
self
.
assertEqual
(
r
.
status_code
,
200
)
self
.
assertIn
(
'
results
'
,
r
.
json
())
...
...
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