123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import { assert } from 'chai';
- import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
- import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
- describe('`domainLockRedirectUrl` validation', () => {
- describe('IsDomainLockRedirectUrl', () => {
- describe('Variant #1: positive validation', () => {
- describe('Variant #1: string with url containing protocol, host and some path', () => {
- let testFunc: () => string;
- beforeEach(() => {
- testFunc = () => JavaScriptObfuscator.obfuscate(
- '',
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- domainLockRedirectUrl: 'https://example.com/path'
- }
- ).getObfuscatedCode();
- });
- it('should pass validation', () => {
- assert.doesNotThrow(testFunc);
- });
- });
- describe('Variant #2: string with url containing host and some path', () => {
- let testFunc: () => string;
- beforeEach(() => {
- testFunc = () => JavaScriptObfuscator.obfuscate(
- '',
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- domainLockRedirectUrl: 'example.com/path'
- }
- ).getObfuscatedCode();
- });
- it('should pass validation', () => {
- assert.doesNotThrow(testFunc);
- });
- });
- describe('Variant #3: string with url containing host and some path', () => {
- let testFunc: () => string;
- beforeEach(() => {
- testFunc = () => JavaScriptObfuscator.obfuscate(
- '',
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- domainLockRedirectUrl: '/path'
- }
- ).getObfuscatedCode();
- });
- it('should pass validation', () => {
- assert.doesNotThrow(testFunc);
- });
- });
- describe('Variant #4: `about:blank` string', () => {
- let testFunc: () => string;
- beforeEach(() => {
- testFunc = () => JavaScriptObfuscator.obfuscate(
- '',
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- domainLockRedirectUrl: 'about:blank'
- }
- ).getObfuscatedCode();
- });
- it('should pass validation', () => {
- assert.doesNotThrow(testFunc);
- });
- });
- });
- describe('Variant #2: negative validation', () => {
- describe('Variant #1: some non-url string', () => {
- const expectedError: string = 'must be an URL address';
- let testFunc: () => string;
- beforeEach(() => {
- testFunc = () => JavaScriptObfuscator.obfuscate(
- '',
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- domainLockRedirectUrl: 'foo'
- }
- ).getObfuscatedCode();
- });
- it('should not pass validation', () => {
- assert.throws(testFunc, expectedError);
- });
- });
- });
- });
- });
|