Skip to content

Commit

Permalink
fix(test): use demo app to test username-password flow in integration…
Browse files Browse the repository at this point in the history
… test (#1635)
  • Loading branch information
xiaoyijun authored Jul 21, 2022
1 parent 0b2bfb1 commit a258587
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/integration-tests/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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}`;
14 changes: 7 additions & 7 deletions packages/integration-tests/tests/username-password-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
});
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('username and password flow', () => {

const authorizationCode = verifyAndParseCodeFromCallbackUri(
callbackUri,
redirectUri,
demoAppRedirectUri,
logtoContext.state
);
expect(authorizationCode).toBeTruthy();
Expand All @@ -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,
},
Expand Down

0 comments on commit a258587

Please sign in to comment.