Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sso
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
ai
sso
Commits
56247c8b
Commit
56247c8b
authored
3 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
More py3 fixes
parent
8a4c673f
No related branches found
No related tags found
1 merge request
!4
Drop Python 2 support
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mod_sso/test/httpd_integration_test.py
+15
-16
15 additions, 16 deletions
src/mod_sso/test/httpd_integration_test.py
with
15 additions
and
16 deletions
src/mod_sso/test/httpd_integration_test.py
+
15
−
16
View file @
56247c8b
#!/usr/bin/python
import
Cookie
import
httplib
import
os
import
re
import
subprocess
import
sys
import
time
import
unittest
import
urllib
import
urlparse
from
http.client
import
HTTPConnection
from
http.cookies
import
SimpleCookie
from
urllib.parse
import
urlencode
,
urlsplit
,
parse_qsl
sys
.
path
.
append
(
"
../../python
"
)
import
sso
...
...
@@ -93,7 +92,7 @@ def _stop_httpd(httpd):
def
_query
(
url
,
host
=
None
,
cookie
=
None
):
"""
Make a simple request to url using httplib.
"""
conn
=
httplib
.
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
conn
=
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
headers
=
{
"
Host
"
:
host
or
"
localhost
"
}
if
cookie
:
headers
[
"
Cookie
"
]
=
cookie
...
...
@@ -268,10 +267,10 @@ class HttpdIntegrationTestBase(unittest.TestCase):
if
not
sso_login_url
:
sso_login_url
=
'
/%s/sso_login
'
%
sso_service
.
split
(
'
/
'
,
1
)[
1
]
cookies
=
Cookie
.
SimpleCookie
()
cookies
=
SimpleCookie
()
# Make a request to a protected URL.
conn
=
httplib
.
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
conn
=
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
conn
.
request
(
"
GET
"
,
url
,
headers
=
{
'
Host
'
:
host_header
})
resp
=
conn
.
getresponse
()
self
.
assertEquals
(
302
,
resp
.
status
)
...
...
@@ -279,16 +278,16 @@ class HttpdIntegrationTestBase(unittest.TestCase):
self
.
assertTrue
(
set_cookie_hdr
)
cookies
.
load
(
set_cookie_hdr
)
location
=
resp
.
getheader
(
"
Location
"
)
location_u
=
urlparse
.
urlsplit
(
location
)
location_args
=
dict
(
urlparse
.
parse_qsl
(
location_u
.
query
))
location_u
=
urlsplit
(
location
)
location_args
=
dict
(
parse_qsl
(
location_u
.
query
))
nonce
=
location_args
.
get
(
'
n
'
)
self
.
assertTrue
(
nonce
)
conn
.
close
()
# Now call the /sso_login endpoint.
conn
=
httplib
.
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
conn
=
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
tkt
=
self
.
_ticket
(
nonce
=
nonce
,
service
=
sso_service
)
conn
.
request
(
"
GET
"
,
sso_login_url
+
"
?
"
+
urllib
.
urlencode
(
conn
.
request
(
"
GET
"
,
sso_login_url
+
"
?
"
+
urlencode
(
{
"
t
"
:
tkt
,
"
d
"
:
"
https://
"
+
host_header
+
url
}),
headers
=
{
"
Cookie
"
:
cookies
.
output
(
attrs
=
[],
header
=
''
,
sep
=
'
;
'
),
"
Host
"
:
host_header
,
...
...
@@ -302,7 +301,7 @@ class HttpdIntegrationTestBase(unittest.TestCase):
conn
.
close
()
# Make the original request again.
conn
=
httplib
.
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
conn
=
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
conn
.
request
(
"
GET
"
,
url
,
headers
=
{
"
Cookie
"
:
cookies
.
output
(
attrs
=
[],
header
=
''
,
sep
=
'
;
'
),
'
Host
'
:
host_header
,
...
...
@@ -345,10 +344,10 @@ class HttpdIntegrationTest(HttpdIntegrationTestBase):
def
test_sso_login
(
self
):
# Call the /sso_login endpoint, verify that it sets the local
# SSO cookie to whatever the 't' parameter says.
cookies
=
Cookie
.
SimpleCookie
()
conn
=
httplib
.
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
cookies
=
SimpleCookie
()
conn
=
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
tkt
=
self
.
_ticket
()
conn
.
request
(
"
GET
"
,
"
/sso_login?%s
"
%
urllib
.
urlencode
(
conn
.
request
(
"
GET
"
,
"
/sso_login?%s
"
%
urlencode
(
{
"
t
"
:
tkt
,
"
d
"
:
"
https://service.example.com/index.html
"
}))
resp
=
conn
.
getresponse
()
self
.
assertEquals
(
302
,
resp
.
status
)
...
...
@@ -360,7 +359,7 @@ class HttpdIntegrationTest(HttpdIntegrationTestBase):
def
test_sso_logout
(
self
):
# test the /sso_logout endpoint
conn
=
httplib
.
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
conn
=
HTTPConnection
(
"
127.0.0.1
"
,
APACHE_PORT
)
conn
.
request
(
"
GET
"
,
"
/sso_logout
"
,
headers
=
{
"
Cookie
"
:
mkcookie
(
self
.
_ticket
())})
resp
=
conn
.
getresponse
()
...
...
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