Exemplo n.º 1
0
        def profile_for_user(username, staff=[], superuser=[]):
            from hbp_app_python_auth.auth import HbpAuth
            import hbp_app_python_auth.settings as s

            def details_side_effect(key):
                if key == 'username':
                    return username
                elif key == 'familyName':
                    return 'Bob'
                elif key == 'givenName':
                    return 'Brain'
                elif key == 'emails':
                    return [{
                        'immutable': True,
                        'primary': True,
                        'value': '*****@*****.**' % username
                    }]

            s.SUPER_USER_NAMES = superuser
            s.STAFF_USER_NAMES = staff
            auth = HbpAuth()
            httpResponseMock = MagicMock()
            httpResponseMock.get.side_effect = details_side_effect
            details = auth.get_user_details(httpResponseMock)
            return details
Exemplo n.º 2
0
    def test_hbp_auth(self):
        with patch('bbp_services.client.get_services') as m:
            m.return_value = {
                'oidc_service': {
                    'prod': {
                        'url': 'url',
                        'api_url': 'api_url'
                    }
                }
            }
            from hbp_app_python_auth.auth import HbpAuth

            auth = HbpAuth()

            httpResponseMock = MagicMock()
            httpResponseMock.get = MagicMock(
                return_value=[{
                    'immutable': True,
                    'primary': True,
                    'value': '*****@*****.**'
                }])

            details = auth.get_user_details(httpResponseMock)
            eq_(details['email'], '*****@*****.**')

            eq_(auth.revoke_token_params('token', 'uuid'), {'token': 'token'})

            eq_(auth.revoke_token_headers('token', 'uuid'),
                {'Content-type': 'application/json'})