コード例 #1
0
    def test_delete_sp_pwd_creds(self, graph_client_mock):
        test_sp_object_id = '11111111-2222-3333-4444-555555555555'
        test_app_object_id = '11111111-2222-3333-4444-666666666666'
        graph_client_mock.return_value = graph_client = mock.MagicMock()

        sp, sp_cred, app, app_cred = mock.MagicMock(), mock.MagicMock(), mock.MagicMock(), mock.MagicMock()
        sp.object_id, app.object_id = test_sp_object_id, test_app_object_id
        sp_cred.key_id, app_cred.key_id = 'nice sp key', 'nice app key'
        sp.service_principal_names = ['good-name']

        graph_client.service_principals.list.return_value = [sp]
        graph_client.service_principals.get.return_value = sp
        graph_client.service_principals.list_password_credentials.return_value = [sp_cred]

        graph_client.applications.list_password_credentials.return_value = [app_cred]
        graph_client.applications.list.return_value = [app]

        # action
        delete_service_principal_credential(mock.MagicMock(), 'nevermind', 'nice app key')

        # assert
        graph_client.service_principals.list.assert_called_once()
        graph_client.service_principals.get.assert_called_once()
        graph_client.service_principals.list_password_credentials.assert_called_once()
        graph_client.applications.list_password_credentials.assert_called_once()
        graph_client.applications.update_password_credentials.assert_called_once_with(test_app_object_id, [])
コード例 #2
0
    def test_delete_sp_cert_creds(self, graph_client_mock):
        test_sp_object_id = '11111111-2222-3333-4444-555555555555'
        graph_client_mock.return_value = graph_client = mock.MagicMock()

        sp, sp_cred = mock.MagicMock(), mock.MagicMock()
        sp.object_id = test_sp_object_id
        sp_cred.key_id = 'nice sp key'
        sp.service_principal_names = ['good-name']

        graph_client.service_principals.list.return_value = [sp]
        graph_client.service_principals.get.return_value = sp
        graph_client.service_principals.list_key_credentials.return_value = [
            sp_cred
        ]

        graph_client.applications.list.return_value = []

        # action
        delete_service_principal_credential(mock.MagicMock(),
                                            'nevermind',
                                            sp_cred.key_id,
                                            cert=True)

        # assert
        graph_client.service_principals.list.assert_called_once()
        graph_client.service_principals.list_key_credentials.assert_called_once(
        )
        graph_client.service_principals.update_key_credentials.assert_called_once_with(
            test_sp_object_id, [])