diff --git a/lib/api/AuthTokensController.cpp b/lib/api/AuthTokensController.cpp index b7f49880..409ddf31 100644 --- a/lib/api/AuthTokensController.cpp +++ b/lib/api/AuthTokensController.cpp @@ -38,6 +38,14 @@ EVTStatus AuthTokensController::SetTicketToken(TicketType type, char const* tok return EVTStatus::EVTStatus_Fail; } +EVTStatus AuthTokensController::Clear() +{ + m_deviceTokens.clear(); + m_userTokens.clear(); + m_tickets.clear(); + return EVTStatus::EVTStatus_OK; +} + std::vector& AuthTokensController::GetTickets() { return m_tickets; diff --git a/lib/api/AuthTokensController.hpp b/lib/api/AuthTokensController.hpp index a730904f..40db3119 100644 --- a/lib/api/AuthTokensController.hpp +++ b/lib/api/AuthTokensController.hpp @@ -33,6 +33,11 @@ class AuthTokensController : public IAuthTokensController /// Ticketvalue virtual EVTStatus SetTicketToken(TicketType type, char const* tokenValue); + /// + /// Clears all tokens. + /// + virtual EVTStatus Clear(); + /// /// Set the Auth ticket. /// diff --git a/lib/api/CommonLogManagerInternal.cpp b/lib/api/CommonLogManagerInternal.cpp index f77287f9..15951a67 100644 --- a/lib/api/CommonLogManagerInternal.cpp +++ b/lib/api/CommonLogManagerInternal.cpp @@ -21,7 +21,7 @@ namespace Microsoft { LogSessionData* our_LogSessionDataP = nullptr; bool our_IsRuningasHost = false; LogConfiguration* our_LogConfiguration = new LogConfiguration(); - AuthTokensController* our_AuthTokenControllerP = nullptr; + AuthTokensController* our_AuthTokenControllerP = new AuthTokensController();; bool CommonLogManagerInternal::IsInitialized() { @@ -41,6 +41,13 @@ namespace Microsoft { return false; } + void call_from_STD_thread(ILogManagerInternal* old_pLogManagerSingletonInstanceP) + { + old_pLogManagerSingletonInstanceP->FlushAndTeardown(); + delete old_pLogManagerSingletonInstanceP; + } + + EVTStatus CommonLogManagerInternal::Initialize( LogConfiguration* logConfigurationP, bool wantController) { ARIASDK_LOG_DETAIL("Initialize[1]:configuration=0x%X", logConfigurationP); @@ -65,8 +72,7 @@ namespace Microsoft { EVTStatus error; our_LogSessionDataP = new LogSessionData(our_LogConfiguration->GetProperty(CFG_STR_CACHE_FILE_PATH, error)); } - - our_AuthTokenControllerP = new AuthTokensController(); + if (wantController & !our_IsRuningasHost) { our_IsRuningasHost = true; @@ -90,11 +96,9 @@ namespace Microsoft { ::ResetEvent(syncEvent); if (nullptr != our_pLogManagerSingletonInstanceP) { - ILogManagerInternal* temp = ILogManagerInternal::Create(*our_LogConfiguration, nullptr); - our_pLogManagerSingletonInstanceP->FlushAndTeardown(); - delete our_pLogManagerSingletonInstanceP; - our_pLogManagerSingletonInstanceP = temp; - + ILogManagerInternal* temp = our_pLogManagerSingletonInstanceP; + std::thread(call_from_STD_thread, temp); + our_pLogManagerSingletonInstanceP = ILogManagerInternal::Create(*our_LogConfiguration, nullptr); ::SetEvent(syncEvent); } } @@ -158,7 +162,7 @@ namespace Microsoft { if (our_AuthTokenControllerP) { - delete our_AuthTokenControllerP; + our_AuthTokenControllerP->Clear(); } if (our_LogConfiguration) { diff --git a/lib/include/public/IAuthTokensController.hpp b/lib/include/public/IAuthTokensController.hpp index fd4ce665..b98ae40e 100644 --- a/lib/include/public/IAuthTokensController.hpp +++ b/lib/include/public/IAuthTokensController.hpp @@ -26,6 +26,11 @@ namespace Microsoft { namespace Applications { namespace Events { /// Ticketvalue virtual EVTStatus SetTicketToken(TicketType type, char const* tokenValue) = 0; + /// + /// clears all tokens. + /// + virtual EVTStatus Clear() = 0; + }; diff --git a/tests/common/MockISqlite3Proxy.hpp b/tests/common/MockISqlite3Proxy.hpp index 89d30181..5d9bd2a4 100644 --- a/tests/common/MockISqlite3Proxy.hpp +++ b/tests/common/MockISqlite3Proxy.hpp @@ -41,6 +41,7 @@ class MockISqlite3Proxy : public ARIASDK_NS::ISqlite3Proxy { MOCK_METHOD0(sqlite3_shutdown, int()); MOCK_METHOD1(sqlite3_step, int(sqlite3_stmt * stmt)); MOCK_METHOD1(sqlite3_value_blob, void const*(sqlite3_value * value)); + MOCK_METHOD1(sqlite3_soft_heap_limit64, int64_t(int64_t N)); MOCK_METHOD1(sqlite3_value_bytes, int(sqlite3_value * value)); MOCK_METHOD1(sqlite3_vfs_find, sqlite3_vfs * (char const* zVfsName)); }; diff --git a/tests/functests/BasicFuncTests.cpp b/tests/functests/BasicFuncTests.cpp index 468d8c95..a6cef38b 100644 --- a/tests/functests/BasicFuncTests.cpp +++ b/tests/functests/BasicFuncTests.cpp @@ -138,14 +138,8 @@ class BasicFuncTests : public ::testing::Test, for (size_t index = 0; index < size; index++) { auto request = receivedRequests.at(index); - auto payload = decodeRequestNoCheck(request, false); - for (auto package : payload.TokenToDataPackagesMap) - { - for (auto pack : package.second) - { - receivedEvnetsLocal = receivedEvnetsLocal + (unsigned)pack.Records.size(); - } - } + auto payload = decodeRequest(request, false); + receivedEvnetsLocal = receivedEvnetsLocal + (unsigned)payload.size(); } receivedEvnets = receivedEvnetsLocal; } @@ -213,7 +207,7 @@ class BasicFuncTests : public ::testing::Test, int64_t now = PAL::getUtcSystemTimeinTicks(); EXPECT_THAT(actual.time, Gt(now - 60000000000)); EXPECT_THAT(actual.time, Le(now)); - EXPECT_THAT(actual.baseType, expected.GetName()); + EXPECT_THAT(actual.name, expected.GetName()); for (std::pair prop : expected.GetProperties()) { if (prop.second.piiKind == PiiKind_None) diff --git a/tests/unittests/HttpClientManagerTests.cpp b/tests/unittests/HttpClientManagerTests.cpp index ea106881..7ce71024 100644 --- a/tests/unittests/HttpClientManagerTests.cpp +++ b/tests/unittests/HttpClientManagerTests.cpp @@ -41,17 +41,17 @@ class HttpClientManagerTests : public StrictMock { TEST_F(HttpClientManagerTests, HandlesRequestFlow) { - std::unique_ptr req(new SimpleHttpRequest("HttpClientManagerTests")); + SimpleHttpRequest* req = new SimpleHttpRequest("HttpClientManagerTests"); auto ctx = EventsUploadContext::create(); ctx->httpRequestId = req->GetId(); - ctx->httpRequest = std::move(req); + ctx->httpRequest = req; ctx->recordIdsAndTenantIds["r1"] = "t1"; ctx->recordIdsAndTenantIds["r2"] = "t1"; ctx->latency = EventLatency_Normal; ctx->packageIds["tenant1-token"] = 0; IHttpResponseCallback* callback = nullptr; - EXPECT_CALL(httpClientMock, SendRequestAsync(ctx->httpRequest.get(), _)) + EXPECT_CALL(httpClientMock, SendRequestAsync(ctx->httpRequest, _)) .WillOnce(SaveArg<1>(&callback)); hcm.sendRequest(ctx); ASSERT_THAT(callback, NotNull()); @@ -64,26 +64,26 @@ TEST_F(HttpClientManagerTests, HandlesRequestFlow) EXPECT_CALL(*this, resultRequestDone(ctx)) .WillOnce(Return()); - IHttpResponse const* rspRef = rsp.get(); + IHttpResponse* rspRef = rsp.get(); callback->OnHttpResponse(rsp.release()); - EXPECT_THAT(ctx->httpResponse.get(), rspRef); + EXPECT_THAT(ctx->httpResponse, rspRef); EXPECT_THAT(ctx->durationMs, Gt(199)); } TEST_F(HttpClientManagerTests, CancelAbortsRequests) { - std::unique_ptr req(new SimpleHttpRequest("HttpClientManagerTests")); + SimpleHttpRequest* req = new SimpleHttpRequest("HttpClientManagerTests"); auto ctx = EventsUploadContext::create(); ctx->httpRequestId = req->GetId(); - ctx->httpRequest = std::move(req); + ctx->httpRequest = req; ctx->recordIdsAndTenantIds["r1"] = "t1"; ctx->recordIdsAndTenantIds["r2"] = "t1"; ctx->latency = EventLatency_Normal; ctx->packageIds["tenant1-token"] = 0; IHttpResponseCallback* callback = nullptr; - EXPECT_CALL(httpClientMock, SendRequestAsync(ctx->httpRequest.get(), _)) + EXPECT_CALL(httpClientMock, SendRequestAsync(ctx->httpRequest, _)) .WillOnce(SaveArg<1>(&callback)); hcm.sendRequest(ctx); ASSERT_THAT(callback, NotNull()); @@ -97,8 +97,8 @@ TEST_F(HttpClientManagerTests, CancelAbortsRequests) EXPECT_CALL(*this, resultRequestDone(ctx)) .WillOnce(Return()); - IHttpResponse const* rspRef = rsp.get(); + IHttpResponse* rspRef = rsp.get(); callback->OnHttpResponse(rsp.release()); - EXPECT_THAT(ctx->httpResponse.get(), rspRef); + EXPECT_THAT(ctx->httpResponse, rspRef); } diff --git a/tests/unittests/HttpClientTests.cpp b/tests/unittests/HttpClientTests.cpp index deb1bef0..a12ba56b 100644 --- a/tests/unittests/HttpClientTests.cpp +++ b/tests/unittests/HttpClientTests.cpp @@ -93,7 +93,7 @@ class HttpClientTests : public PAL::RefCountedImpl, return 0; } - virtual void OnHttpResponse(IHttpResponse const* inResponse) override + virtual void OnHttpResponse(IHttpResponse* inResponse) override { std::lock_guard lock(_lock); diff --git a/tests/unittests/HttpRequestEncoderTests.cpp b/tests/unittests/HttpRequestEncoderTests.cpp index 43618e70..19a006d3 100644 --- a/tests/unittests/HttpRequestEncoderTests.cpp +++ b/tests/unittests/HttpRequestEncoderTests.cpp @@ -43,7 +43,7 @@ TEST_F(HttpRequestEncoderTests, SetsAllParameters) encoder.encode(ctx); ASSERT_THAT(ctx->httpRequestId, Eq("HttpRequestEncoderTests")); - SimpleHttpRequest const* req = static_cast(ctx->httpRequest.get()); + SimpleHttpRequest const* req = static_cast(ctx->httpRequest); EXPECT_THAT(req->m_id, Eq("HttpRequestEncoderTests")); EXPECT_THAT(req->m_method, Eq("POST")); @@ -64,13 +64,13 @@ TEST_F(HttpRequestEncoderTests, AddsCompressionHeader) ctx->compressed = false; encoder.encode(ctx); ASSERT_THAT(ctx->httpRequestId, Eq("HttpRequestEncoderTests")); - SimpleHttpRequest const* req = static_cast(ctx->httpRequest.get()); + SimpleHttpRequest const* req = static_cast(ctx->httpRequest); EXPECT_THAT(req->m_headers, Not(Contains(Pair("Content-Encoding", "deflate")))); ctx->compressed = true; encoder.encode(ctx); ASSERT_THAT(ctx->httpRequestId, Eq("HttpRequestEncoderTests")); - req = static_cast(ctx->httpRequest.get()); + req = static_cast(ctx->httpRequest); EXPECT_THAT(req->m_headers, Contains(Pair("Content-Encoding", "deflate"))); } @@ -80,19 +80,19 @@ TEST_F(HttpRequestEncoderTests, BuildsApiKeyCorrectly) encoder.encode(ctx); ASSERT_THAT(ctx->httpRequestId, Eq("HttpRequestEncoderTests")); - SimpleHttpRequest const* req = static_cast(ctx->httpRequest.get()); + SimpleHttpRequest const* req = static_cast(ctx->httpRequest); EXPECT_THAT(req->m_headers, Contains(Pair("APIKey", ""))); ctx->packageIds["tenant1-token"] = 0; encoder.encode(ctx); ASSERT_THAT(ctx->httpRequestId, Eq("HttpRequestEncoderTests")); - req = static_cast(ctx->httpRequest.get()); + req = static_cast(ctx->httpRequest); EXPECT_THAT(req->m_headers, Contains(Pair("APIKey", "tenant1-token"))); ctx->packageIds["tenant2-token"] = 1; ctx->packageIds["tenant3-token"] = 2; encoder.encode(ctx); ASSERT_THAT(ctx->httpRequestId, Eq("HttpRequestEncoderTests")); - req = static_cast(ctx->httpRequest.get()); + req = static_cast(ctx->httpRequest); EXPECT_THAT(req->m_headers, Contains(Pair("APIKey", "tenant1-token,tenant2-token,tenant3-token"))); } diff --git a/tests/unittests/HttpResponseDecoderTests.cpp b/tests/unittests/HttpResponseDecoderTests.cpp index d2493d5e..752d2595 100644 --- a/tests/unittests/HttpResponseDecoderTests.cpp +++ b/tests/unittests/HttpResponseDecoderTests.cpp @@ -35,14 +35,14 @@ class HttpResponseDecoderTests : public StrictMock { EventsUploadContextPtr createContextWith(HttpResult result, int status, std::string const& body) { - std::unique_ptr rsp(new SimpleHttpResponse("HttpResponseDecoderTests")); + SimpleHttpResponse* rsp = (new SimpleHttpResponse("HttpResponseDecoderTests")); rsp->m_result = result; rsp->m_statusCode = status; rsp->m_body.assign(reinterpret_cast(body.data()), reinterpret_cast(body.data()) + body.size()); EventsUploadContextPtr ctx = EventsUploadContext::create(); ctx->httpRequestId = rsp->GetId(); - ctx->httpResponse = std::move(rsp); + ctx->httpResponse = (rsp); ctx->durationMs = 1234; return ctx; } diff --git a/tests/unittests/LoggerTests.cpp b/tests/unittests/LoggerTests.cpp index a921796e..f8a7fdc3 100644 --- a/tests/unittests/LoggerTests.cpp +++ b/tests/unittests/LoggerTests.cpp @@ -118,14 +118,14 @@ TEST_F(LoggerTests, LogEvent) _logger.LogEvent("name_only"); ASSERT_THAT(_submitted, true); checkBaseAndContextAndRuntimeConfigProps(); - EXPECT_THAT(_submittedRecord.baseType, Eq("name_only")); + EXPECT_THAT(_submittedRecord.name, Eq("name_only")); expectSubmit(); EventProperties props1("name_only_props"); _logger.LogEvent(props1); ASSERT_THAT(_submitted, true); checkBaseAndContextAndRuntimeConfigProps(); - EXPECT_THAT(_submittedRecord.baseType, Eq("name_only_props")); + EXPECT_THAT(_submittedRecord.name, Eq("name_only_props")); expectSubmit(); EventProperties props2("custom_event"); @@ -135,7 +135,7 @@ TEST_F(LoggerTests, LogEvent) _logger.LogEvent(props2); ASSERT_THAT(_submitted, true); checkBaseAndContextAndRuntimeConfigProps(); - EXPECT_THAT(_submittedRecord.baseType, Eq("custom_event")); + EXPECT_THAT(_submittedRecord.name, Eq("custom_event")); EXPECT_THAT(_submittedRecord.data[0].properties["test"].stringValue, "value"); EXPECT_THAT(_submittedRecord.data[0].properties["auxiliary"].stringValue, "long content"); ::AriaProtocol::PII pii; @@ -163,14 +163,14 @@ TEST_F(LoggerTests, CustomEventNameValidation) _logger.LogEvent(props); ASSERT_THAT(_submitted, true); checkBaseAndContextAndRuntimeConfigProps(); - EXPECT_THAT(_submittedRecord.baseType, Eq(props.GetName())); + EXPECT_THAT(_submittedRecord.name, Eq(props.GetName())); expectSubmit(); props.SetName(std::string(100, 'a')); _logger.LogEvent(props); ASSERT_THAT(_submitted, true); checkBaseAndContextAndRuntimeConfigProps(); - EXPECT_THAT(_submittedRecord.baseType, Eq(props.GetName())); + EXPECT_THAT(_submittedRecord.name, Eq(props.GetName())); expectSubmit(); props.SetName(std::string(101, 'a')); @@ -195,7 +195,7 @@ TEST_F(LoggerTests, CustomEventNameValidation) _logger.LogEvent(props); ASSERT_THAT(_submitted, true); checkBaseAndContextAndRuntimeConfigProps(); - EXPECT_THAT(_submittedRecord.baseType, Eq("0123456789_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz")); + EXPECT_THAT(_submittedRecord.name, Eq("0123456789_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz")); std::string banned("\x01" R"( !"#$%&'()*+,-./:;<=>?@[\]^`{|}~)" "\x81"); EXPECT_CALL(_logger, submit(_, _, _, _)).WillRepeatedly(Assign(&_submitted, true)); @@ -334,7 +334,7 @@ TEST_F(LoggerTests, CustomEventPropertiesCanOverrideOrEraseContextOnes) ASSERT_THAT(_submitted, true); checkBaseAndContextAndRuntimeConfigProps(); - EXPECT_THAT(_submittedRecord.baseType, Eq("overridden_event")); + EXPECT_THAT(_submittedRecord.name, Eq("overridden_event")); EXPECT_THAT(_submittedRecord.data[0].properties["plain1"].stringValue, "overridden"); EXPECT_THAT(_submittedRecord.data[0].properties["plain2"].stringValue, ""); diff --git a/tests/unittests/OfflineStorageTests.cpp b/tests/unittests/OfflineStorageTests.cpp index 88b37ff5..67481982 100644 --- a/tests/unittests/OfflineStorageTests.cpp +++ b/tests/unittests/OfflineStorageTests.cpp @@ -139,6 +139,7 @@ TEST_F(OfflineStorageTests, DeleteRecordsIsForwarded) { recordIds.push_back(element.first); } + ctx->fromMemory = fromMemory; EXPECT_CALL(offlineStorageMock, DeleteRecords(recordIds,test, fromMemory)).WillOnce(Return()); EXPECT_THAT(offlineStorage.deleteRecords(ctx), true); } @@ -153,6 +154,7 @@ TEST_F(OfflineStorageTests, ReleaseRecordsIsForwarded) { recordIds.push_back(element.first); } + ctx->fromMemory = fromMemory; EXPECT_CALL(offlineStorageMock, ReleaseRecords(recordIds, false, test, fromMemory)) .WillOnce(Return()); EXPECT_THAT(offlineStorage.releaseRecords(ctx), true); diff --git a/tests/unittests/PalTests.cpp b/tests/unittests/PalTests.cpp index 988e6b18..d6248646 100644 --- a/tests/unittests/PalTests.cpp +++ b/tests/unittests/PalTests.cpp @@ -360,7 +360,7 @@ TEST_F(PalTests, UuidGeneration) std::string mask = uuid0; for (char& ch : mask) { - if (::isdigit(ch) || (::islower(ch) && ::isxdigit(ch))) { + if (::isdigit(ch) || (::isupper(ch) && ::isxdigit(ch))) { ch = 'x'; } }