1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
from BaseHTTPServer import BaseHTTPRequestHandler
try:
import unittest2 as unittest
except ImportError:
import unittest
import requests
from mock import Mock
from leap.base import auth
from leap.base import exceptions
from leap.eip.tests.test_checks import NoLogRequestHandler
from leap.testing.basetest import BaseLeapTest
from leap.testing.https_server import BaseHTTPSServerTestCase
class LeapSRPRegisterTests(BaseHTTPSServerTestCase, BaseLeapTest):
__name__ = "leap_srp_register_test"
provider = "testprovider.example.org"
class request_handler(NoLogRequestHandler, BaseHTTPRequestHandler):
responses = {
'/': ['OK', ''],
}
def do_GET(self):
path = urlparse.urlparse(self.path)
message = '\n'.join(self.responses.get(
path.path, None))
self.send_response(200)
self.end_headers()
self.wfile.write(message)
def setUp(self):
pass
def tearDown(self):
pass
def test_srp_auth_should_implement_check_methods(self):
SERVER = "https://localhost:8443"
srp_auth = auth.LeapSRPRegister(provider=SERVER, verify=False)
self.assertTrue(hasattr(srp_auth, "init_session"),
"missing meth")
self.assertTrue(hasattr(srp_auth, "get_registration_uri"),
"missing meth")
self.assertTrue(hasattr(srp_auth, "register_user"),
"missing meth")
def test_srp_auth_basic_functionality(self):
SERVER = "https://localhost:8443"
srp_auth = auth.LeapSRPRegister(provider=SERVER, verify=False)
self.assertIsInstance(srp_auth.session, requests.sessions.Session)
self.assertEqual(srp_auth.get_registration_uri(),
"https://localhost:8443/1/users.json")
|