@mherod/get-cookie 1.1.4 → 1.1.5
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.
- package/README.md +7 -6
- package/index.js +40 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,27 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
## What is it?
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
get-cookie is a command line utility that allows you to get the value of a cookie from your locally installed browser.
|
|
6
|
+
It is useful for testing web pages that require authentication.
|
|
6
7
|
|
|
7
8
|
## Installation
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
To install get-cookie, run the following command:
|
|
10
11
|
|
|
11
12
|
$ npm install @mherod/get-cookie --global
|
|
12
13
|
|
|
13
14
|
## How do I use it?
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
To use get-cookie, run the following command:
|
|
16
17
|
|
|
17
18
|
$ get-cookie <cookie-name> <domain>
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
For example, to get the value of the `auth` cookie on the `www.example.com` domain, run the following command:
|
|
20
21
|
|
|
21
22
|
$ get-cookie auth www.example.com
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
The output of the command will be the value of the cookie.
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
The library can also be used as a module.
|
|
26
27
|
|
|
27
28
|
```javascript
|
|
28
29
|
const {getCookie} = require('@mherod/get-cookie');
|
package/index.js
CHANGED
|
@@ -73,7 +73,7 @@ async function getFirefoxCookie({name, domain}) {
|
|
|
73
73
|
const defaultChromeRoot = `${process.env.HOME}/Library/Application Support/Google/Chrome`;
|
|
74
74
|
const defaultChromeCookies = `${defaultChromeRoot}/Default/Cookies`;
|
|
75
75
|
|
|
76
|
-
async function getEncryptedChromeCookie(name, domain, file = defaultChromeCookies) {
|
|
76
|
+
async function getEncryptedChromeCookie({name, domain, file = defaultChromeCookies}) {
|
|
77
77
|
if (name && typeof name !== 'string') {
|
|
78
78
|
throw new Error('name must be a string');
|
|
79
79
|
}
|
|
@@ -253,8 +253,26 @@ async function getChromeCookie({name, domain}) {
|
|
|
253
253
|
throw new Error('domain must be a string');
|
|
254
254
|
}
|
|
255
255
|
const chromePasswordPromise = getChromePassword();
|
|
256
|
-
const [encryptedData] = await findAllFiles({
|
|
257
|
-
|
|
256
|
+
const [encryptedData] = await findAllFiles({
|
|
257
|
+
path: defaultChromeRoot,
|
|
258
|
+
name: 'Cookies'
|
|
259
|
+
}).then(files => {
|
|
260
|
+
const promise = Promise.all(files.map(file => {
|
|
261
|
+
return getEncryptedChromeCookie({
|
|
262
|
+
name: name,
|
|
263
|
+
domain: domain,
|
|
264
|
+
file: file
|
|
265
|
+
});
|
|
266
|
+
}));
|
|
267
|
+
if (process.env.VERBOSE) {
|
|
268
|
+
console.log('promise', promise);
|
|
269
|
+
}
|
|
270
|
+
return promise;
|
|
271
|
+
}).catch(error => {
|
|
272
|
+
if (process.env.VERBOSE) {
|
|
273
|
+
console.log('error', error);
|
|
274
|
+
}
|
|
275
|
+
return [];
|
|
258
276
|
});
|
|
259
277
|
const password = await chromePasswordPromise;
|
|
260
278
|
if (process.env.VERBOSE) {
|
|
@@ -294,9 +312,26 @@ async function findAllFiles({path, name, rootSegments = path.split('/').length,
|
|
|
294
312
|
console.log(`Searching for ${name} in ${path}`);
|
|
295
313
|
}
|
|
296
314
|
const files = [];
|
|
297
|
-
|
|
315
|
+
let readdirSync;
|
|
316
|
+
try {
|
|
317
|
+
readdirSync = fs.readdirSync(path);
|
|
318
|
+
} catch (e) {
|
|
319
|
+
if (process.env.VERBOSE) {
|
|
320
|
+
console.log(`Error reading ${path}`, e);
|
|
321
|
+
}
|
|
322
|
+
return files;
|
|
323
|
+
}
|
|
324
|
+
for (const file of readdirSync) {
|
|
298
325
|
const filePath = path + '/' + file;
|
|
299
|
-
|
|
326
|
+
let stat;
|
|
327
|
+
try {
|
|
328
|
+
stat = fs.statSync(filePath);
|
|
329
|
+
} catch (e) {
|
|
330
|
+
if (process.env.VERBOSE) {
|
|
331
|
+
console.error(`Error getting stat for ${filePath}`, e);
|
|
332
|
+
}
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
300
335
|
if (stat.isDirectory()) {
|
|
301
336
|
if (filePath.split('/').length < rootSegments + maxDepth) {
|
|
302
337
|
try {
|