Skip to content
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

Merged
merged 1 commit into from
May 11, 2021
Merged

2. Create OAuth callback action #10

merged 1 commit into from
May 11, 2021

Conversation

MuhammadFarag
Copy link
Contributor

No description provided.

@MuhammadFarag MuhammadFarag changed the base branch from main to update-sesssion-storage May 5, 2021 15:15
@@ -0,0 +1,125 @@
<?php
Copy link
Contributor Author

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

Copy link
Collaborator

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.

Copy link
Contributor Author

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 👍

@MuhammadFarag MuhammadFarag changed the title [WIP] Create OAuth callback action 2. Create OAuth callback action May 6, 2021
@MuhammadFarag MuhammadFarag marked this pull request as ready for review May 6, 2021 06:49
@MuhammadFarag MuhammadFarag requested a review from a team as a code owner May 6, 2021 06:49
Copy link
Collaborator

@paulomarg paulomarg left a 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('/');
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

@@ -0,0 +1,125 @@
<?php
Copy link
Collaborator

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.

Base automatically changed from update-sesssion-storage to main May 11, 2021 18:11
Copy link
Collaborator

@paulomarg paulomarg left a 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
Copy link
Collaborator

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.


$client->expects($this->exactly(1))
->method('sendRequest')
->with($matcher)
->with($this->anything())
Copy link
Collaborator

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'.

Copy link
Contributor Author

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

Comment on lines 102 to 104
$expectedSession = $this->buildExpectedSession($this->session->getId(), false);
$actualSession = Context::$SESSION_STORAGE->loadSession($this->session->getId());
$this->assertEquals($expectedSession, $actualSession);
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants