diff options
author | Borawski.Lukasz <lukasz.borawski@intel.com> | 2018-04-04 12:50:16 +0200 |
---|---|---|
committer | Ed Tanous <ed.tanous@intel.com> | 2018-07-25 10:29:23 -0700 |
commit | 4b1b8683d31260b3032bb9f9fcde1eadaed4e1e5 (patch) | |
tree | e42eb626b813a24db19bb8ed58709faa10e475b1 /src | |
parent | eb547730ed7f37a1d7c36d9785f6b0722cb8ef3d (diff) | |
download | bmcweb-4b1b8683d31260b3032bb9f9fcde1eadaed4e1e5.tar.gz bmcweb-4b1b8683d31260b3032bb9f9fcde1eadaed4e1e5.zip |
Make SessionStore a proper singleton
- SessionStore class now has a proper singleton structure
- session_storage_singleton.hpp is removed
- from_json(..) function for SessionStore is changed to a specialized
template
- minor cosmetic fixes added
- Move the template class usages of Crow App over to a non-template
parameter
Change-Id: Ic9effd5b7bac089a84c80a0caa97bd46d4984416
Signed-off-by: Borawski.Lukasz <lukasz.borawski@intel.com>
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/token_authorization_middleware_test.cpp | 47 | ||||
-rw-r--r-- | src/webserver_main.cpp | 2 |
2 files changed, 33 insertions, 16 deletions
diff --git a/src/token_authorization_middleware_test.cpp b/src/token_authorization_middleware_test.cpp index 8f45834..47acc85 100644 --- a/src/token_authorization_middleware_test.cpp +++ b/src/token_authorization_middleware_test.cpp @@ -1,18 +1,37 @@ #include "token_authorization_middleware.hpp" -#include <crow/app.h> +#include <condition_variable> +#include <future> +#include <mutex> +#include "webserver_common.hpp" #include "gmock/gmock.h" #include "gtest/gtest.h" using namespace crow; -using namespace std; -// Tests that static urls are correctly passed -TEST(TokenAuthentication, TestBasicReject) { - App<crow::PersistentData::Middleware, crow::TokenAuthorization::Middleware> - app; - decltype(app)::server_t server(&app, "127.0.0.1", 45451); - CROW_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); - auto _ = async(launch::async, [&] { server.run(); }); +class TokenAuth : public ::testing::Test { + public: + TokenAuth() + : lk(std::unique_lock<std::mutex>(m)), + io(std::make_shared<boost::asio::io_service>()) {} + + std::mutex m; + std::condition_variable cv; + std::unique_lock<std::mutex> lk; + std::shared_ptr<boost::asio::io_service> io; + int testPort = 45451; +}; + +TEST_F(TokenAuth, SpecialResourcesAreAcceptedWithoutAuth) { + CrowApp app(io); + crow::TokenAuthorization::request_routes(app); + CROW_ROUTE(app, "/redfish/v1") + ([]() { return boost::beast::http::status::ok; }); + auto _ = std::async(std::launch::async, [&] { + app.port(testPort).run(); + cv.notify_one(); + io->run(); + }); + asio::io_service is; std::string sendmsg; @@ -42,7 +61,7 @@ TEST(TokenAuthentication, TestBasicReject) { EXPECT_EQ("404", std::string(buf + 9, buf + 12)); } - server.stop(); + app.stop(); } // Tests that Base64 basic strings work @@ -51,7 +70,7 @@ TEST(TokenAuthentication, TestRejectedResource) { app; app.bindaddr("127.0.0.1").port(45451); CROW_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); - auto _ = async(launch::async, [&] { app.run(); }); + auto _ = async(std::launch::async, [&] { app.run(); }); asio::io_service is; static char buf[2048]; @@ -81,7 +100,7 @@ TEST(TokenAuthentication, TestGetLoginUrl) { app; app.bindaddr("127.0.0.1").port(45451); CROW_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); - auto _ = async(launch::async, [&] { app.run(); }); + auto _ = async(std::launch::async, [&] { app.run(); }); asio::io_service is; static char buf[2048]; @@ -111,7 +130,7 @@ TEST(TokenAuthentication, TestPostBadLoginUrl) { app; app.bindaddr("127.0.0.1").port(45451); CROW_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); - auto _ = async(launch::async, [&] { app.run(); }); + auto _ = async(std::launch::async, [&] { app.run(); }); asio::io_service is; std::array<char, 2048> buf; @@ -195,7 +214,7 @@ TEST(TokenAuthentication, TestSuccessfulLogin) { app; app.bindaddr("127.0.0.1").port(45451); CROW_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); - auto _ = async(launch::async, [&] { app.run(); }); + auto _ = async(std::launch::async, [&] { app.run(); }); asio::io_service is; std::array<char, 2048> buf; diff --git a/src/webserver_main.cpp b/src/webserver_main.cpp index 6454ed3..55152d6 100644 --- a/src/webserver_main.cpp +++ b/src/webserver_main.cpp @@ -47,8 +47,6 @@ int main(int argc, char** argv) { crow::logger::setLogLevel(crow::LogLevel::DEBUG); auto io = std::make_shared<boost::asio::io_service>(); - crow::PersistentData::session_store = - std::make_shared<crow::PersistentData::SessionStore>(); CrowApp app(io); #ifdef CROW_ENABLE_SSL |