Line data Source code
1 : /*
2 : ___________________________________________
3 : | _ ___ _ |
4 : | | | |__ \ | | |
5 : | | |__ ) |__ _ __ _ ___ _ __ | |_ |
6 : | | '_ \ / // _` |/ _` |/ _ \ '_ \| __| | HTTP/2 AGENT FOR MOCK TESTING
7 : | | | | |/ /| (_| | (_| | __/ | | | |_ | Version 0.0.z
8 : | |_| |_|____\__,_|\__, |\___|_| |_|\__| | https://github.com/testillano/h2agent
9 : | __/ | |
10 : | |___/ |
11 : |___________________________________________|
12 :
13 : Licensed under the MIT License <http://opensource.org/licenses/MIT>.
14 : SPDX-License-Identifier: MIT
15 : Copyright (c) 2021 Eduardo Ramos
16 :
17 : Permission is hereby granted, free of charge, to any person obtaining a copy
18 : of this software and associated documentation files (the "Software"), to deal
19 : in the Software without restriction, including without limitation the rights
20 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21 : copies of the Software, and to permit persons to whom the Software is
22 : furnished to do so, subject to the following conditions:
23 :
24 : The above copyright notice and this permission notice shall be included in all
25 : copies or substantial portions of the Software.
26 :
27 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 : SOFTWARE.
34 : */
35 :
36 : #pragma once
37 :
38 : #include <vector>
39 : #include <cstdint>
40 : #include <regex>
41 :
42 : #include <nlohmann/json.hpp>
43 :
44 : #include <Map.hpp>
45 : #include <MockData.hpp>
46 : #include <MockClientEventsHistory.hpp>
47 : #include <MockClientEvent.hpp>
48 :
49 :
50 : namespace h2agent
51 : {
52 : namespace model
53 : {
54 :
55 :
56 : /**
57 : * This class stores the mock client events.
58 : *
59 : * This is useful to post-verify the internal data (content and schema validation) on testing system.
60 : * Also, the last request for an specific key, is used to know the state which is used to get the
61 : * corresponding provision information.
62 : */
63 : class MockClientData : public MockData
64 : {
65 : public:
66 324 : MockClientData() {};
67 323 : ~MockClientData() = default;
68 :
69 : /**
70 : * Loads event data
71 : *
72 : * @param dataKey Events key (client endpoint id, method & uri).
73 : *
74 : * @param clientProvisionId Client provision id responsible for the event
75 : * @param previousState Previous request state
76 : * @param state Request state
77 : * @param sendingTimestampUs Microseconds sending timestamp
78 : * @param receptionTimestampUs Microseconds reception timestamp
79 : * @param responseStatusCode Response status code
80 : * @param requestHeaders Request headers
81 : * @param responseHeaders Response headers
82 : *
83 : * @param requestBody Request body
84 : * @param responseBodyDataPart Response body
85 : * @param sendSeq Send sequence (1..N)
86 : * @param sequence test sequence (1..N)
87 : * @param requestDelayMs Request delay in milliseconds
88 : * @param timeoutMs Timeout in milliseconds
89 : *
90 : * @param historyEnabled Events complete history storage
91 : */
92 : void loadEvent(const DataKey &dataKey, const std::string &clientProvisionId, const std::string &previousState, const std::string &state, const std::chrono::microseconds &sendingTimestampUs, const std::chrono::microseconds &receptionTimestampUs, int responseStatusCode, const nghttp2::asio_http2::header_map &requestHeaders, const nghttp2::asio_http2::header_map &responseHeaders, const std::string &requestBody, DataPart &responseBodyDataPart, std::uint64_t sendSeq, std::int64_t sequence, unsigned int requestDelayMs, unsigned int timeoutMs, bool historyEnabled);
93 :
94 : /**
95 : * Removes a specific event identified by send sequence
96 : *
97 : * @param dataKey Events key (client endpoint id, method & uri).
98 : * @param sendSeq Send sequence identifying the event.
99 : *
100 : * @return Boolean about if something was deleted
101 : */
102 : bool removeEventBySendSeq(const DataKey &dataKey, std::uint64_t sendSeq);
103 :
104 : /**
105 : * Gets event matching a given send sequence within a data key
106 : *
107 : * @param dataKey Events key (client endpoint id, method & uri).
108 : * @param sendSeq Send sequence to match
109 : *
110 : * @return Mock event or nullptr if not found
111 : */
112 : std::shared_ptr<MockEvent> getEventBySendSeq(const DataKey &dataKey, std::uint64_t sendSeq);
113 :
114 : /**
115 : * Gets chronologically ordered sequence of events (direction + method + uri + timestamps)
116 : *
117 : * @param fromTimestampUs Minimum timestamp filter (0 = no filter)
118 : * @param toTimestampUs Maximum timestamp filter (0 = no filter)
119 : * @param requestMethod Filter by exact method (empty = no filter)
120 : * @param uriRegex Filter by URI regex (nullptr = no filter)
121 : *
122 : * @return JSON array sorted by timestamp, interleaving send/recv
123 : */
124 : std::string getSequence(std::uint64_t fromTimestampUs, std::uint64_t toTimestampUs, const std::string &requestMethod, const std::regex *uriRegex) const;
125 : };
126 :
127 : }
128 : }
129 :
|