webclient.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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('3ema.services');
  26. module('3ema.container');
  27. // Inject the service to be tested
  28. inject(function(WebClientService) {
  29. $service = WebClientService;
  30. });
  31. });
  32. it('can skip ICE TLS hosts if a non-TLS TCP server is available', () => {
  33. const allUrlsBefore = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  34. expect(allUrlsBefore.indexOf('turns:turn.threema.ch:443?transport=tcp')).not.toEqual(-1);
  35. $service.skipIceTls();
  36. const allUrlsAfter = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  37. expect(allUrlsAfter.length).toEqual(allUrlsBefore.length - 1);
  38. expect(allUrlsAfter.indexOf('turns:turn.threema.ch:443?transport=tcp')).toEqual(-1);
  39. });
  40. it('can skip ICE TLS hosts if a non-TLS TCP server is available in another server object', () => {
  41. $service.config.ICE_SERVERS = [
  42. {
  43. urls: ['turn:turn.threema.ch:443?transport=udp', 'turns:turn.threema.ch:443?transport=tcp'],
  44. username: 'user', credential: 'credential',
  45. },
  46. {
  47. urls: ['turn:turn.threema.ch:443?transport=tcp'],
  48. username: 'user', credential: 'credential',
  49. }
  50. ];
  51. const allUrlsBefore = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  52. expect(allUrlsBefore.indexOf('turns:turn.threema.ch:443?transport=tcp')).not.toEqual(-1);
  53. $service.skipIceTls();
  54. const allUrlsAfter = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  55. expect(allUrlsAfter.length).toEqual(allUrlsBefore.length - 1);
  56. expect(allUrlsAfter.indexOf('turns:turn.threema.ch:443?transport=tcp')).toEqual(-1);
  57. });
  58. it('does not skip ICE TLS hosts if no non-TLS TCP server is available', () => {
  59. $service.config.ICE_SERVERS = [
  60. {
  61. urls: ['turn:turn.threema.ch:443?transport=udp', 'turns:turn.threema.ch:443?transport=tcp'],
  62. username: 'user',
  63. credential: 'credential',
  64. }
  65. ];
  66. const allUrlsBefore = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  67. expect(allUrlsBefore.indexOf('turns:turn.threema.ch:443?transport=tcp')).not.toEqual(-1);
  68. $service.skipIceTls();
  69. const allUrlsAfter = [].concat(...$service.config.ICE_SERVERS.map((conf) => conf.urls));
  70. expect(allUrlsAfter.length).toEqual(allUrlsBefore.length);
  71. expect(allUrlsAfter.indexOf('turns:turn.threema.ch:443?transport=tcp')).not.toEqual(-1);
  72. });
  73. });