Validation.spec.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { assert } from 'chai';
  2. import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
  3. import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
  4. describe('`domainLockRedirectUrl` validation', () => {
  5. describe('IsDomainLockRedirectUrl', () => {
  6. describe('Variant #1: positive validation', () => {
  7. describe('Variant #1: string with url containing protocol, host and some path', () => {
  8. let testFunc: () => string;
  9. beforeEach(() => {
  10. testFunc = () => JavaScriptObfuscator.obfuscate(
  11. '',
  12. {
  13. ...NO_ADDITIONAL_NODES_PRESET,
  14. domainLockRedirectUrl: 'https://example.com/path'
  15. }
  16. ).getObfuscatedCode();
  17. });
  18. it('should pass validation', () => {
  19. assert.doesNotThrow(testFunc);
  20. });
  21. });
  22. describe('Variant #2: string with url containing host and some path', () => {
  23. let testFunc: () => string;
  24. beforeEach(() => {
  25. testFunc = () => JavaScriptObfuscator.obfuscate(
  26. '',
  27. {
  28. ...NO_ADDITIONAL_NODES_PRESET,
  29. domainLockRedirectUrl: 'example.com/path'
  30. }
  31. ).getObfuscatedCode();
  32. });
  33. it('should pass validation', () => {
  34. assert.doesNotThrow(testFunc);
  35. });
  36. });
  37. describe('Variant #3: string with url containing host and some path', () => {
  38. let testFunc: () => string;
  39. beforeEach(() => {
  40. testFunc = () => JavaScriptObfuscator.obfuscate(
  41. '',
  42. {
  43. ...NO_ADDITIONAL_NODES_PRESET,
  44. domainLockRedirectUrl: '/path'
  45. }
  46. ).getObfuscatedCode();
  47. });
  48. it('should pass validation', () => {
  49. assert.doesNotThrow(testFunc);
  50. });
  51. });
  52. describe('Variant #4: `about:blank` string', () => {
  53. let testFunc: () => string;
  54. beforeEach(() => {
  55. testFunc = () => JavaScriptObfuscator.obfuscate(
  56. '',
  57. {
  58. ...NO_ADDITIONAL_NODES_PRESET,
  59. domainLockRedirectUrl: 'about:blank'
  60. }
  61. ).getObfuscatedCode();
  62. });
  63. it('should pass validation', () => {
  64. assert.doesNotThrow(testFunc);
  65. });
  66. });
  67. });
  68. describe('Variant #2: negative validation', () => {
  69. describe('Variant #1: some non-url string', () => {
  70. const expectedError: string = 'must be an URL address';
  71. let testFunc: () => string;
  72. beforeEach(() => {
  73. testFunc = () => JavaScriptObfuscator.obfuscate(
  74. '',
  75. {
  76. ...NO_ADDITIONAL_NODES_PRESET,
  77. domainLockRedirectUrl: 'foo'
  78. }
  79. ).getObfuscatedCode();
  80. });
  81. it('should not pass validation', () => {
  82. assert.throws(testFunc, expectedError);
  83. });
  84. });
  85. });
  86. });
  87. });