-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
59 additions
and
326 deletions.
There are no files selected for viewing
160 changes: 0 additions & 160 deletions
160
packages/app/.cache-synpress/wallet-setup-dist/basic.setup.mjs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,66 @@ | ||
import { test, expect } from '@playwright/test' | ||
import { getAccessToken } from '@privy-io/react-auth' | ||
import * as jose from 'jose' | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto('http://localhost:3000/studio') | ||
}) | ||
|
||
test('sign in button exists', async ({ page }) => { | ||
await page.keyboard.press('Escape') | ||
async function generatePrivyJWT() { | ||
const { publicKey, privateKey } = await jose.generateKeyPair( | ||
'ES256' | ||
) | ||
|
||
const button = page.getByRole('button') | ||
await expect(button).toBeVisible() | ||
}) | ||
console.log(process.env.PRIVY_APP_ID) | ||
|
||
const session = 'test-session-' + Date.now() | ||
const subject = 'did:privy:test-' + Date.now() | ||
const issuer = 'privy.io' | ||
const audience = process.env.PRIVY_APP_ID || '' | ||
const expiration = '1h' | ||
|
||
const authToken = await new jose.SignJWT({ sid: session }) | ||
.setProtectedHeader({ alg: 'ES256', typ: 'JWT' }) | ||
.setIssuer(issuer) | ||
.setIssuedAt() | ||
.setAudience(audience) | ||
.setSubject(subject) | ||
.setExpirationTime(expiration) | ||
.sign(privateKey) | ||
|
||
try { | ||
const payload = await jose.jwtVerify(authToken, publicKey, { | ||
issuer: 'privy.io', | ||
audience: process.env.PRIVY_APP_ID || '', | ||
}) | ||
console.log('JWT verified successfully. Payload:', payload) | ||
} catch (error) { | ||
console.error(`JWT failed to verify with error: ${error}`) | ||
throw error | ||
} | ||
|
||
return authToken | ||
} | ||
|
||
test('login to studio page with Privy JWT', async ({ page }) => { | ||
const authToken = await generatePrivyJWT() | ||
const accessToken = await getAccessToken() | ||
|
||
console.log(accessToken) | ||
|
||
await page.goto('http://localhost:3000/studio/create', { | ||
waitUntil: 'networkidle', | ||
}) | ||
|
||
await page.evaluate((token) => { | ||
localStorage.setItem('privy:auth:token', token) | ||
}, authToken) | ||
|
||
await page.reload({ waitUntil: 'networkidle' }) | ||
|
||
expect(page.url()).toContain('/studio') | ||
|
||
test('login with metamask', async ({ page }) => { | ||
const button = page.getByRole('button') | ||
await expect(button).toBeVisible() | ||
await expect(page.locator('text=Studio')).toBeVisible({ | ||
timeout: 30000, | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.