qrcode.js 2.4 KB

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