示例#1
0
    def test_fetch_user_info_when_no_response(self, mock_request):
        mock_request.return_value = None

        authenticator = GitlabOAuthAuthenticator(create_config())

        user_info = yield authenticator.fetch_user_info('my_token_2')
        self.assertEqual(None, user_info)
示例#2
0
    def test_fetch_user_info_when_not_active(self, mock_request):
        response = {'email': '*****@*****.**', 'state': 'something'}
        mock_request.return_value = response

        authenticator = GitlabOAuthAuthenticator(create_config())

        user_info = yield authenticator.fetch_user_info('my_token_2')
        self.assertEqual(_OauthUserInfo('*****@*****.**', False, response),
                         user_info)
示例#3
0
    def test_fetch_user_info(self, mock_request):
        response = {'email': '*****@*****.**', 'state': 'active'}
        mock_request.return_value = response

        authenticator = GitlabOAuthAuthenticator(
            create_config(url='https://my.gitlab.host'))

        user_info = yield authenticator.fetch_user_info('my_token_2')
        self.assertEqual(_OauthUserInfo('*****@*****.**', True, response),
                         user_info)

        mock_request.assert_called_with('https://my.gitlab.host/api/v4/user',
                                        'my_token_2')
示例#4
0
    def test_fetch_user_groups_when_search(self, mock_request):
        mock_request.return_value = []

        authenticator = GitlabOAuthAuthenticator(
            create_config(url='https://my.gitlab.host', group_search='abc'))

        yield authenticator.fetch_user_groups('my_token_2')

        mock_request.assert_called_with('https://my.gitlab.host/api/v4/groups',
                                        access_token='my_token_2',
                                        all_available='false',
                                        per_page=100,
                                        search='abc')
示例#5
0
def create_authenticator(auth_object, temp_folder):
    auth_type = auth_object.get('type')

    if not auth_type:
        raise Exception('Auth type should be specified')

    auth_type = auth_type.strip().lower()
    if auth_type == 'ldap':
        from auth.auth_ldap import LdapAuthenticator
        authenticator = LdapAuthenticator(auth_object, temp_folder)
    elif auth_type == 'google_oauth':
        from auth.auth_google_oauth import GoogleOauthAuthenticator
        authenticator = GoogleOauthAuthenticator(auth_object)
    elif auth_type == 'gitlab':
        from auth.auth_gitlab import GitlabOAuthAuthenticator
        authenticator = GitlabOAuthAuthenticator(auth_object)
    elif auth_type == 'htpasswd':
        from auth.auth_htpasswd import HtpasswdAuthenticator
        authenticator = HtpasswdAuthenticator(auth_object)
    else:
        raise Exception(auth_type + ' auth is not supported')

    authenticator.auth_expiration_days = float(
        auth_object.get('expiration_days', 30))

    authenticator.auth_type = auth_type

    return authenticator
示例#6
0
    def test_client_visible_config(self):
        authenticator = GitlabOAuthAuthenticator(
            create_config(url='https://my.gitlab.host'))

        client_visible_config = authenticator._client_visible_config
        self.assertEqual('1234', client_visible_config['client_id'])
        self.assertEqual('https://my.gitlab.host/oauth/authorize',
                         client_visible_config['oauth_url'])
        self.assertEqual('api', client_visible_config['oauth_scope'])
示例#7
0
    def test_fetch_user_groups(self, mock_request):
        response = [{
            'full_path': 'group1'
        }, {
            'full_path': 'group2'
        }, {
            'something': 'group3'
        }]
        mock_request.return_value = response

        authenticator = GitlabOAuthAuthenticator(
            create_config(url='https://my.gitlab.host'))

        groups = yield authenticator.fetch_user_groups('my_token_2')
        self.assertEqual(['group1', 'group2'], groups)

        mock_request.assert_called_with('https://my.gitlab.host/api/v4/groups',
                                        access_token='my_token_2',
                                        all_available='false',
                                        per_page=100)
示例#8
0
    def test_client_visible_config_when_default_url(self):
        authenticator = GitlabOAuthAuthenticator(create_config())

        client_visible_config = authenticator._client_visible_config
        self.assertEqual('https://gitlab.com/oauth/authorize',
                         client_visible_config['oauth_url'])
示例#9
0
    def test_client_visible_config_when_groups_disabled(self):
        authenticator = GitlabOAuthAuthenticator(
            create_config(group_support=False))

        client_visible_config = authenticator._client_visible_config
        self.assertEqual('read_user', client_visible_config['oauth_scope'])