File: test_reverse_proxy.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (57 lines) | stat: -rw-r--r-- 2,955 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
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
import pytest
from azure.messaging.webpubsubservice import WebPubSubServiceClient
from azure.messaging.webpubsubservice._operations._operations import build_web_pub_sub_service_send_to_all_request
from azure.core.credentials import AzureKeyCredential
from testcase import WebpubsubTest, WebpubsubPowerShellPreparer
from azure.identity import DefaultAzureCredential
from devtools_testutils import recorded_by_proxy

@pytest.mark.live_test_only
class TestWebpubsubReverseProxy(WebpubsubTest):

    @recorded_by_proxy
    def test_reverse_proxy_endpoint_redirection_azure_key_credential(self):
        def _callback(pipeline_request):
            assert pipeline_request.http_request.url.startswith("https://apim.contoso.com/")
            raise ValueError("Success!")
        wps_endpoint = "https://wps.contoso.com/"
        apim_endpoint = "https://apim.contoso.com/"
        credential = AzureKeyCredential("AzureKeyCredential")
        client = WebPubSubServiceClient(wps_endpoint, "Hub", credential, reverse_proxy_endpoint=apim_endpoint)
        request = build_web_pub_sub_service_send_to_all_request('Hub', content='test_webpubsub_send_request', content_type='text/plain')

        with pytest.raises(ValueError) as ex:
            client.send_request(request, raw_request_hook=_callback)
        assert "Success!" in str(ex.value)

    @recorded_by_proxy
    def test_reverse_proxy_endpoint_redirection_identity(self):
        def _callback(pipeline_request):
            assert pipeline_request.http_request.url.startswith("https://apim.contoso.com/")
            raise ValueError("Success!")
        wps_endpoint = "https://wps.contoso.com/"
        apim_endpoint = "https://apim.contoso.com/"
        credential = self.get_credential(WebPubSubServiceClient)
        client = WebPubSubServiceClient(wps_endpoint, "Hub", credential, reverse_proxy_endpoint=apim_endpoint)
        request = build_web_pub_sub_service_send_to_all_request('Hub', content='test_webpubsub_send_request', content_type='text/plain')

        with pytest.raises(ValueError) as ex:
            client.send_request(request, raw_request_hook=_callback)
        assert "Success!" in str(ex.value)

    @WebpubsubPowerShellPreparer()
    @recorded_by_proxy
    def test_reverse_proxy_call(self, webpubsub_connection_string, webpubsub_reverse_proxy_endpoint):
        client = self.create_client(
            connection_string=webpubsub_connection_string,
            hub='hub',
            logging_enable=True,
            reverse_proxy_endpoint=webpubsub_reverse_proxy_endpoint
        )
        client.send_to_all({'Hello': 'reverse_proxy_endpoint!'})