qrcode.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. describe('QrCodeService', function() {
  2. let $service;
  3. beforeAll(() => window.onbeforeunload = () => 'Ignoring page reload request');
  4. beforeEach(function() {
  5. module(($provide) => {
  6. $provide.constant('PROTOCOL_VERSION', 1337);
  7. $provide.constant('CONFIG', {
  8. 'SELF_HOSTED': false,
  9. });
  10. });
  11. module('3ema.services');
  12. // Inject the service
  13. inject(function(QrCodeService) {
  14. $service = QrCodeService;
  15. });
  16. });
  17. it('generates correct payload', () => {
  18. // Example from docs/qr_code.md
  19. let permanentKey = Uint8Array.of(66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
  20. 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66);
  21. let authToken = Uint8Array.of(35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
  22. 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35);
  23. let serverKey = Uint8Array.of(19, 55, 19, 55, 19, 55, 19, 55, 19, 55, 19, 55, 19, 55, 19, 55,
  24. 19, 55, 19, 55, 19, 55, 19, 55, 19, 55, 19, 55, 19, 55, 19, 55);
  25. let host = 'saltyrtc.example.org';
  26. let port = 1234;
  27. let persistent = true;
  28. let payload = $service.buildQrCodePayload(permanentKey, authToken, serverKey, host, port, persistent);
  29. expect(payload).toEqual("BTkCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkIjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIxM3EzcTNxM3EzcTNxM3EzcTNxM3EzcTNxM3EzcTNxM3BNJzYWx0eXJ0Yy5leGFtcGxlLm9yZw==");
  30. });
  31. it('sends zero bytes if no server key was specified', () => {
  32. // Example from docs/qr_code.md
  33. let permanentKey = Uint8Array.of(66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
  34. 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66);
  35. let authToken = Uint8Array.of(35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
  36. 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35);
  37. let host = 'saltyrtc.example.org';
  38. let port = 1234;
  39. let persistent = true;
  40. let payload = $service.buildQrCodePayload(permanentKey, authToken, null, host, port, persistent);
  41. expect(payload).toEqual("BTkCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkIjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABNJzYWx0eXJ0Yy5leGFtcGxlLm9yZw==");
  42. });
  43. });