From a258587b4e804615b6a51e336a1af04478d91437 Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Thu, 21 Jul 2022 15:32:05 +0800 Subject: [PATCH] fix(test): use demo app to test username-password flow in integration test (#1635) --- packages/integration-tests/src/constants.ts | 3 ++- .../tests/username-password-flow.test.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/integration-tests/src/constants.ts b/packages/integration-tests/src/constants.ts index 8e8c6b26b..7d9745728 100644 --- a/packages/integration-tests/src/constants.ts +++ b/packages/integration-tests/src/constants.ts @@ -1,7 +1,8 @@ +import { demoAppApplicationId } from '@logto/schemas/lib/seeds'; import { getEnv } from '@silverhand/essentials'; export const logtoUrl = getEnv('LOGTO_URL'); export const discoveryUrl = `${logtoUrl}/oidc/.well-known/openid-configuration`; -export const redirectUri = `${logtoUrl}/console/callback`; +export const demoAppRedirectUri = `${logtoUrl}/${demoAppApplicationId}`; diff --git a/packages/integration-tests/tests/username-password-flow.test.ts b/packages/integration-tests/tests/username-password-flow.test.ts index 459335676..caebf10cc 100644 --- a/packages/integration-tests/tests/username-password-flow.test.ts +++ b/packages/integration-tests/tests/username-password-flow.test.ts @@ -5,12 +5,12 @@ import { generateSignInUri, verifyAndParseCodeFromCallbackUri, } from '@logto/js'; -import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds'; +import { demoAppApplicationId } from '@logto/schemas/lib/seeds'; import got from 'got/dist/source'; import api from '@/api'; -import { discoveryUrl, logtoUrl, redirectUri } from '../src/constants'; +import { discoveryUrl, logtoUrl, demoAppRedirectUri } from '../src/constants'; import { LogtoContext } from '../src/logto-context'; import { extractCookie } from '../src/utils'; @@ -34,8 +34,8 @@ describe('username and password flow', () => { it('should visit authorization endpoint and get interaction cookie', async () => { const signInUri = generateSignInUri({ authorizationEndpoint: logtoContext.authorizationEndpoint, - clientId: adminConsoleApplicationId, - redirectUri, + clientId: demoAppApplicationId, + redirectUri: demoAppRedirectUri, codeChallenge: logtoContext.codeChallenge, state: logtoContext.state, }); @@ -154,7 +154,7 @@ describe('username and password flow', () => { const authorizationCode = verifyAndParseCodeFromCallbackUri( callbackUri, - redirectUri, + demoAppRedirectUri, logtoContext.state ); expect(authorizationCode).toBeTruthy(); @@ -165,9 +165,9 @@ describe('username and password flow', () => { it('should fetch token by authorization code', async () => { const token = await fetchTokenByAuthorizationCode( { - clientId: adminConsoleApplicationId, + clientId: demoAppApplicationId, tokenEndpoint: logtoContext.tokenEndpoint, - redirectUri, + redirectUri: demoAppRedirectUri, codeVerifier: logtoContext.codeVerifier, code: logtoContext.authorizationCode, },