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

Commit

Permalink
Proxy app fix to set shop's session
Browse files Browse the repository at this point in the history
  • Loading branch information
gnikyt committed Jul 24, 2018
1 parent e55c3e8 commit 2b1a131
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:30:"PHPUnit\Runner\TestResultCache":4285:{a:2:{s:7:"defects";a:0:{}s:5:"times";a:91:{s:15:"testItShouldRun";d:0.217;s:25:"testShouldMakeUrlFromName";d:0.022;s:20:"testShouldReturnStub";d:0.024;s:13:"testLoginTest";d:0.255;s:38:"testAuthRedirectsBackToLoginWhenNoShop";d:0.038;s:43:"testAuthRedirectsUserToAuthScreenWhenNoCode";d:0.038;s:49:"testAuthAcceptsShopWithCodeAndUpdatesTokenForShop";d:0.034;s:27:"testAuthRestoresTrashedShop";d:0.053;s:45:"testAuthAcceptsShopWithCodeAndRedirectsToHome";d:0.027;s:64:"testAuthAcceptsShopWithCodeAndRedirectsToLoginIfRequestIsInvalid";d:0.026;s:51:"testAuthenticateDoesNotFiresJobsWhenNoConfigForThem";d:0.04;s:29:"testAuthenticateDoesFiresJobs";d:0.064;s:32:"testAfterAuthenticateFiresInline";d:0.025;s:36:"testAfterAuthenticateFiresDispatched";d:0.026;s:43:"testAfterAuthenticateDoesNotFireForNoConfig";d:0.023;s:28:"testSendsShopToBillingScreen";d:0.043;s:22:"testShopAcceptsBilling";d:0.037;s:23:"testShopDeclinesBilling";d:0.049;s:26:"testReturnsBasePlanDetails";d:0.028;s:35:"testReturnsBasePlanDetailsWithUsage";d:0.033;s:50:"testReturnsBasePlanDetailsChangedByCancelledCharge";d:0.026;s:25:"testReturnsBaseChargeType";d:0.027;s:45:"testNoShopSessionShouldRedirectToAuthenticate";d:0.049;s:51:"testWithMismatchedShopsShouldRedirectToAuthenticate";d:0.042;s:29:"testShopWithSessionShouldLoad";d:0.105;s:44:"testShopWithSessionAndDisabledEsdkShouldLoad";d:0.03;s:36:"testShouldReturn201ResponseOnSuccess";d:0.233;s:38:"testShouldReturnErrorResponseOnFailure";d:0.059;s:25:"testShouldCaseTypeToClass";d:0.024;s:28:"testWebhookShouldRecieveData";d:0.035;s:9:"testBasic";d:0.028;s:18:"testJobAcceptsLoad";d:0.029;s:32:"testJobSoftDeletesShopAndCharges";d:0.032;s:32:"testJobDoesNothingForUnknownShop";d:0.024;s:41:"testJobShouldTestScripttagExistanceMethod";d:0.027;s:34:"testJobShouldNotRecreateScripttags";d:0.038;s:29:"testJobShouldCreateScripttags";d:0.031;s:39:"testJobShouldTestWebhookExistanceMethod";d:0.026;s:32:"testJobShouldNotRecreateWebhooks";d:0.039;s:27:"testJobShouldCreateWebhooks";d:0.027;s:31:"testShouldReturnConfirmationUrl";d:0.03;s:49:"testShouldReturnConfirmationUrlWhenUsageIsEnabled";d:0.024;s:51:"testShouldNotReturnConfirmationUrlAndThrowException";d:0.029;s:22:"testShouldActivatePlan";d:0.033;s:42:"testShouldNotActivatePlanAndThrowException";d:0.025;s:26:"testShouldGetChargeDetails";d:0.026;s:46:"testShouldNotGetChargeDetailsAndThrowException";d:0.026;s:23:"testDenysForMissingShop";d:0.027;s:8:"testRuns";d:0.05;s:33:"testDoesNotRunForInvalidSignature";d:0.064;s:30:"testShopHasNoAccessShouldAbort";d:0.047;s:41:"testShopHasWithAccessShouldPassMiddleware";d:0.041;s:42:"testShopWithNoTokenShouldNotPassMiddleware";d:0.035;s:38:"testShopTrashedShouldNotPassMiddleware";d:0.035;s:66:"testShopsWhichDoNotMatchShouldKillSessionAndDirectToReAuthenticate";d:0.03;s:34:"testHeadersForEsdkShouldBeAdjusted";d:0.031;s:26:"testHeadersForDisabledEsdk";d:0.038;s:29:"testDenysForMissingShopHeader";d:0.035;s:29:"testDenysForMissingHmacHeader";d:0.039;s:22:"testInvalidHmacWontRun";d:0.042;s:32:"testEnabledBillingWithUnpaidShop";d:0.039;s:44:"testEnabledBillingWithShopWhoDeclinedCharges";d:0.036;s:30:"testEnabledBillingWithPaidShop";d:0.031;s:39:"testEnabledBillingWithGrandfatheredShop";d:0.055;s:31:"testDisabledBillingShouldPassOn";d:0.046;s:17:"testBelongsToShop";d:0.067;s:24:"testChargeImplementsType";d:0.035;s:10:"testIsTest";d:0.034;s:10:"testIsType";d:0.031;s:11:"testIsTrial";d:0.03;s:17:"testIsActiveTrial";d:0.028;s:22:"testRemainingTrialDays";d:0.028;s:17:"testUsedTrialDays";d:0.037;s:23:"testAcceptedAndDeclined";d:0.037;s:10:"testActive";d:0.027;s:11:"testOngoing";d:0.026;s:13:"testCancelled";d:0.027;s:32:"testRemainingTrialDaysFromCancel";d:0.027;s:18:"testShopReturnsApi";d:0.026;s:34:"testShopShouldNotSaveWithoutDomain";d:0.057;s:43:"testShopShouldSaveAndAllowForMassAssignment";d:0.032;s:38:"testShopShouldReturnGrandfatheredState";d:0.045;s:34:"testShopCanSoftDeleteAndBeRestored";d:0.041;s:37:"testShouldReturnBoolForChargesApplied";d:0.028;s:22:"testShopWithoutSession";d:0.03;s:19:"testShopWithSession";d:0.026;s:45:"testCreatesNewShopWithSessionIfItDoesNotExist";d:0.024;s:22:"testReturnsApiInstance";d:0.024;s:16:"testShopSanitize";d:0.025;s:25:"testShouldUseDefaultModel";d:0.025;s:31:"testShouldAllowForModelOverride";d:0.025;}}}
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
colors="true"
cacheTokens="false"
verbose="false"
strict="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
Expand Down
4 changes: 4 additions & 0 deletions src/ShopifyApp/Middleware/AuthProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Illuminate\Http\Request;
use OhMyBrew\ShopifyApp\Facades\ShopifyApp;

class AuthProxy
{
Expand Down Expand Up @@ -39,6 +40,9 @@ public function handle(Request $request, Closure $next)
abort(401, 'Invalid proxy signature');
}

// Save shop domain to session
session(['shopify_domain' => ShopifyApp::sanitizeShopDomain(request('shop'))]);

// All good, process proxy request
return $next($request);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Middleware/AuthProxyMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Facades\Input;
use OhMyBrew\ShopifyApp\Middleware\AuthProxy;
use OhMyBrew\ShopifyApp\Test\TestCase;
use OhMyBrew\ShopifyApp\Facades\ShopifyApp;

class AuthProxyMiddlewareTest extends TestCase
{
Expand Down Expand Up @@ -48,12 +49,23 @@ public function testRuns()
{
Input::merge($this->queryParams);

// Confirm no shop
$this->assertEquals(null, session('shopify_domain'));

$called = false;
(new AuthProxy())->handle(request(), function ($request) use (&$called) {
// Should be called
$called = true;

// Session should be set by now
$this->assertEquals($this->queryParams['shop'], session('shopify_domain'));

// Shop should be callable
$shop = ShopifyApp::shop();
$this->assertEquals($this->queryParams['shop'], $shop->shopify_domain);
});

// Confirm full run
$this->assertEquals(true, $called);
}

Expand Down

0 comments on commit 2b1a131

Please sign in to comment.