CryptUtils.spec.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { assert } from 'chai';
  2. import { CryptUtils } from '../../../src/utils/CryptUtils';
  3. describe('CryptUtils', () => {
  4. describe('btoa (string: string): string', () => {
  5. it('should create a base-64 encoded string from a given string', () => {
  6. assert.equal(CryptUtils.btoa('string'), 'c3RyaW5n');
  7. });
  8. });
  9. describe('hideString (str: string, length: number): [string, string]', () => {
  10. let original1: string = 'example.com',
  11. [str1, diff] = CryptUtils.hideString(original1, 30);
  12. it('should return a string with the original string within', () => {
  13. assert.isTrue(str1.length > original1.length);
  14. assert.equal(str1.replace(new RegExp('[' + diff + ']', 'g'), ''), original1);
  15. });
  16. });
  17. describe('rc4 (string: string, key: string): string', () => {
  18. it('should encode string using the rc4 algorithm', () => {
  19. const string: string = 'test';
  20. const key: string = 'key';
  21. assert.notEqual(CryptUtils.rc4(string, key), string);
  22. });
  23. it('should encode and successfully decode string using the rc4 algorithm', () => {
  24. const string: string = 'test';
  25. const key: string = 'key';
  26. assert.equal(CryptUtils.rc4(CryptUtils.rc4(string, key), key), string);
  27. });
  28. });
  29. });