Fixed tests
This commit is contained in:
Родитель
ce2aefc507
Коммит
99adc8cc0f
|
@ -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<std::string>& AuthTokensController::GetTickets()
|
||||
{
|
||||
return m_tickets;
|
||||
|
|
|
@ -33,6 +33,11 @@ class AuthTokensController : public IAuthTokensController
|
|||
/// <param name="ticketValue">Ticketvalue</param>
|
||||
virtual EVTStatus SetTicketToken(TicketType type, char const* tokenValue);
|
||||
|
||||
/// <summary>
|
||||
/// Clears all tokens.
|
||||
/// </summary>
|
||||
virtual EVTStatus Clear();
|
||||
|
||||
/// <summary>
|
||||
/// Set the Auth ticket.
|
||||
/// </summary>
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,11 @@ namespace Microsoft { namespace Applications { namespace Events {
|
|||
/// <param name="ticketValue">Ticketvalue</param>
|
||||
virtual EVTStatus SetTicketToken(TicketType type, char const* tokenValue) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// clears all tokens.
|
||||
/// </summary>
|
||||
virtual EVTStatus Clear() = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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));
|
||||
};
|
||||
|
|
|
@ -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<std::string, EventProperty> prop : expected.GetProperties())
|
||||
{
|
||||
if (prop.second.piiKind == PiiKind_None)
|
||||
|
|
|
@ -41,17 +41,17 @@ class HttpClientManagerTests : public StrictMock<Test> {
|
|||
|
||||
TEST_F(HttpClientManagerTests, HandlesRequestFlow)
|
||||
{
|
||||
std::unique_ptr<SimpleHttpRequest> 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<SimpleHttpRequest> 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);
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ class HttpClientTests : public PAL::RefCountedImpl<HttpClientTests>,
|
|||
return 0;
|
||||
}
|
||||
|
||||
virtual void OnHttpResponse(IHttpResponse const* inResponse) override
|
||||
virtual void OnHttpResponse(IHttpResponse* inResponse) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_lock);
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ TEST_F(HttpRequestEncoderTests, SetsAllParameters)
|
|||
encoder.encode(ctx);
|
||||
|
||||
ASSERT_THAT(ctx->httpRequestId, Eq("HttpRequestEncoderTests"));
|
||||
SimpleHttpRequest const* req = static_cast<SimpleHttpRequest*>(ctx->httpRequest.get());
|
||||
SimpleHttpRequest const* req = static_cast<SimpleHttpRequest*>(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<SimpleHttpRequest*>(ctx->httpRequest.get());
|
||||
SimpleHttpRequest const* req = static_cast<SimpleHttpRequest*>(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<SimpleHttpRequest*>(ctx->httpRequest.get());
|
||||
req = static_cast<SimpleHttpRequest*>(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<SimpleHttpRequest*>(ctx->httpRequest.get());
|
||||
SimpleHttpRequest const* req = static_cast<SimpleHttpRequest*>(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<SimpleHttpRequest*>(ctx->httpRequest.get());
|
||||
req = static_cast<SimpleHttpRequest*>(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<SimpleHttpRequest*>(ctx->httpRequest.get());
|
||||
req = static_cast<SimpleHttpRequest*>(ctx->httpRequest);
|
||||
EXPECT_THAT(req->m_headers, Contains(Pair("APIKey", "tenant1-token,tenant2-token,tenant3-token")));
|
||||
}
|
||||
|
|
|
@ -35,14 +35,14 @@ class HttpResponseDecoderTests : public StrictMock<Test> {
|
|||
|
||||
EventsUploadContextPtr createContextWith(HttpResult result, int status, std::string const& body)
|
||||
{
|
||||
std::unique_ptr<SimpleHttpResponse> rsp(new SimpleHttpResponse("HttpResponseDecoderTests"));
|
||||
SimpleHttpResponse* rsp = (new SimpleHttpResponse("HttpResponseDecoderTests"));
|
||||
rsp->m_result = result;
|
||||
rsp->m_statusCode = status;
|
||||
rsp->m_body.assign(reinterpret_cast<uint8_t const*>(body.data()), reinterpret_cast<uint8_t const*>(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;
|
||||
}
|
||||
|
|
|
@ -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, "");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче