Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
koa-shopify-auth: Accept mixed-case shop parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerball committed Feb 1, 2019
1 parent b64b969 commit c9093b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/koa-shopify-auth/src/auth/create-oauth-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function createOAuthStart(

const shopRegex = new RegExp(
`^[a-z0-9][a-z0-9\\-]*[a-z0-9]\\.${myShopifyDomain}$`,
'i',
);

if (shop == null || !shopRegex.test(shop)) {
Expand Down
16 changes: 16 additions & 0 deletions packages/koa-shopify-auth/src/auth/test/oauth-start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const baseUrl = 'myapp.com/auth';
const callbackPath = '/callback';
const shop = 'sho-p1.myshopify.io';
const badShop = 'shop1myshopify.io';
const uppercaseShop = 'SHO-P1.myshopify.io';
const redirectionURL = `/admin/oauth/authorize`;

const baseConfig: OAuthStartOptions = {
Expand Down Expand Up @@ -80,4 +81,19 @@ describe('OAuthStart', () => {
`https://${shop}${redirectionURL}?abc=123`,
);
});

it('accepts mixed-case shop parameters', () => {
const oAuthStart = createOAuthStart(baseConfig, callbackPath);
const ctx = createMockContext({
url: `https://${baseUrl}?${query({shop: uppercaseShop})}`,
});

(oAuthQueryString as any).mockReturnValueOnce('');

oAuthStart(ctx);

expect(ctx.redirect).toBeCalledWith(
`https://${uppercaseShop}${redirectionURL}?`,
);
});
});

0 comments on commit c9093b2

Please sign in to comment.