def _can_authorize_with_leap_provider(self, username, password):
        config = LeapConfig(ca_cert_bundle=self._leap_provider_ca)
        provider = LeapProvider(self._leap_provider_hostname, config)
        srp = LeapSecureRemotePassword(ca_bundle=which_bundle(provider))

        try:
            srp.authenticate(provider.api_uri, username, password)
            return True
        except LeapAuthException:
            return False
    def test_login(self):
        with HTTMock(srp_login_server_simulator_mock):
            lsrp = LeapSecureRemotePassword()
            leap_session = lsrp.authenticate('https://api.leap.local', 'username', 'password')

            self.assertIsNotNone(leap_session)
            self.assertEqual('username', leap_session.user_name)
            self.assertEqual('1', leap_session.api_version)
            self.assertEqual('https://api.leap.local', leap_session.api_server_name)
            self.assertEqual('some token', leap_session.token)
            self.assertEqual('some_session_id', leap_session.session_id)
Example #3
0
    def test_register(self):
        @urlmatch(netloc=r'(.*\.)?leap\.local$', path='/1/users')
        def register_success(url, request):

            content = {'login': '******', 'ok': True}

            return {'status_code': 201, 'content': content}

        with HTTMock(register_success, not_found_mock):
            lsrp = LeapSecureRemotePassword()
            self.assertTrue(
                lsrp.register('https://api.leap.local', 'username',
                              'password'))
Example #4
0
    def test_login(self):
        with HTTMock(srp_login_server_simulator_mock):
            lsrp = LeapSecureRemotePassword()
            leap_session = lsrp.authenticate('https://api.leap.local',
                                             'username', 'password')

            self.assertIsNotNone(leap_session)
            self.assertEqual('username', leap_session.user_name)
            self.assertEqual('1', leap_session.api_version)
            self.assertEqual('https://api.leap.local',
                             leap_session.api_server_name)
            self.assertEqual('some token', leap_session.token)
            self.assertEqual('some_session_id', leap_session.session_id)
    def test_register(self):
        @urlmatch(netloc=r'(.*\.)?leap\.local$', path='/1/users')
        def register_success(url, request):

            content = {
                'login': '******',
                'ok': True
            }

            return {'status_code': 201,
                    'content': content}

        with HTTMock(register_success, not_found_mock):
            lsrp = LeapSecureRemotePassword()
            self.assertTrue(lsrp.register('https://api.leap.local', 'username', 'password'))
Example #6
0
    def test_register_user_exists(self):
        @urlmatch(netloc=r'(.*\.)?leap\.local$', path='/1/users')
        def register_error_user_exists(url, request):
            content = {
                "errors": {
                    "login": [
                        "has already been taken", "has already been taken",
                        "has already been taken"
                    ]
                }
            }

            return {'status_code': 422, 'content': content}

        with HTTMock(register_error_user_exists, not_found_mock):
            lsrp = LeapSecureRemotePassword()
            self.assertRaises(LeapAuthException, lsrp.register,
                              'https://api.leap.local', 'username', 'password')
Example #7
0
 def test_invalid_password(self):
     with HTTMock(srp_login_server_simulator_mock):
         lsrp = LeapSecureRemotePassword()
         self.assertRaises(LeapAuthException, lsrp.authenticate,
                           'https://api.leap.local', 'username', 'invalid')
Example #8
0
 def test_status_code_is_checked(self):
     with HTTMock(not_found_mock):
         lsrp = LeapSecureRemotePassword()
         self.assertRaises(LeapAuthException, lsrp.authenticate,
                           'https://api.leap.local', 'username', 'password')
Example #9
0
 def test_registration_timeout(self):
     with HTTMock(timeout_mock):
         lsrp = LeapSecureRemotePassword()
         self.assertRaises(LeapAuthException, lsrp.register,
                           'https://api.leap.local', 'username', 'password')
Example #10
0
 def test_register_raises_auth_exception_on_error(self):
     with HTTMock(not_found_mock):
         lsrp = LeapSecureRemotePassword()
         self.assertRaises(LeapAuthException, lsrp.register,
                           'https://api.leap.local', 'username', 'password')
Example #11
0
 def test_timeout(self):
     with HTTMock(timeout_mock):
         lrsp = LeapSecureRemotePassword()
         self.assertRaises(LeapAuthException, lrsp.authenticate,
                           'https://api.leap.local', 'username', 'password')