You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

72 lines
2.3 KiB

  1. import test from 'ava';
  2. import * as urlParser from '../src/services/url-parser';
  3. test('getDomainName', t => {
  4. t.is('lesspass.com', urlParser.getSite('https://lesspass.com/#!/'));
  5. t.is('lesspass.com', urlParser.getSite('https://lesspass.com/api/'));
  6. t.is('api.lesspass.com', urlParser.getSite('https://api.lesspass.com/'));
  7. t.is('lesspass.com', urlParser.getSite('http://lesspass.com'));
  8. t.is('stackoverflow.com', urlParser.getSite('http://stackoverflow.com/questions/3689423/google-chrome-plugin-how-to-get-domain-from-url-tab-url'));
  9. t.is('v4-alpha.getbootstrap.com', urlParser.getSite('http://v4-alpha.getbootstrap.com/components/buttons/'));
  10. t.is('accounts.google.com', urlParser.getSite('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.getSite('https://www.netflix.com/browse'));
  12. t.is('www.bbc.co.uk', urlParser.getSite('https://www.bbc.co.uk'));
  13. t.is('192.168.1.1:10443', urlParser.getSite('https://192.168.1.1:10443/webapp/'));
  14. t.is('', urlParser.getSite(undefined));
  15. });
  16. test('getUrl', t => {
  17. global.chrome = {
  18. tabs: {
  19. query(a, callback){
  20. callback([{url: 'https://example.org'}])
  21. }
  22. }
  23. };
  24. return urlParser.getUrl().then(url => {
  25. t.is(url, 'https://example.org');
  26. });
  27. });
  28. test('getPasswordFromUrlQuery', t => {
  29. const query = {
  30. login: "test@example.org",
  31. site: "example.org",
  32. uppercase: "true",
  33. lowercase: "true",
  34. numbers: "true",
  35. symbols: "false",
  36. length: "16",
  37. counter: "1",
  38. version: "2"
  39. };
  40. const expectedPassword = {
  41. login: "test@example.org",
  42. site: "example.org",
  43. uppercase: true,
  44. lowercase: true,
  45. numbers: true,
  46. symbols: false,
  47. length: 16,
  48. counter: 1,
  49. version: 2
  50. };
  51. t.deepEqual(urlParser.getPasswordFromUrlQuery(query), expectedPassword);
  52. });
  53. test('getPasswordFromUrlQuery booleanish', t => {
  54. const query = {
  55. uppercase: "true",
  56. lowercase: "TrUe",
  57. numbers: "1",
  58. symbols: "0",
  59. };
  60. const expectedPassword = {
  61. uppercase: true,
  62. lowercase: true,
  63. numbers: true,
  64. symbols: false,
  65. };
  66. t.deepEqual(urlParser.getPasswordFromUrlQuery(query), expectedPassword);
  67. });