0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(cli): should proxy google social callback url properly to exp ui (#6458)

* fix(cli): should proxy google social callback url properly to exp ui

* test(cli): add unit tests for tunnel util
This commit is contained in:
Charles Zhao 2024-08-19 12:15:39 +08:00 committed by GitHub
parent e4b028847f
commit 57974a11d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View file

@ -0,0 +1,20 @@
import { expect, describe, it } from 'vitest';
import { isFileAssetPath } from './utils.js';
describe('Tunnel utils', () => {
it('should be able to check if a request path is file asset', () => {
expect(isFileAssetPath('/file.js')).toBe(true);
expect(isFileAssetPath('/file.css')).toBe(true);
expect(isFileAssetPath('/file.png')).toBe(true);
expect(isFileAssetPath('/oidc/.well-known/openid-configuration')).toBe(false);
expect(isFileAssetPath('/oidc/auth')).toBe(false);
expect(isFileAssetPath('/api/interaction/submit')).toBe(false);
expect(isFileAssetPath('/consent')).toBe(false);
expect(
isFileAssetPath(
'/callback/45doq0d004awrjyvdbp92?state=PxsR_Iqtkxw&code=4/0AcvDMrCOMTFXWlKzTcUO24xDify5tQbIMYvaYDS0sj82NzzYlrG4BWXJB4-OxjBI1RPL8g&scope=email%20profile%20openid%20https:/www.googleapis.com/auth/userinfo.profile%20https:/www.googleapis.com/auth/userinfo.email&authuser=0&hd=silverhand.io&prompt=consent'
)
).toBe(false);
});
});

View file

@ -146,10 +146,14 @@ export const checkExperienceInput = (url?: string, staticPath?: string) => {
* @example isLogtoRequestPath('/api/interaction/submit') // true
* @example isLogtoRequestPath('/consent') // true
*/
export const isLogtoRequestPath = (requestPath?: string) =>
export const isLogtoRequestPath = (requestPath?: string): boolean =>
['/oidc/', '/api/'].some((path) => requestPath?.startsWith(path)) || requestPath === '/consent';
const isFileAssetPath = (url: string) => url.split('/').at(-1)?.includes('.');
export const isFileAssetPath = (url: string): boolean => {
// Check if the request URL contains query params. If yes, ignore the params and check the request path
const pathWithoutQuery = url.split('?')[0];
return Boolean(pathWithoutQuery?.split('/').at(-1)?.includes('.'));
};
const getMimeType = (requestPath: string) => {
const fallBackToIndex = !isFileAssetPath(requestPath);