rippled
Loading...
Searching...
No Matches
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 <xrpld/overlay/detail/Handshake.h>
21
22#include <xrpl/beast/unit_test.h>
23
24namespace ripple {
25
26namespace test {
27
29{
30public:
31 handshake_test() = default;
32
33 void
35 {
36 testcase("X-Protocol-Ctl");
37 boost::beast::http::fields headers;
38 headers.insert(
39 "X-Protocol-Ctl",
40 "feature1=v1,v2,v3; feature2=v4; feature3=10; feature4=1; "
41 "feature5=v6");
42 BEAST_EXPECT(!featureEnabled(headers, "feature1"));
43 BEAST_EXPECT(!isFeatureValue(headers, "feature1", "2"));
44 BEAST_EXPECT(isFeatureValue(headers, "feature1", "v1"));
45 BEAST_EXPECT(isFeatureValue(headers, "feature1", "v2"));
46 BEAST_EXPECT(isFeatureValue(headers, "feature1", "v3"));
47 BEAST_EXPECT(isFeatureValue(headers, "feature2", "v4"));
48 BEAST_EXPECT(!isFeatureValue(headers, "feature3", "1"));
49 BEAST_EXPECT(isFeatureValue(headers, "feature3", "10"));
50 BEAST_EXPECT(!isFeatureValue(headers, "feature4", "10"));
51 BEAST_EXPECT(isFeatureValue(headers, "feature4", "1"));
52 BEAST_EXPECT(!featureEnabled(headers, "v6"));
53 }
54
55 void
56 run() override
57 {
59 }
60};
61
62BEAST_DEFINE_TESTSUITE(handshake, ripple_data, ripple);
63
64} // namespace test
65} // namespace ripple
A testsuite class.
Definition: suite.h:55
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:155
void run() override
Runs the suite.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
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:55
bool featureEnabled(boost::beast::http::fields const &headers, std::string const &feature)
Check if a feature is enabled.
Definition: Handshake.cpp:67