Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

143 рядки
4.0 KiB

  1. import test from "ava";
  2. import * as urlParser from "../../src/services/url-parser";
  3. test("cleanUrl", 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("getSuggestions", t => {
  35. t.deepEqual(
  36. ["bbc", "bbc.com", "www.bbc.com"],
  37. urlParser.getSuggestions("https://www.bbc.com")
  38. );
  39. t.deepEqual(
  40. ["example", "example.org", "www.example.org"],
  41. urlParser.getSuggestions("https://www.example.org/api/?offset=100&limit=10")
  42. );
  43. t.deepEqual(
  44. ["example", "example.org"],
  45. urlParser.getSuggestions("https://example.org")
  46. );
  47. t.deepEqual(
  48. ["example", "example.org"],
  49. urlParser.getSuggestions("example.org")
  50. );
  51. t.deepEqual(
  52. [],
  53. urlParser.getSuggestions("https://192.168.1.1:10443/webapp/")
  54. );
  55. t.deepEqual([], urlParser.getSuggestions("example"));
  56. t.deepEqual([], urlParser.getSuggestions("example."));
  57. t.deepEqual([], urlParser.getSuggestions("example.o"));
  58. t.deepEqual(
  59. urlParser.getSuggestions("http://example.org"),
  60. urlParser.getSuggestions("https://example.org")
  61. );
  62. t.deepEqual(
  63. ["example", "example.org"],
  64. urlParser.getSuggestions("EXAMPLE.org")
  65. );
  66. });
  67. test("getSite", t => {
  68. global.chrome = {
  69. tabs: {
  70. query(a, callback) {
  71. callback([{ url: "https://example.org" }]);
  72. }
  73. }
  74. };
  75. return urlParser.getSite().then(site => {
  76. t.is(site, "example.org");
  77. });
  78. });
  79. test("getPasswordFromUrlQuery", t => {
  80. const query = {
  81. login: "test@example.org",
  82. site: "example.org",
  83. uppercase: "true",
  84. lowercase: "true",
  85. numbers: "true",
  86. symbols: "false",
  87. length: "16",
  88. counter: "1",
  89. version: "2"
  90. };
  91. const expectedPassword = {
  92. login: "test@example.org",
  93. site: "example.org",
  94. uppercase: true,
  95. lowercase: true,
  96. numbers: true,
  97. symbols: false,
  98. length: 16,
  99. counter: 1,
  100. version: 2
  101. };
  102. t.deepEqual(urlParser.getPasswordFromUrlQuery(query), expectedPassword);
  103. });
  104. test("getPasswordFromUrlQuery with base 64 encoded password profile", t => {
  105. const query = {
  106. passwordProfileEncoded:
  107. "eyJsb2dpbiI6InRlc3RAZXhhbXBsZS5vcmciLCJzaXRlIjoiZXhhbXBsZS5vcmciLCJ1cHBlcmNhc2UiOnRydWUsImxvd2VyY2FzZSI6dHJ1ZSwibnVtYmVycyI6dHJ1ZSwic3ltYm9scyI6ZmFsc2UsImxlbmd0aCI6MTYsImNvdW50ZXIiOjEsInZlcnNpb24iOjJ9"
  108. };
  109. const expectedPassword = {
  110. login: "test@example.org",
  111. site: "example.org",
  112. uppercase: true,
  113. lowercase: true,
  114. numbers: true,
  115. symbols: false,
  116. length: 16,
  117. counter: 1,
  118. version: 2
  119. };
  120. t.deepEqual(urlParser.getPasswordFromUrlQuery(query), expectedPassword);
  121. });
  122. test("getPasswordFromUrlQuery booleanish", t => {
  123. const query = {
  124. uppercase: "true",
  125. lowercase: "TrUe",
  126. numbers: "1",
  127. symbols: "0"
  128. };
  129. const expectedPassword = {
  130. uppercase: true,
  131. lowercase: true,
  132. numbers: true,
  133. symbols: false
  134. };
  135. t.deepEqual(urlParser.getPasswordFromUrlQuery(query), expectedPassword);
  136. });