|
1 | 1 | import { invariant } from '@epic-web/invariant' |
2 | 2 | import { faker } from '@faker-js/faker' |
| 3 | +import { SetCookie } from '@mjackson/headers' |
3 | 4 | import { http } from 'msw' |
4 | 5 | import { afterEach, expect, test } from 'vitest' |
5 | 6 | import { twoFAVerificationType } from '#app/routes/settings+/profile.two-factor.tsx' |
6 | 7 | import { getSessionExpirationDate, sessionKey } from '#app/utils/auth.server.ts' |
7 | | -import { connectionSessionStorage } from '#app/utils/connections.server.ts' |
8 | 8 | import { GITHUB_PROVIDER_NAME } from '#app/utils/connections.tsx' |
9 | 9 | import { prisma } from '#app/utils/db.server.ts' |
10 | 10 | import { authSessionStorage } from '#app/utils/session.server.ts' |
@@ -35,7 +35,7 @@ test('when auth fails, send the user to login with a toast', async () => { |
35 | 35 | consoleError.mockImplementation(() => {}) |
36 | 36 | server.use( |
37 | 37 | http.post('https://github.com/login/oauth/access_token', async () => { |
38 | | - return new Response('error', { status: 400 }) |
| 38 | + return new Response(null, { status: 400 }) |
39 | 39 | }), |
40 | 40 | ) |
41 | 41 | const request = await setupRequest() |
@@ -219,19 +219,25 @@ async function setupRequest({ |
219 | 219 | const state = faker.string.uuid() |
220 | 220 | url.searchParams.set('state', state) |
221 | 221 | url.searchParams.set('code', code) |
222 | | - const connectionSession = await connectionSessionStorage.getSession() |
223 | | - connectionSession.set('oauth2:state', state) |
224 | 222 | const authSession = await authSessionStorage.getSession() |
225 | 223 | if (sessionId) authSession.set(sessionKey, sessionId) |
226 | 224 | const setSessionCookieHeader = |
227 | 225 | await authSessionStorage.commitSession(authSession) |
228 | | - const setConnectionSessionCookieHeader = |
229 | | - await connectionSessionStorage.commitSession(connectionSession) |
| 226 | + const searchParams = new URLSearchParams({ code, state }) |
| 227 | + let authCookie = new SetCookie({ |
| 228 | + name: 'github', |
| 229 | + value: searchParams.toString(), |
| 230 | + path: '/', |
| 231 | + sameSite: 'Lax', |
| 232 | + httpOnly: true, |
| 233 | + maxAge: 60 * 10, |
| 234 | + secure: process.env.NODE_ENV === 'production' || undefined, |
| 235 | + }) |
230 | 236 | const request = new Request(url.toString(), { |
231 | 237 | method: 'GET', |
232 | 238 | headers: { |
233 | 239 | cookie: [ |
234 | | - convertSetCookieToCookie(setConnectionSessionCookieHeader), |
| 240 | + authCookie.toString(), |
235 | 241 | convertSetCookieToCookie(setSessionCookieHeader), |
236 | 242 | ].join('; '), |
237 | 243 | }, |
|
0 commit comments