mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
Jul 5th update
This commit is contained in:
@@ -70,7 +70,7 @@ RestConn::parseConn() const
|
||||
|
||||
string uri;
|
||||
os >> uri;
|
||||
string identifier = uri.substr(uri.find_last_of('/') + 1);
|
||||
string identifier = uri.substr(uri.find_first_of('/') + 1);
|
||||
|
||||
uint len = 0;
|
||||
while (true) {
|
||||
|
@@ -47,6 +47,7 @@ public:
|
||||
|
||||
bool bindRestServerSocket(struct sockaddr_in &addr, vector<uint16_t> port_range);
|
||||
bool addRestCall(RestAction oper, const string &uri, unique_ptr<RestInit> &&init) override;
|
||||
uint16_t getListeningPort() const override { return listening_port; }
|
||||
Maybe<std::string> getSchema(const std::string &uri) const override;
|
||||
Maybe<std::string> invokeRest(const std::string &uri, istream &in) const override;
|
||||
|
||||
@@ -60,7 +61,7 @@ private:
|
||||
I_MainLoop::RoutineID id;
|
||||
I_MainLoop *mainloop;
|
||||
map<string, unique_ptr<RestInit>> rest_calls;
|
||||
uint16_t port_used = 0;
|
||||
uint16_t listening_port = 0;
|
||||
vector<uint16_t> port_range;
|
||||
};
|
||||
|
||||
@@ -138,7 +139,7 @@ RestServer::Impl::init()
|
||||
is_primary.ok() && *is_primary
|
||||
);
|
||||
|
||||
uint16_t listening_port = ntohs(addr.sin_port);
|
||||
listening_port = ntohs(addr.sin_port);
|
||||
dbgInfo(D_API) << "REST server started: " << listening_port;
|
||||
Singleton::Consume<I_Environment>::by<RestServer>()->registerValue<int>("Listening Port", listening_port);
|
||||
};
|
||||
|
@@ -99,6 +99,8 @@ TEST_F(RestConfigTest, alternative_port_used)
|
||||
);
|
||||
mainloop->run();
|
||||
|
||||
EXPECT_EQ(Singleton::Consume<I_RestApi>::from(rest_server)->getListeningPort(), *alternative_port);
|
||||
|
||||
sa.sin_port = htons(alternative_port.unpack());
|
||||
EXPECT_EQ(bind(file_descriptor, reinterpret_cast<struct sockaddr *>(&sa), sizeof(struct sockaddr_in)), -1);
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <sstream>
|
||||
#include "customized_cereal_map.h"
|
||||
#include "customized_cereal_multimap.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -175,6 +176,14 @@ class MustMapInt : public ServerRest
|
||||
C2S_PARAM(mapStringInt, must_map_int);
|
||||
};
|
||||
|
||||
class MustMultiMap : public ServerRest
|
||||
{
|
||||
void doCall() override {}
|
||||
|
||||
using mapStringInt = SerializableMultiMap<string, int>;
|
||||
C2S_PARAM(mapStringInt, must_multimap);
|
||||
};
|
||||
|
||||
TEST(RestSchema, must_map)
|
||||
{
|
||||
stringstream string_map_schema;
|
||||
@@ -214,6 +223,32 @@ TEST(RestSchema, must_map)
|
||||
" ]\n"
|
||||
"}"
|
||||
);
|
||||
|
||||
stringstream multi_map_schema;
|
||||
MustMultiMap().performOutputingSchema(multi_map_schema);
|
||||
EXPECT_EQ(
|
||||
multi_map_schema.str(),
|
||||
"{\n"
|
||||
" \"properties\": {\n"
|
||||
" \"must_multimap\": {\n"
|
||||
" \"type\": \"object\",\n"
|
||||
" \"additionalProperties\": {\n"
|
||||
" \"anyOf\": [\n"
|
||||
" {\n"
|
||||
" \"type\": \"string\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"type\": \"integer\"\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" },\n"
|
||||
" \"required\": [\n"
|
||||
" \"must_multimap\"\n"
|
||||
" ]\n"
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
class MustObject : public ServerRest
|
||||
|
Reference in New Issue
Block a user