{
LogDebug("Loading library: " << m_libraryPath);
m_libraryHandle = dlopen(m_libraryPath.c_str(), RTLD_LAZY | RTLD_LOCAL);
- if (!m_libraryHandle)
- {
- ThrowMsg(ServiceException::InvalidSharedLib,
- "Unable to load library(" << m_libraryPath << "): " << dlerror());
- }
+ if (m_libraryPath.empty() || !m_libraryHandle)
+ LogError("Unable to load library(" << m_libraryPath << "): " << dlerror());
+ else
+ m_libraryEnabled = true;
}
DLLoader::~DLLoader()
{
return sym;
}
+void DLLoader::SetLibraryEnabled(bool enable)
+{
+ m_libraryEnabled = enable;
+}
+
+bool DLLoader::LibraryEnabled()
+{
+ return m_libraryEnabled;
+}
+
} // namespace WebAuthn
\ No newline at end of file
virtual ~DLLoader();
virtual void *ResolveFunction(const std::string &name) noexcept;
+ bool LibraryEnabled();
template<typename ReturnValue, typename... Args>
ReturnValue Invoke(const std::string &name, Args... args)
return func(args...);
}
+protected:
+ void SetLibraryEnabled(bool enable);
+
private:
std::string m_libraryPath;
void* m_libraryHandle = nullptr;
+ bool m_libraryEnabled = false;
};
} // namespace WebAuthn
\ No newline at end of file
manager.RegisterSocketService(std::move(service));
manager.MainLoop();
return EXIT_SUCCESS;
- } catch (const ServiceException::InvalidSharedLib &e) {
- LogError("Error in starting service, not supported: " << e.DumpToString());
} catch (const std::exception &e) {
LogError("Error in starting service, details:\n" << e.what());
} catch (...) {
LogDebug("Processing message for socket " << msg.connectionID.sock <<
" counter " << msg.connectionID.counter);
int ret = try_catch([&]() -> int {
+ if (!PluginEnabled())
+ return HandleNotSupported(std::move(msg));
// deserialize API call type
int call_type_int;
Deserialization::Deserialize(msg.buffer, call_type_int);
m_isBusy = false;
}
+bool GenericService::PluginEnabled()
+{
+ return m_pluginHybrid->LibraryEnabled();
+}
+
+int GenericService::HandleNotSupported(Event &&msg)
+{
+ LogDebug("Shared library is not enabled");
+ MessageBuffer responseBuffer(m_serviceManager->newMessage());
+ responseBuffer.ModeStreaming();
+ Serialization::Serialize(responseBuffer, WAUTHN_ERROR_NOT_SUPPORTED);
+ m_serviceManager->Write(msg.connectionID, std::move(responseBuffer));
+ return WAUTHN_ERROR_NONE;
+}
+
int GenericService::CheckBusyAndCred(SocketManager::ConnectionID connectionID)
{
std::lock_guard<std::mutex> ulock(m_isBusyMutex);
*/
void UnsetBusy();
+ bool PluginEnabled();
+
+ int HandleNotSupported(Event &&msg);
+
SocketManager *m_serviceManager = nullptr;
bool m_isBusy = false;
std::mutex m_isBusyMutex;
SET(UNIT_TESTS_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/unittests.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test-common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/webauthn-client-test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/client-request-test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/file-lock-test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/serialization-test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dl-loader-test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/socket-manager-test.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test-common.cpp
${PRJ_SRC_SERVER_PATH}/dl-loader.cpp
${PRJ_SRC_SERVER_PATH}/service.cpp
public:
explicit TestDLLoader ()
{
- try{
- DLLoader("");
- }catch (...) {}
+ DLLoader("");
+ SetLibraryEnabled(true);
}
+
void* ResolveFunction(const std::string &name) noexcept override
{
if (name == WAH_API_MC)
}
};
+TEST_F(ClientRequestTest, request_to_not_supported_server_N)
+{
+ int ret = 1;
+ WA::SocketManager manager;
+ try{
+ auto service = std::make_unique<WA::TestService>(std::make_shared<DLLoader>(""));
+ manager.RegisterSocketService(std::move(service));
+ SocketManagerLoop loop(manager);
+ {
+ int retVal = WAUTHN_ERROR_NONE;
+ wauthn_mc_callbacks_s *callbacks = nullptr;
+ callbacks = (wauthn_mc_callbacks_s*) calloc(1, sizeof(wauthn_mc_callbacks_s));
+ callbacks->qrcode_callback = test_cb_display_qrcode;
+ callbacks->response_callback = test_cb_mc_response;
+ test_user_data_s *userdata = (test_user_data_s*) calloc(1, sizeof(test_user_data_s));
+ userdata->test_data = (char*)("user data");
+ userdata->test_int = 999;
+ callbacks->user_data = userdata;
+ retVal = wauthn_process<TestClientRequestMC>(&TestCommonData::clientData,
+ &TestCommonData::pubkeyCredCreationOptions, callbacks);
+
+ EXPECT_EQ(retVal, WAUTHN_ERROR_NOT_SUPPORTED)
+ << "[wauthn_process<TestClientRequestMC>] failed. "
+ << "retVal=" << wauthn_error_to_string(ret) << std::endl;
+ sleep(1);
+ free(userdata);
+ free(callbacks);
+ }
+ sleep(1);
+ ret = 0;
+ } catch (...) {
+ std::cout << "Error in starting service, unknown exception occured" << std::endl;
+ ret = -1;
+ }
+ EXPECT_EQ(ret, 0);
+}
TEST_F(ClientRequestTest, MC_without_QR_callback_P)
{
auto service = std::make_unique<WA::TestService>(std::make_shared<TestDLLoader>());
manager.RegisterSocketService(std::move(service));
SocketManagerLoop loop(manager);
-
{
int retVal = WAUTHN_ERROR_NONE;
wauthn_mc_callbacks_s *callbacks = nullptr;
auto service = std::make_unique<WA::TestService>(std::make_shared<TestDLLoader>());
manager.RegisterSocketService(std::move(service));
SocketManagerLoop loop(manager);
-
{
int retVal = WAUTHN_ERROR_NONE;
wauthn_mc_callbacks_s *callbacks = nullptr;
auto service = std::make_unique<WA::TestService>(std::make_shared<TestDLLoader>());
manager.RegisterSocketService(std::move(service));
SocketManagerLoop loop(manager);
-
{
int retVal = WAUTHN_ERROR_NONE;
wauthn_ga_callbacks_s *callbacks = nullptr;
auto service = std::make_unique<WA::TestService>(std::make_shared<TestDLLoader>());
manager.RegisterSocketService(std::move(service));
SocketManagerLoop loop(manager);
-
{
int retVal = WAUTHN_ERROR_NONE;
wauthn_ga_callbacks_s *callbacks = nullptr;
auto service = std::make_unique<WA::TestService>(std::make_shared<TestDLLoader>());
manager.RegisterSocketService(std::move(service));
SocketManagerLoop loop(manager);
-
{
int retVal = WAUTHN_ERROR_NONE;
wauthn_mc_callbacks_s *mc_callbacks = nullptr;
auto service = std::make_unique<WA::TestService>(std::make_shared<TestDLLoader>());
manager.RegisterSocketService(std::move(service));
SocketManagerLoop loop(manager);
-
{
int retVal = WAUTHN_ERROR_NONE;
wauthn_mc_callbacks_s *mc_callbacks = nullptr;
int ret = 0;
try{
auto dlLoader = std::make_unique<DLLoader>(WAH_PLUGIN_SO_PATH_HYBRID);
+ EXPECT_EQ(dlLoader->LibraryEnabled(), true);
} catch (...)
{
ret = -1;
EXPECT_EQ(ret, 0);
}
-TEST_F(DLLoaderTest, DLLoader_N)
+TEST_F(DLLoaderTest, DLLoader_empty_path_N)
{
int ret = 0;
try{
- auto dlLoader = std::make_unique<DLLoader>("invalid_so_path");
- } catch (const ServiceException::InvalidSharedLib &e)
+ auto dlLoader = std::make_unique<DLLoader>("");
+ EXPECT_EQ(dlLoader->LibraryEnabled(), false);
+ } catch (...)
{
ret = -1;
+ }
+
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(DLLoaderTest, DLLoader_invalid_path_N)
+{
+ int ret = 0;
+ try{
+ auto dlLoader = std::make_unique<DLLoader>("invalid_so_path");
+ EXPECT_EQ(dlLoader->LibraryEnabled(), false);
} catch (...)
{
- ret = -2;
+ ret = -1;
}
- EXPECT_EQ(ret, -1);
+ EXPECT_EQ(ret, 0);
}
TEST_F(DLLoaderTest, Invoke_P)
int ret = 0;
try{
auto dlLoader = std::make_unique<DLLoader>(WAH_PLUGIN_SO_PATH_HYBRID);
+ EXPECT_EQ(dlLoader->LibraryEnabled(), true);
dlLoader->Invoke<int>(WAH_API_CANCEL);
} catch (...)
{
int ret = 0;
try{
auto dlLoader = std::make_unique<DLLoader>(WAH_PLUGIN_SO_PATH_HYBRID);
+ EXPECT_EQ(dlLoader->LibraryEnabled(), true);
dlLoader->Invoke<int>("invalid_api_name");
} catch (const ServiceException::InvalidSharedLib &e)
{
int ret = 1;
WA::SocketManager manager;
try{
- auto service = std::make_unique<WA::TestService>(std::make_shared<DLLoader>(WAH_PLUGIN_SO_PATH_HYBRID));
+ auto service = std::make_unique<WA::TestService>(
+ std::make_shared<DLLoader>(WAH_PLUGIN_SO_PATH_HYBRID));
manager.RegisterSocketService(std::move(service));
SocketManagerLoop loop(manager);
sleep(1);