def test_access_command_grant_when_self_approved(self, mocked_testbot): mocked_testbot._bot.callback_message = callback_message_fn(mocked_testbot._bot) mocked_testbot.push_message("access to Xxx") mocked_testbot.push_message(f"yes {access_request_id}") assert "valid request" in mocked_testbot.pop_message() assert "access request" in mocked_testbot.pop_message() assert "Granting" in mocked_testbot.pop_message()
def test_show_resources_command_when_sent_via_team(self, mocked_testbot): mocked_testbot._bot.callback_message = MagicMock( side_effect=callback_message_fn(mocked_testbot._bot, from_email=account_name, approver_is_admin=True)) mocked_testbot.push_message("show available resources") message = mocked_testbot.pop_message() assert "Aaa (type: DummyResource)" in message assert "Bbb (type: DummyResource)" in message
def test_fail_access_command_when_not_admin_self_approved(self, mocked_testbot): mocked_testbot._bot.callback_message = MagicMock(side_effect=callback_message_fn( mocked_testbot._bot, from_email=account_name )) mocked_testbot.push_message("access to Xxx") mocked_testbot.push_message(f"yes {access_request_id}") assert "valid request" in mocked_testbot.pop_message() assert "access request" in mocked_testbot.pop_message() assert "not an admin to self approve" in mocked_testbot.pop_message()
def test_fail_assign_role_command_when_self_approved(self, mocked_testbot): accessbot = mocked_testbot.bot.plugin_manager.plugins['AccessBot'] mocked_testbot._bot.callback_message = callback_message_fn( mocked_testbot._bot, from_email=account_name) with patch('datetime.datetime', new=self.NewDate): mocked_testbot.push_message(f"access to role {role_name}") mocked_testbot.push_message(f"yes {access_request_id}") assert "valid request" in mocked_testbot.pop_message() assert "assign request" in mocked_testbot.pop_message() assert "not an admin to self approve" in mocked_testbot.pop_message( )
def test_show_roles_command(self, mocked_testbot): mocked_testbot._bot.callback_message = MagicMock(side_effect=callback_message_fn( mocked_testbot._bot, from_email=account_name, approver_is_admin=True )) mocked_testbot.push_message("show available roles") message = mocked_testbot.pop_message() # For some reason we cannot assert the text enclosed between stars assert "Aaa" in message assert "~~Bbb~~ (not allowed)" in message
def test_access_command_grant_approved(self, mocked_testbot): mocked_testbot._bot.callback_message = MagicMock(side_effect=callback_message_fn( mocked_testbot._bot, from_email=account_name, approver_is_admin=True )) mocked_testbot.push_message("access to Xxx") mocked_testbot.push_message(f"yes {access_request_id}") assert "valid request" in mocked_testbot.pop_message() assert "access request" in mocked_testbot.pop_message() assert "Granting" in mocked_testbot.pop_message()
def test_assign_role_command(self, mocked_testbot): accessbot = mocked_testbot.bot.plugin_manager.plugins['AccessBot'] mocked_testbot._bot.callback_message = callback_message_fn( mocked_testbot._bot) grant_temporary_access_mock = accessbot.get_sdm_service( ).grant_temporary_access with patch('datetime.datetime', new=self.NewDate): mocked_testbot.push_message(f"access to role {role_name}") mocked_testbot.push_message(f"yes {access_request_id}") assert "valid request" in mocked_testbot.pop_message() assert "assign request" in mocked_testbot.pop_message() assert "Granting" in mocked_testbot.pop_message() start_from = datetime.datetime(2021, 5, 12, 0, 0) valid_until = datetime.datetime(2021, 5, 12, 1, 0) grant_temporary_access_mock.assert_called_with( resource_id, account_id, start_from, valid_until)