-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHIBUI-1391 added validation for regex
- Loading branch information
Showing
15 changed files
with
186 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
21 changes: 21 additions & 0 deletions
21
ui/src/app/metadata/domain/entity/filter/nameid-format-filter.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,21 @@ | ||
import { NameIDFormatFilterEntity } from './nameid-format-filter'; | ||
|
||
describe('NameIDFormatFilterEntity Entity', () => { | ||
let entity: NameIDFormatFilterEntity; | ||
beforeEach(() => { | ||
entity = new NameIDFormatFilterEntity({ | ||
resourceId: 'foo', | ||
filterEnabled: false | ||
}); | ||
}); | ||
|
||
it('should be an instance', () => { | ||
expect(entity).toBeDefined(); | ||
expect(entity.resourceId).toBe('foo'); | ||
expect(entity.enabled).toBe(entity.filterEnabled); | ||
expect(entity.id).toBe(entity.resourceId); | ||
expect(entity.getId()).toBe(entity.resourceId); | ||
expect(entity.getDisplayId()).toBe(entity.resourceId); | ||
expect(entity.isDraft()).toBe(false); | ||
}); | ||
}); |
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
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
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
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
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
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
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
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,21 @@ | ||
import { memoize } from './memo'; | ||
|
||
const fns = { | ||
square(n) { | ||
return n * n; | ||
} | ||
}; | ||
|
||
describe('memoize function', () => { | ||
it('should return a memoized function', () => { | ||
spyOn(fns, 'square').and.callThrough(); | ||
const memoized = memoize(fns.square); | ||
const call1 = memoized(1); | ||
const call2 = memoized(2); | ||
const call3 = memoized(2); | ||
expect(call1).toBe(1); | ||
expect(call2).toBe(4); | ||
expect(call3).toBe(4); | ||
expect(fns.square).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
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,15 @@ | ||
export function memoize(func) { | ||
const cache = {}; | ||
return function (...args: any[]) { | ||
const key = JSON.stringify(args); | ||
if (cache[key]) { | ||
return cache[key]; | ||
} else { | ||
const val = func.apply(null, args); | ||
cache[key] = val; | ||
return val; | ||
} | ||
}; | ||
} | ||
|
||
export default { memoize }; |
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,18 @@ | ||
import { RegexValidator } from './regex.validator'; | ||
|
||
describe('RegexValidator', () => { | ||
describe('isValidRegex method', () => { | ||
it('should return true if no error is thrown', () => { | ||
expect(RegexValidator.isValidRegex('/abc/')).toBe(true); | ||
expect(RegexValidator.isValidRegex('/*123/')).toBe(true); | ||
}); | ||
|
||
it('should return false if an error is thrown trying to construct a regex', () => { | ||
expect(RegexValidator.isValidRegex(')')).toBe(false); | ||
}); | ||
|
||
it('should return false if the regex doesnt begin and end with slashes', () => { | ||
expect(RegexValidator.isValidRegex('abc')).toBe(false); | ||
}); | ||
}); | ||
}); |
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,18 @@ | ||
const regexChecker = new RegExp('^\/|\/$', 'g'); | ||
|
||
export class RegexValidator { | ||
static isValidRegex(pattern: string): boolean { | ||
if (!pattern) { | ||
return true; | ||
} | ||
let regex; | ||
try { | ||
regex = new RegExp(pattern); | ||
} catch (err) { | ||
return false; | ||
} | ||
return regexChecker.test(pattern); | ||
} | ||
} | ||
|
||
export default RegexValidator; |