20 #include <ripple/beast/unit_test.h>
21 #include <ripple/protocol/ErrorCodes.h>
22 #include <ripple/protocol/jss.h>
25 #include <test/jtx/WSClient.h>
37 using namespace test::jtx;
42 BEAST_EXPECT(env.
rpc(
"ping")[
"result"][
"role"] ==
"admin");
44 ->invoke(
"ping")[
"result"][
"unlimited"]
50 BEAST_EXPECT(!env.rpc(
"ping")[
"result"].isMember(
"role"));
52 makeWSClient(env.app().config())->invoke(
"ping")[
"result"];
54 !wsRes.isMember(
"unlimited") || !wsRes[
"unlimited"].asBool());
59 BEAST_EXPECT(env.rpc(
"ping")[
"result"][
"role"] ==
"proxied");
61 makeWSClient(env.app().config())->invoke(
"ping")[
"result"];
63 !wsRes.isMember(
"unlimited") || !wsRes[
"unlimited"].asBool());
66 headers[
"X-Forwarded-For"] =
"12.34.56.78";
67 auto rpcRes = env.rpc(headers,
"ping")[
"result"];
68 BEAST_EXPECT(rpcRes[
"role"] ==
"proxied");
69 BEAST_EXPECT(rpcRes[
"ip"] ==
"12.34.56.78");
71 headers[
"X-Forwarded-For"] =
"87.65.43.21, 44.33.22.11";
72 rpcRes = env.rpc(headers,
"ping")[
"result"];
73 BEAST_EXPECT(rpcRes[
"ip"] ==
"87.65.43.21");
74 headers.
erase(
"X-Forwarded-For");
76 headers[
"Forwarded"] =
"for=88.77.66.55";
77 rpcRes = env.rpc(headers,
"ping")[
"result"];
78 BEAST_EXPECT(rpcRes[
"ip"] ==
"88.77.66.55");
80 headers[
"Forwarded"] =
81 "what=where;for=55.66.77.88;for=nobody;"
83 rpcRes = env.rpc(headers,
"ping")[
"result"];
84 BEAST_EXPECT(rpcRes[
"ip"] ==
"55.66.77.88");
86 headers[
"Forwarded"] =
87 "what=where;for=55.66.77.88, 99.00.11.22;"
89 rpcRes = env.rpc(headers,
"ping")[
"result"];
90 BEAST_EXPECT(rpcRes[
"ip"] ==
"55.66.77.88");
92 wsRes =
makeWSClient(env.app().config(),
true, 2, headers)
93 ->invoke(
"ping")[
"result"];
95 !wsRes.isMember(
"unlimited") || !wsRes[
"unlimited"].asBool());
98 headers[
"X-User"] = name;
99 rpcRes = env.rpc(headers,
"ping")[
"result"];
100 BEAST_EXPECT(rpcRes[
"role"] ==
"identified");
101 BEAST_EXPECT(rpcRes[
"username"] == name);
102 BEAST_EXPECT(rpcRes[
"ip"] ==
"55.66.77.88");
103 wsRes =
makeWSClient(env.app().config(),
true, 2, headers)
104 ->invoke(
"ping")[
"result"];
105 BEAST_EXPECT(wsRes[
"unlimited"].asBool());
std::unique_ptr< Config > secure_gateway(std::unique_ptr< Config >)
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
std::unique_ptr< Config > no_admin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
virtual Config & config()=0
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::unique_ptr< WSClient > makeWSClient(Config const &cfg, bool v2, unsigned rpc_version, std::unordered_map< std::string, std::string > const &headers)
Returns a client operating through WebSockets/S.
A transaction testing environment.
Json::Value rpc(std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)