Asserts that a TokenAuthenticationError is returned when the token authenticates, but is not authorized.
(clear_funcs)
| 575 | |
| 576 | @pytest.mark.slow_test |
| 577 | def test_runner_token_authorization_error(clear_funcs): |
| 578 | """ |
| 579 | Asserts that a TokenAuthenticationError is returned when the token authenticates, but is |
| 580 | not authorized. |
| 581 | """ |
| 582 | token = "asdfasdfasdfasdf" |
| 583 | clear_load = {"token": token, "fun": "test.arg"} |
| 584 | mock_token = {"token": token, "eauth": "foo", "name": "test"} |
| 585 | mock_ret = { |
| 586 | "error": { |
| 587 | "name": "TokenAuthenticationError", |
| 588 | "message": ( |
| 589 | 'Authentication failure of type "token" occurred for user test.' |
| 590 | ), |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | with patch( |
| 595 | "salt.auth.LoadAuth.authenticate_token", MagicMock(return_value=mock_token) |
| 596 | ), patch("salt.auth.LoadAuth.get_auth_list", MagicMock(return_value=[])): |
| 597 | ret = clear_funcs.runner(clear_load) |
| 598 | |
| 599 | assert ret == mock_ret |
| 600 | |
| 601 | |
| 602 | @pytest.mark.slow_test |