Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Check for isJson on middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
gnikyt committed Jan 10, 2019
1 parent d9eb61b commit 3cd65e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ShopifyApp/Middleware/AuthShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function handle(Request $request, Closure $next)

// Shop is OK, move on...
$response = $next($request);
if (!$request->ajax()) {
if (($request->ajax() || $request->wantsJson() || $request->isJson()) === false) {
// Request is not AJAX, continue as normal
if (!$response instanceof Response && !$response instanceof RedirectResponse) {
// We need a response object to modify headers
Expand Down
21 changes: 19 additions & 2 deletions tests/Middleware/AuthShopMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testHeadersForEsdkShouldBeAdjusted()
Session::put('shopify_domain', $shop->shopify_domain);

// Run the middleware
$result = $this->runAuthShop();
$result = $this->runAuthShop(null, Request::instance());

// Assert the headers were modified
$this->assertEquals('CP="Not used"', $result[0]->headers->get('p3p'));
Expand All @@ -114,6 +114,23 @@ public function testAjaxCallShouldNotAdjustResponse()
$this->assertNull($result[0]);
}

public function testJsonCallShouldNotAdjustResponse()
{
// Set a shop
$shop = factory(Shop::class)->create();
Session::put('shopify_domain', $shop->shopify_domain);

// Set the request
$request = Request::instance();
$request->headers->set('content-type', 'application/json');

// Run the middleware
$result = $this->runAuthShop(null, $request);

// Assert the headers were not modified
$this->assertNull($result[0]);
}

public function testHeadersForDisabledEsdk()
{
// Set a shop
Expand All @@ -124,7 +141,7 @@ public function testHeadersForDisabledEsdk()
Config::set('shopify-app.esdk_enabled', false);

// Run the middleware
$result = $this->runAuthShop();
$result = $this->runAuthShop(null, Request::instance());

// Assert the headers were not modified
$this->assertNull($result[0]->headers->get('p3p'));
Expand Down

0 comments on commit 3cd65e1

Please sign in to comment.