예제 #1
0
    def test_authenticate_client_header(self):
        # Authenticate using header
        obs = self.post('/qiita_db/authenticate/', {'grant_type': 'client'}, {
            'Authorization':
            'Basic MTluZGtPM29NS3NvQ2hqVlZXbHVGN1FreEhSZl'
            'loVEtTRmJBVnQ4SWhLN2daZ0RhTzQ6SjdGZlE3Q1FkT3'
            'h1S2hRQWYxZW9HZ0JBRTgxTnM4R3UzRUthV0ZtM0lPMk'
            'pLaEFtbUNXWnVhYmUwTzVNcDI4czE='
        })
        self.assertEqual(obs.code, 200)
        obs_body = loads(obs.body)
        exp = {
            'access_token': 'token',
            'token_type': 'Bearer',
            'expires_in': 3600
        }
        self.assertItemsEqual(obs_body.keys(), exp.keys())
        self.assertEqual(obs_body['token_type'], exp['token_type'])
        self.assertEqual(obs_body['expires_in'], exp['expires_in'])
        self.assertEqual(len(obs_body['access_token']), 55)
        self.assertEqual(type(obs_body['access_token']), unicode)

        # Make sure token in system with proper ttl
        token = r_client.hgetall(obs_body['access_token'])
        self.assertNotEqual(token, {})
        self.assertItemsEqual(token.keys(),
                              ['timestamp', 'client_id', 'grant_type'])
        self.assertEqual(r_client.ttl(obs_body['access_token']), 3600)
예제 #2
0
    def test_authenticate_password(self):
        obs = self.post(
            '/qiita_db/authenticate/', {
                'grant_type': 'password',
                'client_id': 'DWelYzEYJYcZ4wlqUp0bHGXojrvZVz0CNBJvOqUKcrPQ5p4U'
                'qE',
                'username': '******',
                'password': '******'
            })
        self.assertEqual(obs.code, 200)
        obs_body = loads(obs.body)
        exp = {
            'access_token': 'placeholder',
            'token_type': 'Bearer',
            'expires_in': 3600
        }
        self.assertItemsEqual(obs_body.keys(), exp.keys())
        self.assertEqual(obs_body['token_type'], exp['token_type'])
        self.assertEqual(obs_body['expires_in'], exp['expires_in'])
        self.assertEqual(len(obs_body['access_token']), 55)
        self.assertEqual(type(obs_body['access_token']), unicode)

        # Make sure token in system with proper ttl
        token = r_client.hgetall(obs_body['access_token'])
        self.assertNotEqual(token, {})
        self.assertItemsEqual(token.keys(),
                              ['timestamp', 'user', 'client_id', 'grant_type'])
        self.assertEqual(token['user'], '*****@*****.**')
        self.assertEqual(token['grant_type'], 'password')
        self.assertEqual(r_client.ttl(obs_body['access_token']), 3600)
예제 #3
0
    def test_authenticate_client_post(self):
        # Authenticate using post only
        obs = self.post(
            '/qiita_db/authenticate/', {
                'grant_type':
                'client',
                'client_id':
                '19ndkO3oMKsoChjVVWluF7QkxHRfYhTKSFbAVt8IhK7gZgDa'
                'O4',
                'client_secret':
                'J7FfQ7CQdOxuKhQAf1eoGgBAE81Ns8Gu3EKaWFm3IO2J'
                'KhAmmCWZuabe0O5Mp28s1'
            })
        self.assertEqual(obs.code, 200)
        obs_body = loads(obs.body)
        exp = {
            'access_token': 'placeholder',
            'token_type': 'Bearer',
            'expires_in': 3600
        }
        self.assertItemsEqual(obs_body.keys(), exp.keys())
        self.assertEqual(obs_body['token_type'], exp['token_type'])
        self.assertEqual(obs_body['expires_in'], exp['expires_in'])
        self.assertEqual(len(obs_body['access_token']), 55)
        self.assertEqual(type(obs_body['access_token']), unicode)

        # Make sure token in system with proper ttl
        token = r_client.hgetall(obs_body['access_token'])
        self.assertNotEqual(token, {})
        self.assertItemsEqual(token.keys(),
                              ['timestamp', 'client_id', 'grant_type'])
        self.assertEqual(token['grant_type'], 'client')
        self.assertEqual(r_client.ttl(obs_body['access_token']), 3600)
예제 #4
0
    def test_authenticate_client_header(self):
        # Authenticate using header
        obs = self.post(
            '/qiita_db/authenticate/', {'grant_type': 'client'}, {
                'Authorization': 'Basic MTluZGtPM29NS3NvQ2hqVlZXbHVGN1FreEhSZl'
                                 'loVEtTRmJBVnQ4SWhLN2daZ0RhTzQ6SjdGZlE3Q1FkT3'
                                 'h1S2hRQWYxZW9HZ0JBRTgxTnM4R3UzRUthV0ZtM0lPMk'
                                 'pLaEFtbUNXWnVhYmUwTzVNcDI4czE='})
        self.assertEqual(obs.code, 200)
        obs_body = loads(obs.body)
        exp = {'access_token': 'token',
               'token_type': 'Bearer',
               'expires_in': 3600}
        self.assertItemsEqual(obs_body.keys(), exp.keys())
        self.assertEqual(obs_body['token_type'], exp['token_type'])
        self.assertEqual(obs_body['expires_in'], exp['expires_in'])
        self.assertEqual(len(obs_body['access_token']), 55)
        self.assertEqual(type(obs_body['access_token']), unicode)

        # Make sure token in system with proper ttl
        token = r_client.hgetall(obs_body['access_token'])
        self.assertNotEqual(token, {})
        self.assertItemsEqual(token.keys(), ['timestamp', 'client_id',
                                             'grant_type'])
        self.assertEqual(r_client.ttl(obs_body['access_token']), 3600)
예제 #5
0
    def test_authenticate_password(self):
        obs = self.post(
            '/qiita_db/authenticate/', {
                'grant_type': 'password',
                'client_id': 'DWelYzEYJYcZ4wlqUp0bHGXojrvZVz0CNBJvOqUKcrPQ5p4U'
                             'qE',
                'username': '******',
                'password': '******'})
        self.assertEqual(obs.code, 200)
        obs_body = loads(obs.body)
        exp = {'access_token': 'placeholder',
               'token_type': 'Bearer',
               'expires_in': 3600}
        self.assertItemsEqual(obs_body.keys(), exp.keys())
        self.assertEqual(obs_body['token_type'], exp['token_type'])
        self.assertEqual(obs_body['expires_in'], exp['expires_in'])
        self.assertEqual(len(obs_body['access_token']), 55)
        self.assertEqual(type(obs_body['access_token']), unicode)

        # Make sure token in system with proper ttl
        token = r_client.hgetall(obs_body['access_token'])
        self.assertNotEqual(token, {})
        self.assertItemsEqual(token.keys(), ['timestamp', 'user', 'client_id',
                                             'grant_type'])
        self.assertEqual(token['user'], '*****@*****.**')
        self.assertEqual(token['grant_type'], 'password')
        self.assertEqual(r_client.ttl(obs_body['access_token']), 3600)
예제 #6
0
    def test_authenticate_client_post(self):
        # Authenticate using post only
        obs = self.post(
            '/qiita_db/authenticate/', {
                'grant_type': 'client',
                'client_id': '19ndkO3oMKsoChjVVWluF7QkxHRfYhTKSFbAVt8IhK7gZgDa'
                             'O4',
                'client_secret': 'J7FfQ7CQdOxuKhQAf1eoGgBAE81Ns8Gu3EKaWFm3IO2J'
                                 'KhAmmCWZuabe0O5Mp28s1'})
        self.assertEqual(obs.code, 200)
        obs_body = loads(obs.body)
        exp = {'access_token': 'placeholder',
               'token_type': 'Bearer',
               'expires_in': 3600}
        self.assertItemsEqual(obs_body.keys(), exp.keys())
        self.assertEqual(obs_body['token_type'], exp['token_type'])
        self.assertEqual(obs_body['expires_in'], exp['expires_in'])
        self.assertEqual(len(obs_body['access_token']), 55)
        self.assertEqual(type(obs_body['access_token']), unicode)

        # Make sure token in system with proper ttl
        token = r_client.hgetall(obs_body['access_token'])
        self.assertNotEqual(token, {})
        self.assertItemsEqual(token.keys(), ['timestamp', 'client_id',
                                             'grant_type'])
        self.assertEqual(token['grant_type'], 'client')
        self.assertEqual(r_client.ttl(obs_body['access_token']), 3600)