rippled
handshake_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2020 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/beast/unit_test.h>
21 #include <ripple/overlay/impl/Handshake.h>
22 
23 namespace ripple {
24 
25 namespace test {
26 
27 class handshake_test : public beast::unit_test::suite
28 {
29 public:
30  handshake_test() = default;
31 
32  void
34  {
35  testcase("X-Protocol-Ctl");
36  boost::beast::http::fields headers;
37  headers.insert(
38  "X-Protocol-Ctl",
39  "feature1=v1,v2,v3; feature2=v4; feature3=10; feature4=1; "
40  "feature5=v6");
41  BEAST_EXPECT(!featureEnabled(headers, "feature1"));
42  BEAST_EXPECT(!isFeatureValue(headers, "feature1", "2"));
43  BEAST_EXPECT(isFeatureValue(headers, "feature1", "v1"));
44  BEAST_EXPECT(isFeatureValue(headers, "feature1", "v2"));
45  BEAST_EXPECT(isFeatureValue(headers, "feature1", "v3"));
46  BEAST_EXPECT(isFeatureValue(headers, "feature2", "v4"));
47  BEAST_EXPECT(!isFeatureValue(headers, "feature3", "1"));
48  BEAST_EXPECT(isFeatureValue(headers, "feature3", "10"));
49  BEAST_EXPECT(!isFeatureValue(headers, "feature4", "10"));
50  BEAST_EXPECT(isFeatureValue(headers, "feature4", "1"));
51  BEAST_EXPECT(!featureEnabled(headers, "v6"));
52  }
53 
54  void
55  run() override
56  {
57  testHandshake();
58  }
59 };
60 
61 BEAST_DEFINE_TESTSUITE(handshake, ripple_data, ripple);
62 
63 } // namespace test
64 } // namespace ripple
ripple::test::handshake_test::handshake_test
handshake_test()=default
ripple::isFeatureValue
bool isFeatureValue(boost::beast::http::fields const &headers, std::string const &feature, std::string const &value)
Check if a feature's value is equal to the specified value.
Definition: Handshake.cpp:54
ripple::featureEnabled
bool featureEnabled(boost::beast::http::fields const &headers, std::string const &feature)
Check if a feature is enabled.
Definition: Handshake.cpp:66
ripple::test::handshake_test::testHandshake
void testHandshake()
Definition: handshake_test.cpp:33
ripple::test::handshake_test::run
void run() override
Definition: handshake_test.cpp:55
ripple::test::handshake_test
Definition: handshake_test.cpp:27
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)