diff --git a/storeapi/test/CMakeLists.txt b/storeapi/test/CMakeLists.txt index 516959ad3..5ac438c09 100644 --- a/storeapi/test/CMakeLists.txt +++ b/storeapi/test/CMakeLists.txt @@ -15,7 +15,7 @@ set(StoreApi_SRCS "../base/Exception.hpp" "../base/Purchase.hpp" "../base/StoreService.hpp" - "../agent/ServerStoreService.cpp" + "../agent/ServerStoreService.hpp" "../gui/ClientStoreService.hpp" ) diff --git a/storeapi/test/ServerStoreServiceTest.cpp b/storeapi/test/ServerStoreServiceTest.cpp index a2e154405..0708a62d8 100644 --- a/storeapi/test/ServerStoreServiceTest.cpp +++ b/storeapi/test/ServerStoreServiceTest.cpp @@ -8,12 +8,22 @@ namespace StoreApi { using namespace ::testing; -TEST(UserInfo, PredictableSizes) { - auto user = UserInfo::Current().get(); - auto size = user.id.size(); - EXPECT_TRUE(size == 0 || size == 64) - << "User ID of unexpected size: " << size << " <" - << winrt::to_string(user.id) << '\n'; +TEST(ServerStoreService, NoUsersLikeInCI) { + auto service = ServerStoreService{}; + EXPECT_THROW({auto user = service.CurrentUserInfo();}, Exception); +} + +TEST(ServerStoreService, TooManyUsers) { + auto service = ServerStoreService{}; + EXPECT_THROW({auto user = service.CurrentUserInfo();}, Exception); +} + +TEST(ServerStoreService, FindOneUser) { + static constexpr char goodHash[] = "goodHash"; + auto service = ServerStoreService{}; + FindOneUser::goodHash = goodHash; + auto user = service.CurrentUserInfo(); + EXPECT_EQ(user.id, goodHash); } TEST(ServerStoreService, EmptyJwtThrows) { @@ -21,7 +31,7 @@ TEST(ServerStoreService, EmptyJwtThrows) { UserInfo user{.id = L"my@name.com"}; EXPECT_THROW( { - auto jwt = service.GenerateUserJwt("this-is-a-web-token", user).get(); + auto jwt = service.GenerateUserJwt("this-is-a-web-token", user); }, Exception); } @@ -30,19 +40,10 @@ TEST(ServerStoreService, NonEmptyJwtNeverThrows) { auto service = ServerStoreService{}; UserInfo user{.id = L"my@name.com"}; std::string token{"this-is-a-web-token"}; - auto jwt = service.GenerateUserJwt(token, user).get(); + auto jwt = service.GenerateUserJwt(token, user); EXPECT_EQ(token, jwt); } -TEST(ServerStoreService, RealServerFailsUnderTest) { - auto service = ServerStoreService{}; - UserInfo user{.id = L"my@name.com"}; - std::string token{"this-is-a-web-token"}; - // This fails because the test is not an app deployed through the store. - EXPECT_THROW({ auto jwt = service.GenerateUserJwt(token, user).get(); }, - Exception); -} - TEST(ServerStoreService, ExpirationDateUnsubscribed) { auto service = ServerStoreService{}; diff --git a/storeapi/test/stubs.hpp b/storeapi/test/stubs.hpp index 2a101fda4..c0c86bdb8 100644 --- a/storeapi/test/stubs.hpp +++ b/storeapi/test/stubs.hpp @@ -4,23 +4,16 @@ #include #include -// For WinRT basic types and coroutines. -#include -// For non-WinRT coroutines -#include - -// Win32 APIs, such as the Timezone -#include - #include #include #include #include #include #include +// For timegm +#include #if defined _MSC_VER -#include #include #define timegm _mkgmtime #endif @@ -89,9 +82,8 @@ struct EmptyJwtContext { return {Product{.kind = kinds[0], .id = ids[0]}}; } - winrt::Windows::Foundation::IAsyncOperation GenerateUserJwt( - winrt::hstring hToken, winrt::hstring hUserId) { - co_return {}; + std::string GenerateUserJwt(std::string hToken, std::string hUserId) { + return {}; } }; @@ -107,9 +99,8 @@ struct IdentityJwtContext { return {Product{.kind = kinds[0], .id = ids[0]}}; } - winrt::Windows::Foundation::IAsyncOperation GenerateUserJwt( - winrt::hstring hToken, winrt::hstring hUserId) { - co_return hToken; + std::string GenerateUserJwt(std::string hToken, std::string hUserId) { + return hToken; } }; @@ -132,9 +123,8 @@ struct NeverSubscribedContext { return {Product{.kind = kinds[0], .id = ids[0]}}; } - winrt::Windows::Foundation::IAsyncOperation GenerateUserJwt( - winrt::hstring hToken, winrt::hstring hUserId) { - co_return hToken; + std::string GenerateUserJwt(std::string hToken, std::string hUserId) { + return hToken; } }; @@ -158,9 +148,8 @@ struct UnixEpochContext { return {Product{.kind = kinds[0], .id = ids[0]}}; } - winrt::Windows::Foundation::IAsyncOperation GenerateUserJwt( - winrt::hstring hToken, winrt::hstring hUserId) { - co_return hToken; + std::string GenerateUserJwt(std::string hToken, std::string hUserId) { + return hToken; } }; @@ -187,9 +176,8 @@ struct AlreadyPurchasedContext { return {Product{.kind = kinds[0], .id = ids[0]}}; } - winrt::Windows::Foundation::IAsyncOperation GenerateUserJwt( - winrt::hstring hToken, winrt::hstring hUserId) { - co_return hToken; + std::string GenerateUserJwt(std::string hToken, std::string hUserId) { + return hToken; } // noop @@ -219,11 +207,29 @@ struct PurchaseSuccessContext { return {Product{.kind = kinds[0], .id = ids[0]}}; } - winrt::Windows::Foundation::IAsyncOperation GenerateUserJwt( - winrt::hstring hToken, winrt::hstring hUserId) { - co_return hToken; + std::string GenerateUserJwt(std::string hToken, std::string hUserId) { + return hToken; } // noop void InitDialogs(Window window) {} }; + +struct TooManyUsersContext { + std::vector AllLocallyAuthenticatedUserHashes() { + return {"first-user", "second-user"}; + } +}; + +struct NoUsers{ + std::vector AllLocallyAuthenticatedUserHashes() { + return {}; + } +}; + +struct FindOneUser{ + static std::string goodHash; + std::vector AllLocallyAuthenticatedUserHashes() { + return {goodHash}; + } +};