File: proxy_tests.cpp

package info (click to toggle)
cpprest 2.10.10-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,812 kB
  • sloc: cpp: 69,785; sh: 254; makefile: 167
file content (92 lines) | stat: -rw-r--r-- 2,777 bytes parent folder | download | duplicates (3)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/***
 * Copyright (C) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 *
 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
 *
 * proxy_tests.cpp
 *
 * Tests cases for covering proxies using websocket_client
 *
 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 ****/

#include "stdafx.h"

#if defined(__cplusplus_winrt) || !defined(_M_ARM)

using namespace web::websockets;
using namespace web::websockets::client;

using namespace tests::functional::websocket::utilities;

namespace tests
{
namespace functional
{
namespace websocket
{
namespace client
{
SUITE(proxy_tests)
{
#ifdef __cplusplus_winrt
    TEST_FIXTURE(uri_address, no_proxy_options_on_winrt)
    {
        websocket_client_config config;
        config.set_proxy(web::web_proxy::use_auto_discovery);
        websocket_client client(config);
        VERIFY_THROWS(client.connect(m_uri).wait(), websocket_exception);
    }
#endif

#ifndef __cplusplus_winrt
    // Can't specify a proxy with WinRT implementation.
    TEST_FIXTURE(uri_address, proxy_with_credentials, "Ignore:Android", "390")
    {
        web::web_proxy proxy(U("http://netproxy.redmond.corp.microsoft.com"));
        web::credentials cred(U("artur"), U("fred")); // relax, this is not my real password
        proxy.set_credentials(cred);
        websocket_client_config config;
        config.set_proxy(proxy);

        websocket_client client(config);

        try
        {
            client.connect(U("wss://echo.websocket.org/")).wait();
            const auto text = std::string("hello");
            websocket_outgoing_message msg;
            msg.set_utf8_message(text);
            client.send(msg).wait();
            auto response = client.receive().get();
            VERIFY_ARE_EQUAL(text, response.extract_string().get());
            client.close().wait();
        }
        catch (websocket_exception const& e)
        {
            if (e.error_code().value() == 12007)
            {
                // The above "netproxy.redmond.corp.microsoft.com" is an internal site not generally accessible.
                // This will cause a failure to resolve the URL.
                // This is ok.
                return;
            }
            else if (e.error_code().value() == 9 || e.error_code().value() == 5)
            {
                // Timer expired case, since this is an outside test don't fail due to timing out.
                return;
            }
            throw;
        }
    }
#endif

} // SUITE(proxy_tests)

} // namespace client
} // namespace websocket
} // namespace functional
} // namespace tests

#endif