File: conftest.py

package info (click to toggle)
python-azure 20230112%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 749,544 kB
  • sloc: python: 6,815,827; javascript: 287; makefile: 195; xml: 109; sh: 105
file content (70 lines) | stat: -rw-r--r-- 3,394 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import pytest
from azure.communication.phonenumbers._shared.utils import parse_connection_str
from devtools_testutils import (
    add_body_key_sanitizer,
    add_general_string_sanitizer,
    add_general_regex_sanitizer,
    add_header_regex_sanitizer,
    test_proxy
)


@pytest.fixture(scope="session", autouse=True)
def add_sanitizers(test_proxy):
    fake_connection_str = "endpoint=https://sanitized.communication.azure.com/;accesskey=fake=="

    client_id = os.getenv("AZURE_CLIENT_ID", "sanitized")
    client_secret = os.getenv("AZURE_CLIENT_SECRET", "sanitized")
    tenant_id = os.getenv("AZURE_TENANT_ID", "sanitized")
    connection_str = os.getenv("COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING",
                               fake_connection_str)
    dynamic_connection_str = os.getenv("COMMUNICATION_LIVETEST_DYNAMIC_CONNECTION_STRING",
                                       fake_connection_str)
    endpoint, *_, access_key = parse_connection_str(connection_str)
    dynamic_endpoint, * \
        _, dynamic_access_key = parse_connection_str(dynamic_connection_str)

    add_general_string_sanitizer(target=client_id, value="sanitized")
    add_general_string_sanitizer(target=client_secret, value="sanitized")
    add_general_string_sanitizer(target=tenant_id, value="sanitized")
    add_general_string_sanitizer(
        target=connection_str, value=fake_connection_str)
    add_general_string_sanitizer(
        target=endpoint, value="sanitized.communication.azure.com")
    add_general_string_sanitizer(target=access_key, value="fake==")

    add_general_string_sanitizer(
        target=dynamic_connection_str, value=fake_connection_str)
    add_general_string_sanitizer(
        target=dynamic_endpoint, value="sanitized.communication.azure.com")
    add_general_string_sanitizer(target=dynamic_access_key, value="fake==")

    add_body_key_sanitizer(json_path="id", value="sanitized")
    add_body_key_sanitizer(json_path="phoneNumber", value="sanitized")
    add_body_key_sanitizer(json_path="phoneNumbers[*].id", value="sanitized")
    add_body_key_sanitizer(
        json_path="phoneNumbers[*].phoneNumber", value="sanitized")

    add_general_regex_sanitizer(regex=r"[%2B\d]{10,15}", value="sanitized")

    add_general_regex_sanitizer(
        regex=r"phoneNumbers/[%2B\d]{10,15}", value="phoneNumbers/sanitized")

    add_general_regex_sanitizer(
        regex=r"\.[0-9a-fA-F]{32}\.com", value=".sanitized.com")

    add_header_regex_sanitizer(key="P3P", value="sanitized")
    add_header_regex_sanitizer(key="Set-Cookie", value="sanitized")
    add_header_regex_sanitizer(key="Date", value="sanitized")
    add_header_regex_sanitizer(key="Cookie", value="sanitized")
    add_header_regex_sanitizer(key="client-request-id", value="sanitized")
    add_header_regex_sanitizer(key="MS-CV", value="sanitized")
    add_header_regex_sanitizer(key="X-Azure-Ref", value="sanitized")
    add_header_regex_sanitizer(key="x-ms-content-sha256", value="sanitized")
    add_header_regex_sanitizer(key="x-ms-client-request-id", value="sanitized")
    add_header_regex_sanitizer(key="x-ms-date", value="sanitized")
    add_header_regex_sanitizer(key="x-ms-ests-server", value="sanitized")
    add_header_regex_sanitizer(key="x-ms-request-id", value="sanitized")
    add_header_regex_sanitizer(
        key="Content-Security-Policy-Report-Only", value="sanitized")