Skip to content

Commit 097b81a

Browse files
committed
fix: use URL hostname check instead of substring match for accounts.shopify.com
1 parent e3c0788 commit 097b81a

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

packages/e2e/setup/global-auth.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ import {chromium} from '@playwright/test'
1717
import * as path from 'path'
1818
import * as fs from 'fs'
1919

20+
function isAccountsShopifyUrl(rawUrl: string): boolean {
21+
try {
22+
return new URL(rawUrl).hostname === 'accounts.shopify.com'
23+
// eslint-disable-next-line no-catch-all/no-catch-all
24+
} catch {
25+
return false
26+
}
27+
}
28+
2029
export default async function globalSetup() {
2130
const email = process.env.E2E_ACCOUNT_EMAIL
2231
const password = process.env.E2E_ACCOUNT_PASSWORD
@@ -105,7 +114,7 @@ export default async function globalSetup() {
105114
await page.waitForTimeout(BROWSER_TIMEOUT.medium)
106115

107116
// Handle account picker if shown
108-
if (page.url().includes('accounts.shopify.com')) {
117+
if (isAccountsShopifyUrl(page.url())) {
109118
const accountButton = page.locator(`text=${email}`).first()
110119
if (await accountButton.isVisible({timeout: BROWSER_TIMEOUT.long}).catch(() => false)) {
111120
await accountButton.click()
@@ -117,7 +126,7 @@ export default async function globalSetup() {
117126
await page.goto(`https://dev.shopify.com/dashboard/${orgId}/apps`, {waitUntil: 'domcontentloaded'})
118127
await page.waitForTimeout(BROWSER_TIMEOUT.medium)
119128

120-
if (page.url().includes('accounts.shopify.com')) {
129+
if (isAccountsShopifyUrl(page.url())) {
121130
const accountButton = page.locator(`text=${email}`).first()
122131
if (await accountButton.isVisible({timeout: BROWSER_TIMEOUT.long}).catch(() => false)) {
123132
await accountButton.click()

0 commit comments

Comments
 (0)