-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-134061 / 25.10 / Apps - UI validates
uri
type more strictly tha…
…n middleware (#11530) * NAS-134061: Apps - UI validates `uri` type more strictly than middleware * NAS-134061: PR update
- Loading branch information
1 parent
2a701fc
commit b920c4a
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/app/modules/forms/ix-forms/validators/url-validation.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { UrlValidationService } from './url-validation.service'; | ||
|
||
describe('UrlValidationService', () => { | ||
let service: UrlValidationService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(UrlValidationService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should validate correct URLs', () => { | ||
const validUrls = [ | ||
'http://example.com', | ||
'https://example.com', | ||
'https://example.com:8080/path', | ||
'ftp://ftp.example.com', | ||
'mqtt://server:1234', | ||
'whatever://anything', | ||
'ws://websocket.server', | ||
'wss://secure.websocket.server', | ||
]; | ||
|
||
validUrls.forEach((url) => { | ||
expect(service.urlRegex.test(url)).toBe(true); | ||
}); | ||
}); | ||
|
||
it('should invalidate incorrect URLs', () => { | ||
const invalidUrls = [ | ||
'example.com', | ||
'http//invalid.com', | ||
'://invalid.com', | ||
'http://inva lid.com', | ||
'mqtt://server:', | ||
'wss://', | ||
'ftp://example.com:abc', | ||
'http:/example.com', | ||
]; | ||
|
||
invalidUrls.forEach((url) => { | ||
expect(service.urlRegex.test(url)).toBe(false); | ||
}); | ||
}); | ||
|
||
it('should allow URLs with ports', () => { | ||
expect(service.urlRegex.test('http://example.com:8080')).toBe(true); | ||
expect(service.urlRegex.test('mqtt://server:1883')).toBe(true); | ||
}); | ||
|
||
it('should allow URLs with paths and query params', () => { | ||
expect(service.urlRegex.test('https://example.com/path/to/resource')).toBe(true); | ||
expect(service.urlRegex.test('ftp://example.com/files?name=test')).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters