def test_list_mails_command_encoding(mocker, client):
    """Unit test
    Given
    - an email query
    When
    - calling list_mails
    Then
    - Validate that the queried value is properly url-encoded
    """
    client = MsGraphClient(True,
                           'tenant',
                           'auth_token_url',
                           'enc_key',
                           'app_name',
                           'https://example.com',
                           use_ssl=True,
                           proxy=False,
                           ok_codes=(200, ),
                           mailbox_to_fetch='mailbox',
                           folder_to_fetch='folder',
                           first_fetch_interval=10,
                           emails_fetch_limit=10)
    mocker.patch.object(client.ms_client, 'get_access_token')

    search = 'Test&$%^'
    search_encoded = quote(search)

    with requests_mock.Mocker() as request_mocker:
        mocked = request_mocker.get(
            f'https://example.com/users/user_id/messages?$top=20&$search=%22{search_encoded}%22',
            json={})
        client.list_mails('user_id', search=search)
    assert mocked.call_count == 1
Exemple #2
0
def oproxy_client():
    auth_id = "dummy_auth_id"
    enc_key = "dummy_enc_key"
    token_retrieval_url = "url_to_retrieval"
    auth_and_token_url = f'{auth_id}@{token_retrieval_url}'
    app_name = "ms-graph-mail"
    mailbox_to_fetch = "*****@*****.**"  # disable-secrets-detection
    folder_to_fetch = "Phishing"
    first_fetch_interval = "20 minutes"
    emails_fetch_limit = 50
    base_url = "https://graph.microsoft.com/v1.0"
    ok_codes = (200, 201, 202)

    return MsGraphClient(self_deployed=False,
                         tenant_id='',
                         auth_and_token_url=auth_and_token_url,
                         enc_key=enc_key,
                         app_name=app_name,
                         base_url=base_url,
                         use_ssl=True,
                         proxy=False,
                         ok_codes=ok_codes,
                         mailbox_to_fetch=mailbox_to_fetch,
                         folder_to_fetch=folder_to_fetch,
                         first_fetch_interval=first_fetch_interval,
                         emails_fetch_limit=emails_fetch_limit)
Exemple #3
0
def self_deployed_client():
    tenant_id = "dummy_tenant"
    client_id = "dummy_client_id"
    client_secret = "dummy_secret"
    mailbox_to_fetch = "*****@*****.**"  # disable-secrets-detection
    folder_to_fetch = "Phishing"
    first_fetch_interval = "20 minutes"
    emails_fetch_limit = 50
    base_url = "https://graph.microsoft.com/v1.0"
    ok_codes = (200, 201, 202)

    return MsGraphClient(self_deployed=True, tenant_id=tenant_id, auth_and_token_url=client_id, enc_key=client_secret,
                         base_url=base_url, use_ssl=True, proxy=False, ok_codes=ok_codes, app_name='',
                         mailbox_to_fetch=mailbox_to_fetch, folder_to_fetch=folder_to_fetch,
                         first_fetch_interval=first_fetch_interval, emails_fetch_limit=emails_fetch_limit)