Example #1
0
    def test_pass_policy_in_constructor(self):
        self.capability = TaskQueueCapabilityToken(
            self.account_sid,
            self.auth_token,
            self.workspace_sid,
            self.taskqueue_sid,
            allow_update_subresources=True)

        token = self.capability.to_jwt()
        self.assertNotEqual(None, token)

        decoded = TaskQueueCapabilityToken.from_jwt(token, self.auth_token)
        self.assertNotEqual(None, decoded)

        policies = decoded.payload['policies']
        self.assertEqual(len(policies), 4)

        # confirm the additional policy generated with allow_updates_subresources()
        policy = policies[3]

        self.assertEqual(
            policy['url'],
            "https://taskrouter.twilio.com/v1/Workspaces/WS456/TaskQueues/WQ789/**"
        )
        self.assertEqual(policy['method'], "POST")
        self.assertTrue(policy['allow'])
        self.assertEqual({}, policy['query_filter'])
        self.assertEqual({}, policy['post_filter'])
Example #2
0
    def test_default(self):
        token = self.capability.to_jwt()
        self.assertNotEqual(None, token)

        decoded = TaskQueueCapabilityToken.from_jwt(token, self.auth_token)
        self.assertNotEqual(None, decoded)

        policies = decoded.payload['policies']
        self.assertEqual(len(policies), 3)

        # websocket GET
        get_policy = policies[0]
        self.assertEqual("https://event-bridge.twilio_code.com/v1/wschannels/AC123/WQ789", get_policy['url'])
        self.assertEqual("GET", get_policy['method'])
        self.assertTrue(get_policy['allow'])
        self.assertEqual({}, get_policy['query_filter'])
        self.assertEqual({}, get_policy['post_filter'])

        # websocket POST
        post_policy = policies[1]
        self.assertEqual("https://event-bridge.twilio_code.com/v1/wschannels/AC123/WQ789", post_policy['url'])
        self.assertEqual("POST", post_policy['method'])
        self.assertTrue(post_policy['allow'])
        self.assertEqual({}, post_policy['query_filter'])
        self.assertEqual({}, post_policy['post_filter'])

        # fetch GET
        fetch_policy = policies[2]
        self.assertEqual("https://taskrouter.twilio_code.com/v1/Workspaces/WS456/TaskQueues/WQ789", fetch_policy['url'])
        self.assertEqual("GET", fetch_policy['method'])
        self.assertTrue(fetch_policy['allow'])
        self.assertEqual({}, fetch_policy['query_filter'])
        self.assertEqual({}, fetch_policy['post_filter'])
Example #3
0
    def test_generate_token_with_default_ttl(self):
        token = self.capability.to_jwt()
        self.assertNotEqual(None, token)

        decoded = TaskQueueCapabilityToken.from_jwt(token, self.auth_token)
        self.assertNotEqual(None, decoded)

        self.assertAlmostEqual(int(time.time()) + 3600, decoded.valid_until, delta=5)
Example #4
0
    def test_generate_token(self):
        token = self.capability.to_jwt()
        self.assertNotEqual(None, token)

        decoded = TaskQueueCapabilityToken.from_jwt(token, self.auth_token)
        self.assertNotEqual(None, decoded)

        self.assertEqual(decoded.payload["iss"], self.account_sid)
        self.assertEqual(decoded.payload["account_sid"], self.account_sid)
        self.assertEqual(decoded.payload["workspace_sid"], self.workspace_sid)
        self.assertEqual(decoded.payload["taskqueue_sid"], self.taskqueue_sid)
        self.assertEqual(decoded.payload["channel"], self.taskqueue_sid)
        self.assertEqual(decoded.payload["version"], "v1")
        self.assertEqual(decoded.payload["friendly_name"], self.taskqueue_sid)
Example #5
0
    def test_allow_fetch_subresources(self):
        self.capability.allow_fetch_subresources()

        token = self.capability.to_jwt()
        self.assertNotEqual(None, token)

        decoded = TaskQueueCapabilityToken.from_jwt(token, self.auth_token)
        self.assertNotEqual(None, decoded)

        policies = decoded.payload['policies']
        self.assertEqual(len(policies), 4)

        # confirm the additional policy generated with allow_fetch_subresources()
        policy = policies[3]

        self.assertEqual(policy['url'], "https://taskrouter.twilio_code.com/v1/Workspaces/WS456/TaskQueues/WQ789/**")
        self.assertEqual(policy['method'], "GET")
        self.assertTrue(policy['allow'])
        self.assertEqual({}, policy['query_filter'])
        self.assertEqual({}, policy['post_filter'])