-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implements a Context that talks to the store mock server #293
Conversation
Handles the inner details of calling HTTP Returns a JsonObject on success winrt::hresult_error exceptions will bubble up on failure, Including JSON parsing error.
To avoid code duplication The exact same implementation is needed in the mock client.
That requires having a constructor exposing all fields.
Maybe we grow it when we start using the mock in tests
in the CMakeLists.txt Similar to what was done with Flutter Detects the env var UP4W_TEST_WITH_MS_STORE_MOCK Defines the services test wth mocks Including a mock server config
std::chrono::system_clock::time_point tp{}; | ||
std::stringstream ss{winrt::to_string(obj.GetNamedString(L"ExpirationDate"))}; | ||
ss >> std::chrono::parse("%FT%T%Tz", tp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This little gem is only available for GCC on trunk :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole mock storeAPI is really cool 😄
Just a few minor comments.
@@ -84,6 +84,23 @@ std::vector<std::string> WinMockContext::AllLocallyAuthenticatedUserHashes() { | |||
return result; | |||
} | |||
|
|||
std::string WinMockContext::GenerateUserJwt(std::string token, | |||
std::string userId) const { | |||
assert(!token.empty() && "Azure AD token is required"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this simply mirrors the store context, but I'm thinking that, in both contexts, this assertion should also be run on Release (or remove it and let the server fail, doesn't really matter).
If we leave it as-is, we have diferent failure modes in Release and Debug, so we won't be testing the right thing. Maybe we can create a card and deal with these in a future PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of an assertion is to educate the programmers to ensure those checks won't be needed in release.
If we are unsure about whether we are safe to trust that those checks aren't needed in production, then we should revisit the usage of assertions and maybe convert into wide contracts with exceptions being thrown for invalid arguments.
I personally like assertions because they clearly state: "you'll called me outside of our contract, that's a bug, take your crash". Once we crash enough in debug mode, those checks shouldn't be necessary anymore. Exceptions are more fuzzy. What is an exceptional situation? As always, it depends...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like having assertions mostly where an error is critical: to avoid segfaults or undefined behaviour. In this case, since this would error out anyways (just server-side), I'm not sure it is worth having a release/debug split. Particularly because we test error paths quite intensely, so we'd be testing a ficticious path here.
Since this is not performance-critital, it seems that it would not hurt to always return error, or to always let the server fail. Either way, this is not critical to this PR.
The JsonObject forward declaration seems good enough. No actual leakage of WinRT types to be consistent with the production API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, cool, cool.
This PR adds a replacement for the thin MS Store API wrapper by a not-so-thin client of the store mock server we presented in #268.
For ease of implementation I opted for writing a Windows specific version of the mock client. You'll see that it's indeed not that hard to talk to REST API's using WinRT. Since we adopted a very consistent calling convention in our REST API, a single
call()
function models very well talking to any of the exposed endpoints, so that theWinMockContext
methods just wrap around it passing the appropriate arguments. The actual HTTP call could be more elaborated, using streamed data to prevent against large responses, but I don't believe this is necessary, because we control the server and we know the responses are rather small.Since this client code is not trivial, I added a few test cases for it, but I didn't plug it in CI right away because running it is a bit cumbersome:
UP4W_MS_STORE_MOCK_ENDPOINT
with the address the mock server will run (localhost:port
)UP4W_TEST_WITH_MS_STORE_MOCK
so the replacement context takes the stage instead of the production one.Not that complicated, but requires Go to build the store mock server and a few lines of powershell scripting to do the port thingy. So I found that this is not the appropriate moment for pluging this on in the CI. Also, the mock client is for supporting testing higher level components, and this is testing it, not the targets.
Here's a gist of how I run on my computer:
Fixes Udeng-1258