def setUp(self): capability = {"*": ["*"]} self.permit_all = six.text_type(Capability(capability)) self.ably = AblyRest(key=test_vars["keys"][0]["key_str"], rest_host=test_vars["host"], port=test_vars["port"], tls_port=test_vars["tls_port"], tls=test_vars["tls"])
async def test_request_token_with_system_timestamp(self): pre_time = await self.server_time() token_details = await self.ably.auth.request_token(query_time=True) post_time = await self.server_time() assert token_details.token is not None, "Expected token" assert token_details.issued >= pre_time, "Unexpected issued time" assert token_details.issued <= post_time, "Unexpected issued time" assert self.permit_all == str(Capability( token_details.capability)), "Unexpected Capability"
def test_request_token_with_capability_that_subsets_key_capability(self): capability = Capability({"onlythischannel": ["subscribe"]}) token_details = self.ably.auth.request_token( token_params={'capability': capability}) assert token_details is not None assert token_details.token is not None assert capability == token_details.capability, "Unexpected capability"
async def test_request_token_explicit_timestamp(self): pre_time = await self.server_time() token_details = await self.ably.auth.request_token( token_params={'timestamp': pre_time}) post_time = await self.server_time() assert token_details.token is not None, "Expected token" assert token_details.issued >= pre_time, "Unexpected issued time" assert token_details.issued <= post_time, "Unexpected issued time" assert self.permit_all == str(Capability( token_details.capability)), "Unexpected Capability"
def test_request_token_with_capability_that_subsets_key_capability(self): capability = Capability({"onlythischannel": ["subscribe"]}) token_details = self.ably.auth.request_token( token_params={'capability': capability}) self.assertIsNotNone(token_details) self.assertIsNotNone(token_details.token) self.assertEqual(capability, token_details.capability, msg="Unexpected capability")
def test_request_token_with_system_timestamp(self): pre_time = self.server_time() token_details = self.ably.auth.request_token(query_time=True) post_time = self.server_time() self.assertIsNotNone(token_details.token, msg="Expected token") self.assertGreaterEqual(token_details.issued, pre_time, msg="Unexpected issued time") self.assertLessEqual(token_details.issued, post_time, msg="Unexpected issued time") self.assertEqual(self.permit_all, six.text_type(Capability(token_details.capability)), msg="Unexpected Capability")
def test_accept_all_token_params(self): token_params = { 'ttl': 1000, 'capability': Capability({'channel': ['publish']}), 'client_id': 'a_id', 'timestamp': 1000, 'nonce': 'a_nonce', } token_request = self.ably.auth.create_token_request( token_params, key_name=self.key_name, key_secret=self.key_secret, ) self.assertEqual(token_request.ttl, token_params['ttl']) self.assertEqual(token_request.capability, str(token_params['capability'])) self.assertEqual(token_request.client_id, token_params['client_id']) self.assertEqual(token_request.timestamp, token_params['timestamp']) self.assertEqual(token_request.nonce, token_params['nonce'])
async def test_accept_all_token_params(self): token_params = { 'ttl': 1000, 'capability': Capability({'channel': ['publish']}), 'client_id': 'a_id', 'timestamp': 1000, 'nonce': 'a_nonce', } token_request = await self.ably.auth.create_token_request( token_params, key_name=self.key_name, key_secret=self.key_secret, ) assert token_request.ttl == token_params['ttl'] assert token_request.capability == str(token_params['capability']) assert token_request.client_id == token_params['client_id'] assert token_request.timestamp == token_params['timestamp'] assert token_request.nonce == token_params['nonce']
def test_capability(self): capability = Capability({'channel': ['publish']}) token_request = self.ably.auth.create_token_request( key_name=self.key_name, key_secret=self.key_secret, token_params={'capability': capability}) assert token_request.capability == str(capability) def auth_callback(token_params): return token_request ably = RestSetup.get_ably_rest( key=None, auth_callback=auth_callback, use_binary_protocol=self.use_binary_protocol) token = ably.auth.authorize() assert str(token.capability) == str(capability)
def test_capability(self): capability = Capability({'channel': ['publish']}) token_request = self.ably.auth.create_token_request( key_name=self.key_name, key_secret=self.key_secret, token_params={'capability': capability}) self.assertEqual(token_request.capability, str(capability)) def auth_callback(token_params): return token_request ably = AblyRest(auth_callback=auth_callback, rest_host=test_vars["host"], port=test_vars["port"], tls_port=test_vars["tls_port"], tls=test_vars["tls"], use_binary_protocol=self.use_binary_protocol) token = ably.auth.authorise() self.assertEqual(str(token.capability), str(capability))
async def setUp(self): capability = {"*": ["*"]} self.permit_all = str(Capability(capability)) self.ably = await RestSetup.get_ably_rest()
def setUp(self): capability = {"*": ["*"]} self.permit_all = six.text_type(Capability(capability)) self.ably = RestSetup.get_ably_rest()