Skip to content

Commit 2fc2de8

Browse files
committed
test: Keep the existing WebSocket proxy credential tests unchanged
Restore WebSocketCredentialsStayWithTheirHop() and the two tests that use it to their original form, and give the setter tests their own helper, WebSocketSetterCredentialsStayWithTheirHop(), which sets the origin credentials through set_basic_auth()/set_bearer_token_auth() instead of a constructor header.
1 parent 4628521 commit 2fc2de8

1 file changed

Lines changed: 37 additions & 14 deletions

File tree

‎test/test.cc‎

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32172,19 +32172,45 @@ class ScopedWebSocketOrigin {
3217232172
no_proxy_test::ScopedServer server_;
3217332173
};
3217432174

32175-
// Connects through a proxy that requires `proxy_authz` and checks that it and
32176-
// `origin_authz` each reach only their own hop. `set_credentials` sets the
32177-
// proxy credentials, and the origin ones unless they come in `headers`.
32175+
// Connects through a proxy that requires `proxy_authz`, with `origin_authz`
32176+
// passed as a constructor header, and checks that each reaches only its hop.
3217832177
void WebSocketCredentialsStayWithTheirHop(
32178+
const std::function<void(ws::WebSocketClient &)> &set_proxy_credentials,
32179+
const std::string &proxy_authz, const std::string &origin_authz) {
32180+
ScopedWebSocketOrigin origin;
32181+
ScopedConnectProxy proxy(
32182+
origin.port(), require_proxy_auth(proxy_authz, "Basic realm=\"proxy\""));
32183+
ASSERT_NE(0, proxy.port());
32184+
32185+
ws::WebSocketClient client(origin.url(), {{"Authorization", origin_authz}});
32186+
client.set_proxy("127.0.0.1", proxy.port());
32187+
set_proxy_credentials(client);
32188+
auto res = client.connect();
32189+
ASSERT_TRUE(res) << "Error: " << to_string(res.error());
32190+
32191+
std::string msg;
32192+
ASSERT_TRUE(client.read(msg));
32193+
EXPECT_EQ("authorization:" + origin_authz + "|proxy-authorization:", msg);
32194+
client.close();
32195+
32196+
EXPECT_EQ(1, proxy.connect_hits());
32197+
EXPECT_EQ(std::string::npos,
32198+
proxy.connect_request().find("\r\nAuthorization: "))
32199+
<< "origin credentials must not be sent to the proxy";
32200+
}
32201+
32202+
// Like WebSocketCredentialsStayWithTheirHop(), but with no constructor
32203+
// headers: `set_credentials` sets both the proxy and the origin credentials
32204+
// through the setters, and `origin_authz` is what the origin should receive.
32205+
void WebSocketSetterCredentialsStayWithTheirHop(
3217932206
const std::function<void(ws::WebSocketClient &)> &set_credentials,
32180-
const std::string &proxy_authz, const std::string &origin_authz,
32181-
const Headers &headers = {}) {
32207+
const std::string &proxy_authz, const std::string &origin_authz) {
3218232208
ScopedWebSocketOrigin origin;
3218332209
ScopedConnectProxy proxy(
3218432210
origin.port(), require_proxy_auth(proxy_authz, "Basic realm=\"proxy\""));
3218532211
ASSERT_NE(0, proxy.port());
3218632212

32187-
ws::WebSocketClient client(origin.url(), headers);
32213+
ws::WebSocketClient client(origin.url());
3218832214
client.set_proxy("127.0.0.1", proxy.port());
3218932215
set_credentials(client);
3219032216
auto res = client.connect();
@@ -32301,27 +32327,24 @@ TEST(WebSocketProxyTest, TunnelsThroughConnect) {
3230132327
}
3230232328

3230332329
TEST(WebSocketProxyTest, BasicCredentialsStayWithTheirHop) {
32304-
auto origin_authz =
32305-
"Basic " + detail::base64_encode("origin-user:origin-pass");
3230632330
proxy_tunnel_test::WebSocketCredentialsStayWithTheirHop(
3230732331
[](ws::WebSocketClient &cli) {
3230832332
cli.set_proxy_basic_auth("proxy-user", "proxy-pass");
3230932333
},
32310-
"Basic " + detail::base64_encode("proxy-user:proxy-pass"), origin_authz,
32311-
{{"Authorization", origin_authz}});
32334+
"Basic " + detail::base64_encode("proxy-user:proxy-pass"),
32335+
"Basic " + detail::base64_encode("origin-user:origin-pass"));
3231232336
}
3231332337

3231432338
TEST(WebSocketProxyTest, BearerCredentialsStayWithTheirHop) {
3231532339
proxy_tunnel_test::WebSocketCredentialsStayWithTheirHop(
3231632340
[](ws::WebSocketClient &cli) {
3231732341
cli.set_proxy_bearer_token_auth("proxy-token");
3231832342
},
32319-
"Bearer proxy-token", "Bearer origin-token",
32320-
{{"Authorization", "Bearer origin-token"}});
32343+
"Bearer proxy-token", "Bearer origin-token");
3232132344
}
3232232345

3232332346
TEST(WebSocketProxyTest, BasicAuthSetterStaysWithItsHop) {
32324-
proxy_tunnel_test::WebSocketCredentialsStayWithTheirHop(
32347+
proxy_tunnel_test::WebSocketSetterCredentialsStayWithTheirHop(
3232532348
[](ws::WebSocketClient &cli) {
3232632349
cli.set_proxy_basic_auth("proxy-user", "proxy-pass");
3232732350
cli.set_basic_auth("origin-user", "origin-pass");
@@ -32331,7 +32354,7 @@ TEST(WebSocketProxyTest, BasicAuthSetterStaysWithItsHop) {
3233132354
}
3233232355

3233332356
TEST(WebSocketProxyTest, BearerTokenAuthSetterStaysWithItsHop) {
32334-
proxy_tunnel_test::WebSocketCredentialsStayWithTheirHop(
32357+
proxy_tunnel_test::WebSocketSetterCredentialsStayWithTheirHop(
3233532358
[](ws::WebSocketClient &cli) {
3233632359
cli.set_proxy_bearer_token_auth("proxy-token");
3233732360
cli.set_bearer_token_auth("origin-token");

0 commit comments

Comments
 (0)