webclient.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. describe('WebClientService', function() {
  2. let $service;
  3. beforeEach(function() {
  4. module(($provide) => {
  5. // Provide configuration
  6. $provide.constant('CONFIG', {
  7. ICE_SERVERS: [
  8. {
  9. urls: [
  10. 'turn:turn.threema.ch:443?transport=tcp',
  11. 'turn:turn.threema.ch:443?transport=udp',
  12. 'turns:turn.threema.ch:443?transport=tcp',
  13. ],
  14. username: 'user',
  15. credential: 'credential',
  16. },
  17. ],
  18. });
  19. // Mock some dependencies that we don't really need
  20. $provide.constant('PROTOCOL_VERSION', 1337);
  21. $provide.constant('$state', null);
  22. $provide.constant('$translate', null);
  23. });
  24. // Load modules
  25. module('ngAria');
  26. module('ngAnimate');
  27. module('ngMaterial');
  28. module('3ema.services');
  29. module('3ema.container');
  30. // Inject the service to be tested
  31. inject(function(WebClientService) {
  32. $service = WebClientService;
  33. });
  34. });
  35. it('can skip ICE TLS hosts if a non-TLS TCP server is available', () => {
  36. const allUrlsBefore = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  37. expect(allUrlsBefore.indexOf('turns:turn.threema.ch:443?transport=tcp')).not.toEqual(-1);
  38. $service.skipIceTls();
  39. const allUrlsAfter = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  40. expect(allUrlsAfter.length).toEqual(allUrlsBefore.length - 1);
  41. expect(allUrlsAfter.indexOf('turns:turn.threema.ch:443?transport=tcp')).toEqual(-1);
  42. });
  43. it('can skip ICE TLS hosts if a non-TLS TCP server is available in another server object', () => {
  44. $service.config.ICE_SERVERS = [
  45. {
  46. urls: ['turn:turn.threema.ch:443?transport=udp', 'turns:turn.threema.ch:443?transport=tcp'],
  47. username: 'user', credential: 'credential',
  48. },
  49. {
  50. urls: ['turn:turn.threema.ch:443?transport=tcp'],
  51. username: 'user', credential: 'credential',
  52. }
  53. ];
  54. const allUrlsBefore = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  55. expect(allUrlsBefore.indexOf('turns:turn.threema.ch:443?transport=tcp')).not.toEqual(-1);
  56. $service.skipIceTls();
  57. const allUrlsAfter = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  58. expect(allUrlsAfter.length).toEqual(allUrlsBefore.length - 1);
  59. expect(allUrlsAfter.indexOf('turns:turn.threema.ch:443?transport=tcp')).toEqual(-1);
  60. });
  61. it('does not skip ICE TLS hosts if no non-TLS TCP server is available', () => {
  62. $service.config.ICE_SERVERS = [
  63. {
  64. urls: ['turn:turn.threema.ch:443?transport=udp', 'turns:turn.threema.ch:443?transport=tcp'],
  65. username: 'user',
  66. credential: 'credential',
  67. }
  68. ];
  69. const allUrlsBefore = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  70. expect(allUrlsBefore.indexOf('turns:turn.threema.ch:443?transport=tcp')).not.toEqual(-1);
  71. $service.skipIceTls();
  72. const allUrlsAfter = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  73. expect(allUrlsAfter.length).toEqual(allUrlsBefore.length);
  74. expect(allUrlsAfter.indexOf('turns:turn.threema.ch:443?transport=tcp')).not.toEqual(-1);
  75. });
  76. });