Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
authserv
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ai
authserv
Commits
f0394e59
Commit
f0394e59
authored
8 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
update tests for python 2.7 ssl
parent
47268a9b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
authserv/test/test_integration.py
+11
-7
11 additions, 7 deletions
authserv/test/test_integration.py
with
11 additions
and
7 deletions
authserv/test/test_integration.py
+
11
−
7
View file @
f0394e59
...
...
@@ -3,6 +3,7 @@ from gevent import subprocess
import
httplib
import
os
import
socket
import
ssl
import
sys
import
time
import
urllib
...
...
@@ -22,8 +23,10 @@ def _relpath(x):
class
HTTPSClientAuthHandler
(
urllib2
.
HTTPSHandler
):
def
__init__
(
self
,
cert
,
key
):
urllib2
.
HTTPSHandler
.
__init__
(
self
)
def
__init__
(
self
,
cert
,
key
,
cafile
):
urllib2
.
HTTPSHandler
.
__init__
(
self
,
context
=
ssl
.
create_default_context
(
purpose
=
ssl
.
Purpose
.
SERVER_AUTH
,
cafile
=
cafile
))
self
.
key
=
key
self
.
cert
=
cert
...
...
@@ -34,7 +37,8 @@ class HTTPSClientAuthHandler(urllib2.HTTPSHandler):
return
self
.
do_open
(
self
.
getConnection
,
req
)
def
getConnection
(
self
,
host
,
timeout
=
300
):
return
httplib
.
HTTPSConnection
(
host
,
key_file
=
self
.
key
,
cert_file
=
self
.
cert
)
return
httplib
.
HTTPSConnection
(
host
,
key_file
=
self
.
key
,
cert_file
=
self
.
cert
,
context
=
self
.
_context
)
class
SSLServerTest
(
unittest
.
TestCase
):
...
...
@@ -67,14 +71,14 @@ class SSLServerTest(unittest.TestCase):
print
>>
sys
.
stderr
,
'
starting HTTP server on port
'
,
cls
.
port
server
.
run
(
app
,
'
127.0.0.1
'
,
cls
.
port
,
cls
.
ssl_ca
,
app
,
'
localhost
'
,
cls
.
port
,
cls
.
ssl_ca
,
cls
.
ssl_cert
,
cls
.
ssl_key
,
cls
.
dhparams
)
gevent
.
spawn
(
_runserver
)
gevent
.
sleep
(
1
)
cls
.
opener
=
urllib2
.
build_opener
(
HTTPSClientAuthHandler
(
cls
.
client_cert
,
cls
.
client_key
))
HTTPSClientAuthHandler
(
cls
.
client_cert
,
cls
.
client_key
,
cls
.
ssl_ca
))
@classmethod
def
teardown_class
(
cls
):
...
...
@@ -82,7 +86,7 @@ class SSLServerTest(unittest.TestCase):
os
.
kill
(
cls
.
pid
,
15
)
def
test_python_request_failure_without_cert
(
self
):
req
=
urllib2
.
Request
(
'
https://
127.0.0.1
:%d%s
'
%
(
self
.
port
,
URL
),
req
=
urllib2
.
Request
(
'
https://
localhost
:%d%s
'
%
(
self
.
port
,
URL
),
data
=
urllib
.
urlencode
(
{
'
username
'
:
'
user2
'
,
'
password
'
:
'
pass2
'
,
...
...
@@ -91,7 +95,7 @@ class SSLServerTest(unittest.TestCase):
self
.
assertRaises
(
urllib2
.
URLError
,
urllib2
.
urlopen
,
req
)
def
test_python_auth_simple_ok
(
self
):
req
=
urllib2
.
Request
(
'
https://
127.0.0.1
:%d%s
'
%
(
self
.
port
,
URL
),
req
=
urllib2
.
Request
(
'
https://
localhost
:%d%s
'
%
(
self
.
port
,
URL
),
data
=
urllib
.
urlencode
(
{
'
username
'
:
'
user2
'
,
'
password
'
:
'
pass2
'
,
...
...
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