-
Notifications
You must be signed in to change notification settings - Fork 92
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
2. Create OAuth callback action #10
Conversation
tests/Feature/HttpRequestMatcher.php
Outdated
@@ -0,0 +1,125 @@ | |||
<?php |
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 is copied from our library, since test files are not exported. It might be a good idea to expose some test helpers with the library
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.
Perhaps we don't need this test to be so 'deep', and we can only check that we get a POST to the expected address without necessarily checking everything else - we already check that the library fires off the appropriate requests in its own repo, and we're more interested in whether the session is properly set up rather than whether the access token fetch has all the expected params.
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.
That's actually a very good point 👍
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 is great, code-wise I have very little to say!
routes/web.php
Outdated
|
||
Route::get('/auth/callback', function (Request $request) { | ||
OAuth::callback($request->cookie(), $request->query()); | ||
return redirect('/'); |
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 think we'll probably want to include the shop
query param in this redirection, otherwise we'll end up failing in the 'main' action which needs to check if the shop is there.
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.
Done 👍
tests/Feature/HttpRequestMatcher.php
Outdated
@@ -0,0 +1,125 @@ | |||
<?php |
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.
Perhaps we don't need this test to be so 'deep', and we can only check that we get a POST to the expected address without necessarily checking everything else - we already check that the library fires off the appropriate requests in its own repo, and we're more interested in whether the session is properly set up rather than whether the access token fetch has all the expected params.
283a91d
to
eda87f2
Compare
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.
Couple of minor comments, but happy for this to be merged once they're addressed (or skipped!).
$response->assertRedirect("?shop=$this->domain"); | ||
} | ||
|
||
private function mockClient(): ClientInterface|MockObject |
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 that we do this generically so we don't accidentally run actual requests. We may want to run it for every test so we're guaranteed not to fire actual requests.
tests/Feature/CallbackTest.php
Outdated
|
||
$client->expects($this->exactly(1)) | ||
->method('sendRequest') | ||
->with($matcher) | ||
->with($this->anything()) |
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.
Would it be overkill to make this a callback and just check that we're POSTing to the access token address? I'm leaning towards 'yes'.
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.
Done :) I am not a fan of callbacks, just because of the cryptic message we get on error. But, I am always a fan of more testing :D
tests/Feature/CallbackTest.php
Outdated
$expectedSession = $this->buildExpectedSession($this->session->getId(), false); | ||
$actualSession = Context::$SESSION_STORAGE->loadSession($this->session->getId()); | ||
$this->assertEquals($expectedSession, $actualSession); |
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 think this is worth keeping around - we want to make sure the session is there in this scenario, and that it's setting the access token.
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 think this is internal to the library. The assumption that the library is working correctly, and the dbSessionStorage tests are working correctly.
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.
Fair enough!
No description provided.