File: conftest.py

package info (click to toggle)
python-azure 20251104%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 770,224 kB
  • sloc: python: 6,357,217; ansic: 804; javascript: 287; makefile: 198; sh: 193; xml: 109
file content (62 lines) | stat: -rw-r--r-- 3,210 bytes parent folder | download | duplicates (2)
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
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import sys
import pytest
import os
import asyncio
from devtools_testutils import (
    test_proxy,
    add_general_regex_sanitizer,
    add_header_regex_sanitizer,
    set_default_session_settings,
    add_body_key_sanitizer,
    add_general_string_sanitizer,
    remove_batch_sanitizers,
    set_custom_default_matcher
)


# autouse=True will trigger this fixture on each pytest run, even if it's not explicitly used by a test method
@pytest.fixture(scope="session", autouse=True)
def start_proxy(test_proxy):
    set_default_session_settings()

    # On python 3.14, azure-core sends an additional 'Accept-Encoding' header value that causes playback issues.
    # By ignoring it, we can avoid really wonky mismatch errors, while still validating the other headers
    if sys.version_info >= (3, 14):
        headers_to_ignore = "Accept-Encoding"
        set_custom_default_matcher(ignored_headers=headers_to_ignore)

    fake_connection_str = "endpoint=https://sanitized.communication.azure.com/;accesskey=fake=="
    connection_str = os.getenv("COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING", fake_connection_str)
    add_general_string_sanitizer(target=connection_str, value=fake_connection_str)

    add_general_regex_sanitizer(regex="https://[^/]+", value="https://sanitized")
    add_general_regex_sanitizer(regex="wss://[^/]+", value="wss://sanitized")
    add_body_key_sanitizer(json_path="callbackUri", value="https://sanitized/")
    add_body_key_sanitizer(json_path="transportUrl", value="https://sanitized/")
    add_body_key_sanitizer(json_path="$..file.uri", value="https://REDACTED/prompt.wav")
    add_body_key_sanitizer(json_path="$..incomingCallContext", value="REDACTED")
    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-request-id", value="sanitized")
    add_header_regex_sanitizer(key="Content-Security-Policy-Report-Only", value="sanitized")
    add_header_regex_sanitizer(key="Repeatability-First-Sent", value="sanitized")
    add_header_regex_sanitizer(key="Repeatability-Request-ID", value="sanitized")
    add_header_regex_sanitizer(key="x-ms-host", value="sanitized")

    # Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
    #  - AZSDK3430: $..id
    remove_batch_sanitizers(["AZSDK3430"])

    return