ai 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (340) hide show
  1. package/LICENSE +10 -24
  2. package/dist/ai-stream.d.ts +18 -0
  3. package/dist/ai-stream.js +132 -0
  4. package/dist/ai-stream.mjs +13 -0
  5. package/dist/anthropic-stream.d.ts +5 -0
  6. package/dist/anthropic-stream.js +133 -0
  7. package/dist/anthropic-stream.mjs +8 -0
  8. package/dist/chunk-265FSSO4.mjs +91 -0
  9. package/dist/chunk-2L3ZO4UM.mjs +45 -0
  10. package/dist/chunk-EZJ7FC5E.mjs +33 -0
  11. package/dist/chunk-JGDC3BXD.mjs +22 -0
  12. package/dist/chunk-NK2CVBLI.mjs +38 -0
  13. package/dist/chunk-PEYAHBDF.mjs +43 -0
  14. package/dist/chunk-TJMME6CL.mjs +24 -0
  15. package/dist/huggingface-stream.d.ts +5 -0
  16. package/dist/huggingface-stream.js +121 -0
  17. package/dist/huggingface-stream.mjs +8 -0
  18. package/dist/index.d.ts +131 -0
  19. package/dist/index.js +278 -0
  20. package/dist/index.mjs +35 -0
  21. package/dist/index.test.d.ts +2 -0
  22. package/dist/index.test.js +12 -0
  23. package/dist/index.test.mjs +10 -0
  24. package/dist/langchain-stream.d.ts +12 -0
  25. package/dist/langchain-stream.js +102 -0
  26. package/dist/langchain-stream.mjs +8 -0
  27. package/dist/openai-stream.d.ts +5 -0
  28. package/dist/openai-stream.js +144 -0
  29. package/dist/openai-stream.mjs +8 -0
  30. package/dist/streaming-text-response.d.ts +17 -0
  31. package/dist/streaming-text-response.js +75 -0
  32. package/dist/streaming-text-response.mjs +9 -0
  33. package/package.json +78 -29
  34. package/react/dist/chunk-5PP6W52J.mjs +202 -0
  35. package/react/dist/chunk-6EH3SWMP.mjs +55 -0
  36. package/react/dist/chunk-PW6HSU2N.mjs +154 -0
  37. package/react/dist/index.d.ts +3 -0
  38. package/react/dist/index.js +424 -0
  39. package/react/dist/index.mjs +12 -0
  40. package/react/dist/types-f862f74a.d.ts +123 -0
  41. package/react/dist/use-chat.d.ts +42 -0
  42. package/react/dist/use-chat.js +276 -0
  43. package/react/dist/use-chat.mjs +8 -0
  44. package/react/dist/use-completion.d.ts +47 -0
  45. package/react/dist/use-completion.js +229 -0
  46. package/react/dist/use-completion.mjs +8 -0
  47. package/svelte/dist/chunk-6USBQIV6.mjs +177 -0
  48. package/svelte/dist/chunk-BQ64GHZ3.mjs +136 -0
  49. package/svelte/dist/chunk-CENOSGDG.mjs +493 -0
  50. package/svelte/dist/index.d.ts +4 -0
  51. package/svelte/dist/index.js +808 -0
  52. package/svelte/dist/index.mjs +11 -0
  53. package/svelte/dist/types-f862f74a.d.ts +123 -0
  54. package/svelte/dist/use-chat.d.ts +39 -0
  55. package/svelte/dist/use-chat.js +680 -0
  56. package/svelte/dist/use-chat.mjs +7 -0
  57. package/svelte/dist/use-completion.d.ts +38 -0
  58. package/svelte/dist/use-completion.js +640 -0
  59. package/svelte/dist/use-completion.mjs +7 -0
  60. package/.npmignore +0 -15
  61. package/.travis.yml +0 -4
  62. package/README.md +0 -21
  63. package/bin/ai.js +0 -22
  64. package/index.js +0 -37
  65. package/node_modules/request/.npmignore +0 -2
  66. package/node_modules/request/.travis.yml +0 -12
  67. package/node_modules/request/CHANGELOG.md +0 -954
  68. package/node_modules/request/LICENSE +0 -55
  69. package/node_modules/request/README.md +0 -421
  70. package/node_modules/request/index.js +0 -166
  71. package/node_modules/request/lib/cookies.js +0 -40
  72. package/node_modules/request/lib/copy.js +0 -8
  73. package/node_modules/request/lib/debug.js +0 -7
  74. package/node_modules/request/lib/getSafe.js +0 -34
  75. package/node_modules/request/lib/optional.js +0 -5
  76. package/node_modules/request/node_modules/aws-sign2/LICENSE +0 -55
  77. package/node_modules/request/node_modules/aws-sign2/README.md +0 -4
  78. package/node_modules/request/node_modules/aws-sign2/index.js +0 -202
  79. package/node_modules/request/node_modules/aws-sign2/package.json +0 -47
  80. package/node_modules/request/node_modules/forever-agent/LICENSE +0 -55
  81. package/node_modules/request/node_modules/forever-agent/README.md +0 -4
  82. package/node_modules/request/node_modules/forever-agent/index.js +0 -119
  83. package/node_modules/request/node_modules/forever-agent/package.json +0 -46
  84. package/node_modules/request/node_modules/form-data/License +0 -19
  85. package/node_modules/request/node_modules/form-data/Readme.md +0 -175
  86. package/node_modules/request/node_modules/form-data/lib/form_data.js +0 -351
  87. package/node_modules/request/node_modules/form-data/node_modules/async/.travis.yml +0 -3
  88. package/node_modules/request/node_modules/form-data/node_modules/async/LICENSE +0 -19
  89. package/node_modules/request/node_modules/form-data/node_modules/async/README.md +0 -1646
  90. package/node_modules/request/node_modules/form-data/node_modules/async/component.json +0 -11
  91. package/node_modules/request/node_modules/form-data/node_modules/async/lib/async.js +0 -1123
  92. package/node_modules/request/node_modules/form-data/node_modules/async/package.json +0 -60
  93. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/License +0 -19
  94. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/Readme.md +0 -132
  95. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/lib/combined_stream.js +0 -186
  96. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/.npmignore +0 -2
  97. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/License +0 -19
  98. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Makefile +0 -7
  99. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Readme.md +0 -154
  100. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js +0 -99
  101. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/package.json +0 -42
  102. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/common.js +0 -6
  103. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-http-upload.js +0 -38
  104. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-auto-pause.js +0 -21
  105. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-pause.js +0 -14
  106. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream.js +0 -48
  107. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-handle-source-errors.js +0 -15
  108. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-max-data-size.js +0 -18
  109. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-pipe-resumes.js +0 -13
  110. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-proxy-readable.js +0 -13
  111. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/run.js +0 -7
  112. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/package.json +0 -61
  113. package/node_modules/request/node_modules/form-data/node_modules/mime/LICENSE +0 -19
  114. package/node_modules/request/node_modules/form-data/node_modules/mime/README.md +0 -66
  115. package/node_modules/request/node_modules/form-data/node_modules/mime/mime.js +0 -114
  116. package/node_modules/request/node_modules/form-data/node_modules/mime/package.json +0 -59
  117. package/node_modules/request/node_modules/form-data/node_modules/mime/test.js +0 -84
  118. package/node_modules/request/node_modules/form-data/node_modules/mime/types/mime.types +0 -1588
  119. package/node_modules/request/node_modules/form-data/node_modules/mime/types/node.types +0 -77
  120. package/node_modules/request/node_modules/form-data/package.json +0 -80
  121. package/node_modules/request/node_modules/hawk/.npmignore +0 -18
  122. package/node_modules/request/node_modules/hawk/.travis.yml +0 -5
  123. package/node_modules/request/node_modules/hawk/LICENSE +0 -24
  124. package/node_modules/request/node_modules/hawk/Makefile +0 -10
  125. package/node_modules/request/node_modules/hawk/README.md +0 -625
  126. package/node_modules/request/node_modules/hawk/example/usage.js +0 -78
  127. package/node_modules/request/node_modules/hawk/images/hawk.png +0 -0
  128. package/node_modules/request/node_modules/hawk/images/logo.png +0 -0
  129. package/node_modules/request/node_modules/hawk/index.js +0 -1
  130. package/node_modules/request/node_modules/hawk/lib/browser.js +0 -507
  131. package/node_modules/request/node_modules/hawk/lib/client.js +0 -371
  132. package/node_modules/request/node_modules/hawk/lib/crypto.js +0 -118
  133. package/node_modules/request/node_modules/hawk/lib/index.js +0 -15
  134. package/node_modules/request/node_modules/hawk/lib/server.js +0 -523
  135. package/node_modules/request/node_modules/hawk/lib/utils.js +0 -183
  136. package/node_modules/request/node_modules/hawk/node_modules/boom/.npmignore +0 -18
  137. package/node_modules/request/node_modules/hawk/node_modules/boom/.travis.yml +0 -5
  138. package/node_modules/request/node_modules/hawk/node_modules/boom/LICENSE +0 -24
  139. package/node_modules/request/node_modules/hawk/node_modules/boom/Makefile +0 -11
  140. package/node_modules/request/node_modules/hawk/node_modules/boom/README.md +0 -6
  141. package/node_modules/request/node_modules/hawk/node_modules/boom/images/boom.png +0 -0
  142. package/node_modules/request/node_modules/hawk/node_modules/boom/index.js +0 -1
  143. package/node_modules/request/node_modules/hawk/node_modules/boom/lib/index.js +0 -207
  144. package/node_modules/request/node_modules/hawk/node_modules/boom/package.json +0 -64
  145. package/node_modules/request/node_modules/hawk/node_modules/boom/test/index.js +0 -245
  146. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.npmignore +0 -18
  147. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.travis.yml +0 -5
  148. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/LICENSE +0 -24
  149. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/Makefile +0 -11
  150. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/README.md +0 -6
  151. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/index.js +0 -1
  152. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/lib/index.js +0 -68
  153. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/package.json +0 -65
  154. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/test/index.js +0 -101
  155. package/node_modules/request/node_modules/hawk/node_modules/hoek/.npmignore +0 -18
  156. package/node_modules/request/node_modules/hawk/node_modules/hoek/.travis.yml +0 -5
  157. package/node_modules/request/node_modules/hawk/node_modules/hoek/LICENSE +0 -33
  158. package/node_modules/request/node_modules/hawk/node_modules/hoek/Makefile +0 -10
  159. package/node_modules/request/node_modules/hawk/node_modules/hoek/README.md +0 -436
  160. package/node_modules/request/node_modules/hawk/node_modules/hoek/images/hoek.png +0 -0
  161. package/node_modules/request/node_modules/hawk/node_modules/hoek/index.js +0 -1
  162. package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/escape.js +0 -132
  163. package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/index.js +0 -585
  164. package/node_modules/request/node_modules/hawk/node_modules/hoek/package.json +0 -70
  165. package/node_modules/request/node_modules/hawk/node_modules/hoek/test/escaper.js +0 -86
  166. package/node_modules/request/node_modules/hawk/node_modules/hoek/test/index.js +0 -1078
  167. package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test1.js +0 -1
  168. package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test2.js +0 -1
  169. package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test3.js +0 -1
  170. package/node_modules/request/node_modules/hawk/node_modules/sntp/.npmignore +0 -18
  171. package/node_modules/request/node_modules/hawk/node_modules/sntp/.travis.yml +0 -5
  172. package/node_modules/request/node_modules/hawk/node_modules/sntp/LICENSE +0 -24
  173. package/node_modules/request/node_modules/hawk/node_modules/sntp/Makefile +0 -11
  174. package/node_modules/request/node_modules/hawk/node_modules/sntp/README.md +0 -68
  175. package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/offset.js +0 -16
  176. package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/time.js +0 -25
  177. package/node_modules/request/node_modules/hawk/node_modules/sntp/index.js +0 -1
  178. package/node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js +0 -409
  179. package/node_modules/request/node_modules/hawk/node_modules/sntp/package.json +0 -65
  180. package/node_modules/request/node_modules/hawk/node_modules/sntp/test/index.js +0 -359
  181. package/node_modules/request/node_modules/hawk/package.json +0 -70
  182. package/node_modules/request/node_modules/hawk/test/browser.js +0 -817
  183. package/node_modules/request/node_modules/hawk/test/client.js +0 -206
  184. package/node_modules/request/node_modules/hawk/test/crypto.js +0 -86
  185. package/node_modules/request/node_modules/hawk/test/index.js +0 -316
  186. package/node_modules/request/node_modules/hawk/test/message.js +0 -246
  187. package/node_modules/request/node_modules/hawk/test/readme.js +0 -98
  188. package/node_modules/request/node_modules/hawk/test/server.js +0 -686
  189. package/node_modules/request/node_modules/hawk/test/uri.js +0 -456
  190. package/node_modules/request/node_modules/hawk/test/utils.js +0 -120
  191. package/node_modules/request/node_modules/http-signature/.dir-locals.el +0 -6
  192. package/node_modules/request/node_modules/http-signature/.npmignore +0 -7
  193. package/node_modules/request/node_modules/http-signature/LICENSE +0 -18
  194. package/node_modules/request/node_modules/http-signature/README.md +0 -75
  195. package/node_modules/request/node_modules/http-signature/http_signing.md +0 -296
  196. package/node_modules/request/node_modules/http-signature/lib/index.js +0 -25
  197. package/node_modules/request/node_modules/http-signature/lib/parser.js +0 -304
  198. package/node_modules/request/node_modules/http-signature/lib/signer.js +0 -179
  199. package/node_modules/request/node_modules/http-signature/lib/util.js +0 -249
  200. package/node_modules/request/node_modules/http-signature/lib/verify.js +0 -42
  201. package/node_modules/request/node_modules/http-signature/node_modules/asn1/.npmignore +0 -2
  202. package/node_modules/request/node_modules/http-signature/node_modules/asn1/LICENSE +0 -19
  203. package/node_modules/request/node_modules/http-signature/node_modules/asn1/README.md +0 -50
  204. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/errors.js +0 -13
  205. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/index.js +0 -27
  206. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/reader.js +0 -267
  207. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/types.js +0 -36
  208. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/writer.js +0 -317
  209. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/index.js +0 -20
  210. package/node_modules/request/node_modules/http-signature/node_modules/asn1/package.json +0 -63
  211. package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/reader.test.js +0 -172
  212. package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/writer.test.js +0 -296
  213. package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/README.md +0 -126
  214. package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/assert.js +0 -196
  215. package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/package.json +0 -38
  216. package/node_modules/request/node_modules/http-signature/node_modules/ctype/CHANGELOG +0 -71
  217. package/node_modules/request/node_modules/http-signature/node_modules/ctype/LICENSE +0 -24
  218. package/node_modules/request/node_modules/http-signature/node_modules/ctype/README +0 -82
  219. package/node_modules/request/node_modules/http-signature/node_modules/ctype/README.old +0 -298
  220. package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctf.js +0 -245
  221. package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctio.js +0 -1485
  222. package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctype.js +0 -944
  223. package/node_modules/request/node_modules/http-signature/node_modules/ctype/man/man3ctype/ctio.3ctype +0 -241
  224. package/node_modules/request/node_modules/http-signature/node_modules/ctype/package.json +0 -36
  225. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsl.conf +0 -129
  226. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsstyle +0 -839
  227. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/float.json +0 -13
  228. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/int.json +0 -13
  229. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/psinfo.json +0 -104
  230. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/struct.json +0 -19
  231. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.fail.js +0 -39
  232. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.float.js +0 -14
  233. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.int.js +0 -14
  234. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.psinfo.js +0 -17
  235. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.struct.js +0 -18
  236. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.typedef.js +0 -15
  237. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/typedef.json +0 -14
  238. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.rfloat.js +0 -767
  239. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.wfloat.js +0 -753
  240. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.64.js +0 -638
  241. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.rint.js +0 -101
  242. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wbounds.js +0 -53
  243. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wint.js +0 -92
  244. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.64.js +0 -451
  245. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.roundtrip.js +0 -81
  246. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.ruint.js +0 -95
  247. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.wuint.js +0 -156
  248. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicr.js +0 -50
  249. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicw.js +0 -44
  250. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.char.js +0 -42
  251. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.endian.js +0 -45
  252. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.oldwrite.js +0 -28
  253. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.readSize.js +0 -128
  254. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.structw.js +0 -28
  255. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.writeStruct.js +0 -31
  256. package/node_modules/request/node_modules/http-signature/package.json +0 -54
  257. package/node_modules/request/node_modules/json-stringify-safe/LICENSE +0 -27
  258. package/node_modules/request/node_modules/json-stringify-safe/README.md +0 -49
  259. package/node_modules/request/node_modules/json-stringify-safe/package.json +0 -51
  260. package/node_modules/request/node_modules/json-stringify-safe/stringify.js +0 -39
  261. package/node_modules/request/node_modules/json-stringify-safe/test.js +0 -128
  262. package/node_modules/request/node_modules/mime-types/.npmignore +0 -14
  263. package/node_modules/request/node_modules/mime-types/.travis.yml +0 -12
  264. package/node_modules/request/node_modules/mime-types/LICENSE +0 -22
  265. package/node_modules/request/node_modules/mime-types/Makefile +0 -9
  266. package/node_modules/request/node_modules/mime-types/README.md +0 -101
  267. package/node_modules/request/node_modules/mime-types/SOURCES.md +0 -17
  268. package/node_modules/request/node_modules/mime-types/component.json +0 -16
  269. package/node_modules/request/node_modules/mime-types/lib/custom.json +0 -27
  270. package/node_modules/request/node_modules/mime-types/lib/index.js +0 -75
  271. package/node_modules/request/node_modules/mime-types/lib/mime.json +0 -3317
  272. package/node_modules/request/node_modules/mime-types/lib/node.json +0 -55
  273. package/node_modules/request/node_modules/mime-types/package.json +0 -69
  274. package/node_modules/request/node_modules/node-uuid/.npmignore +0 -2
  275. package/node_modules/request/node_modules/node-uuid/LICENSE.md +0 -2
  276. package/node_modules/request/node_modules/node-uuid/README.md +0 -207
  277. package/node_modules/request/node_modules/node-uuid/benchmark/README.md +0 -53
  278. package/node_modules/request/node_modules/node-uuid/benchmark/bench.gnu +0 -174
  279. package/node_modules/request/node_modules/node-uuid/benchmark/bench.sh +0 -34
  280. package/node_modules/request/node_modules/node-uuid/benchmark/benchmark-native.c +0 -34
  281. package/node_modules/request/node_modules/node-uuid/benchmark/benchmark.js +0 -84
  282. package/node_modules/request/node_modules/node-uuid/component.json +0 -18
  283. package/node_modules/request/node_modules/node-uuid/package.json +0 -54
  284. package/node_modules/request/node_modules/node-uuid/test/compare_v1.js +0 -63
  285. package/node_modules/request/node_modules/node-uuid/test/test.html +0 -17
  286. package/node_modules/request/node_modules/node-uuid/test/test.js +0 -228
  287. package/node_modules/request/node_modules/node-uuid/uuid.js +0 -245
  288. package/node_modules/request/node_modules/oauth-sign/LICENSE +0 -55
  289. package/node_modules/request/node_modules/oauth-sign/README.md +0 -4
  290. package/node_modules/request/node_modules/oauth-sign/index.js +0 -43
  291. package/node_modules/request/node_modules/oauth-sign/package.json +0 -49
  292. package/node_modules/request/node_modules/oauth-sign/test.js +0 -49
  293. package/node_modules/request/node_modules/qs/.jshintignore +0 -1
  294. package/node_modules/request/node_modules/qs/.jshintrc +0 -10
  295. package/node_modules/request/node_modules/qs/.npmignore +0 -18
  296. package/node_modules/request/node_modules/qs/.travis.yml +0 -4
  297. package/node_modules/request/node_modules/qs/LICENSE +0 -28
  298. package/node_modules/request/node_modules/qs/Makefile +0 -8
  299. package/node_modules/request/node_modules/qs/Readme.md +0 -120
  300. package/node_modules/request/node_modules/qs/index.js +0 -1
  301. package/node_modules/request/node_modules/qs/lib/index.js +0 -15
  302. package/node_modules/request/node_modules/qs/lib/parse.js +0 -151
  303. package/node_modules/request/node_modules/qs/lib/stringify.js +0 -52
  304. package/node_modules/request/node_modules/qs/lib/utils.js +0 -131
  305. package/node_modules/request/node_modules/qs/package.json +0 -61
  306. package/node_modules/request/node_modules/qs/test/parse.js +0 -236
  307. package/node_modules/request/node_modules/qs/test/stringify.js +0 -123
  308. package/node_modules/request/node_modules/stringstream/.npmignore +0 -15
  309. package/node_modules/request/node_modules/stringstream/.travis.yml +0 -4
  310. package/node_modules/request/node_modules/stringstream/LICENSE.txt +0 -4
  311. package/node_modules/request/node_modules/stringstream/README.md +0 -38
  312. package/node_modules/request/node_modules/stringstream/example.js +0 -27
  313. package/node_modules/request/node_modules/stringstream/package.json +0 -48
  314. package/node_modules/request/node_modules/stringstream/stringstream.js +0 -102
  315. package/node_modules/request/node_modules/tough-cookie/.jshintrc +0 -70
  316. package/node_modules/request/node_modules/tough-cookie/.npmignore +0 -3
  317. package/node_modules/request/node_modules/tough-cookie/.travis.yml +0 -8
  318. package/node_modules/request/node_modules/tough-cookie/LICENSE +0 -78
  319. package/node_modules/request/node_modules/tough-cookie/README.md +0 -412
  320. package/node_modules/request/node_modules/tough-cookie/generate-pubsuffix.js +0 -239
  321. package/node_modules/request/node_modules/tough-cookie/lib/cookie.js +0 -1107
  322. package/node_modules/request/node_modules/tough-cookie/lib/memstore.js +0 -123
  323. package/node_modules/request/node_modules/tough-cookie/lib/pubsuffix.js +0 -69
  324. package/node_modules/request/node_modules/tough-cookie/lib/store.js +0 -37
  325. package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/LICENSE-MIT.txt +0 -20
  326. package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/README.md +0 -176
  327. package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/package.json +0 -87
  328. package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/punycode.js +0 -528
  329. package/node_modules/request/node_modules/tough-cookie/package.json +0 -67
  330. package/node_modules/request/node_modules/tough-cookie/public-suffix.txt +0 -5229
  331. package/node_modules/request/node_modules/tough-cookie/test.js +0 -1625
  332. package/node_modules/request/node_modules/tunnel-agent/.jshintrc +0 -5
  333. package/node_modules/request/node_modules/tunnel-agent/LICENSE +0 -55
  334. package/node_modules/request/node_modules/tunnel-agent/README.md +0 -4
  335. package/node_modules/request/node_modules/tunnel-agent/index.js +0 -236
  336. package/node_modules/request/node_modules/tunnel-agent/package.json +0 -46
  337. package/node_modules/request/package.json +0 -77
  338. package/node_modules/request/request.js +0 -1428
  339. package/test/fixtures/github-response.json +0 -1367
  340. package/test/index.js +0 -55
@@ -1,1625 +0,0 @@
1
- /*
2
- * Copyright GoInstant, Inc. and other contributors. All rights reserved.
3
- * Permission is hereby granted, free of charge, to any person obtaining a copy
4
- * of this software and associated documentation files (the "Software"), to
5
- * deal in the Software without restriction, including without limitation the
6
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
- * sell copies of the Software, and to permit persons to whom the Software is
8
- * furnished to do so, subject to the following conditions:
9
- *
10
- * The above copyright notice and this permission notice shall be included in
11
- * all copies or substantial portions of the Software.
12
- *
13
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
- * IN THE SOFTWARE.
20
- */
21
- 'use strict';
22
- var vows = require('vows');
23
- var assert = require('assert');
24
- var async = require('async');
25
-
26
- // NOTE use require("tough-cookie") in your own code:
27
- var tough = require('./lib/cookie');
28
- var Cookie = tough.Cookie;
29
- var CookieJar = tough.CookieJar;
30
-
31
-
32
- function dateVows(table) {
33
- var theVows = { };
34
- Object.keys(table).forEach(function(date) {
35
- var expect = table[date];
36
- theVows[date] = function() {
37
- var got = tough.parseDate(date) ? 'valid' : 'invalid';
38
- assert.equal(got, expect ? 'valid' : 'invalid');
39
- };
40
- });
41
- return { "date parsing": theVows };
42
- }
43
-
44
- function matchVows(func,table) {
45
- var theVows = {};
46
- table.forEach(function(item) {
47
- var str = item[0];
48
- var dom = item[1];
49
- var expect = item[2];
50
- var label = str+(expect?" matches ":" doesn't match ")+dom;
51
- theVows[label] = function() {
52
- assert.equal(func(str,dom),expect);
53
- };
54
- });
55
- return theVows;
56
- }
57
-
58
- function defaultPathVows(table) {
59
- var theVows = {};
60
- table.forEach(function(item) {
61
- var str = item[0];
62
- var expect = item[1];
63
- var label = str+" gives "+expect;
64
- theVows[label] = function() {
65
- assert.equal(tough.defaultPath(str),expect);
66
- };
67
- });
68
- return theVows;
69
- }
70
-
71
- var atNow = Date.now();
72
- function at(offset) { return {now: new Date(atNow+offset)}; }
73
-
74
- vows.describe('Cookie Jar')
75
- .addBatch({
76
- "all defined": function() {
77
- assert.ok(Cookie);
78
- assert.ok(CookieJar);
79
- },
80
- })
81
- .addBatch(
82
- dateVows({
83
- "Wed, 09 Jun 2021 10:18:14 GMT": true,
84
- "Wed, 09 Jun 2021 22:18:14 GMT": true,
85
- "Tue, 18 Oct 2011 07:42:42.123 GMT": true,
86
- "18 Oct 2011 07:42:42 GMT": true,
87
- "8 Oct 2011 7:42:42 GMT": true,
88
- "8 Oct 2011 7:2:42 GMT": false,
89
- "Oct 18 2011 07:42:42 GMT": true,
90
- "Tue Oct 18 2011 07:05:03 GMT+0000 (GMT)": true,
91
- "09 Jun 2021 10:18:14 GMT": true,
92
- "99 Jix 3038 48:86:72 ZMT": false,
93
- '01 Jan 1970 00:00:00 GMT': true,
94
- '01 Jan 1600 00:00:00 GMT': false, // before 1601
95
- '01 Jan 1601 00:00:00 GMT': true,
96
- '10 Feb 81 13:00:00 GMT': true, // implicit year
97
- 'Thu, 01 Jan 1970 00:00:010 GMT': true, // strange time, non-strict OK
98
- 'Thu, 17-Apr-2014 02:12:29 GMT': true, // dashes
99
- 'Thu, 17-Apr-2014 02:12:29 UTC': true, // dashes and UTC
100
- })
101
- )
102
- .addBatch({
103
- "strict date parse of Thu, 01 Jan 1970 00:00:010 GMT": {
104
- topic: function() {
105
- return tough.parseDate('Thu, 01 Jan 1970 00:00:010 GMT', true) ? true : false;
106
- },
107
- "invalid": function(date) {
108
- assert.equal(date,false);
109
- },
110
- }
111
- })
112
- .addBatch({
113
- "formatting": {
114
- "a simple cookie": {
115
- topic: function() {
116
- var c = new Cookie();
117
- c.key = 'a';
118
- c.value = 'b';
119
- return c;
120
- },
121
- "validates": function(c) {
122
- assert.ok(c.validate());
123
- },
124
- "to string": function(c) {
125
- assert.equal(c.toString(), 'a=b');
126
- },
127
- },
128
- "a cookie with spaces in the value": {
129
- topic: function() {
130
- var c = new Cookie();
131
- c.key = 'a';
132
- c.value = 'beta gamma';
133
- return c;
134
- },
135
- "doesn't validate": function(c) {
136
- assert.ok(!c.validate());
137
- },
138
- "'garbage in, garbage out'": function(c) {
139
- assert.equal(c.toString(), 'a=beta gamma');
140
- },
141
- },
142
- "with an empty value and HttpOnly": {
143
- topic: function() {
144
- var c = new Cookie();
145
- c.key = 'a';
146
- c.httpOnly = true;
147
- return c;
148
- },
149
- "to string": function(c) {
150
- assert.equal(c.toString(), 'a=; HttpOnly');
151
- }
152
- },
153
- "with an expiry": {
154
- topic: function() {
155
- var c = new Cookie();
156
- c.key = 'a';
157
- c.value = 'b';
158
- c.setExpires("Oct 18 2011 07:05:03 GMT");
159
- return c;
160
- },
161
- "validates": function(c) {
162
- assert.ok(c.validate());
163
- },
164
- "to string": function(c) {
165
- assert.equal(c.toString(), 'a=b; Expires=Tue, 18 Oct 2011 07:05:03 GMT');
166
- },
167
- "to short string": function(c) {
168
- assert.equal(c.cookieString(), 'a=b');
169
- },
170
- },
171
- "with a max-age": {
172
- topic: function() {
173
- var c = new Cookie();
174
- c.key = 'a';
175
- c.value = 'b';
176
- c.setExpires("Oct 18 2011 07:05:03 GMT");
177
- c.maxAge = 12345;
178
- return c;
179
- },
180
- "validates": function(c) {
181
- assert.ok(c.validate()); // mabe this one *shouldn't*?
182
- },
183
- "to string": function(c) {
184
- assert.equal(c.toString(), 'a=b; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Max-Age=12345');
185
- },
186
- },
187
- "with a bunch of things": function() {
188
- var c = new Cookie();
189
- c.key = 'a';
190
- c.value = 'b';
191
- c.setExpires("Oct 18 2011 07:05:03 GMT");
192
- c.maxAge = 12345;
193
- c.domain = 'example.com';
194
- c.path = '/foo';
195
- c.secure = true;
196
- c.httpOnly = true;
197
- c.extensions = ['MyExtension'];
198
- assert.equal(c.toString(), 'a=b; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Max-Age=12345; Domain=example.com; Path=/foo; Secure; HttpOnly; MyExtension');
199
- },
200
- "a host-only cookie": {
201
- topic: function() {
202
- var c = new Cookie();
203
- c.key = 'a';
204
- c.value = 'b';
205
- c.hostOnly = true;
206
- c.domain = 'shouldnt-stringify.example.com';
207
- c.path = '/should-stringify';
208
- return c;
209
- },
210
- "validates": function(c) {
211
- assert.ok(c.validate());
212
- },
213
- "to string": function(c) {
214
- assert.equal(c.toString(), 'a=b; Path=/should-stringify');
215
- },
216
- },
217
- "minutes are '10'": {
218
- topic: function() {
219
- var c = new Cookie();
220
- c.key = 'a';
221
- c.value = 'b';
222
- c.expires = new Date(1284113410000);
223
- return c;
224
- },
225
- "validates": function(c) {
226
- assert.ok(c.validate());
227
- },
228
- "to string": function(c) {
229
- var str = c.toString();
230
- assert.notEqual(str, 'a=b; Expires=Fri, 010 Sep 2010 010:010:010 GMT');
231
- assert.equal(str, 'a=b; Expires=Fri, 10 Sep 2010 10:10:10 GMT');
232
- },
233
- }
234
- }
235
- })
236
- .addBatch({
237
- "TTL with max-age": function() {
238
- var c = new Cookie();
239
- c.maxAge = 123;
240
- assert.equal(c.TTL(), 123000);
241
- assert.equal(c.expiryTime(new Date(9000000)), 9123000);
242
- },
243
- "TTL with zero max-age": function() {
244
- var c = new Cookie();
245
- c.key = 'a'; c.value = 'b';
246
- c.maxAge = 0; // should be treated as "earliest representable"
247
- assert.equal(c.TTL(), 0);
248
- assert.equal(c.expiryTime(new Date(9000000)), -Infinity);
249
- assert.ok(!c.validate()); // not valid, really: non-zero-digit *DIGIT
250
- },
251
- "TTL with negative max-age": function() {
252
- var c = new Cookie();
253
- c.key = 'a'; c.value = 'b';
254
- c.maxAge = -1; // should be treated as "earliest representable"
255
- assert.equal(c.TTL(), 0);
256
- assert.equal(c.expiryTime(new Date(9000000)), -Infinity);
257
- assert.ok(!c.validate()); // not valid, really: non-zero-digit *DIGIT
258
- },
259
- "TTL with max-age and expires": function() {
260
- var c = new Cookie();
261
- c.maxAge = 123;
262
- c.expires = new Date(Date.now()+9000);
263
- assert.equal(c.TTL(), 123000);
264
- assert.ok(c.isPersistent());
265
- },
266
- "TTL with expires": function() {
267
- var c = new Cookie();
268
- var now = Date.now();
269
- c.expires = new Date(now+9000);
270
- assert.equal(c.TTL(now), 9000);
271
- assert.equal(c.expiryTime(), c.expires.getTime());
272
- },
273
- "TTL with old expires": function() {
274
- var c = new Cookie();
275
- c.setExpires('17 Oct 2010 00:00:00 GMT');
276
- assert.ok(c.TTL() < 0);
277
- assert.ok(c.isPersistent());
278
- },
279
- "default TTL": {
280
- topic: function() { return new Cookie(); },
281
- "is Infinite-future": function(c) { assert.equal(c.TTL(), Infinity) },
282
- "is a 'session' cookie": function(c) { assert.ok(!c.isPersistent()) },
283
- },
284
- }).addBatch({
285
- "Parsing": {
286
- "simple": {
287
- topic: function() {
288
- return Cookie.parse('a=bcd',true) || null;
289
- },
290
- "parsed": function(c) { assert.ok(c) },
291
- "key": function(c) { assert.equal(c.key, 'a') },
292
- "value": function(c) { assert.equal(c.value, 'bcd') },
293
- "no path": function(c) { assert.equal(c.path, null) },
294
- "no domain": function(c) { assert.equal(c.domain, null) },
295
- "no extensions": function(c) { assert.ok(!c.extensions) },
296
- },
297
- "with expiry": {
298
- topic: function() {
299
- return Cookie.parse('a=bcd; Expires=Tue, 18 Oct 2011 07:05:03 GMT',true) || null;
300
- },
301
- "parsed": function(c) { assert.ok(c) },
302
- "key": function(c) { assert.equal(c.key, 'a') },
303
- "value": function(c) { assert.equal(c.value, 'bcd') },
304
- "has expires": function(c) {
305
- assert.ok(c.expires !== Infinity, 'expiry is infinite when it shouldn\'t be');
306
- assert.equal(c.expires.getTime(), 1318921503000);
307
- },
308
- },
309
- "with expiry and path": {
310
- topic: function() {
311
- return Cookie.parse('abc="xyzzy!"; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Path=/aBc',true) || null;
312
- },
313
- "parsed": function(c) { assert.ok(c) },
314
- "key": function(c) { assert.equal(c.key, 'abc') },
315
- "value": function(c) { assert.equal(c.value, 'xyzzy!') },
316
- "has expires": function(c) {
317
- assert.ok(c.expires !== Infinity, 'expiry is infinite when it shouldn\'t be');
318
- assert.equal(c.expires.getTime(), 1318921503000);
319
- },
320
- "has path": function(c) { assert.equal(c.path, '/aBc'); },
321
- "no httponly or secure": function(c) {
322
- assert.ok(!c.httpOnly);
323
- assert.ok(!c.secure);
324
- },
325
- },
326
- "with everything": {
327
- topic: function() {
328
- return Cookie.parse('abc="xyzzy!"; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Path=/aBc; Domain=example.com; Secure; HTTPOnly; Max-Age=1234; Foo=Bar; Baz', true) || null;
329
- },
330
- "parsed": function(c) { assert.ok(c) },
331
- "key": function(c) { assert.equal(c.key, 'abc') },
332
- "value": function(c) { assert.equal(c.value, 'xyzzy!') },
333
- "has expires": function(c) {
334
- assert.ok(c.expires !== Infinity, 'expiry is infinite when it shouldn\'t be');
335
- assert.equal(c.expires.getTime(), 1318921503000);
336
- },
337
- "has path": function(c) { assert.equal(c.path, '/aBc'); },
338
- "has domain": function(c) { assert.equal(c.domain, 'example.com'); },
339
- "has httponly": function(c) { assert.equal(c.httpOnly, true); },
340
- "has secure": function(c) { assert.equal(c.secure, true); },
341
- "has max-age": function(c) { assert.equal(c.maxAge, 1234); },
342
- "has extensions": function(c) {
343
- assert.ok(c.extensions);
344
- assert.equal(c.extensions[0], 'Foo=Bar');
345
- assert.equal(c.extensions[1], 'Baz');
346
- },
347
- },
348
- "invalid expires": {
349
- "strict": function() { assert.ok(!Cookie.parse("a=b; Expires=xyzzy", true)) },
350
- "non-strict": function() {
351
- var c = Cookie.parse("a=b; Expires=xyzzy");
352
- assert.ok(c);
353
- assert.equal(c.expires, Infinity);
354
- },
355
- },
356
- "zero max-age": {
357
- "strict": function() { assert.ok(!Cookie.parse("a=b; Max-Age=0", true)) },
358
- "non-strict": function() {
359
- var c = Cookie.parse("a=b; Max-Age=0");
360
- assert.ok(c);
361
- assert.equal(c.maxAge, 0);
362
- },
363
- },
364
- "negative max-age": {
365
- "strict": function() { assert.ok(!Cookie.parse("a=b; Max-Age=-1", true)) },
366
- "non-strict": function() {
367
- var c = Cookie.parse("a=b; Max-Age=-1");
368
- assert.ok(c);
369
- assert.equal(c.maxAge, -1);
370
- },
371
- },
372
- "empty domain": {
373
- "strict": function() { assert.ok(!Cookie.parse("a=b; domain=", true)) },
374
- "non-strict": function() {
375
- var c = Cookie.parse("a=b; domain=");
376
- assert.ok(c);
377
- assert.equal(c.domain, null);
378
- },
379
- },
380
- "dot domain": {
381
- "strict": function() { assert.ok(!Cookie.parse("a=b; domain=.", true)) },
382
- "non-strict": function() {
383
- var c = Cookie.parse("a=b; domain=.");
384
- assert.ok(c);
385
- assert.equal(c.domain, null);
386
- },
387
- },
388
- "uppercase domain": {
389
- "strict lowercases": function() {
390
- var c = Cookie.parse("a=b; domain=EXAMPLE.COM");
391
- assert.ok(c);
392
- assert.equal(c.domain, 'example.com');
393
- },
394
- "non-strict lowercases": function() {
395
- var c = Cookie.parse("a=b; domain=EXAMPLE.COM");
396
- assert.ok(c);
397
- assert.equal(c.domain, 'example.com');
398
- },
399
- },
400
- "trailing dot in domain": {
401
- topic: function() {
402
- return Cookie.parse("a=b; Domain=example.com.", true) || null;
403
- },
404
- "has the domain": function(c) { assert.equal(c.domain,"example.com.") },
405
- "but doesn't validate": function(c) { assert.equal(c.validate(),false) },
406
- },
407
- "empty path": {
408
- "strict": function() { assert.ok(!Cookie.parse("a=b; path=", true)) },
409
- "non-strict": function() {
410
- var c = Cookie.parse("a=b; path=");
411
- assert.ok(c);
412
- assert.equal(c.path, null);
413
- },
414
- },
415
- "no-slash path": {
416
- "strict": function() { assert.ok(!Cookie.parse("a=b; path=xyzzy", true)) },
417
- "non-strict": function() {
418
- var c = Cookie.parse("a=b; path=xyzzy");
419
- assert.ok(c);
420
- assert.equal(c.path, null);
421
- },
422
- },
423
- "trailing semi-colons after path": {
424
- topic: function () {
425
- return [
426
- "a=b; path=/;",
427
- "c=d;;;;"
428
- ];
429
- },
430
- "strict": function (t) {
431
- assert.ok(!Cookie.parse(t[0], true));
432
- assert.ok(!Cookie.parse(t[1], true));
433
- },
434
- "non-strict": function (t) {
435
- var c1 = Cookie.parse(t[0]);
436
- var c2 = Cookie.parse(t[1]);
437
- assert.ok(c1);
438
- assert.ok(c2);
439
- assert.equal(c1.path, '/');
440
- }
441
- },
442
- "secure-with-value": {
443
- "strict": function() { assert.ok(!Cookie.parse("a=b; Secure=xyzzy", true)) },
444
- "non-strict": function() {
445
- var c = Cookie.parse("a=b; Secure=xyzzy");
446
- assert.ok(c);
447
- assert.equal(c.secure, true);
448
- },
449
- },
450
- "httponly-with-value": {
451
- "strict": function() { assert.ok(!Cookie.parse("a=b; HttpOnly=xyzzy", true)) },
452
- "non-strict": function() {
453
- var c = Cookie.parse("a=b; HttpOnly=xyzzy");
454
- assert.ok(c);
455
- assert.equal(c.httpOnly, true);
456
- },
457
- },
458
- "garbage": {
459
- topic: function() {
460
- return Cookie.parse("\x08", true) || null;
461
- },
462
- "doesn't parse": function(c) { assert.equal(c,null) },
463
- },
464
- "public suffix domain": {
465
- topic: function() {
466
- return Cookie.parse("a=b; domain=kyoto.jp", true) || null;
467
- },
468
- "parses fine": function(c) {
469
- assert.ok(c);
470
- assert.equal(c.domain, 'kyoto.jp');
471
- },
472
- "but fails validation": function(c) {
473
- assert.ok(c);
474
- assert.ok(!c.validate());
475
- },
476
- },
477
- "Ironically, Google 'GAPS' cookie has very little whitespace": {
478
- topic: function() {
479
- return Cookie.parse("GAPS=1:A1aaaaAaAAa1aaAaAaaAAAaaa1a11a:aaaAaAaAa-aaaA1-;Path=/;Expires=Thu, 17-Apr-2014 02:12:29 GMT;Secure;HttpOnly");
480
- },
481
- "parsed": function(c) { assert.ok(c) },
482
- "key": function(c) { assert.equal(c.key, 'GAPS') },
483
- "value": function(c) { assert.equal(c.value, '1:A1aaaaAaAAa1aaAaAaaAAAaaa1a11a:aaaAaAaAa-aaaA1-') },
484
- "path": function(c) {
485
- assert.notEqual(c.path, '/;Expires'); // BUG
486
- assert.equal(c.path, '/');
487
- },
488
- "expires": function(c) {
489
- assert.notEqual(c.expires, Infinity);
490
- assert.equal(c.expires.getTime(), 1397700749000);
491
- },
492
- "secure": function(c) { assert.ok(c.secure) },
493
- "httponly": function(c) { assert.ok(c.httpOnly) },
494
- },
495
- "lots of equal signs": {
496
- topic: function() {
497
- return Cookie.parse("queryPref=b=c&d=e; Path=/f=g; Expires=Thu, 17 Apr 2014 02:12:29 GMT; HttpOnly");
498
- },
499
- "parsed": function(c) { assert.ok(c) },
500
- "key": function(c) { assert.equal(c.key, 'queryPref') },
501
- "value": function(c) { assert.equal(c.value, 'b=c&d=e') },
502
- "path": function(c) {
503
- assert.equal(c.path, '/f=g');
504
- },
505
- "expires": function(c) {
506
- assert.notEqual(c.expires, Infinity);
507
- assert.equal(c.expires.getTime(), 1397700749000);
508
- },
509
- "httponly": function(c) { assert.ok(c.httpOnly) },
510
- },
511
- "spaces in value": {
512
- "strict": {
513
- topic: function() {
514
- return Cookie.parse('a=one two three',true) || null;
515
- },
516
- "did not parse": function(c) { assert.isNull(c) },
517
- },
518
- "non-strict": {
519
- topic: function() {
520
- return Cookie.parse('a=one two three',false) || null;
521
- },
522
- "parsed": function(c) { assert.ok(c) },
523
- "key": function(c) { assert.equal(c.key, 'a') },
524
- "value": function(c) { assert.equal(c.value, 'one two three') },
525
- "no path": function(c) { assert.equal(c.path, null) },
526
- "no domain": function(c) { assert.equal(c.domain, null) },
527
- "no extensions": function(c) { assert.ok(!c.extensions) },
528
- },
529
- },
530
- "quoted spaces in value": {
531
- "strict": {
532
- topic: function() {
533
- return Cookie.parse('a="one two three"',true) || null;
534
- },
535
- "did not parse": function(c) { assert.isNull(c) },
536
- },
537
- "non-strict": {
538
- topic: function() {
539
- return Cookie.parse('a="one two three"',false) || null;
540
- },
541
- "parsed": function(c) { assert.ok(c) },
542
- "key": function(c) { assert.equal(c.key, 'a') },
543
- "value": function(c) { assert.equal(c.value, 'one two three') },
544
- "no path": function(c) { assert.equal(c.path, null) },
545
- "no domain": function(c) { assert.equal(c.domain, null) },
546
- "no extensions": function(c) { assert.ok(!c.extensions) },
547
- }
548
- },
549
- "non-ASCII in value": {
550
- "strict": {
551
- topic: function() {
552
- return Cookie.parse('farbe=weiß',true) || null;
553
- },
554
- "did not parse": function(c) { assert.isNull(c) },
555
- },
556
- "non-strict": {
557
- topic: function() {
558
- return Cookie.parse('farbe=weiß',false) || null;
559
- },
560
- "parsed": function(c) { assert.ok(c) },
561
- "key": function(c) { assert.equal(c.key, 'farbe') },
562
- "value": function(c) { assert.equal(c.value, 'weiß') },
563
- "no path": function(c) { assert.equal(c.path, null) },
564
- "no domain": function(c) { assert.equal(c.domain, null) },
565
- "no extensions": function(c) { assert.ok(!c.extensions) },
566
- },
567
- },
568
- }
569
- })
570
- .addBatch({
571
- "domain normalization": {
572
- "simple": function() {
573
- var c = new Cookie();
574
- c.domain = "EXAMPLE.com";
575
- assert.equal(c.canonicalizedDomain(), "example.com");
576
- },
577
- "extra dots": function() {
578
- var c = new Cookie();
579
- c.domain = ".EXAMPLE.com";
580
- assert.equal(c.cdomain(), "example.com");
581
- },
582
- "weird trailing dot": function() {
583
- var c = new Cookie();
584
- c.domain = "EXAMPLE.ca.";
585
- assert.equal(c.canonicalizedDomain(), "example.ca.");
586
- },
587
- "weird internal dots": function() {
588
- var c = new Cookie();
589
- c.domain = "EXAMPLE...ca.";
590
- assert.equal(c.canonicalizedDomain(), "example...ca.");
591
- },
592
- "IDN": function() {
593
- var c = new Cookie();
594
- c.domain = "δοκιμή.δοκιμή"; // "test.test" in greek
595
- assert.equal(c.canonicalizedDomain(), "xn--jxalpdlp.xn--jxalpdlp");
596
- }
597
- }
598
- })
599
- .addBatch({
600
- "Domain Match":matchVows(tough.domainMatch, [
601
- // str, dom, expect
602
- ["example.com", "example.com", true],
603
- ["eXaMpLe.cOm", "ExAmPlE.CoM", true],
604
- ["no.ca", "yes.ca", false],
605
- ["wwwexample.com", "example.com", false],
606
- ["www.example.com", "example.com", true],
607
- ["example.com", "www.example.com", false],
608
- ["www.subdom.example.com", "example.com", true],
609
- ["www.subdom.example.com", "subdom.example.com", true],
610
- ["example.com", "example.com.", false], // RFC6265 S4.1.2.3
611
- ["192.168.0.1", "168.0.1", false], // S5.1.3 "The string is a host name"
612
- [null, "example.com", null],
613
- ["example.com", null, null],
614
- [null, null, null],
615
- [undefined, undefined, null],
616
- ])
617
- })
618
- .addBatch({
619
- "default-path": defaultPathVows([
620
- [null,"/"],
621
- ["/","/"],
622
- ["/file","/"],
623
- ["/dir/file","/dir"],
624
- ["noslash","/"],
625
- ])
626
- })
627
- .addBatch({
628
- "Path-Match": matchVows(tough.pathMatch, [
629
- // request, cookie, match
630
- ["/","/",true],
631
- ["/dir","/",true],
632
- ["/","/dir",false],
633
- ["/dir/","/dir/", true],
634
- ["/dir/file","/dir/",true],
635
- ["/dir/file","/dir",true],
636
- ["/directory","/dir",false],
637
- ])
638
- })
639
- .addBatch({
640
- "Cookie Sorting": {
641
- topic: function() {
642
- var cookies = [];
643
- var now = Date.now();
644
- cookies.push(Cookie.parse("a=0; Domain=example.com"));
645
- cookies.push(Cookie.parse("b=1; Domain=www.example.com"));
646
- cookies.push(Cookie.parse("c=2; Domain=example.com; Path=/pathA"));
647
- cookies.push(Cookie.parse("d=3; Domain=www.example.com; Path=/pathA"));
648
- cookies.push(Cookie.parse("e=4; Domain=example.com; Path=/pathA/pathB"));
649
- cookies.push(Cookie.parse("f=5; Domain=www.example.com; Path=/pathA/pathB"));
650
-
651
- // force a stable creation time consistent with the order above since
652
- // some may have been created at now + 1ms.
653
- var i = cookies.length;
654
- cookies.forEach(function(cookie) {
655
- cookie.creation = new Date(now - 100*(i--));
656
- });
657
-
658
- // weak shuffle:
659
- cookies = cookies.sort(function(){return Math.random()-0.5});
660
-
661
- cookies = cookies.sort(tough.cookieCompare);
662
- return cookies;
663
- },
664
- "got": function(cookies) {
665
- assert.lengthOf(cookies, 6);
666
- var names = cookies.map(function(c) {return c.key});
667
- assert.deepEqual(names, ['e','f','c','d','a','b']);
668
- },
669
- }
670
- })
671
- .addBatch({
672
- "CookieJar": {
673
- "Setting a basic cookie": {
674
- topic: function() {
675
- var cj = new CookieJar();
676
- var c = Cookie.parse("a=b; Domain=example.com; Path=/");
677
- assert.strictEqual(c.hostOnly, null);
678
- assert.instanceOf(c.creation, Date);
679
- assert.strictEqual(c.lastAccessed, null);
680
- c.creation = new Date(Date.now()-10000);
681
- cj.setCookie(c, 'http://example.com/index.html', this.callback);
682
- },
683
- "works": function(c) { assert.instanceOf(c,Cookie) }, // C is for Cookie, good enough for me
684
- "gets timestamped": function(c) {
685
- assert.ok(c.creation);
686
- assert.ok(Date.now() - c.creation.getTime() < 5000); // recently stamped
687
- assert.ok(c.lastAccessed);
688
- assert.equal(c.creation, c.lastAccessed);
689
- assert.equal(c.TTL(), Infinity);
690
- assert.ok(!c.isPersistent());
691
- },
692
- },
693
- "Setting a no-path cookie": {
694
- topic: function() {
695
- var cj = new CookieJar();
696
- var c = Cookie.parse("a=b; Domain=example.com");
697
- assert.strictEqual(c.hostOnly, null);
698
- assert.instanceOf(c.creation, Date);
699
- assert.strictEqual(c.lastAccessed, null);
700
- c.creation = new Date(Date.now()-10000);
701
- cj.setCookie(c, 'http://example.com/index.html', this.callback);
702
- },
703
- "domain": function(c) { assert.equal(c.domain, 'example.com') },
704
- "path is /": function(c) { assert.equal(c.path, '/') },
705
- "path was derived": function(c) { assert.strictEqual(c.pathIsDefault, true) },
706
- },
707
- "Setting a cookie already marked as host-only": {
708
- topic: function() {
709
- var cj = new CookieJar();
710
- var c = Cookie.parse("a=b; Domain=example.com");
711
- assert.strictEqual(c.hostOnly, null);
712
- assert.instanceOf(c.creation, Date);
713
- assert.strictEqual(c.lastAccessed, null);
714
- c.creation = new Date(Date.now()-10000);
715
- c.hostOnly = true;
716
- cj.setCookie(c, 'http://example.com/index.html', this.callback);
717
- },
718
- "domain": function(c) { assert.equal(c.domain, 'example.com') },
719
- "still hostOnly": function(c) { assert.strictEqual(c.hostOnly, true) },
720
- },
721
- "Setting a session cookie": {
722
- topic: function() {
723
- var cj = new CookieJar();
724
- var c = Cookie.parse("a=b");
725
- assert.strictEqual(c.path, null);
726
- cj.setCookie(c, 'http://www.example.com/dir/index.html', this.callback);
727
- },
728
- "works": function(c) { assert.instanceOf(c,Cookie) },
729
- "gets the domain": function(c) { assert.equal(c.domain, 'www.example.com') },
730
- "gets the default path": function(c) { assert.equal(c.path, '/dir') },
731
- "is 'hostOnly'": function(c) { assert.ok(c.hostOnly) },
732
- },
733
- "Setting wrong domain cookie": {
734
- topic: function() {
735
- var cj = new CookieJar();
736
- var c = Cookie.parse("a=b; Domain=fooxample.com; Path=/");
737
- cj.setCookie(c, 'http://example.com/index.html', this.callback);
738
- },
739
- "fails": function(err,c) {
740
- assert.ok(err.message.match(/domain/i));
741
- assert.ok(!c);
742
- },
743
- },
744
- "Setting sub-domain cookie": {
745
- topic: function() {
746
- var cj = new CookieJar();
747
- var c = Cookie.parse("a=b; Domain=www.example.com; Path=/");
748
- cj.setCookie(c, 'http://example.com/index.html', this.callback);
749
- },
750
- "fails": function(err,c) {
751
- assert.ok(err.message.match(/domain/i));
752
- assert.ok(!c);
753
- },
754
- },
755
- "Setting super-domain cookie": {
756
- topic: function() {
757
- var cj = new CookieJar();
758
- var c = Cookie.parse("a=b; Domain=example.com; Path=/");
759
- cj.setCookie(c, 'http://www.app.example.com/index.html', this.callback);
760
- },
761
- "success": function(err,c) {
762
- assert.ok(!err);
763
- assert.equal(c.domain, 'example.com');
764
- },
765
- },
766
- "Setting a sub-path cookie on a super-domain": {
767
- topic: function() {
768
- var cj = new CookieJar();
769
- var c = Cookie.parse("a=b; Domain=example.com; Path=/subpath");
770
- assert.strictEqual(c.hostOnly, null);
771
- assert.instanceOf(c.creation, Date);
772
- assert.strictEqual(c.lastAccessed, null);
773
- c.creation = new Date(Date.now()-10000);
774
- cj.setCookie(c, 'http://www.example.com/index.html', this.callback);
775
- },
776
- "domain is super-domain": function(c) { assert.equal(c.domain, 'example.com') },
777
- "path is /subpath": function(c) { assert.equal(c.path, '/subpath') },
778
- "path was NOT derived": function(c) { assert.strictEqual(c.pathIsDefault, null) },
779
- },
780
- "Setting HttpOnly cookie over non-HTTP API": {
781
- topic: function() {
782
- var cj = new CookieJar();
783
- var c = Cookie.parse("a=b; Domain=example.com; Path=/; HttpOnly");
784
- cj.setCookie(c, 'http://example.com/index.html', {http:false}, this.callback);
785
- },
786
- "fails": function(err,c) {
787
- assert.match(err.message, /HttpOnly/i);
788
- assert.ok(!c);
789
- },
790
- },
791
- },
792
- "Cookie Jar store eight cookies": {
793
- topic: function() {
794
- var cj = new CookieJar();
795
- var ex = 'http://example.com/index.html';
796
- var tasks = [];
797
- tasks.push(function(next) {
798
- cj.setCookie('a=1; Domain=example.com; Path=/',ex,at(0),next);
799
- });
800
- tasks.push(function(next) {
801
- cj.setCookie('b=2; Domain=example.com; Path=/; HttpOnly',ex,at(1000),next);
802
- });
803
- tasks.push(function(next) {
804
- cj.setCookie('c=3; Domain=example.com; Path=/; Secure',ex,at(2000),next);
805
- });
806
- tasks.push(function(next) { // path
807
- cj.setCookie('d=4; Domain=example.com; Path=/foo',ex,at(3000),next);
808
- });
809
- tasks.push(function(next) { // host only
810
- cj.setCookie('e=5',ex,at(4000),next);
811
- });
812
- tasks.push(function(next) { // other domain
813
- cj.setCookie('f=6; Domain=nodejs.org; Path=/','http://nodejs.org',at(5000),next);
814
- });
815
- tasks.push(function(next) { // expired
816
- cj.setCookie('g=7; Domain=example.com; Path=/; Expires=Tue, 18 Oct 2011 00:00:00 GMT',ex,at(6000),next);
817
- });
818
- tasks.push(function(next) { // expired via Max-Age
819
- cj.setCookie('h=8; Domain=example.com; Path=/; Max-Age=1',ex,next);
820
- });
821
- var cb = this.callback;
822
- async.parallel(tasks, function(err,results){
823
- setTimeout(function() {
824
- cb(err,cj,results);
825
- }, 2000); // so that 'h=8' expires
826
- });
827
- },
828
- "setup ok": function(err,cj,results) {
829
- assert.ok(!err);
830
- assert.ok(cj);
831
- assert.ok(results);
832
- },
833
- "then retrieving for http://nodejs.org": {
834
- topic: function(cj,oldResults) {
835
- assert.ok(oldResults);
836
- cj.getCookies('http://nodejs.org',this.callback);
837
- },
838
- "get a nodejs cookie": function(cookies) {
839
- assert.lengthOf(cookies, 1);
840
- var cookie = cookies[0];
841
- assert.equal(cookie.domain, 'nodejs.org');
842
- },
843
- },
844
- "then retrieving for https://example.com": {
845
- topic: function(cj,oldResults) {
846
- assert.ok(oldResults);
847
- cj.getCookies('https://example.com',{secure:true},this.callback);
848
- },
849
- "get a secure example cookie with others": function(cookies) {
850
- var names = cookies.map(function(c) {return c.key});
851
- assert.deepEqual(names, ['a','b','c','e']);
852
- },
853
- },
854
- "then retrieving for https://example.com (missing options)": {
855
- topic: function(cj,oldResults) {
856
- assert.ok(oldResults);
857
- cj.getCookies('https://example.com',this.callback);
858
- },
859
- "get a secure example cookie with others": function(cookies) {
860
- var names = cookies.map(function(c) {return c.key});
861
- assert.deepEqual(names, ['a','b','c','e']);
862
- },
863
- },
864
- "then retrieving for http://example.com": {
865
- topic: function(cj,oldResults) {
866
- assert.ok(oldResults);
867
- cj.getCookies('http://example.com',this.callback);
868
- },
869
- "get a bunch of cookies": function(cookies) {
870
- var names = cookies.map(function(c) {return c.key});
871
- assert.deepEqual(names, ['a','b','e']);
872
- },
873
- },
874
- "then retrieving for http://EXAMPlE.com": {
875
- topic: function(cj,oldResults) {
876
- assert.ok(oldResults);
877
- cj.getCookies('http://EXAMPlE.com',this.callback);
878
- },
879
- "get a bunch of cookies": function(cookies) {
880
- var names = cookies.map(function(c) {return c.key});
881
- assert.deepEqual(names, ['a','b','e']);
882
- },
883
- },
884
- "then retrieving for http://example.com, non-HTTP": {
885
- topic: function(cj,oldResults) {
886
- assert.ok(oldResults);
887
- cj.getCookies('http://example.com',{http:false},this.callback);
888
- },
889
- "get a bunch of cookies": function(cookies) {
890
- var names = cookies.map(function(c) {return c.key});
891
- assert.deepEqual(names, ['a','e']);
892
- },
893
- },
894
- "then retrieving for http://example.com/foo/bar": {
895
- topic: function(cj,oldResults) {
896
- assert.ok(oldResults);
897
- cj.getCookies('http://example.com/foo/bar',this.callback);
898
- },
899
- "get a bunch of cookies": function(cookies) {
900
- var names = cookies.map(function(c) {return c.key});
901
- assert.deepEqual(names, ['d','a','b','e']);
902
- },
903
- },
904
- "then retrieving for http://example.com as a string": {
905
- topic: function(cj,oldResults) {
906
- assert.ok(oldResults);
907
- cj.getCookieString('http://example.com',this.callback);
908
- },
909
- "get a single string": function(cookieHeader) {
910
- assert.equal(cookieHeader, "a=1; b=2; e=5");
911
- },
912
- },
913
- "then retrieving for http://example.com as a set-cookie header": {
914
- topic: function(cj,oldResults) {
915
- assert.ok(oldResults);
916
- cj.getSetCookieStrings('http://example.com',this.callback);
917
- },
918
- "get a single string": function(cookieHeaders) {
919
- assert.lengthOf(cookieHeaders, 3);
920
- assert.equal(cookieHeaders[0], "a=1; Domain=example.com; Path=/");
921
- assert.equal(cookieHeaders[1], "b=2; Domain=example.com; Path=/; HttpOnly");
922
- assert.equal(cookieHeaders[2], "e=5; Path=/");
923
- },
924
- },
925
- "then retrieving for http://www.example.com/": {
926
- topic: function(cj,oldResults) {
927
- assert.ok(oldResults);
928
- cj.getCookies('http://www.example.com/foo/bar',this.callback);
929
- },
930
- "get a bunch of cookies": function(cookies) {
931
- var names = cookies.map(function(c) {return c.key});
932
- assert.deepEqual(names, ['d','a','b']); // note lack of 'e'
933
- },
934
- },
935
- },
936
- "Repeated names": {
937
- topic: function() {
938
- var cb = this.callback;
939
- var cj = new CookieJar();
940
- var ex = 'http://www.example.com/';
941
- var sc = cj.setCookie;
942
- var tasks = [];
943
- var now = Date.now();
944
- tasks.push(sc.bind(cj,'aaaa=xxxx',ex,at(0)));
945
- tasks.push(sc.bind(cj,'aaaa=1111; Domain=www.example.com',ex,at(1000)));
946
- tasks.push(sc.bind(cj,'aaaa=2222; Domain=example.com',ex,at(2000)));
947
- tasks.push(sc.bind(cj,'aaaa=3333; Domain=www.example.com; Path=/pathA',ex,at(3000)));
948
- async.series(tasks,function(err,results) {
949
- results = results.filter(function(e) {return e !== undefined});
950
- cb(err,{cj:cj, cookies:results, now:now});
951
- });
952
- },
953
- "all got set": function(err,t) {
954
- assert.lengthOf(t.cookies,4);
955
- },
956
- "then getting 'em back": {
957
- topic: function(t) {
958
- var cj = t.cj;
959
- cj.getCookies('http://www.example.com/pathA',this.callback);
960
- },
961
- "there's just three": function (err,cookies) {
962
- var vals = cookies.map(function(c) {return c.value});
963
- // may break with sorting; sorting should put 3333 first due to longest path:
964
- assert.deepEqual(vals, ['3333','1111','2222']);
965
- }
966
- },
967
- },
968
- "CookieJar setCookie errors": {
969
- "public-suffix domain": {
970
- topic: function() {
971
- var cj = new CookieJar();
972
- cj.setCookie('i=9; Domain=kyoto.jp; Path=/','kyoto.jp',this.callback);
973
- },
974
- "errors": function(err,cookie) {
975
- assert.ok(err);
976
- assert.ok(!cookie);
977
- assert.match(err.message, /public suffix/i);
978
- },
979
- },
980
- "wrong domain": {
981
- topic: function() {
982
- var cj = new CookieJar();
983
- cj.setCookie('j=10; Domain=google.com; Path=/','google.ca',this.callback);
984
- },
985
- "errors": function(err,cookie) {
986
- assert.ok(err);
987
- assert.ok(!cookie);
988
- assert.match(err.message, /not in this host's domain/i);
989
- },
990
- },
991
- "old cookie is HttpOnly": {
992
- topic: function() {
993
- var cb = this.callback;
994
- var next = function (err,c) {
995
- c = null;
996
- return cb(err,cj);
997
- };
998
- var cj = new CookieJar();
999
- cj.setCookie('k=11; Domain=example.ca; Path=/; HttpOnly','http://example.ca',{http:true},next);
1000
- },
1001
- "initial cookie is set": function(err,cj) {
1002
- assert.ok(!err);
1003
- assert.ok(cj);
1004
- },
1005
- "but when trying to overwrite": {
1006
- topic: function(cj) {
1007
- var cb = this.callback;
1008
- var next = function(err,c) {
1009
- c = null;
1010
- cb(null,err);
1011
- };
1012
- cj.setCookie('k=12; Domain=example.ca; Path=/','http://example.ca',{http:false},next);
1013
- },
1014
- "it's an error": function(err) {
1015
- assert.ok(err);
1016
- },
1017
- "then, checking the original": {
1018
- topic: function(ignored,cj) {
1019
- assert.ok(cj instanceof CookieJar);
1020
- cj.getCookies('http://example.ca',{http:true},this.callback);
1021
- },
1022
- "cookie has original value": function(err,cookies) {
1023
- assert.equal(err,null);
1024
- assert.lengthOf(cookies, 1);
1025
- assert.equal(cookies[0].value,11);
1026
- },
1027
- },
1028
- },
1029
- },
1030
- },
1031
- })
1032
- .addBatch({
1033
- "JSON": {
1034
- "serialization": {
1035
- topic: function() {
1036
- var c = Cookie.parse('alpha=beta; Domain=example.com; Path=/foo; Expires=Tue, 19 Jan 2038 03:14:07 GMT; HttpOnly');
1037
- return JSON.stringify(c);
1038
- },
1039
- "gives a string": function(str) {
1040
- assert.equal(typeof str, "string");
1041
- },
1042
- "date is in ISO format": function(str) {
1043
- assert.match(str, /"expires":"2038-01-19T03:14:07\.000Z"/, 'expires is in ISO format');
1044
- },
1045
- },
1046
- "deserialization": {
1047
- topic: function() {
1048
- var json = '{"key":"alpha","value":"beta","domain":"example.com","path":"/foo","expires":"2038-01-19T03:14:07.000Z","httpOnly":true,"lastAccessed":2000000000123}';
1049
- return Cookie.fromJSON(json);
1050
- },
1051
- "works": function(c) {
1052
- assert.ok(c);
1053
- },
1054
- "key": function(c) { assert.equal(c.key, "alpha") },
1055
- "value": function(c) { assert.equal(c.value, "beta") },
1056
- "domain": function(c) { assert.equal(c.domain, "example.com") },
1057
- "path": function(c) { assert.equal(c.path, "/foo") },
1058
- "httpOnly": function(c) { assert.strictEqual(c.httpOnly, true) },
1059
- "secure": function(c) { assert.strictEqual(c.secure, false) },
1060
- "hostOnly": function(c) { assert.strictEqual(c.hostOnly, null) },
1061
- "expires is a date object": function(c) {
1062
- assert.equal(c.expires.getTime(), 2147483647000);
1063
- },
1064
- "lastAccessed is a date object": function(c) {
1065
- assert.equal(c.lastAccessed.getTime(), 2000000000123);
1066
- },
1067
- "creation defaulted": function(c) {
1068
- assert.ok(c.creation.getTime());
1069
- }
1070
- },
1071
- "null deserialization": {
1072
- topic: function() {
1073
- return Cookie.fromJSON(null);
1074
- },
1075
- "is null": function(cookie) {
1076
- assert.equal(cookie,null);
1077
- },
1078
- },
1079
- },
1080
- "expiry deserialization": {
1081
- "Infinity": {
1082
- topic: Cookie.fromJSON.bind(null, '{"expires":"Infinity"}'),
1083
- "is infinite": function(c) {
1084
- assert.strictEqual(c.expires, "Infinity");
1085
- assert.equal(c.expires, Infinity);
1086
- },
1087
- },
1088
- },
1089
- "maxAge serialization": {
1090
- topic: function() {
1091
- return function(toSet) {
1092
- var c = new Cookie();
1093
- c.key = 'foo'; c.value = 'bar';
1094
- c.setMaxAge(toSet);
1095
- return JSON.stringify(c);
1096
- };
1097
- },
1098
- "zero": {
1099
- topic: function(f) { return f(0) },
1100
- "looks good": function(str) {
1101
- assert.match(str, /"maxAge":0/);
1102
- },
1103
- },
1104
- "Infinity": {
1105
- topic: function(f) { return f(Infinity) },
1106
- "looks good": function(str) {
1107
- assert.match(str, /"maxAge":"Infinity"/);
1108
- },
1109
- },
1110
- "-Infinity": {
1111
- topic: function(f) { return f(-Infinity) },
1112
- "looks good": function(str) {
1113
- assert.match(str, /"maxAge":"-Infinity"/);
1114
- },
1115
- },
1116
- "null": {
1117
- topic: function(f) { return f(null) },
1118
- "looks good": function(str) {
1119
- assert.match(str, /"maxAge":null/);
1120
- },
1121
- },
1122
- },
1123
- "maxAge deserialization": {
1124
- "number": {
1125
- topic: Cookie.fromJSON.bind(null,'{"key":"foo","value":"bar","maxAge":123}'),
1126
- "is the number": function(c) {
1127
- assert.strictEqual(c.maxAge, 123);
1128
- },
1129
- },
1130
- "null": {
1131
- topic: Cookie.fromJSON.bind(null,'{"key":"foo","value":"bar","maxAge":null}'),
1132
- "is null": function(c) {
1133
- assert.strictEqual(c.maxAge, null);
1134
- },
1135
- },
1136
- "less than zero": {
1137
- topic: Cookie.fromJSON.bind(null,'{"key":"foo","value":"bar","maxAge":-123}'),
1138
- "is -123": function(c) {
1139
- assert.strictEqual(c.maxAge, -123);
1140
- },
1141
- },
1142
- "Infinity": {
1143
- topic: Cookie.fromJSON.bind(null,'{"key":"foo","value":"bar","maxAge":"Infinity"}'),
1144
- "is inf-as-string": function(c) {
1145
- assert.strictEqual(c.maxAge, "Infinity");
1146
- },
1147
- },
1148
- "-Infinity": {
1149
- topic: Cookie.fromJSON.bind(null,'{"key":"foo","value":"bar","maxAge":"-Infinity"}'),
1150
- "is inf-as-string": function(c) {
1151
- assert.strictEqual(c.maxAge, "-Infinity");
1152
- },
1153
- },
1154
- }
1155
- })
1156
- .addBatch({
1157
- "permuteDomain": {
1158
- "base case": {
1159
- topic: tough.permuteDomain.bind(null,'example.com'),
1160
- "got the domain": function(list) {
1161
- assert.deepEqual(list, ['example.com']);
1162
- },
1163
- },
1164
- "two levels": {
1165
- topic: tough.permuteDomain.bind(null,'foo.bar.example.com'),
1166
- "got three things": function(list) {
1167
- assert.deepEqual(list, ['example.com','bar.example.com','foo.bar.example.com']);
1168
- },
1169
- },
1170
- "invalid domain": {
1171
- topic: tough.permuteDomain.bind(null,'foo.bar.example.localduhmain'),
1172
- "got three things": function(list) {
1173
- assert.equal(list, null);
1174
- },
1175
- },
1176
- },
1177
- "permutePath": {
1178
- "base case": {
1179
- topic: tough.permutePath.bind(null,'/'),
1180
- "just slash": function(list) {
1181
- assert.deepEqual(list,['/']);
1182
- },
1183
- },
1184
- "single case": {
1185
- topic: tough.permutePath.bind(null,'/foo'),
1186
- "two things": function(list) {
1187
- assert.deepEqual(list,['/foo','/']);
1188
- },
1189
- "path matching": function(list) {
1190
- list.forEach(function(e) {
1191
- assert.ok(tough.pathMatch('/foo',e));
1192
- });
1193
- },
1194
- },
1195
- "double case": {
1196
- topic: tough.permutePath.bind(null,'/foo/bar'),
1197
- "four things": function(list) {
1198
- assert.deepEqual(list,['/foo/bar','/foo','/']);
1199
- },
1200
- "path matching": function(list) {
1201
- list.forEach(function(e) {
1202
- assert.ok(tough.pathMatch('/foo/bar',e));
1203
- });
1204
- },
1205
- },
1206
- "trailing slash": {
1207
- topic: tough.permutePath.bind(null,'/foo/bar/'),
1208
- "three things": function(list) {
1209
- assert.deepEqual(list,['/foo/bar','/foo','/']);
1210
- },
1211
- "path matching": function(list) {
1212
- list.forEach(function(e) {
1213
- assert.ok(tough.pathMatch('/foo/bar/',e));
1214
- });
1215
- },
1216
- },
1217
- }
1218
- })
1219
- .addBatch({
1220
- "Issue 1": {
1221
- topic: function() {
1222
- var cj = new CookieJar();
1223
- cj.setCookie('hello=world; path=/some/path/', 'http://domain/some/path/file', function(err,cookie) {
1224
- this.callback(err,{cj:cj, cookie:cookie});
1225
- }.bind(this));
1226
- },
1227
- "stored a cookie": function(t) {
1228
- assert.ok(t.cookie);
1229
- },
1230
- "cookie's path was modified to remove unnecessary slash": function(t) {
1231
- assert.equal(t.cookie.path, '/some/path');
1232
- },
1233
- "getting it back": {
1234
- topic: function(t) {
1235
- t.cj.getCookies('http://domain/some/path/file', function(err,cookies) {
1236
- this.callback(err, {cj:t.cj, cookies:cookies||[]});
1237
- }.bind(this));
1238
- },
1239
- "got one cookie": function(t) {
1240
- assert.lengthOf(t.cookies, 1);
1241
- },
1242
- "it's the right one": function(t) {
1243
- var c = t.cookies[0];
1244
- assert.equal(c.key, 'hello');
1245
- assert.equal(c.value, 'world');
1246
- },
1247
- }
1248
- }
1249
- })
1250
- .addBatch({
1251
- "expiry option": {
1252
- topic: function() {
1253
- var cb = this.callback;
1254
- var cj = new CookieJar();
1255
- cj.setCookie('near=expiry; Domain=example.com; Path=/; Max-Age=1','http://www.example.com',at(-1), function(err,cookie) {
1256
-
1257
- cb(err, {cj:cj, cookie:cookie});
1258
- });
1259
- },
1260
- "set the cookie": function(t) {
1261
- assert.ok(t.cookie, "didn't set?!");
1262
- assert.equal(t.cookie.key, 'near');
1263
- },
1264
- "then, retrieving": {
1265
- topic: function(t) {
1266
- var cb = this.callback;
1267
- setTimeout(function() {
1268
- t.cj.getCookies('http://www.example.com', {http:true, expire:false}, function(err,cookies) {
1269
- t.cookies = cookies;
1270
- cb(err,t);
1271
- });
1272
- },2000);
1273
- },
1274
- "got the cookie": function(t) {
1275
- assert.lengthOf(t.cookies, 1);
1276
- assert.equal(t.cookies[0].key, 'near');
1277
- },
1278
- }
1279
- }
1280
- })
1281
- .addBatch({
1282
- "trailing semi-colon set into cj": {
1283
- topic: function () {
1284
- var cb = this.callback;
1285
- var cj = new CookieJar();
1286
- var ex = 'http://www.example.com';
1287
- var tasks = [];
1288
- tasks.push(function(next) {
1289
- cj.setCookie('broken_path=testme; path=/;',ex,at(-1),next);
1290
- });
1291
- tasks.push(function(next) {
1292
- cj.setCookie('b=2; Path=/;;;;',ex,at(-1),next);
1293
- });
1294
- async.parallel(tasks, function (err, cookies) {
1295
- cb(null, {
1296
- cj: cj,
1297
- cookies: cookies
1298
- });
1299
- });
1300
- },
1301
- "check number of cookies": function (t) {
1302
- assert.lengthOf(t.cookies, 2, "didn't set");
1303
- },
1304
- "check *broken_path* was set properly": function (t) {
1305
- assert.equal(t.cookies[0].key, "broken_path");
1306
- assert.equal(t.cookies[0].value, "testme");
1307
- assert.equal(t.cookies[0].path, "/");
1308
- },
1309
- "check *b* was set properly": function (t) {
1310
- assert.equal(t.cookies[1].key, "b");
1311
- assert.equal(t.cookies[1].value, "2");
1312
- assert.equal(t.cookies[1].path, "/");
1313
- },
1314
- "retrieve the cookie": {
1315
- topic: function (t) {
1316
- var cb = this.callback;
1317
- t.cj.getCookies('http://www.example.com', {}, function (err, cookies) {
1318
- t.cookies = cookies;
1319
- cb(err, t);
1320
- });
1321
- },
1322
- "get the cookie": function(t) {
1323
- assert.lengthOf(t.cookies, 2);
1324
- assert.equal(t.cookies[0].key, 'broken_path');
1325
- assert.equal(t.cookies[0].value, 'testme');
1326
- assert.equal(t.cookies[1].key, "b");
1327
- assert.equal(t.cookies[1].value, "2");
1328
- assert.equal(t.cookies[1].path, "/");
1329
- },
1330
- },
1331
- }
1332
- })
1333
- .addBatch({
1334
- "Constructor":{
1335
- topic: function () {
1336
- return new Cookie({
1337
- key: 'test',
1338
- value: 'b',
1339
- maxAge: 60
1340
- });
1341
- },
1342
- 'check for key property': function (c) {
1343
- assert.ok(c);
1344
- assert.equal(c.key, 'test');
1345
- },
1346
- 'check for value property': function (c) {
1347
- assert.equal(c.value, 'b');
1348
- },
1349
- 'check for maxAge': function (c) {
1350
- assert.equal(c.maxAge, 60);
1351
- },
1352
- 'check for default values for unspecified properties': function (c) {
1353
- assert.equal(c.expires, "Infinity");
1354
- assert.equal(c.secure, false);
1355
- assert.equal(c.httpOnly, false);
1356
- }
1357
- }
1358
- })
1359
- .addBatch({
1360
- "allPaths option": {
1361
- topic: function() {
1362
- var cj = new CookieJar();
1363
- var tasks = [];
1364
- tasks.push(cj.setCookie.bind(cj, 'nopath_dom=qq; Path=/; Domain=example.com', 'http://example.com', {}));
1365
- tasks.push(cj.setCookie.bind(cj, 'path_dom=qq; Path=/foo; Domain=example.com', 'http://example.com', {}));
1366
- tasks.push(cj.setCookie.bind(cj, 'nopath_host=qq; Path=/', 'http://www.example.com', {}));
1367
- tasks.push(cj.setCookie.bind(cj, 'path_host=qq; Path=/foo', 'http://www.example.com', {}));
1368
- tasks.push(cj.setCookie.bind(cj, 'other=qq; Path=/', 'http://other.example.com/', {}));
1369
- tasks.push(cj.setCookie.bind(cj, 'other2=qq; Path=/foo', 'http://other.example.com/foo', {}));
1370
- var cb = this.callback;
1371
- async.parallel(tasks, function(err,results) {
1372
- cb(err, {cj:cj, cookies: results});
1373
- });
1374
- },
1375
- "all set": function(t) {
1376
- assert.equal(t.cookies.length, 6);
1377
- assert.ok(t.cookies.every(function(c) { return !!c }));
1378
- },
1379
- "getting without allPaths": {
1380
- topic: function(t) {
1381
- var cb = this.callback;
1382
- var cj = t.cj;
1383
- cj.getCookies('http://www.example.com/', {}, function(err,cookies) {
1384
- cb(err, {cj:cj, cookies:cookies});
1385
- });
1386
- },
1387
- "found just two cookies": function(t) {
1388
- assert.equal(t.cookies.length, 2);
1389
- },
1390
- "all are path=/": function(t) {
1391
- assert.ok(t.cookies.every(function(c) { return c.path === '/' }));
1392
- },
1393
- "no 'other' cookies": function(t) {
1394
- assert.ok(!t.cookies.some(function(c) { return (/^other/).test(c.name) }));
1395
- },
1396
- },
1397
- "getting without allPaths for /foo": {
1398
- topic: function(t) {
1399
- var cb = this.callback;
1400
- var cj = t.cj;
1401
- cj.getCookies('http://www.example.com/foo', {}, function(err,cookies) {
1402
- cb(err, {cj:cj, cookies:cookies});
1403
- });
1404
- },
1405
- "found four cookies": function(t) {
1406
- assert.equal(t.cookies.length, 4);
1407
- },
1408
- "no 'other' cookies": function(t) {
1409
- assert.ok(!t.cookies.some(function(c) { return (/^other/).test(c.name) }));
1410
- },
1411
- },
1412
- "getting with allPaths:true": {
1413
- topic: function(t) {
1414
- var cb = this.callback;
1415
- var cj = t.cj;
1416
- cj.getCookies('http://www.example.com/', {allPaths:true}, function(err,cookies) {
1417
- cb(err, {cj:cj, cookies:cookies});
1418
- });
1419
- },
1420
- "found four cookies": function(t) {
1421
- assert.equal(t.cookies.length, 4);
1422
- },
1423
- "no 'other' cookies": function(t) {
1424
- assert.ok(!t.cookies.some(function(c) { return (/^other/).test(c.name) }));
1425
- },
1426
- },
1427
- }
1428
- })
1429
- .addBatch({
1430
- "remove cookies": {
1431
- topic: function() {
1432
- var jar = new CookieJar();
1433
- var cookie = Cookie.parse("a=b; Domain=example.com; Path=/");
1434
- var cookie2 = Cookie.parse("a=b; Domain=foo.com; Path=/");
1435
- var cookie3 = Cookie.parse("foo=bar; Domain=foo.com; Path=/");
1436
- jar.setCookie(cookie, 'http://example.com/index.html', function(){});
1437
- jar.setCookie(cookie2, 'http://foo.com/index.html', function(){});
1438
- jar.setCookie(cookie3, 'http://foo.com/index.html', function(){});
1439
- return jar;
1440
- },
1441
- "all from matching domain": function(jar){
1442
- jar.store.removeCookies('example.com',null, function(err) {
1443
- assert(err == null);
1444
-
1445
- jar.store.findCookies('example.com', null, function(err, cookies){
1446
- assert(err == null);
1447
- assert(cookies != null);
1448
- assert(cookies.length === 0, 'cookie was not removed');
1449
- });
1450
-
1451
- jar.store.findCookies('foo.com', null, function(err, cookies){
1452
- assert(err == null);
1453
- assert(cookies != null);
1454
- assert(cookies.length === 2, 'cookies should not have been removed');
1455
- });
1456
- });
1457
- },
1458
- "from cookie store matching domain and key": function(jar){
1459
- jar.store.removeCookie('foo.com', '/', 'foo', function(err) {
1460
- assert(err == null);
1461
-
1462
- jar.store.findCookies('foo.com', null, function(err, cookies){
1463
- assert(err == null);
1464
- assert(cookies != null);
1465
- assert(cookies.length === 1, 'cookie was not removed correctly');
1466
- assert(cookies[0].key === 'a', 'wrong cookie was removed');
1467
- });
1468
- });
1469
- }
1470
- }
1471
- })
1472
- .addBatch({
1473
- "Synchronous CookieJar": {
1474
- "setCookieSync": {
1475
- topic: function() {
1476
- var jar = new CookieJar();
1477
- var cookie = Cookie.parse("a=b; Domain=example.com; Path=/");
1478
- cookie = jar.setCookieSync(cookie, 'http://example.com/index.html');
1479
- return cookie;
1480
- },
1481
- "returns a copy of the cookie": function(cookie) {
1482
- assert.instanceOf(cookie, Cookie);
1483
- }
1484
- },
1485
-
1486
- "setCookieSync strict parse error": {
1487
- topic: function() {
1488
- var jar = new CookieJar();
1489
- var opts = { strict: true };
1490
- try {
1491
- jar.setCookieSync("farbe=weiß", 'http://example.com/index.html', opts);
1492
- return false;
1493
- } catch (e) {
1494
- return e;
1495
- }
1496
- },
1497
- "throws the error": function(err) {
1498
- assert.instanceOf(err, Error);
1499
- assert.equal(err.message, "Cookie failed to parse");
1500
- }
1501
- },
1502
-
1503
- "getCookiesSync": {
1504
- topic: function() {
1505
- var jar = new CookieJar();
1506
- var url = 'http://example.com/index.html';
1507
- jar.setCookieSync("a=b; Domain=example.com; Path=/", url);
1508
- jar.setCookieSync("c=d; Domain=example.com; Path=/", url);
1509
- return jar.getCookiesSync(url);
1510
- },
1511
- "returns the cookie array": function(err, cookies) {
1512
- assert.ok(!err);
1513
- assert.ok(Array.isArray(cookies));
1514
- assert.lengthOf(cookies, 2);
1515
- cookies.forEach(function(cookie) {
1516
- assert.instanceOf(cookie, Cookie);
1517
- });
1518
- }
1519
- },
1520
-
1521
- "getCookieStringSync": {
1522
- topic: function() {
1523
- var jar = new CookieJar();
1524
- var url = 'http://example.com/index.html';
1525
- jar.setCookieSync("a=b; Domain=example.com; Path=/", url);
1526
- jar.setCookieSync("c=d; Domain=example.com; Path=/", url);
1527
- return jar.getCookieStringSync(url);
1528
- },
1529
- "returns the cookie header string": function(err, str) {
1530
- assert.ok(!err);
1531
- assert.typeOf(str, 'string');
1532
- }
1533
- },
1534
-
1535
- "getSetCookieStringsSync": {
1536
- topic: function() {
1537
- var jar = new CookieJar();
1538
- var url = 'http://example.com/index.html';
1539
- jar.setCookieSync("a=b; Domain=example.com; Path=/", url);
1540
- jar.setCookieSync("c=d; Domain=example.com; Path=/", url);
1541
- return jar.getSetCookieStringsSync(url);
1542
- },
1543
- "returns the cookie header string": function(err, headers) {
1544
- assert.ok(!err);
1545
- assert.ok(Array.isArray(headers));
1546
- assert.lengthOf(headers, 2);
1547
- headers.forEach(function(header) {
1548
- assert.typeOf(header, 'string');
1549
- });
1550
- }
1551
- },
1552
- }
1553
- })
1554
- .addBatch({
1555
- "Synchronous API on async CookieJar": {
1556
- topic: function() {
1557
- return new tough.Store();
1558
- },
1559
- "setCookieSync": {
1560
- topic: function(store) {
1561
- var jar = new CookieJar(store);
1562
- try {
1563
- jar.setCookieSync("a=b", 'http://example.com/index.html');
1564
- return false;
1565
- } catch(e) {
1566
- return e;
1567
- }
1568
- },
1569
- "fails": function(err) {
1570
- assert.instanceOf(err, Error);
1571
- assert.equal(err.message,
1572
- 'CookieJar store is not synchronous; use async API instead.');
1573
- }
1574
- },
1575
- "getCookiesSync": {
1576
- topic: function(store) {
1577
- var jar = new CookieJar(store);
1578
- try {
1579
- jar.getCookiesSync('http://example.com/index.html');
1580
- return false;
1581
- } catch(e) {
1582
- return e;
1583
- }
1584
- },
1585
- "fails": function(err) {
1586
- assert.instanceOf(err, Error);
1587
- assert.equal(err.message,
1588
- 'CookieJar store is not synchronous; use async API instead.');
1589
- }
1590
- },
1591
- "getCookieStringSync": {
1592
- topic: function(store) {
1593
- var jar = new CookieJar(store);
1594
- try {
1595
- jar.getCookieStringSync('http://example.com/index.html');
1596
- return false;
1597
- } catch(e) {
1598
- return e;
1599
- }
1600
- },
1601
- "fails": function(err) {
1602
- assert.instanceOf(err, Error);
1603
- assert.equal(err.message,
1604
- 'CookieJar store is not synchronous; use async API instead.');
1605
- }
1606
- },
1607
- "getSetCookieStringsSync": {
1608
- topic: function(store) {
1609
- var jar = new CookieJar(store);
1610
- try {
1611
- jar.getSetCookieStringsSync('http://example.com/index.html');
1612
- return false;
1613
- } catch(e) {
1614
- return e;
1615
- }
1616
- },
1617
- "fails": function(err) {
1618
- assert.instanceOf(err, Error);
1619
- assert.equal(err.message,
1620
- 'CookieJar store is not synchronous; use async API instead.');
1621
- }
1622
- },
1623
- }
1624
- })
1625
- .export(module);