Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

url-parser.js 2.7 KiB

pirms 7 gadiem
pirms 7 gadiem
pirms 7 gadiem
pirms 7 gadiem
pirms 7 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import test from 'ava';
  2. import * as urlParser from '../src/domain/url-parser';
  3. test('urlParser.getDomainName v2', 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('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('getbootstrap.com', urlParser.getDomainName('http://v4-alpha.getbootstrap.com/components/buttons/'));
  10. 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'));
  11. t.is('netflix.com', urlParser.getDomainName('https://www.netflix.com/browse'));
  12. t.is('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. t.is('192.168.1.1', urlParser.getDomainName('http://192.168.1.1'));
  15. t.is('192.168.1.1', urlParser.getDomainName('https://192.168.1.1/'));
  16. t.is('', urlParser.getDomainName(undefined));
  17. });
  18. test('get current tab', t => {
  19. const url = 'https://example.org';
  20. global.chrome = {
  21. tabs: {
  22. query(a, callback){
  23. callback([{url}])
  24. }
  25. }
  26. };
  27. return urlParser.getSite().then(response => {
  28. t.is(response.url, url);
  29. t.is(response.site, 'example.org')
  30. });
  31. });
  32. test('getPasswordFromUrlQuery', t => {
  33. const query = {
  34. login: "test@example.org",
  35. site: "example.org",
  36. uppercase: "true",
  37. lowercase: "true",
  38. numbers: "true",
  39. symbols: "false",
  40. length: "16",
  41. counter: "1",
  42. version: "2"
  43. };
  44. const expectedPassword = {
  45. login: "test@example.org",
  46. site: "example.org",
  47. uppercase: true,
  48. lowercase: true,
  49. numbers: true,
  50. symbols: false,
  51. length: 16,
  52. counter: 1,
  53. version: 2
  54. };
  55. t.deepEqual(urlParser.getPasswordFromUrlQuery(query), expectedPassword);
  56. });
  57. test('getPasswordFromUrlQuery booleanish', t => {
  58. const query = {
  59. uppercase: "true",
  60. lowercase: "TrUe",
  61. numbers: "1",
  62. symbols: "0",
  63. };
  64. const expectedPassword = {
  65. uppercase: true,
  66. lowercase: true,
  67. numbers: true,
  68. symbols: false,
  69. };
  70. t.deepEqual(urlParser.getPasswordFromUrlQuery(query), expectedPassword);
  71. });