Skip to content

Commit

Permalink
[iam] Implement CertReceiver subscription in ProvisionManager
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Kobets <[email protected]>
  • Loading branch information
mykola-kobets-epam committed Oct 3, 2024
1 parent 21cb940 commit 587e954
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
34 changes: 34 additions & 0 deletions include/aos/iam/provisionmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ class ProvisionManagerItf {
certhandler::CertInfo& resCert)
= 0;

/**
* Subscribes certificates receiver.
*
* @param certType certificate type.
* @param certReceiver certificate receiver.
* @returns Error.
*/
virtual Error SubscribeCertReceiver(const String& certType, certhandler::CertReceiverItf& certReceiver) = 0;

/**
* Unsubscribes certificate receiver.
*
* @param certReceiver certificate receiver.
* @returns Error.
*/
virtual Error UnsubscribeCertReceiver(certhandler::CertReceiverItf& certReceiver) = 0;

/**
* Finishes provisioning.
*
Expand Down Expand Up @@ -204,6 +221,23 @@ class ProvisionManager : public ProvisionManagerItf {
Error GetCert(const String& certType, const Array<uint8_t>& issuer, const Array<uint8_t>& serial,
certhandler::CertInfo& resCert) override;

/**
* Subscribes certificates receiver.
*
* @param certType certificate type.
* @param certReceiver certificate receiver.
* @returns Error.
*/
Error SubscribeCertReceiver(const String& certType, certhandler::CertReceiverItf& certReceiver) override;

/**
* Unsubscribes certificate receiver.
*
* @param certReceiver certificate receiver.
* @returns Error.
*/
Error UnsubscribeCertReceiver(certhandler::CertReceiverItf& certReceiver) override;

/**
* Finishes provisioning.
*
Expand Down
14 changes: 14 additions & 0 deletions src/iam/provisionmanager/provisionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,18 @@ Error ProvisionManager::GetCert(
return AOS_ERROR_WRAP(mCertHandler->GetCertificate(certType, issuer, serial, resCert));
}

Error ProvisionManager::SubscribeCertReceiver(const String& certType, certhandler::CertReceiverItf& certReceiver)
{
LOG_DBG() << "Subscribe cert receiver: type = " << certType;

return AOS_ERROR_WRAP(mCertHandler->SubscribeCertReceiver(certType, certReceiver));
}

Error ProvisionManager::UnsubscribeCertReceiver(certhandler::CertReceiverItf& certReceiver)
{
LOG_DBG() << "Unsubscribe cert receiver";

return AOS_ERROR_WRAP(mCertHandler->UnsubscribeCertReceiver(certReceiver));
}

} // namespace aos::iam::provisionmanager
14 changes: 14 additions & 0 deletions tests/iam/provisionmanager/provisionmanager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <aos/iam/provisionmanager.hpp>

#include "mocks/certhandlermock.hpp"
#include "mocks/certreceivermock.hpp"
#include "mocks/provisioningcallbackmock.hpp"

using namespace testing;
Expand Down Expand Up @@ -293,6 +294,19 @@ TEST_F(ProvisionManagerTest, GetCert)
EXPECT_EQ(result, certInfo);
}

TEST_F(ProvisionManagerTest, SubscribeCertReceiver)
{
const aos::String certType = "iam";

CertReceiverItfMock certReceiver;

EXPECT_CALL(mCertHandler, SubscribeCertReceiver(certType, _)).WillOnce(Return(aos::ErrorEnum::eNone));
ASSERT_TRUE(mProvisionManager.SubscribeCertReceiver(certType, certReceiver).IsNone());

EXPECT_CALL(mCertHandler, UnsubscribeCertReceiver(Ref(certReceiver))).WillOnce(Return(aos::ErrorEnum::eNone));
ASSERT_TRUE(mProvisionManager.UnsubscribeCertReceiver(certReceiver).IsNone());
}

TEST_F(ProvisionManagerTest, Deprovision)
{
EXPECT_CALL(mCallback, OnDeprovision).WillOnce(Return(aos::ErrorEnum::eNone));
Expand Down

0 comments on commit 587e954

Please sign in to comment.