示例#1
0
    def test_jwt_expiry(self, hge_ctx, ws_client):
        curr_time = datetime.utcnow()
        self.claims = {
            'sub': '1234567890',
            'name': 'John Doe',
            'iat': math.floor(curr_time.timestamp())
        }
        hasura_claims = mk_claims(hge_ctx.hge_jwt_conf, {
            'x-hasura-user-id': '1',
            'x-hasura-default-role': 'user',
            'x-hasura-allowed-roles': ['user'],
        })
        claims_namespace_path = None
        if 'claims_namespace_path' in hge_ctx.hge_jwt_conf_dict:
            claims_namespace_path = hge_ctx.hge_jwt_conf_dict['claims_namespace_path']

        self.claims = mk_claims_with_namespace_path(self.claims,hasura_claims,claims_namespace_path)
        exp = curr_time + timedelta(seconds=4)
        self.claims['exp'] = round(exp.timestamp())
        token = jwt.encode(self.claims, hge_ctx.hge_jwt_key, algorithm='RS512').decode('utf-8')
        payload = {
            'headers': {
                'Authorization': 'Bearer ' + token
            }
        }
        init_ws_conn(hge_ctx, ws_client, payload)
        time.sleep(6)
        assert ws_client.remote_closed == True, ws_client.remote_closed
示例#2
0
def connect_with(hge_ctx, ws_client, headers):
    headers['X-Hasura-Role']      = 'user'
    headers['X-Hasura-User-Id']   = '1234321'
    headers['X-Hasura-Auth-Mode'] = 'webhook'

    token = base64.b64encode(json.dumps(headers).encode('utf-8')).decode('utf-8')
    headers['Authorization'] = 'Bearer ' + token
    payload = {'headers': headers}
    init_ws_conn(hge_ctx, ws_client, payload)
示例#3
0
 def test_jwt_expiry(self, hge_ctx, ws_client):
     curr_time = datetime.now()
     self.claims = {
         'sub': '1234567890',
         'name': 'John Doe',
         'iat': math.floor(curr_time.timestamp())
     }
     self.claims['https://hasura.io/jwt/claims'] = mk_claims(
         hge_ctx.hge_jwt_conf, {
             'x-hasura-user-id': '1',
             'x-hasura-default-role': 'user',
             'x-hasura-allowed-roles': ['user'],
         })
     exp = curr_time + timedelta(seconds=5)
     self.claims['exp'] = round(exp.timestamp())
     token = jwt.encode(self.claims, hge_ctx.hge_jwt_key,
                        algorithm='RS512').decode('utf-8')
     payload = {'headers': {'Authorization': 'Bearer ' + token}}
     init_ws_conn(hge_ctx, ws_client, payload)
     time.sleep(5)
     assert ws_client.remote_closed == True, ws_client.remote_closed