def test_connection_test_failed(self): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.auth_token = None with self.assertRaises(ConnectionTestException): self.connection.test()
def test_admin_actions(self): log = logging.getLogger("TestLogger") test_connection = Connection() test_disable = DisableUserAccount() test_enable = EnableUserAccount() test_connection.logger = log test_disable.logger = log test_enable.logger = log with open("../tests/get_user_info.json") as file: data = json.load(file) connection_params = data.get("body").get("connection") action_params = {"user_id": "*****@*****.**"} test_connection.connect(connection_params) test_disable.connection = test_connection test_enable.connection = test_connection success = test_disable.run(action_params) self.assertTrue(success) success = test_enable.run(action_params) self.assertTrue(success) pass
def test_get_group_by_name(self): log = logging.getLogger("TestLogger") test_connection = Connection() test_get_group_by_name = GetGroupByName() test_connection.logger = log test_get_group_by_name.logger = log with open("../tests/get_user_info.json") as file: data = json.load(file) connection_params = data.get("body").get("connection") action_params = {"name": "Dream Team"} test_connection.connect(connection_params) test_get_group_by_name.connection = test_connection result = test_get_group_by_name.run(action_params) expected = { "group": { "id": "d2cc6aa2-8071-44d9-a97a-0a758da420a8", "createdDateTime": "2018-07-13T17:46:51Z", "creationOptions": ["Team", "ExchangeProvisioningFlags:3552"], "description": "Komand test for plugin", "displayName": "Dream Team", "groupTypes": ["Unified"], "mail": "*****@*****.**", "mailEnabled": True, "mailNickname": "DreamTeam", "proxyAddresses": [ "SPO:SPO_5f0de1c4-0f19-4eab-9ede-00c06c2dab4b@SPO_5c824599-dc8c-4d31-96fb-3b886d4f8f10", "SMTP:[email protected]", ], "renewedDateTime": "2018-07-13T17:46:51Z", "resourceBehaviorOptions": [ "HideGroupInOutlook", "SubscribeMembersToCalendarEventsDisabled", "WelcomeEmailDisabled", ], "resourceProvisioningOptions": ["Team"], "securityEnabled": False, "visibility": "Public", "onPremisesProvisioningErrors": [], } } self.assertEqual(result, expected) self.assertEqual(result.get("group").get("displayName"), "Dream Team")
def test_get_group_by_name(self): log = logging.getLogger("TestLogger") test_connection = Connection() test_get_group_by_name = GetGroupByName() test_connection.logger = log test_get_group_by_name.logger = log with open("../tests/get_user_info.json") as file: data = json.load(file) connection_params = data.get("body").get("connection") action_params = {"name": "Dream Team"} test_connection.connect(connection_params) test_get_group_by_name.connection = test_connection result = test_get_group_by_name.run(action_params) expected = { 'group': { 'id': 'd2cc6aa2-8071-44d9-a97a-0a758da420a8', 'createdDateTime': '2018-07-13T17:46:51Z', 'creationOptions': ['Team', 'ExchangeProvisioningFlags:3552'], 'description': 'Komand test for plugin', 'displayName': 'Dream Team', 'groupTypes': ['Unified'], 'mail': '*****@*****.**', 'mailEnabled': True, 'mailNickname': 'DreamTeam', 'proxyAddresses': [ 'SPO:SPO_5f0de1c4-0f19-4eab-9ede-00c06c2dab4b@SPO_5c824599-dc8c-4d31-96fb-3b886d4f8f10', 'SMTP:[email protected]' ], 'renewedDateTime': '2018-07-13T17:46:51Z', 'resourceBehaviorOptions': [ 'HideGroupInOutlook', 'SubscribeMembersToCalendarEventsDisabled', 'WelcomeEmailDisabled' ], 'resourceProvisioningOptions': ['Team'], 'securityEnabled': False, 'visibility': 'Public', 'onPremisesProvisioningErrors': [] } } self.assertEqual(result, expected) self.assertEqual(result.get("group").get("displayName"), "Dream Team")
def test_connection_test(self): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.auth_token = "this is a token" try: self.connection.test() except Exception: self.fail("Connection test failed!!!")
def test_get_headers(self): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") actual_val = self.connection.get_headers(TEST_API_TOKEN) expected_val = { 'Authorization': 'Bearer FLYYOUFOOLS', 'Content-type': 'application/json' } self.assertEqual(actual_val, expected_val)
def test_get_auth_token(self, mock): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.time_ago = 100000 self.connection.time_now = time.time() self.connection.app_secret = TEST_CLIENT_SECRET self.connection.app_id = TEST_APP_ID self.connection.tenant = TEST_TENANT token = self.connection.get_auth_token() self.assertEqual(token, TEST_API_TOKEN)
def test_get_auth_fails(self, mock): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.time_ago = 0 self.connection.time_now = time.time() self.connection.auth_token = None self.connection.app_secret = TEST_CLIENT_SECRET self.connection.app_id = TEST_APP_ID self.connection.tenant = TEST_TENANT with self.assertRaises(PluginException): self.connection.get_auth_token()
def test_get_auth_token_under_one_hour(self, mock): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.time_ago = time.time() self.connection.time_now = time.time() self.connection.auth_token = None self.connection.app_secret = TEST_CLIENT_SECRET self.connection.app_id = TEST_APP_ID self.connection.tenant = TEST_TENANT token = self.connection.get_auth_token() self.assertEqual(token, None)
def test_force_user_to_change_password(self): log = logging.getLogger("TestLogger") test_connection = Connection() test_force_user = ForceUserToChangePassword() test_connection.logger = log test_force_user.logger = log # Read in tests file and get connection params with open("../tests/get_user_info.json") as file: data = json.load(file) connection_params = data.get("body").get("connection") action_params = {"user_id": "*****@*****.**"} test_connection.connect(connection_params) test_force_user.connection = test_connection result = test_force_user.run(action_params) expected = {"success": True} self.assertEqual(result, expected)
def test_get_user_info(self): log = logging.getLogger("TestLogger") test_connection = Connection() test_get_user_info = GetUserInfo() test_connection.logger = log test_get_user_info.logger = log with open("../tests/get_user_info.json") as file: data = json.load(file) connection_params = data.get("body").get("connection") action_params = {"user_id": "*****@*****.**"} test_connection.connect(connection_params) test_get_user_info.connection = test_connection result = test_get_user_info.run(action_params) expected = { 'user_information': { '@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#users/$entity', 'businessPhones': [], 'displayName': 'Joey McAdams', 'givenName': 'Joey', 'jobTitle': 'Sr. Software Engineer', 'mail': '', 'mobilePhone': '', 'officeLocation': '', 'preferredLanguage': '', 'surname': 'McAdams', 'userPrincipalName': '*****@*****.**', 'id': '08290005-23ba-46b4-a377-b381d651a2fb', 'accountEnabled': True } } self.assertEqual(result, expected)
def test_get_user_info(self): log = logging.getLogger("TestLogger") test_connection = Connection() test_get_user_info = GetUserInfo() test_connection.logger = log test_get_user_info.logger = log with open("../tests/get_user_info.json") as file: data = json.load(file) connection_params = data.get("body").get("connection") action_params = {"user_id": "*****@*****.**"} test_connection.connect(connection_params) test_get_user_info.connection = test_connection result = test_get_user_info.run(action_params) expected = { "user_information": { "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity", "businessPhones": [], "displayName": "Joey McAdams", "givenName": "Joey", "jobTitle": "Sr. Software Engineer", "mail": "", "mobilePhone": "", "officeLocation": "", "preferredLanguage": "", "surname": "McAdams", "userPrincipalName": "*****@*****.**", "id": "08290005-23ba-46b4-a377-b381d651a2fb", "accountEnabled": True, } } self.assertEqual(result, expected)
def test_get_add_user_to_group(self): log = logging.getLogger("TestLogger") test_connection = Connection() test_add_user_to_group = AddUserToGroup() test_connection.logger = log test_add_user_to_group.logger = log with open("../tests/get_user_info.json") as file: data = json.load(file) connection_params = data.get("body").get("connection") action_params = { "user_id": "*****@*****.**", "group_name": "Azure AD Test Security Group" } test_connection.connect(connection_params) test_add_user_to_group.connection = test_connection result = test_add_user_to_group.run(action_params) expected = {'success': True} self.assertEqual(result, expected)
def test_remove_user_from_group(self): log = logging.getLogger("TestLogger") test_connection = Connection() test_remove = RemoveUserFromGroup() test_connection.logger = log test_remove.logger = log with open("../tests/get_user_info.json") as file: data = json.load(file) connection_params = data.get("body").get("connection") action_params = { "user_id": "*****@*****.**", "group_name": "Azure AD Test Security Group", } test_connection.connect(connection_params) test_remove.connection = test_connection result = test_remove.run(action_params) expected = {"success": True} self.assertEqual(result, expected)
def test_can_connect(self, mock): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.connect(self.params) self.assertEqual(self.connection.auth_token, TEST_API_TOKEN)
class TestConnection(TestCase): def setUp(self) -> None: self.params = { "application_id": TEST_CLIENT_ID, "application_secret": { "secretKey": TEST_CLIENT_SECRET }, "tenant_id": TEST_TENANT } def tearDown(self) -> None: pass @mock.patch('requests.post', side_effect=mocked_requests_get) def test_can_connect(self, mock): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.connect(self.params) self.assertEqual(self.connection.auth_token, TEST_API_TOKEN) @mock.patch('requests.post', side_effect=mocked_requests_get) def test_get_auth_token(self, mock): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.time_ago = 100000 self.connection.time_now = time.time() self.connection.app_secret = TEST_CLIENT_SECRET self.connection.app_id = TEST_APP_ID self.connection.tenant = TEST_TENANT token = self.connection.get_auth_token() self.assertEqual(token, TEST_API_TOKEN) @mock.patch('requests.post', side_effect=mocked_requests_get) def test_get_auth_token_under_one_hour(self, mock): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.time_ago = time.time() self.connection.time_now = time.time() self.connection.auth_token = None self.connection.app_secret = TEST_CLIENT_SECRET self.connection.app_id = TEST_APP_ID self.connection.tenant = TEST_TENANT token = self.connection.get_auth_token() self.assertEqual(token, None) @mock.patch('requests.post', side_effect=mocked_requests_get_fails) def test_get_auth_fails(self, mock): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.time_ago = 0 self.connection.time_now = time.time() self.connection.auth_token = None self.connection.app_secret = TEST_CLIENT_SECRET self.connection.app_id = TEST_APP_ID self.connection.tenant = TEST_TENANT with self.assertRaises(PluginException): self.connection.get_auth_token() def test_connection_test(self): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.auth_token = "this is a token" try: self.connection.test() except Exception: self.fail("Connection test failed!!!") def test_connection_test_failed(self): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") self.connection.auth_token = None with self.assertRaises(ConnectionTestException): self.connection.test() def test_get_headers(self): self.connection = Connection() self.connection.logger = logging.getLogger("test_logger") actual_val = self.connection.get_headers(TEST_API_TOKEN) expected_val = { 'Authorization': 'Bearer FLYYOUFOOLS', 'Content-type': 'application/json' } self.assertEqual(actual_val, expected_val)