qrcode.js 2.5 KB

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