@abtnode/util 1.16.13-beta-55b3e93d → 1.16.13-beta-423a40b1
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.
|
@@ -36,9 +36,7 @@ const ensureStarted = async ({ host, port, timeout = 10 * ONE_SECOND, elapse = 0
|
|
|
36
36
|
const spend = elapse + (Date.now() - startTime);
|
|
37
37
|
|
|
38
38
|
if (spend >= timeout) {
|
|
39
|
-
throw new Error(
|
|
40
|
-
`the service is not ready within ${Math.ceil(timeout / ONE_SECOND)} seconds, please check your network`
|
|
41
|
-
);
|
|
39
|
+
throw new Error(`service not ready within ${Math.ceil(timeout / ONE_SECOND)} seconds`);
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
return ensureStarted({ host, port, timeout, elapse: spend });
|
|
@@ -46,7 +44,7 @@ const ensureStarted = async ({ host, port, timeout = 10 * ONE_SECOND, elapse = 0
|
|
|
46
44
|
};
|
|
47
45
|
|
|
48
46
|
const ensureHealthy = async ({ host, port, minConsecutiveTime = 5 * ONE_SECOND }) => {
|
|
49
|
-
const checkInterval =
|
|
47
|
+
const checkInterval = 200; // ms
|
|
50
48
|
const minCheckTimes = Math.ceil(minConsecutiveTime / checkInterval);
|
|
51
49
|
|
|
52
50
|
debug('check if healthy', { port });
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fork from https://github.com/tkellen/js-express-bearer-token
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const parseCookie = require('cookie').parse;
|
|
6
|
+
const decodeCookie = require('cookie-parser').signedCookie;
|
|
7
|
+
|
|
8
|
+
const getCookie = (serializedCookies, key) => parseCookie(serializedCookies)[key] || false;
|
|
9
|
+
|
|
10
|
+
module.exports = (opts) => {
|
|
11
|
+
if (!opts) {
|
|
12
|
+
// eslint-disable-next-line no-param-reassign
|
|
13
|
+
opts = {
|
|
14
|
+
cookie: false,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const queryKey = opts.queryKey || 'access_token';
|
|
19
|
+
const bodyKey = opts.bodyKey || 'access_token';
|
|
20
|
+
const headerName = opts.headerName || 'authorization';
|
|
21
|
+
const headerKey = opts.headerKey || 'Bearer';
|
|
22
|
+
const reqKey = opts.reqKey || 'token';
|
|
23
|
+
const { cookie } = opts;
|
|
24
|
+
|
|
25
|
+
if (cookie && !cookie.key) {
|
|
26
|
+
cookie.key = 'access_token';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (cookie && cookie.signed && !cookie.secret) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
'[express-bearer-token]: You must provide a secret token to cookie attribute, or disable signed property'
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (req, res, next) => {
|
|
36
|
+
let token;
|
|
37
|
+
let error;
|
|
38
|
+
|
|
39
|
+
// query
|
|
40
|
+
if (req.query && req.query[queryKey]) {
|
|
41
|
+
token = req.query[queryKey];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// body
|
|
45
|
+
if (req.body && req.body[bodyKey]) {
|
|
46
|
+
if (token) {
|
|
47
|
+
error = true;
|
|
48
|
+
}
|
|
49
|
+
token = req.body[bodyKey];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// headers
|
|
53
|
+
if (req.headers) {
|
|
54
|
+
if (req.headers[headerName]) {
|
|
55
|
+
const parts = req.headers[headerName].split(' ');
|
|
56
|
+
if (parts.length === 2 && parts[0] === headerKey) {
|
|
57
|
+
if (token) {
|
|
58
|
+
error = true;
|
|
59
|
+
}
|
|
60
|
+
// eslint-disable-next-line prefer-destructuring
|
|
61
|
+
token = parts[1];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// cookie
|
|
66
|
+
if (cookie && req.headers.cookie) {
|
|
67
|
+
const plainCookie = getCookie(req.headers.cookie || '', cookie.key); // seeks the key
|
|
68
|
+
if (plainCookie) {
|
|
69
|
+
const cookieToken = cookie.signed ? decodeCookie(plainCookie, cookie.secret) : plainCookie;
|
|
70
|
+
|
|
71
|
+
if (cookieToken) {
|
|
72
|
+
if (token) {
|
|
73
|
+
error = true;
|
|
74
|
+
}
|
|
75
|
+
token = cookieToken;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// RFC6750 states the access_token MUST NOT be provided
|
|
82
|
+
// in more than one place in a single request.
|
|
83
|
+
if (error) {
|
|
84
|
+
res.status(400).send('Access token found in multiple locations');
|
|
85
|
+
} else {
|
|
86
|
+
req[reqKey] = token;
|
|
87
|
+
next();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.13-beta-
|
|
6
|
+
"version": "1.16.13-beta-423a40b1",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.16.13-beta-
|
|
22
|
-
"@abtnode/logger": "1.16.13-beta-
|
|
23
|
-
"@blocklet/constant": "1.16.13-beta-
|
|
21
|
+
"@abtnode/constant": "1.16.13-beta-423a40b1",
|
|
22
|
+
"@abtnode/logger": "1.16.13-beta-423a40b1",
|
|
23
|
+
"@blocklet/constant": "1.16.13-beta-423a40b1",
|
|
24
24
|
"@ocap/client": "1.18.84",
|
|
25
25
|
"@ocap/mcrypto": "1.18.84",
|
|
26
26
|
"@ocap/util": "1.18.84",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"axios-mock-adapter": "^1.21.2",
|
|
31
31
|
"axon": "^2.0.3",
|
|
32
|
+
"cookie": "^0.5.0",
|
|
33
|
+
"cookie-parser": "^1.4.6",
|
|
32
34
|
"cross-spawn": "^7.0.3",
|
|
33
35
|
"dayjs": "^1.11.7",
|
|
34
36
|
"debug": "^4.3.4",
|
|
@@ -65,11 +67,12 @@
|
|
|
65
67
|
"which": "^2.0.2"
|
|
66
68
|
},
|
|
67
69
|
"devDependencies": {
|
|
70
|
+
"cookie-signature": "^1.0.6",
|
|
68
71
|
"detect-port": "^1.5.1",
|
|
69
72
|
"express": "^4.18.2",
|
|
70
73
|
"fs-extra": "^10.1.0",
|
|
71
74
|
"jest": "^27.5.1",
|
|
72
75
|
"unzipper": "^0.10.11"
|
|
73
76
|
},
|
|
74
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "1aee04f45042bd4784ca72f9f8b93918980be4d4"
|
|
75
78
|
}
|