Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

135 Zeilen
5.2 KiB

  1. import test from 'ava';
  2. import * as urlParser from '../src/domain/url-parser';
  3. test(t => {
  4. t.is('lesspass.com', urlParser.getDomainName('https://lesspass.com/#!/'));
  5. t.is('lesspass.com', urlParser.getDomainName('https://lesspass.com/api/'));
  6. t.is('api.lesspass.com', urlParser.getDomainName('https://api.lesspass.com/'));
  7. t.is('lesspass.com', urlParser.getDomainName('http://lesspass.com'));
  8. t.is('stackoverflow.com', urlParser.getDomainName('http://stackoverflow.com/questions/3689423/google-chrome-plugin-how-to-get-domain-from-url-tab-url'));
  9. t.is('v4-alpha.getbootstrap.com', urlParser.getDomainName('http://v4-alpha.getbootstrap.com/components/buttons/'));
  10. t.is('accounts.google.com', urlParser.getDomainName('https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier'));
  11. t.is('www.netflix.com', urlParser.getDomainName('https://www.netflix.com/browse'));
  12. t.is('www.bbc.co.uk', urlParser.getDomainName('https://www.bbc.co.uk'));
  13. t.is('192.168.1.1:10443', urlParser.getDomainName('https://192.168.1.1:10443/webapp/'));
  14. });
  15. test('urlParser.getDomainName v2', t => {
  16. t.is('lesspass.com', urlParser.getDomainName('https://lesspass.com/#!/', 2));
  17. t.is('lesspass.com', urlParser.getDomainName('https://lesspass.com/api/', 2));
  18. t.is('lesspass.com', urlParser.getDomainName('https://api.lesspass.com/', 2));
  19. t.is('lesspass.com', urlParser.getDomainName('http://lesspass.com', 2));
  20. t.is('stackoverflow.com', urlParser.getDomainName('http://stackoverflow.com/questions/3689423/google-chrome-plugin-how-to-get-domain-from-url-tab-url', 2));
  21. t.is('getbootstrap.com', urlParser.getDomainName('http://v4-alpha.getbootstrap.com/components/buttons/', 2));
  22. t.is('google.com', urlParser.getDomainName('https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier', 2));
  23. t.is('netflix.com', urlParser.getDomainName('https://www.netflix.com/browse', 2));
  24. t.is('bbc.co.uk', urlParser.getDomainName('https://www.bbc.co.uk', 2));
  25. t.is('192.168.1.1:10443', urlParser.getDomainName('https://192.168.1.1:10443/webapp/', 2));
  26. t.is('192.168.1.1', urlParser.getDomainName('http://192.168.1.1', 2));
  27. t.is('192.168.1.1', urlParser.getDomainName('https://192.168.1.1/', 2));
  28. t.is('', urlParser.getDomainName(undefined, 2));
  29. });
  30. test('ip validator', t => {
  31. t.true(urlParser._ipIsValid('192.168.23.215'));
  32. t.true(urlParser._ipIsValid('127.0.0.1'));
  33. t.false(urlParser._ipIsValid('210.110'), 'must have 4 octets');
  34. t.false(urlParser._ipIsValid('255'), 'must have 4 octets');
  35. t.false(urlParser._ipIsValid('y.y.y.y'), 'only digits are allowed');
  36. t.false(urlParser._ipIsValid('255.0.0.y'), 'only digits are allowed');
  37. t.false(urlParser._ipIsValid('666.10.10.20'), 'octet number must be between [0-255]');
  38. t.false(urlParser._ipIsValid('4444.11.11.11'), 'octet number must be between [0-255]');
  39. t.false(urlParser._ipIsValid('33.3333.33.3'), 'octet number must be between [0-255]');
  40. });
  41. test('get web extension context', t => {
  42. global.chrome = undefined;
  43. t.false(urlParser.isWebExtension())
  44. });
  45. test('get web extension context', t => {
  46. global.chrome = {
  47. tabs: {
  48. query(a, b){
  49. console.log(a, b)
  50. }
  51. }
  52. };
  53. t.true(urlParser.isWebExtension())
  54. });
  55. test('get current tab', t => {
  56. const url = 'example.org';
  57. global.chrome = {
  58. tabs: {
  59. query(a, callback){
  60. callback([{url}])
  61. }
  62. }
  63. };
  64. return urlParser.getCurrentUrl().then(currentUrl => {
  65. t.is(currentUrl, url)
  66. });
  67. });
  68. test('get default site', t => {
  69. global.chrome = {
  70. tabs: {
  71. query(a, callback){
  72. callback([{url: 'https://example.org'}])
  73. }
  74. }
  75. };
  76. return urlParser.getSite().then(site => {
  77. t.is(site, 'example.org')
  78. });
  79. });
  80. test('get default site if not in web extension', t => {
  81. global.chrome = undefined;
  82. return urlParser.getSite().then(site => {
  83. t.is(site, '')
  84. });
  85. });
  86. test('getPasswordFromUrlQuery', t => {
  87. const query = {
  88. login: "test@example.org",
  89. site: "example.org",
  90. uppercase: "true",
  91. lowercase: "true",
  92. numbers: "true",
  93. symbols: "false",
  94. length: "16",
  95. counter: "1",
  96. version: "2"
  97. };
  98. const expectedPassword = {
  99. login: "test@example.org",
  100. site: "example.org",
  101. uppercase: true,
  102. lowercase: true,
  103. numbers: true,
  104. symbols: false,
  105. length: 16,
  106. counter: 1,
  107. version: 2
  108. };
  109. t.deepEqual(urlParser.getPasswordFromUrlQuery(query), expectedPassword);
  110. });
  111. test('getPasswordFromUrlQuery booleanish', t => {
  112. const query = {
  113. uppercase: "true",
  114. lowercase: "TrUe",
  115. numbers: "1",
  116. symbols: "0",
  117. };
  118. const expectedPassword = {
  119. uppercase: true,
  120. lowercase: true,
  121. numbers: true,
  122. symbols: false,
  123. };
  124. t.deepEqual(urlParser.getPasswordFromUrlQuery(query), expectedPassword);
  125. });