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.

url-parser.js 2.4 KiB

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