CryptUtilsSwappedAlphabet.spec.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import 'reflect-metadata';
  2. import { assert } from 'chai';
  3. import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
  4. import { ICryptUtilsSwappedAlphabet } from '../../../src/interfaces/utils/ICryptUtilsSwappedAlphabet';
  5. import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
  6. import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
  7. import { swapLettersCase } from '../../helpers/swapLettersCase';
  8. describe('CryptUtilsSwappedAlphabet', () => {
  9. let cryptUtilsSwappedAlphabet: ICryptUtilsSwappedAlphabet;
  10. before(() => {
  11. const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
  12. inversifyContainerFacade.load('', '', {});
  13. cryptUtilsSwappedAlphabet = inversifyContainerFacade
  14. .get<ICryptUtilsSwappedAlphabet>(ServiceIdentifiers.ICryptUtilsSwappedAlphabet);
  15. });
  16. describe('btoa', () => {
  17. const expectedString: string = swapLettersCase('c3RyaW5n');
  18. let string: string;
  19. before(() => {
  20. string = cryptUtilsSwappedAlphabet.btoa('string');
  21. });
  22. it('should create a base-64 encoded string with swapped alphabet from a given string', () => {
  23. assert.equal(string, expectedString);
  24. });
  25. });
  26. describe('rc4', () => {
  27. const string: string = 'test';
  28. const key: string = 'key';
  29. let encodedString: string,
  30. decodedString: string;
  31. before(() => {
  32. encodedString = cryptUtilsSwappedAlphabet.rc4(string, key);
  33. decodedString = cryptUtilsSwappedAlphabet.rc4(encodedString, key);
  34. });
  35. it('should encode string using the rc4 algorithm', () => {
  36. assert.notEqual(encodedString, string);
  37. });
  38. it('should encode and successfully decode string using the rc4 algorithm', () => {
  39. assert.equal(decodedString, string);
  40. });
  41. });
  42. });