Skip to content

Commit

Permalink
test(cli): add unit tests for tunnel util
Browse files Browse the repository at this point in the history
  • Loading branch information
charIeszhao committed Aug 16, 2024
1 parent 36951a6 commit adc1e25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/cli/src/commands/tunnel/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
2 changes: 1 addition & 1 deletion packages/cli/src/commands/tunnel/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const checkExperienceInput = (url?: string, staticPath?: string) => {
export const isLogtoRequestPath = (requestPath?: string): boolean =>
['/oidc/', '/api/'].some((path) => requestPath?.startsWith(path)) || requestPath === '/consent';

const isFileAssetPath = (url: string): boolean => {
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('.'));
Expand Down

0 comments on commit adc1e25

Please sign in to comment.