コード例 #1
0
ファイル: auth.py プロジェクト: nicky1108/api-gateway
 def test_auth(self):
     client = APIClient(self.access_key, self.secret_key, self.api_server)
     req = APIRequest(client, self.endpoint, self.version)
     r = req.get('/resource')
     self.assertEqual(r.status_code, 200)
     r = req.get('/resource/not_exist')
     self.assertEqual(r.status_code, 404)
コード例 #2
0
ファイル: auth.py プロジェクト: flycn1985/api-gateway
 def test_auth(self):
     client = APIClient(self.access_key, self.secret_key, self.api_server)
     req = APIRequest(client, self.endpoint, self.version)
     r = req.get('/resource')
     self.assertEqual(r.status_code, 200)
     r = req.get('/resource/not_exist')
     self.assertEqual(r.status_code, 404)
コード例 #3
0
ファイル: auth.py プロジェクト: nicky1108/api-gateway
    def test_acl(self):
        client = APIClient(self.access_key, self.secret_key, self.api_server)
        req = APIRequest(client, self.endpoint, self.version)
        r = req.get('/resource')
        self.assertEqual(r.status_code, 200)

        client = APIClient(self.access_key, self.secret_key, self.api_server)
        req = APIRequest(client, self.endpoint, self.version)
        r = req.get('/forbidden/')
        self.assertEqual(r.status_code, GATEWAY_ERROR_STATUS_CODE)
コード例 #4
0
ファイル: auth.py プロジェクト: flycn1985/api-gateway
    def test_acl(self):
        client = APIClient(self.access_key, self.secret_key, self.api_server)
        req = APIRequest(client, self.endpoint, self.version)
        r = req.get('/resource')
        self.assertEqual(r.status_code, 200)

        client = APIClient(self.access_key, self.secret_key, self.api_server)
        req = APIRequest(client, self.endpoint, self.version)
        r = req.get('/forbidden/')
        self.assertEqual(r.status_code, GATEWAY_ERROR_STATUS_CODE)
コード例 #5
0
ファイル: auth.py プロジェクト: nicky1108/api-gateway
    def test_signature(self):
        client = APIClient(self.access_key, 'bad secret key', self.api_server)
        req = APIRequest(client, self.endpoint, self.version)
        r = req.get('/resource/')
        self.assertEqual(r.status_code, GATEWAY_ERROR_STATUS_CODE)

        client = APIClient(self.access_key, 'bad secret key', self.api_server)
        req = APIRequest(client, self.endpoint, self.version)

        r = req.get('/resource/')
        self.assertEqual(r.status_code, GATEWAY_ERROR_STATUS_CODE)
コード例 #6
0
ファイル: auth.py プロジェクト: flycn1985/api-gateway
    def test_signature(self):
        client = APIClient(self.access_key, 'bad secret key', self.api_server)
        req = APIRequest(client, self.endpoint, self.version)
        r = req.get('/resource/')
        self.assertEqual(r.status_code, GATEWAY_ERROR_STATUS_CODE)

        client = APIClient(self.access_key, 'bad secret key', self.api_server)
        req = APIRequest(client, self.endpoint, self.version)

        r = req.get('/resource/')
        self.assertEqual(r.status_code, GATEWAY_ERROR_STATUS_CODE)
コード例 #7
0
ファイル: auth.py プロジェクト: nicky1108/api-gateway
    def test_aes_get(self):
        client = APIClient(self.access_key, self.secret_key, self.api_server)
        req = APIRequest(client, self.endpoint, self.version, encrypt_type='aes')

        r = req.get('/resource/')

        self.assertEqual(r.status_code, 200)
        self.assertEqual(utf8('get'), utf8(r.content))
コード例 #8
0
ファイル: auth.py プロジェクト: flycn1985/api-gateway
    def test_aes_get(self):
        client = APIClient(self.access_key, self.secret_key, self.api_server)
        req = APIRequest(client, self.endpoint, self.version, encrypt_type='aes')

        r = req.get('/resource/')

        self.assertEqual(r.status_code, 200)
        self.assertEqual(utf8('get'), utf8(r.content))
コード例 #9
0
ファイル: auth.py プロジェクト: nicky1108/api-gateway
    def test_get(self):
        client = APIClient(self.access_key, self.secret_key, self.api_server)
        req = APIRequest(client, self.endpoint, self.version,
                         require_hmac=False, require_response_sign=False)

        r = req.get('/resource/')

        self.assertEqual(r.status_code, 200)
        self.assertEqual(utf8('get'), utf8(r.content))
コード例 #10
0
ファイル: auth.py プロジェクト: nicky1108/api-gateway
    def test_aes_login_refresh_logout(self):
        client = APIClient(self.access_key, self.secret_key, self.api_server)
        req = APIRequest(client, self.endpoint, self.version, encrypt_type='aes')

        r = req.get('/login')
        print(r.content)
        self.assertEqual(r.status_code, 405)
        json_data = {
            'name': 'name',
            'password': '******'
        }
        r = req.post('/login', json=json_data)
        self.assertEqual(r.status_code, 200)
        schema = {
            'code': {
                'type': 'integer',
                'required': True,
                'allowed': [APIStatusCode.SUCCESS]
            },
            'msg': {
                'type': 'string',
                'required': True,
            },
            'data': {
                'type': 'dict',
                'required': True,
            }
        }
        v = Validator(schema=schema, allow_unknown=True)
        logger.debug(r.content)
        j = json_decode(r.content)
        logger.debug(j)
        logger.debug(r.json())
        logger.debug(v.validate(r.json()))
        self.assertEqual(v.validate(r.json()), True)

        # refresh_token
        json_data = {
            'refresh_token': r.json()['data']['refresh_token']
        }
        logger.debug(json_data)

        r = req.post('/token', json=json_data)
        self.assertEqual(r.status_code, 200)
        v = Validator(schema=schema, allow_unknown=True)
        logger.debug(r.json())
        self.assertEqual(v.validate(r.json()), True)

        # ---------------------
        json_data = {
            'test': 'test'
        }

        auth_req = APIRequest(client, 'test_api_login', 'v1', encrypt_type='aes')

        access_token = r.json()['data']['access_token']
        ar = auth_req.post('/protected/?access_token=%s' % access_token,
                           json=json_data)
        self.assertEqual(r.status_code, 200)
        v = Validator(schema=schema, allow_unknown=True)
        logger.debug(ar.content)
        logger.debug(ar.json())
        self.assertEqual(v.validate(ar.json()), True)
        # ---------------------
        # logout
        json_data = {
            'access_token': r.json()['data']['access_token']
        }
        r = req.post('/logout', json=json_data)
        self.assertEqual(r.status_code, 200)
        schema = {
            'code': {
                'type': 'integer',
                'required': True,
                'allowed': [APIStatusCode.SUCCESS]
            },
            'msg': {
                'type': 'string',
                'required': True,
            }
        }
        v = Validator(schema=schema, allow_unknown=True)
        self.assertEqual(v.validate(r.json()), True)
コード例 #11
0
ファイル: auth.py プロジェクト: flycn1985/api-gateway
    def test_login_refresh_logout(self):
        client = APIClient(self.access_key, self.secret_key, self.api_server)
        req = APIRequest(client, self.endpoint, self.version)

        r = req.get('/login')
        self.assertEqual(r.status_code, 405)
        json_data = {
            'name': 'name',
            'password': '******'
        }
        r = req.post('/login', json=json_data)
        self.assertEqual(r.status_code, 200)
        schema = {
            'code': {
                'type': 'integer',
                'required': True,
                'allowed': [APIStatusCode.SUCCESS]
            },
            'msg': {
                'type': 'string',
                'required': True,
            },
            'data': {
                'type': 'dict',
                'required': True,
            }
        }
        v = Validator(schema=schema, allow_unknown=True)
        logger.debug(r.json())
        logger.debug(v.validate(r.json()))
        self.assertEqual(v.validate(r.json()), True)

        # refresh_token
        json_data = {
            'refresh_token': r.json()['data']['refresh_token']
        }
        logger.debug(json_data)
        r = req.post('/token', json=json_data)
        self.assertEqual(r.status_code, 200)
        v = Validator(schema=schema, allow_unknown=True)
        logger.debug(r.json())
        self.assertEqual(v.validate(r.json()), True)

        # ---------------------
        json_data = {
            'test': 'test'
        }

        auth_req = APIRequest(client, 'test_api_login', 'v1')

        access_token = r.json()['data']['access_token']
        ar = auth_req.post('/protected/?access_token=%s' % access_token,
                           json=json_data)
        self.assertEqual(r.status_code, 200)
        v = Validator(schema=schema, allow_unknown=True)
        logger.debug(ar.json())
        self.assertEqual(v.validate(ar.json()), True)
        # ---------------------
        # logout
        json_data = {
            'access_token': r.json()['data']['access_token']
        }
        r = req.post('/logout', json=json_data)
        self.assertEqual(r.status_code, 200)
        schema = {
            'code': {
                'type': 'integer',
                'required': True,
                'allowed': [APIStatusCode.SUCCESS]
            },
            'msg': {
                'type': 'string',
                'required': True,
            }
        }
        v = Validator(schema=schema, allow_unknown=True)
        self.assertEqual(v.validate(r.json()), True)