#include #include #include #include "core_response_generator.hpp" #include "pam_info_mock.hpp" using namespace rublon; using namespace testing; namespace { Configuration conf; } class CoreHandlerMock : public CoreHandlerInterface< CoreHandlerMock > { public: CoreHandlerMock() {} MOCK_METHOD(( tl::expected< Document, Error > ), request, ( std::string_view, const Document & ), (const)); CoreHandlerMock & statusPending() { gen.status = "pending"; return *this; } CoreHandlerMock & brokenBody() { gen.generateBrokenData = true; return *this; } CoreHandlerMock & methods(std::initializer_list< std::string > methods) { gen.withMethods(methods); return *this; } CoreHandlerMock & tid(std::string tid) { gen.withTid(tid); return *this; } operator tl::expected< Document, Error >() { auto body = gen.generateBody(); rublon::Document doc; doc.Parse(body.c_str()); return doc; } auto create() { return static_cast< tl::expected< Document, Error > >(*this); } CoreResponseGenerator gen; }; class MethodFactoryMock { public: using MethodFactoryCreate_t = tl::expected< MethodProxy, Error >; template < typename... Args > MethodFactoryMock(Args &&...) {} MOCK_METHOD(MethodFactoryCreate_t, create, (const mocks::PamInfoMock &, std::string tid), (const)); }; class RublonHttpInitTest : public testing::Test { public: void expectDefaultPamInfo() { EXPECT_CALL(pam, ip()).WillOnce(Return("192.168.0.1")); EXPECT_CALL(pam, username()).WillOnce(Return("bwi")); } RublonHttpInitTest() : coreHandler{}, pam{}, sut{conf} { expectDefaultPamInfo(); } CoreHandlerMock coreHandler; mocks::PamInfoMock pam; Init< MethodFactoryMock > sut; // MethodFactoryMock &methodFactoryMock; }; using CoreReturn = tl::expected< Document, CoreHandlerError >; TEST_F(RublonHttpInitTest, initializationSendsRequestOnGoodPath) { EXPECT_CALL(coreHandler, request("/api/transaction/init", _)) .WillOnce(Return(tl::unexpected{CoreHandlerError{CoreHandlerError::BadSigature}})); sut.handle(coreHandler, pam); } /// TODO fix //MATCHER_P(HoldsPamAction, action, "") { // return not arg.has_value() && arg.error() == action; //} //TEST_F(RublonHttpInitTest, rublon_Accept_pamLoginWhenThereIsNoConnection) { // EXPECT_CALL(coreHandler, request(_, _)).WillOnce(Return(tl::unexpected{CoreHandlerError{CoreHandlerError::ConnectionError}})); // EXPECT_THAT(sut.handle(coreHandler, pam), HoldsPamAction(PamAction::decline)); //} //TEST_F(RublonHttpInitTest, rublon_Decline_pamLoginWhenServerHasBadSignature) { // EXPECT_CALL(coreHandler, request(_, _)).WillOnce(Return(tl::unexpected{CoreHandlerError{CoreHandlerError::BadSigature}})); // EXPECT_THAT(sut.handle(coreHandler, pam), HoldsPamAction(PamAction::decline)); //} //TEST_F(RublonHttpInitTest, rublon_Decline_pamLoginWhenServerReturnsBrokenData) { // EXPECT_CALL(coreHandler, request(_, _)).WillOnce(Return(tl::unexpected{CoreHandlerError{CoreHandlerError::BrokenData}})); // EXPECT_THAT(sut.handle(coreHandler, pam), HoldsPamAction(PamAction::decline)); //} //TEST_F(RublonHttpInitTest, rublon_Decline_pamLoginWhenServerReturnsCoreException) { // EXPECT_CALL(coreHandler, request(_, _)).WillOnce(Return(tl::unexpected{CoreHandlerError{CoreHandlerError::CoreException}})); // EXPECT_THAT(sut.handle(coreHandler, pam), HoldsPamAction(PamAction::decline)); //} //TEST_F(RublonHttpInitTest, AllNeededInformationNeedsToBePassedToMethodFactory) { // EXPECT_CALL(coreHandler, request(_, _)) // .WillOnce(Return(coreHandler.statusPending().methods({"sms", "otp"}).tid("transaction ID").create())); // // EXPECT_CALL(methodFactoryMock, create_mocked(_,"transaction ID") ); // sut.handle(coreHandler, pam); //}