Exemplo n.º 1
0
    def test_get_user(self):
        """get_user() makes a GET request to /Users/<id>"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        uaac.get_user('foo')
        m.assert_called_with(urljoin('/Users', 'foo'), 'GET')
Exemplo n.º 2
0
    def test_get_user(self):
        """get_user() makes a GET request to /Users/<id>"""

        uaac = UAAClient("http://example.com", "foo", False)
        m = Mock()
        uaac._request = m

        uaac.get_user("foo")
        m.assert_called_with(urljoin("/Users", "foo"), "GET")
Exemplo n.º 3
0
    def test_get_user(self):
        """get_user() makes a GET request to /Users/<id>"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        uaac.get_user('foo')
        m.assert_called_with(urljoin('/Users', 'foo'), 'GET')
Exemplo n.º 4
0
    def test_change_password(self):
        """change_password() makes a PUT request to /Users/<id>/password"""

        uaac = UAAClient("http://example.com", "foo", False)
        m = Mock()
        uaac._request = m

        uaac.change_password("foo", "bar", "baz")

        m.assert_called_with(
            "/Users/foo/password", "PUT", body={"oldPassword": "******", "password": "******"}
        )
Exemplo n.º 5
0
    def test_request_bad(self, requests):
        """UAAError is reaised when it occurs"""

        r = Mock()
        r.status_code = 500
        r.text = json.dumps({"error_description": "oh no"})
        requests.get.return_value = r

        uaac = UAAClient("http://example.com", "foo", True)

        with self.assertRaises(UAAError):
            uaac._request("/bar", "GET")

        requests.get.assert_called_with(
            "http://example.com/bar",
            headers={"Authorization": "Bearer foo"},
            json=None,
            params=None,
            auth=None,
            verify=True,
        )
Exemplo n.º 6
0
    def test_idps(self):
        """idps() makes a GET request to /identity-providers"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        uaac.idps(active_only=True)
        m.assert_called_with('/identity-providers', 'GET', params={'active_only': 'true'})

        uaac.idps(active_only=False)
        m.assert_called_with('/identity-providers', 'GET', params={'active_only': 'false'})
Exemplo n.º 7
0
    def test_idps(self):
        """idps() makes a GET request to /identity-providers"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        uaac.idps(active_only=True)
        m.assert_called_with('/identity-providers', 'GET', params={'active_only': 'true'})

        uaac.idps(active_only=False)
        m.assert_called_with('/identity-providers', 'GET', params={'active_only': 'false'})
Exemplo n.º 8
0
    def test_request_bad(self, requests):
        """UAAError is reaised when it occurs"""

        r = Mock()
        r.status_code = 500
        r.text = json.dumps({'error_description': 'oh no'})
        requests.get.return_value = r

        uaac = UAAClient('http://example.com', 'foo', True)

        with self.assertRaises(UAAError):
            uaac._request('/bar', 'GET')

        requests.get.assert_called_with(
            'http://example.com/bar',
            headers={'Authorization': 'Bearer foo'},
            json=None,
            params=None,
            auth=None,
            verify=True
        )
Exemplo n.º 9
0
    def test_request_bad(self, requests):
        """UAAError is reaised when it occurs"""

        r = Mock()
        r.status_code = 500
        r.text = json.dumps({'error_description': 'oh no'})
        requests.get.return_value = r

        uaac = UAAClient('http://example.com', 'foo', True)

        with self.assertRaises(UAAError):
            uaac._request('/bar', 'GET')

        requests.get.assert_called_with(
            'http://example.com/bar',
            headers={'Authorization': 'Bearer foo'},
            json=None,
            params=None,
            auth=None,
            verify=True
        )
Exemplo n.º 10
0
    def test_put_user(self):
        """put_user() makes a PUT request to /Users/<id> with appropriate headers"""

        uaac = UAAClient("http://example.com", "foo", False)
        m = Mock()
        uaac._request = m

        user = {"id": "foo", "meta": {"version": "123"}}

        uaac.put_user(user)

        m.assert_called_with(
            urljoin("/Users", "foo"), "PUT", body=user, headers={"If-Match": "123"}
        )
Exemplo n.º 11
0
    def test_idps(self):
        """idps() makes a GET request to /identity-providers"""

        uaac = UAAClient("http://example.com", "foo", False)
        m = Mock()
        uaac._request = m

        uaac.idps(active_only=True)
        m.assert_called_with(
            "/identity-providers", "GET", params={"active_only": "true"}
        )

        uaac.idps(active_only=False)
        m.assert_called_with(
            "/identity-providers", "GET", params={"active_only": "false"}
        )
Exemplo n.º 12
0
    def test_change_password(self):
        """change_password() makes a PUT request to /Users/<id>/password"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        uaac.change_password('foo', 'bar', 'baz')

        m.assert_called_with(
            '/Users/foo/password',
            'PUT',
            body={
                'oldPassword': '******',
                'password': '******'
            }
        )
Exemplo n.º 13
0
    def test_change_password(self):
        """change_password() makes a PUT request to /Users/<id>/password"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        uaac.change_password('foo', 'bar', 'baz')

        m.assert_called_with(
            '/Users/foo/password',
            'PUT',
            body={
                'oldPassword': '******',
                'password': '******'
            }
        )
Exemplo n.º 14
0
    def test_invite_users(self):
        """invite_users() makes a PUT request to /invite_users<id>"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        email = '*****@*****.**'
        redirect_uri = 'http://www.example.com'

        uaac.invite_users(email, redirect_uri)

        m.assert_called_with(
            '/invite_users',
            'POST',
            body={'emails': [email]},
            params={'redirect_uri': redirect_uri}
        )
Exemplo n.º 15
0
    def test_users_with_token(self):
        """invite_users() makes a PUT request to /invite_users<id>"""

        uaac = UAAClient("http://example.com", "foo", False)
        m = Mock()
        uaac._request = m

        email = "*****@*****.**"
        redirect_uri = "http://www.example.com"

        uaac.invite_users(email, redirect_uri, token="foobar")

        m.assert_called_with(
            "/invite_users",
            "POST",
            body={"emails": [email]},
            headers={"Authorization": "Bearer foobar"},
            params={"redirect_uri": redirect_uri},
        )
Exemplo n.º 16
0
    def test_users_with_token(self):
        """invite_users() makes a PUT request to /invite_users<id>"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        email = '*****@*****.**'
        redirect_uri = 'http://www.example.com'

        uaac.invite_users(email, redirect_uri, token="foobar")

        m.assert_called_with(
            '/invite_users',
            'POST',
            body={'emails': [email]},
            headers={'Authorization': 'Bearer foobar'},
            params={'redirect_uri': redirect_uri}
        )
Exemplo n.º 17
0
    def test_get_client_token(self):
        """_get_client_token() makes a POST to /oauth/token with the appropriate headers and query params"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        uaac._get_client_token('bar', 'baz')

        args, kwargs = m.call_args

        assert args == ('/oauth/token', 'POST')

        assert kwargs['params'] == {
            'grant_type': 'client_credentials',
            'response_type': 'token'
        }

        assert isinstance(kwargs['auth'], HTTPBasicAuth)
        assert kwargs['auth'].username == 'bar'
        assert kwargs['auth'].password == 'baz'
Exemplo n.º 18
0
    def test_get_client_token(self):
        """_get_client_token() makes a POST to /oauth/token with the appropriate headers and query params"""

        uaac = UAAClient("http://example.com", "foo", False)
        m = Mock()
        uaac._request = m

        uaac._get_client_token("bar", "baz")

        args, kwargs = m.call_args

        assert args == ("/oauth/token", "POST")

        assert kwargs["params"] == {
            "grant_type": "client_credentials",
            "response_type": "token",
        }

        assert isinstance(kwargs["auth"], HTTPBasicAuth)
        assert kwargs["auth"].username == "bar"
        assert kwargs["auth"].password == "baz"
Exemplo n.º 19
0
    def test_get_client_token(self):
        """_get_client_token() makes a POST to /oauth/token with the appropriate headers and query params"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        uaac._get_client_token('bar', 'baz')

        args, kwargs = m.call_args

        assert args == ('/oauth/token', 'POST')

        assert kwargs['params'] == {
            'grant_type': 'client_credentials',
            'response_type': 'token'
        }

        assert isinstance(kwargs['auth'], HTTPBasicAuth)
        assert kwargs['auth'].username == 'bar'
        assert kwargs['auth'].password == 'baz'
Exemplo n.º 20
0
    def test_put_user(self):
        """put_user() makes a PUT request to /Users/<id> with appropriate headers"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        user = {
            'id': 'foo',
            'meta': {
                'version': '123'
            }
        }

        uaac.put_user(user)

        m.assert_called_with(
            urljoin('/Users', 'foo'),
            'PUT',
            body=user,
            headers={'If-Match': '123'}
        )
Exemplo n.º 21
0
    def test_request_post_body(self, requests):
        """Body is included in request if provided"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({'test': 'value'})
        requests.post.return_value = r

        uaac = UAAClient('http://example.com', 'foo', False)

        resp = uaac._request('/bar', 'POST', body='hi')

        requests.post.assert_called_with(
            'http://example.com/bar',
            headers={'Authorization': 'Bearer foo'},
            json='hi',
            params=None,
            auth=None,
            verify=False
        )

        assert resp['test'] == 'value'
Exemplo n.º 22
0
    def test_request_post_body(self, requests):
        """Body is included in request if provided"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({"test": "value"})
        requests.post.return_value = r

        uaac = UAAClient("http://example.com", "foo", False)

        resp = uaac._request("/bar", "POST", body="hi")

        requests.post.assert_called_with(
            "http://example.com/bar",
            headers={"Authorization": "Bearer foo"},
            json="hi",
            params=None,
            auth=None,
            verify=False,
        )

        assert resp["test"] == "value"
Exemplo n.º 23
0
    def test_request_get_insecure(self, requests):
        """Insecure GET request is made"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({'test': 'value'})
        requests.get.return_value = r

        uaac = UAAClient('http://example.com', 'foo', False)

        resp = uaac._request('/bar', 'GET')

        requests.get.assert_called_with(
            'http://example.com/bar',
            headers={'Authorization': 'Bearer foo'},
            json=None,
            params=None,
            auth=None,
            verify=False
        )

        assert resp['test'] == 'value'
Exemplo n.º 24
0
    def test_request_get_auth(self, requests):
        """Auth value is passed directly to requests"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({'test': 'value'})
        requests.get.return_value = r

        uaac = UAAClient('http://example.com', 'foo', False)

        resp = uaac._request('/bar', 'GET', auth='this should be basic')

        requests.get.assert_called_with(
            'http://example.com/bar',
            headers={},
            json=None,
            params=None,
            auth='this should be basic',
            verify=False
        )

        assert resp['test'] == 'value'
Exemplo n.º 25
0
    def test_put_user(self):
        """put_user() makes a PUT request to /Users/<id> with appropriate headers"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        user = {
            'id': 'foo',
            'meta': {
                'version': '123'
            }
        }

        uaac.put_user(user)

        m.assert_called_with(
            urljoin('/Users', 'foo'),
            'PUT',
            body=user,
            headers={'If-Match': '123'}
        )
Exemplo n.º 26
0
    def test_request_get_insecure(self, requests):
        """Insecure GET request is made"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({"test": "value"})
        requests.get.return_value = r

        uaac = UAAClient("http://example.com", "foo", False)

        resp = uaac._request("/bar", "GET")

        requests.get.assert_called_with(
            "http://example.com/bar",
            headers={"Authorization": "Bearer foo"},
            json=None,
            params=None,
            auth=None,
            verify=False,
        )

        assert resp["test"] == "value"
Exemplo n.º 27
0
    def test_request_get_params(self, requests):
        """Query string is sent if params are provided"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({"test": "value"})
        requests.get.return_value = r

        uaac = UAAClient("http://example.com", "foo", False)

        resp = uaac._request("/bar", "GET", params={"omg": "lol"})

        requests.get.assert_called_with(
            "http://example.com/bar",
            headers={"Authorization": "Bearer foo"},
            json=None,
            params={"omg": "lol"},
            auth=None,
            verify=False,
        )

        assert resp["test"] == "value"
Exemplo n.º 28
0
    def test_request_get_auth(self, requests):
        """Auth value is passed directly to requests"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({"test": "value"})
        requests.get.return_value = r

        uaac = UAAClient("http://example.com", "foo", False)

        resp = uaac._request("/bar", "GET", auth="this should be basic")

        requests.get.assert_called_with(
            "http://example.com/bar",
            headers={},
            json=None,
            params=None,
            auth="this should be basic",
            verify=False,
        )

        assert resp["test"] == "value"
Exemplo n.º 29
0
    def test_request_get_auth(self, requests):
        """Auth value is passed directly to requests"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({'test': 'value'})
        requests.get.return_value = r

        uaac = UAAClient('http://example.com', 'foo', False)

        resp = uaac._request('/bar', 'GET', auth='this should be basic')

        requests.get.assert_called_with(
            'http://example.com/bar',
            headers={},
            json=None,
            params=None,
            auth='this should be basic',
            verify=False
        )

        assert resp['test'] == 'value'
Exemplo n.º 30
0
    def test_request_post_body(self, requests):
        """Body is included in request if provided"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({'test': 'value'})
        requests.post.return_value = r

        uaac = UAAClient('http://example.com', 'foo', False)

        resp = uaac._request('/bar', 'POST', body='hi')

        requests.post.assert_called_with(
            'http://example.com/bar',
            headers={'Authorization': 'Bearer foo'},
            json='hi',
            params=None,
            auth=None,
            verify=False
        )

        assert resp['test'] == 'value'
Exemplo n.º 31
0
    def test_request_get_insecure(self, requests):
        """Insecure GET request is made"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({'test': 'value'})
        requests.get.return_value = r

        uaac = UAAClient('http://example.com', 'foo', False)

        resp = uaac._request('/bar', 'GET')

        requests.get.assert_called_with(
            'http://example.com/bar',
            headers={'Authorization': 'Bearer foo'},
            json=None,
            params=None,
            auth=None,
            verify=False
        )

        assert resp['test'] == 'value'
Exemplo n.º 32
0
    def test_request_get_params(self, requests):
        """Query string is sent if params are provided"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({'test': 'value'})
        requests.get.return_value = r

        uaac = UAAClient('http://example.com', 'foo', False)

        resp = uaac._request('/bar', 'GET', params={'omg': 'lol'})

        requests.get.assert_called_with(
            'http://example.com/bar',
            headers={'Authorization': 'Bearer foo'},
            json=None,
            params={'omg': 'lol'},
            auth=None,
            verify=False
        )

        assert resp['test'] == 'value'
Exemplo n.º 33
0
    def test_request_get_params(self, requests):
        """Query string is sent if params are provided"""

        r = Mock()
        r.status_code = 200
        r.text = json.dumps({'test': 'value'})
        requests.get.return_value = r

        uaac = UAAClient('http://example.com', 'foo', False)

        resp = uaac._request('/bar', 'GET', params={'omg': 'lol'})

        requests.get.assert_called_with(
            'http://example.com/bar',
            headers={'Authorization': 'Bearer foo'},
            json=None,
            params={'omg': 'lol'},
            auth=None,
            verify=False
        )

        assert resp['test'] == 'value'
Exemplo n.º 34
0
    def test_users(self):
        """users() makes a GET request to /Users"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        uaac.users()
        m.assert_called_with('/Users', 'GET', params={'startIndex': 1}, headers={})

        uaac.users(start=2)
        m.assert_called_with('/Users', 'GET', params={'startIndex': 2}, headers={})

        uaac.users(list_filter='test filter')
        m.assert_called_with('/Users', 'GET',
                             params={'filter': 'test filter', 'startIndex': 1}, headers={})

        uaac.users(token='FOO')
        m.assert_called_with('/Users', 'GET', params={'startIndex': 1},
                             headers={'Authorization': 'Bearer FOO'})

        uaac.users('test filter', 'FOO', 9)
        m.assert_called_with('/Users', 'GET', params={'filter': 'test filter', 'startIndex': 9},
                             headers={'Authorization': 'Bearer FOO'})
Exemplo n.º 35
0
    def test_users(self):
        """users() makes a GET request to /Users"""

        uaac = UAAClient('http://example.com', 'foo', False)
        m = Mock()
        uaac._request = m

        uaac.users()
        m.assert_called_with('/Users', 'GET', params={'startIndex': 1}, headers={})

        uaac.users(start=2)
        m.assert_called_with('/Users', 'GET', params={'startIndex': 2}, headers={})

        uaac.users(list_filter='test filter')
        m.assert_called_with('/Users', 'GET',
                             params={'filter': 'test filter', 'startIndex': 1}, headers={})

        uaac.users(token='FOO')
        m.assert_called_with('/Users', 'GET', params={'startIndex': 1},
                             headers={'Authorization': 'Bearer FOO'})

        uaac.users('test filter', 'FOO', 9)
        m.assert_called_with('/Users', 'GET', params={'filter': 'test filter', 'startIndex': 9},
                             headers={'Authorization': 'Bearer FOO'})
Exemplo n.º 36
0
    def test_users(self):
        """users() makes a GET request to /Users"""

        uaac = UAAClient("http://example.com", "foo", False)
        m = Mock()
        uaac._request = m

        uaac.users()
        m.assert_called_with("/Users", "GET", params={"startIndex": 1}, headers={})

        uaac.users(start=2)
        m.assert_called_with("/Users", "GET", params={"startIndex": 2}, headers={})

        uaac.users(list_filter="test filter")
        m.assert_called_with(
            "/Users",
            "GET",
            params={"filter": "test filter", "startIndex": 1},
            headers={},
        )

        uaac.users(token="FOO")
        m.assert_called_with(
            "/Users",
            "GET",
            params={"startIndex": 1},
            headers={"Authorization": "Bearer FOO"},
        )

        uaac.users("test filter", "FOO", 9)
        m.assert_called_with(
            "/Users",
            "GET",
            params={"filter": "test filter", "startIndex": 9},
            headers={"Authorization": "Bearer FOO"},
        )