| 1 | import unittest |
| 2 | from unittest import mock |
| 3 | |
| 4 | from auth0.authentication.delegated import Delegated |
| 5 | |
| 6 | |
| 7 | class TestDelegated(unittest.TestCase): |
| 8 | @mock.patch("auth0.authentication.delegated.Delegated.post") |
| 9 | def test_get_token_id_token(self, mock_post): |
| 10 | d = Delegated("my.domain.com", "cid") |
| 11 | |
| 12 | d.get_token( |
| 13 | target="tgt", |
| 14 | api_type="apt", |
| 15 | grant_type="gt", |
| 16 | id_token="idt", |
| 17 | scope="openid profile", |
| 18 | ) |
| 19 | |
| 20 | args, kwargs = mock_post.call_args |
| 21 | |
| 22 | self.assertEqual(args[0], "https://my.domain.com/delegation") |
| 23 | self.assertEqual( |
| 24 | kwargs["data"], |
| 25 | { |
| 26 | "client_id": "cid", |
| 27 | "grant_type": "gt", |
| 28 | "id_token": "idt", |
| 29 | "target": "tgt", |
| 30 | "scope": "openid profile", |
| 31 | "api_type": "apt", |
| 32 | }, |
| 33 | ) |
| 34 | |
| 35 | @mock.patch("auth0.authentication.delegated.Delegated.post") |
| 36 | def test_get_token_refresh_token(self, mock_post): |
| 37 | d = Delegated("my.domain.com", "cid") |
| 38 | |
| 39 | d.get_token( |
| 40 | target="tgt", |
| 41 | api_type="apt", |
| 42 | grant_type="gt", |
| 43 | refresh_token="rtk", |
| 44 | ) |
| 45 | |
| 46 | args, kwargs = mock_post.call_args |
| 47 | |
| 48 | self.assertEqual(args[0], "https://my.domain.com/delegation") |
| 49 | self.assertEqual( |
| 50 | kwargs["data"], |
| 51 | { |
| 52 | "client_id": "cid", |
| 53 | "grant_type": "gt", |
| 54 | "refresh_token": "rtk", |
| 55 | "target": "tgt", |
| 56 | "scope": "openid", |
| 57 | "api_type": "apt", |
| 58 | }, |
| 59 | ) |
| 60 | |
| 61 | @mock.patch("auth0.authentication.delegated.Delegated.post") |
| 62 | def test_get_token_value_error(self, mock_post): |
| 63 | d = Delegated("my.domain.com", "cid") |
| 64 | |
| 65 | with self.assertRaises(ValueError): |
| 66 | d.get_token( |
| 67 | target="tgt", |
| 68 | api_type="apt", |
| 69 | grant_type="gt", |
| 70 | refresh_token="rtk", |
| 71 | id_token="idt", |
| 72 | ) |