From 1e823d88e2c0ae77dc2003577155a08e94284461 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Wed, 20 Jun 2018 09:11:19 -0700 Subject: [PATCH] Ignore case on handlerVersion (#941) --- .../CommonLib/config_utility.h | 2 +- test/CommonLibTests/ConfigUtilityTests.cpp | 121 +++++++++--------- 2 files changed, 61 insertions(+), 62 deletions(-) diff --git a/src/AspNetCoreModuleV2/CommonLib/config_utility.h b/src/AspNetCoreModuleV2/CommonLib/config_utility.h index 0a53ff63e3..8fde16f010 100644 --- a/src/AspNetCoreModuleV2/CommonLib/config_utility.h +++ b/src/AspNetCoreModuleV2/CommonLib/config_utility.h @@ -68,7 +68,7 @@ public: } - if (strHandlerName.Equals(CS_ASPNETCORE_HANDLER_VERSION)) + if (strHandlerName.Equals(CS_ASPNETCORE_HANDLER_VERSION, TRUE)) { hr = strHandlerVersionValue->Copy(strHandlerValue); goto Finished; diff --git a/test/CommonLibTests/ConfigUtilityTests.cpp b/test/CommonLibTests/ConfigUtilityTests.cpp index fbed259117..e37abe896a 100644 --- a/test/CommonLibTests/ConfigUtilityTests.cpp +++ b/test/CommonLibTests/ConfigUtilityTests.cpp @@ -8,75 +8,69 @@ using ::testing::NiceMock; namespace ConfigUtilityTests { - TEST(ConfigUtilityTest, HandlerVersionSet) + using ::testing::Test; + + class ConfigUtilityTest : public Test { - IAppHostElement* retElement = NULL; + protected: + void Test(std::wstring key, std::wstring value, std::wstring expected) + { + IAppHostElement* retElement = NULL; - STRU handlerVersion; + STRU handlerVersion; + BSTR bstrKey = SysAllocString(key.c_str()); + BSTR bstrValue = SysAllocString(value.c_str()); - // NiceMock removes warnings about "uninteresting calls", - auto element = std::make_unique>(); - auto innerElement = std::make_unique>(); - auto collection = std::make_unique>(); - auto nameElement = std::make_unique>(); - auto mockProperty = std::make_unique>(); + // NiceMock removes warnings about "uninteresting calls", + auto element = std::make_unique>(); + auto innerElement = std::make_unique>(); + auto collection = std::make_unique>(); + auto nameElement = std::make_unique>(); + auto mockProperty = std::make_unique>(); - ON_CALL(*element, GetElementByName(_, _)) - .WillByDefault(DoAll(testing::SetArgPointee<1>(innerElement.get()), testing::Return(S_OK))); - ON_CALL(*innerElement, get_Collection(_)) - .WillByDefault(testing::DoAll(testing::SetArgPointee<0>(collection.get()), testing::Return(S_OK))); - ON_CALL(*collection, get_Count(_)) - .WillByDefault(DoAll(testing::SetArgPointee<0>(1), testing::Return(S_OK))); - ON_CALL(*collection, get_Item(_, _)) - .WillByDefault(DoAll(testing::SetArgPointee<1>(nameElement.get()), testing::Return(S_OK))); - ON_CALL(*nameElement, GetPropertyByName(_, _)) - .WillByDefault(DoAll(testing::SetArgPointee<1>(mockProperty.get()), testing::Return(S_OK))); - EXPECT_CALL(*mockProperty, get_StringValue(_)) - .WillOnce(DoAll(testing::SetArgPointee<0>(SysAllocString(L"handlerVersion")), testing::Return(S_OK))) - .WillOnce(DoAll(testing::SetArgPointee<0>(SysAllocString(L"value")), testing::Return(S_OK))); + ON_CALL(*element, GetElementByName(_, _)) + .WillByDefault(DoAll(testing::SetArgPointee<1>(innerElement.get()), testing::Return(S_OK))); + ON_CALL(*innerElement, get_Collection(_)) + .WillByDefault(testing::DoAll(testing::SetArgPointee<0>(collection.get()), testing::Return(S_OK))); + ON_CALL(*collection, get_Count(_)) + .WillByDefault(DoAll(testing::SetArgPointee<0>(1), testing::Return(S_OK))); + ON_CALL(*collection, get_Item(_, _)) + .WillByDefault(DoAll(testing::SetArgPointee<1>(nameElement.get()), testing::Return(S_OK))); + ON_CALL(*nameElement, GetPropertyByName(_, _)) + .WillByDefault(DoAll(testing::SetArgPointee<1>(mockProperty.get()), testing::Return(S_OK))); + EXPECT_CALL(*mockProperty, get_StringValue(_)) + .WillOnce(DoAll(testing::SetArgPointee<0>(bstrKey), testing::Return(S_OK))) + .WillOnce(DoAll(testing::SetArgPointee<0>(bstrValue), testing::Return(S_OK))); - HRESULT hr = ConfigUtility::FindHandlerVersion(element.get(), &handlerVersion); + HRESULT hr = ConfigUtility::FindHandlerVersion(element.get(), &handlerVersion); - EXPECT_STREQ(handlerVersion.QueryStr(), L"value"); + EXPECT_STREQ(handlerVersion.QueryStr(), expected.c_str()); + + SysFreeString(bstrKey); + SysFreeString(bstrValue); + } + }; + + TEST_F(ConfigUtilityTest, CheckHandlerVersionKeysAndValues) + { + Test(L"handlerVersion", L"value", L"value"); + Test(L"handlerversion", L"value", L"value"); + Test(L"HandlerversioN", L"value", L"value"); + Test(L"randomvalue", L"value", L""); + Test(L"", L"value", L""); + Test(L"", L"", L""); } - TEST(ConfigUtilityTest, NoHandlerVersion) - { - IAppHostElement* retElement = NULL; - - STRU handlerVersion; - - // NiceMock removes warnings about "uninteresting calls", - auto element = std::make_unique>(); - auto innerElement = std::make_unique>(); - auto collection = std::make_unique>(); - auto nameElement = std::make_unique>(); - auto mockProperty = std::make_unique>(); - - ON_CALL(*element, GetElementByName(_, _)) - .WillByDefault(DoAll(testing::SetArgPointee<1>(innerElement.get()), testing::Return(S_OK))); - ON_CALL(*innerElement, get_Collection(_)) - .WillByDefault(testing::DoAll(testing::SetArgPointee<0>(collection.get()), testing::Return(S_OK))); - ON_CALL(*collection, get_Count(_)) - .WillByDefault(DoAll(testing::SetArgPointee<0>(1), testing::Return(S_OK))); - ON_CALL(*collection, get_Item(_, _)) - .WillByDefault(DoAll(testing::SetArgPointee<1>(nameElement.get()), testing::Return(S_OK))); - ON_CALL(*nameElement, GetPropertyByName(_, _)) - .WillByDefault(DoAll(testing::SetArgPointee<1>(mockProperty.get()), testing::Return(S_OK))); - EXPECT_CALL(*mockProperty, get_StringValue(_)) - .WillOnce(DoAll(testing::SetArgPointee<0>(SysAllocString(L"randomvalue")), testing::Return(S_OK))) - .WillOnce(DoAll(testing::SetArgPointee<0>(SysAllocString(L"value")), testing::Return(S_OK))); - - HRESULT hr = ConfigUtility::FindHandlerVersion(element.get(), &handlerVersion); - - EXPECT_STREQ(handlerVersion.QueryStr(), L""); - } - - TEST(ConfigUtilityTest, MultipleElements) + TEST(ConfigUtilityTestSingle, MultipleElements) { IAppHostElement* retElement = NULL; STRU handlerVersion; + BSTR bstrKey = SysAllocString(L"key"); + BSTR bstrValue = SysAllocString(L"value"); + BSTR bstrKey2 = SysAllocString(L"handlerVersion"); + BSTR bstrValue2 = SysAllocString(L"value2"); + auto element = std::make_unique>(); auto innerElement = std::make_unique>(); auto collection = std::make_unique>(); @@ -94,13 +88,18 @@ namespace ConfigUtilityTests ON_CALL(*nameElement, GetPropertyByName(_, _)) .WillByDefault(DoAll(testing::SetArgPointee<1>(mockProperty.get()), testing::Return(S_OK))); EXPECT_CALL(*mockProperty, get_StringValue(_)) - .WillOnce(DoAll(testing::SetArgPointee<0>(SysAllocString(L"key")), testing::Return(S_OK))) - .WillOnce(DoAll(testing::SetArgPointee<0>(SysAllocString(L"value")), testing::Return(S_OK))) - .WillOnce(DoAll(testing::SetArgPointee<0>(SysAllocString(L"handlerVersion")), testing::Return(S_OK))) - .WillOnce(DoAll(testing::SetArgPointee<0>(SysAllocString(L"value2")), testing::Return(S_OK))); + .WillOnce(DoAll(testing::SetArgPointee<0>(bstrKey), testing::Return(S_OK))) + .WillOnce(DoAll(testing::SetArgPointee<0>(bstrValue), testing::Return(S_OK))) + .WillOnce(DoAll(testing::SetArgPointee<0>(bstrKey2), testing::Return(S_OK))) + .WillOnce(DoAll(testing::SetArgPointee<0>(bstrValue2), testing::Return(S_OK))); HRESULT hr = ConfigUtility::FindHandlerVersion(element.get(), &handlerVersion); EXPECT_STREQ(handlerVersion.QueryStr(), L"value2"); + + SysFreeString(bstrKey); + SysFreeString(bstrValue); + SysFreeString(bstrKey2); + SysFreeString(bstrValue2); } }