0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

fix: test cases

This commit is contained in:
Charles Zhao 2024-01-08 17:54:58 +08:00
parent 0ce2631edb
commit dc5f7e81e9
No known key found for this signature in database
GPG key ID: 4858774754C92DF2
2 changed files with 11 additions and 4 deletions

View file

@ -3,7 +3,15 @@ export const phoneRegEx = /^\d+$/;
export const phoneInputRegEx = /^\+?[\d-( )]+$/; export const phoneInputRegEx = /^\+?[\d-( )]+$/;
export const usernameRegEx = /^[A-Z_a-z]\w*$/; export const usernameRegEx = /^[A-Z_a-z]\w*$/;
export const webRedirectUriProtocolRegEx = /^https?:$/; export const webRedirectUriProtocolRegEx = /^https?:$/;
/**
* Strict custom URI scheme check that matches the OIDC recommended pattern: a reversed domain name followed by a colon.
* E.g. `com.myapp://callback` is a valid redirect URI, but `myapp://callback` is not.
*/
export const mobileUriSchemeProtocolRegEx = /^[a-z][\d+_a-z-]*(\.[\d+_a-z-]+)+:$/; export const mobileUriSchemeProtocolRegEx = /^[a-z][\d+_a-z-]*(\.[\d+_a-z-]+)+:$/;
/**
* Loose custom URI scheme check that matches any non-whitespace character followed by a colon, for better compatibility.
* Community reports that some windows native apps use this scheme pattern. E.g. `myapp://callback`
*/
export const looseNativeUriSchemeProtocolRegEx = /^\S*:$/; export const looseNativeUriSchemeProtocolRegEx = /^\S*:$/;
export const hexColorRegEx = /^#[\da-f]{3}([\da-f]{3})?$/i; export const hexColorRegEx = /^#[\da-f]{3}([\da-f]{3})?$/i;
export const dateRegex = /^\d{4}(-\d{2}){2}/; export const dateRegex = /^\d{4}(-\d{2}){2}/;

View file

@ -17,11 +17,10 @@ describe('url utilities', () => {
it('should detect invalid redirect URIs', () => { it('should detect invalid redirect URIs', () => {
expect(validateRedirectUrl('io.logto://my-app/callback', 'web')).toBeFalsy(); expect(validateRedirectUrl('io.logto://my-app/callback', 'web')).toBeFalsy();
expect(validateRedirectUrl('ws://com.company://demo:1234', 'web')).toBeFalsy();
expect(validateRedirectUrl('abc.com', 'web')).toBeFalsy(); expect(validateRedirectUrl('abc.com', 'web')).toBeFalsy();
expect(validateRedirectUrl('abc.com', 'native')).toBeFalsy(); // Does not have colon.
expect(validateRedirectUrl('http://localhost:3001', 'native')).toBeFalsy();
expect(validateRedirectUrl('https://logto.dev/callback', 'native')).toBeFalsy();
expect(validateRedirectUrl('demoApp/callback', 'native')).toBeFalsy(); expect(validateRedirectUrl('demoApp/callback', 'native')).toBeFalsy();
// Does not have non-whitespace characters before colon.
expect(validateRedirectUrl('://callback', 'native')).toBeFalsy();
}); });
}); });