Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/iam/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@
err = InitIdentifierModule(config.mValue.mIdentifier);
AOS_ERROR_CHECK_AND_THROW(err, "can't initialize identifier module");

if (config.mValue.mEnablePermissionsHandler) {
mPermHandler = std::make_unique<permhandler::PermHandler>();
}

err = mCryptoProvider.Init();
AOS_ERROR_CHECK_AND_THROW(err, "can't initialize crypto provider");

Expand All @@ -254,6 +250,13 @@
err = InitCertModules(config.mValue);
AOS_ERROR_CHECK_AND_THROW(err, "can't initialize cert modules");

if (config.mValue.mEnablePermissionsHandler) {
mPermHandler = std::make_unique<permhandler::PermHandler>();

Check warning on line 254 in src/iam/app/app.cpp

View check run for this annotation

Codecov / codecov/patch

src/iam/app/app.cpp#L254

Added line #L254 was not covered by tests

err = mPermHandler->Init(mCryptoProvider);
AOS_ERROR_CHECK_AND_THROW(err, "can't initialize permissions handler");

Check warning on line 257 in src/iam/app/app.cpp

View check run for this annotation

Codecov / codecov/patch

src/iam/app/app.cpp#L256-L257

Added lines #L256 - L257 were not covered by tests
}

err = mNodeManager.Init(mDatabase);
AOS_ERROR_CHECK_AND_THROW(err, "can't initialize node manager");

Expand Down Expand Up @@ -459,7 +462,7 @@
} else if (config.mPlugin == "visidentifier") {
auto visIdentifier = std::make_unique<visidentifier::VISIdentifier>();

if (auto err = visIdentifier->Init(config, mIAMServer); !err.IsNone()) {
if (auto err = visIdentifier->Init(config, mIAMServer, mCryptoProvider); !err.IsNone()) {
return err;
}

Expand Down
10 changes: 8 additions & 2 deletions src/iam/identhandler/visidentifier/pocowsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
* Public
**********************************************************************************************************************/

PocoWSClient::PocoWSClient(const aos::iam::config::VISIdentifierModuleParams& config, MessageHandlerFunc handler)
PocoWSClient::PocoWSClient(const aos::iam::config::VISIdentifierModuleParams& config, crypto::UUIDItf& uuidProvider,
MessageHandlerFunc handler)
: mConfig(config)
, mUUIDProvider(&uuidProvider)
, mHandleSubscription(std::move(handler))
{
mHttpRequest.setMethod(Poco::Net::HTTPRequest::HTTP_GET);
Expand Down Expand Up @@ -122,7 +124,11 @@

std::string PocoWSClient::GenerateRequestID()
{
const auto uuid = aos::uuid::CreateUUID();
auto [uuid, err] = mUUIDProvider->CreateUUIDv4();
if (!err.IsNone()) {
throw WSException("Failed to generate UUID", AOS_ERROR_WRAP(ErrorEnum::eFailed));

Check warning on line 129 in src/iam/identhandler/visidentifier/pocowsclient.cpp

View check run for this annotation

Codecov / codecov/patch

src/iam/identhandler/visidentifier/pocowsclient.cpp#L129

Added line #L129 was not covered by tests
}

const auto uuidStr = aos::uuid::UUIDToString(uuid);

return {uuidStr.begin(), uuidStr.end()};
Expand Down
9 changes: 7 additions & 2 deletions src/iam/identhandler/visidentifier/pocowsclient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <Poco/Net/HTTPSClientSession.h>
#include <Poco/Net/WebSocket.h>

#include <aos/common/crypto/crypto.hpp>

#include <iam/config/config.hpp>
#include <iam/identhandler/visidentifier/wsclient.hpp>

Expand All @@ -37,9 +39,11 @@ class PocoWSClient : public WSClientItf {
* Creates Web socket client instance.
*
* @param config VIS config.
* @param uuidProvider UUID provider.
* @param handler handler functor.
*/
PocoWSClient(const aos::iam::config::VISIdentifierModuleParams& config, MessageHandlerFunc handler);
PocoWSClient(const aos::iam::config::VISIdentifierModuleParams& config, crypto::UUIDItf& uuidProvider,
MessageHandlerFunc handler);

/**
* Connects to Web Socket server.
Expand Down Expand Up @@ -100,7 +104,8 @@ class PocoWSClient : public WSClientItf {
void StopReceiveFramesThread();
Duration GetWebSocketTimeout();

aos::iam::config::VISIdentifierModuleParams mConfig;
config::VISIdentifierModuleParams mConfig;
crypto::UUIDItf* mUUIDProvider {};
std::recursive_mutex mMutex;
std::thread mReceivedFramesThread;
std::unique_ptr<Poco::Net::HTTPSClientSession> mClientSession;
Expand Down
16 changes: 11 additions & 5 deletions src/iam/identhandler/visidentifier/tests/pocowsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <gmock/gmock.h>

#include <aos/common/crypto/cryptoprovider.hpp>
#include <mocks/identhandlermock.hpp>

#include <common/logger/logger.hpp>
Expand Down Expand Up @@ -59,7 +60,11 @@ class PocoWSClientTests : public Test {

void SetUp() override
{
ASSERT_NO_THROW(mWsClientPtr = std::make_shared<PocoWSClient>(cConfig, WSClientItf::MessageHandlerFunc()));
mCryptoProvider = std::make_unique<crypto::DefaultCryptoProvider>();
ASSERT_TRUE(mCryptoProvider->Init().IsNone()) << "Failed to initialize crypto provider";

ASSERT_NO_THROW(mWsClientPtr
= std::make_shared<PocoWSClient>(cConfig, *mCryptoProvider, WSClientItf::MessageHandlerFunc()));
}

// This method is called before any test cases in the test suite
Expand All @@ -85,7 +90,8 @@ class PocoWSClientTests : public Test {
Poco::Net::uninitializeSSL();
}

std::shared_ptr<PocoWSClient> mWsClientPtr;
std::unique_ptr<crypto::DefaultCryptoProvider> mCryptoProvider;
std::shared_ptr<PocoWSClient> mWsClientPtr;
};

const config::VISIdentifierModuleParams PocoWSClientTests::cConfig {cWebSocketURI, cClientCertPath, 5 * Time::cSeconds};
Expand Down Expand Up @@ -170,7 +176,7 @@ TEST_F(PocoWSClientTests, VisidentifierGetSystemID)

iam::identhandler::SubjectsObserverMock observer;

ASSERT_TRUE(visIdentifier.Init(config, observer).IsNone());
ASSERT_TRUE(visIdentifier.Init(config, observer, *mCryptoProvider).IsNone());
ASSERT_TRUE(visIdentifier.Start().IsNone());

const std::string expectedSystemId {"test-system-id"};
Expand All @@ -191,7 +197,7 @@ TEST_F(PocoWSClientTests, VisidentifierGetUnitModel)

iam::identhandler::SubjectsObserverMock observer;

ASSERT_TRUE(visIdentifier.Init(config, observer).IsNone());
ASSERT_TRUE(visIdentifier.Init(config, observer, *mCryptoProvider).IsNone());
ASSERT_TRUE(visIdentifier.Start().IsNone());

const std::string expectedUnitModel {"test-unit-model"};
Expand All @@ -212,7 +218,7 @@ TEST_F(PocoWSClientTests, VisidentifierGetSubjects)

iam::identhandler::SubjectsObserverMock observer;

ASSERT_TRUE(visIdentifier.Init(config, observer).IsNone());
ASSERT_TRUE(visIdentifier.Init(config, observer, *mCryptoProvider).IsNone());
ASSERT_TRUE(visIdentifier.Start().IsNone());

const std::vector<std::string> testSubjects {"1", "2", "3"};
Expand Down
21 changes: 13 additions & 8 deletions src/iam/identhandler/visidentifier/tests/visidentifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <gmock/gmock.h>

#include <aos/common/crypto/cryptoprovider.hpp>
#include <mocks/identhandlermock.hpp>

#include <common/logger/logger.hpp>
Expand Down Expand Up @@ -49,11 +50,12 @@ class VisidentifierTest : public testing::Test {
const std::string cTestSubscriptionId {"1234-4321"};
const config::VISIdentifierModuleParams cVISConfig {"vis-service", "ca-path", 1};

WSClientEvent mWSClientEvent;
iam::identhandler::SubjectsObserverMock mVISSubjectsObserverMock;
WSClientMockPtr mWSClientItfMockPtr {std::make_shared<StrictMock<WSClientMock>>()};
TestVISIdentifier mVisIdentifier;
config::IdentifierConfig mConfig;
WSClientEvent mWSClientEvent;
iam::identhandler::SubjectsObserverMock mVISSubjectsObserverMock;
std::unique_ptr<crypto::DefaultCryptoProvider> mCryptoProvider;
WSClientMockPtr mWSClientItfMockPtr {std::make_shared<StrictMock<WSClientMock>>()};
TestVISIdentifier mVisIdentifier;
config::IdentifierConfig mConfig;

// This method is called before any test cases in the test suite
static void SetUpTestSuite()
Expand All @@ -76,6 +78,9 @@ class VisidentifierTest : public testing::Test {
mConfig.mParams = object;

mVisIdentifier.SetWSClient(mWSClientItfMockPtr);

mCryptoProvider = std::make_unique<crypto::DefaultCryptoProvider>();
ASSERT_TRUE(mCryptoProvider->Init().IsNone()) << "Failed to initialize crypto provider";
}

void ExpectStopSucceeded()
Expand Down Expand Up @@ -127,7 +132,7 @@ class VisidentifierTest : public testing::Test {
EXPECT_CALL(mVisIdentifier, InitWSClient).WillOnce(Return(ErrorEnum::eNone));
EXPECT_CALL(*mWSClientItfMockPtr, WaitForEvent).WillOnce(Invoke([this]() { return mWSClientEvent.Wait(); }));

ASSERT_TRUE(mVisIdentifier.Init(mConfig, mVISSubjectsObserverMock).IsNone());
ASSERT_TRUE(mVisIdentifier.Init(mConfig, mVISSubjectsObserverMock, *mCryptoProvider).IsNone());

ASSERT_TRUE(mVisIdentifier.Start().IsNone());

Expand Down Expand Up @@ -158,7 +163,7 @@ class VisidentifierTest : public testing::Test {
TEST_F(VisidentifierTest, InitFailsOnEmptyConfig)
{
VISIdentifier identifier;
ASSERT_TRUE(identifier.Init(config::IdentifierConfig {}, mVISSubjectsObserverMock).IsNone());
ASSERT_TRUE(identifier.Init(config::IdentifierConfig {}, mVISSubjectsObserverMock, *mCryptoProvider).IsNone());

EXPECT_FALSE(identifier.Start().IsNone());
}
Expand Down Expand Up @@ -294,7 +299,7 @@ TEST_F(VisidentifierTest, ReconnectOnFailSendFrame)
return {str.cbegin(), str.cend()};
}));

EXPECT_TRUE(mVisIdentifier.Init(mConfig, mVISSubjectsObserverMock).IsNone());
EXPECT_TRUE(mVisIdentifier.Init(mConfig, mVISSubjectsObserverMock, *mCryptoProvider).IsNone());
EXPECT_TRUE(mVisIdentifier.Start().IsNone());

mVisIdentifier.WaitUntilConnected();
Expand Down
10 changes: 6 additions & 4 deletions src/iam/identhandler/visidentifier/visidentifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ VISIdentifier::VISIdentifier()
{
}

Error VISIdentifier::Init(
const config::IdentifierConfig& config, aos::iam::identhandler::SubjectsObserverItf& subjectsObserver)
Error VISIdentifier::Init(const config::IdentifierConfig& config, identhandler::SubjectsObserverItf& subjectsObserver,
crypto::UUIDItf& uuidProvider)
{
LOG_DBG() << "Initializing VIS identifier";

mSubjectsObserver = &subjectsObserver;
mConfig = config;
mSubjectsObserver = &subjectsObserver;
mUUIDProvider = &uuidProvider;

return ErrorEnum::eNone;
}
Expand Down Expand Up @@ -213,7 +215,7 @@ Error VISIdentifier::InitWSClient(const config::IdentifierConfig& config)
}

mWsClientPtr = std::make_shared<PocoWSClient>(
visParams, std::bind(&VISIdentifier::HandleSubscription, this, std::placeholders::_1));
visParams, *mUUIDProvider, std::bind(&VISIdentifier::HandleSubscription, this, std::placeholders::_1));
} catch (const std::exception& e) {
LOG_ERR() << "Failed to create WS client: error = " << e.what();

Expand Down
7 changes: 5 additions & 2 deletions src/iam/identhandler/visidentifier/visidentifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ class VISIdentifier : public iam::identhandler::IdentHandlerItf {
*
* @param config identifier config.
* @param subjectsObserver subject observer.
* @param uuidProvider UUID provider.
* @return Error.
*/
Error Init(const config::IdentifierConfig& config, iam::identhandler::SubjectsObserverItf& subjectsObserver);
Error Init(const config::IdentifierConfig& config, identhandler::SubjectsObserverItf& subjectsObserver,
crypto::UUIDItf& uuidProvider);

/**
* Starts vis identifier.
Expand Down Expand Up @@ -132,7 +134,8 @@ class VISIdentifier : public iam::identhandler::IdentHandlerItf {
std::vector<std::string> GetValueArrayByPath(Poco::Dynamic::Var object, const std::string& valueChildTagName);

std::shared_ptr<WSClientItf> mWsClientPtr;
iam::identhandler::SubjectsObserverItf* mSubjectsObserver = nullptr;
identhandler::SubjectsObserverItf* mSubjectsObserver = nullptr;
crypto::UUIDItf* mUUIDProvider = nullptr;
VISSubscriptions mSubscriptions;
StaticString<cSystemIDLen> mSystemId;
StaticString<cUnitModelLen> mUnitModel;
Expand Down
2 changes: 1 addition & 1 deletion src/sm/app/aoscore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@

err = mLauncher.Init(mConfig.mLauncherConfig, mIAMClientPublic, mServiceManager, mLayerManager, mResourceManager,
mNetworkManager, mIAMClientPermissions, mRunner, mRuntime, mResourceMonitor, mOCISpec, mSMClient, mSMClient,
mDatabase);
mDatabase, mCryptoProvider);

Check warning on line 145 in src/sm/app/aoscore.cpp

View check run for this annotation

Codecov / codecov/patch

src/sm/app/aoscore.cpp#L145

Added line #L145 was not covered by tests
AOS_ERROR_CHECK_AND_THROW(err, "can't initialize launcher");

// Initialize SM client
Expand Down
Loading