meadow 2.0.44 → 2.0.46
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meadow",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.46",
|
|
4
4
|
"description": "A data access library.",
|
|
5
5
|
"main": "source/Meadow.js",
|
|
6
6
|
"scripts": {
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"alasql": "^4.17.0",
|
|
89
89
|
"dgraph-js-http": "^21.3.0",
|
|
90
|
-
"fable": "^3.1.
|
|
90
|
+
"fable": "^3.1.78",
|
|
91
91
|
"gulp-util": "^3.0.8",
|
|
92
92
|
"meadow-connection-dgraph": "^1.0.3",
|
|
93
93
|
"meadow-connection-mongodb": "^1.0.3",
|
|
@@ -56,7 +56,14 @@ var MeadowProvider = function()
|
|
|
56
56
|
var buildURL = function(pAddress)
|
|
57
57
|
{
|
|
58
58
|
let tmpEndpointSettings = getEndpointSettings();
|
|
59
|
-
|
|
59
|
+
let tmpURL = `${tmpEndpointSettings.ServerProtocol}://${tmpEndpointSettings.ServerAddress}:${tmpEndpointSettings.ServerPort}/${tmpEndpointSettings.ServerEndpointPrefix}${pAddress}`;
|
|
60
|
+
// e.g. 'skipDecoration=true' — lets machine-to-machine connections
|
|
61
|
+
// opt out of per-row presentation decoration the remote applies.
|
|
62
|
+
if (typeof(tmpEndpointSettings.AdditionalQueryString) === 'string' && tmpEndpointSettings.AdditionalQueryString.length > 0)
|
|
63
|
+
{
|
|
64
|
+
tmpURL += (tmpURL.indexOf('?') >= 0) ? `&${tmpEndpointSettings.AdditionalQueryString}` : `?${tmpEndpointSettings.AdditionalQueryString}`;
|
|
65
|
+
}
|
|
66
|
+
return tmpURL;
|
|
60
67
|
};
|
|
61
68
|
|
|
62
69
|
var buildRequestOptions = function(pQuery)
|
|
@@ -75,13 +82,43 @@ var MeadowProvider = function()
|
|
|
75
82
|
let tmpCookies = (tmpInstance && Array.isArray(tmpInstance.cookies))
|
|
76
83
|
? tmpInstance.cookies : [];
|
|
77
84
|
|
|
85
|
+
// Explicit timeout: Node 20+ installs a ~5s socket timeout on
|
|
86
|
+
// http.globalAgent; an explicit request timeout takes that default
|
|
87
|
+
// out of play (same workaround as fable's RestClient). Configurable
|
|
88
|
+
// per connection (settings.RequestTimeout) for slow decorated reads.
|
|
89
|
+
let tmpEndpointSettings = getEndpointSettings();
|
|
90
|
+
let tmpRequestTimeout = (typeof(tmpEndpointSettings.RequestTimeout) === 'number')
|
|
91
|
+
? tmpEndpointSettings.RequestTimeout : 60000;
|
|
92
|
+
|
|
78
93
|
let tmpRequestOptions = (
|
|
79
94
|
{
|
|
80
95
|
url: tmpURL,
|
|
81
|
-
headers: _Fable.Utility.extend({cookie: ''}, tmpHeaders)
|
|
96
|
+
headers: _Fable.Utility.extend({cookie: ''}, tmpHeaders),
|
|
97
|
+
timeout: tmpRequestTimeout
|
|
82
98
|
});
|
|
83
99
|
|
|
84
|
-
|
|
100
|
+
// Per-request session override: when an operation carries a caller
|
|
101
|
+
// session (a forwarded identity — e.g. a databeacon proxying a
|
|
102
|
+
// user's request, or a cron run impersonating a RunAs user), present
|
|
103
|
+
// THAT session upstream instead of the connection's bound machine
|
|
104
|
+
// session, so the remote enforces row-level auth as the real caller.
|
|
105
|
+
// The override rides the per-operation query (concurrency-safe — it
|
|
106
|
+
// never touches the connection's shared cookie state). Absent or a
|
|
107
|
+
// default placeholder session falls back to the bound cookies.
|
|
108
|
+
let tmpSessionOverride = (pQuery && pQuery.query && pQuery.query.parameters)
|
|
109
|
+
? pQuery.query.parameters.MeadowEndpointsSessionOverride : null;
|
|
110
|
+
if (tmpSessionOverride && typeof(tmpSessionOverride.SessionID) === 'string'
|
|
111
|
+
&& tmpSessionOverride.SessionID.length > 0 && tmpSessionOverride.SessionID !== '0x0000')
|
|
112
|
+
{
|
|
113
|
+
let tmpCookieName = (tmpEndpointSettings.Authentication && tmpEndpointSettings.Authentication.CookieName)
|
|
114
|
+
? tmpEndpointSettings.Authentication.CookieName
|
|
115
|
+
: (tmpEndpointSettings.SessionCookieName || 'UserSession');
|
|
116
|
+
tmpRequestOptions.headers.cookie = `${tmpCookieName}=${tmpSessionOverride.SessionID}`;
|
|
117
|
+
}
|
|
118
|
+
else
|
|
119
|
+
{
|
|
120
|
+
tmpRequestOptions.headers.cookie = tmpCookies.join(';');
|
|
121
|
+
}
|
|
85
122
|
|
|
86
123
|
|
|
87
124
|
if (pQuery.logLevel > 0 ||
|
|
@@ -121,3 +121,124 @@ suite('MeadowEndpoints provider instance-driven configuration', function ()
|
|
|
121
121
|
Expect(Array.isArray(tmpOutcome.Records)).to.equal(true);
|
|
122
122
|
});
|
|
123
123
|
});
|
|
124
|
+
|
|
125
|
+
function readAnimalsWithSession(pDAL, pSessionOverride)
|
|
126
|
+
{
|
|
127
|
+
return new Promise((fResolve) =>
|
|
128
|
+
{
|
|
129
|
+
let tmpQuery = pDAL.query.clone().setCap(1);
|
|
130
|
+
tmpQuery.query.parameters.MeadowEndpointsSessionOverride = pSessionOverride;
|
|
131
|
+
pDAL.doReads(tmpQuery, (pError, pQuery, pRecords) => fResolve({ Error: pError, Records: pRecords }));
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
suite('MeadowEndpoints provider per-request session override', function ()
|
|
136
|
+
{
|
|
137
|
+
suiteSetup(async function () { await startStubAPI(); });
|
|
138
|
+
suiteTeardown(function () { if (_Server) { _Server.close(); } });
|
|
139
|
+
setup(function () { _LastRequest = null; });
|
|
140
|
+
|
|
141
|
+
test('a forwarded caller session is presented upstream INSTEAD of the bound machine session', async function ()
|
|
142
|
+
{
|
|
143
|
+
const tmpInstance = { settings: serverSettings(), headers: {}, cookies: [ 'UserSession=machine-bound' ] };
|
|
144
|
+
await readAnimalsWithSession(buildDAL(tmpInstance), { SessionID: 'caller-session-xyz' });
|
|
145
|
+
Expect(_LastRequest.Cookie).to.equal('UserSession=caller-session-xyz', 'the per-request caller session wins; the bound machine session is not sent');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('the upstream cookie name follows the connection Authentication.CookieName', async function ()
|
|
149
|
+
{
|
|
150
|
+
const tmpSettings = Object.assign(serverSettings(), { Authentication: { CookieName: 'SessionID' } });
|
|
151
|
+
const tmpInstance = { settings: tmpSettings, headers: {}, cookies: [ 'SessionID=machine-bound' ] };
|
|
152
|
+
await readAnimalsWithSession(buildDAL(tmpInstance), { SessionID: 'caller-abc' });
|
|
153
|
+
Expect(_LastRequest.Cookie).to.equal('SessionID=caller-abc');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('a default placeholder session (0x0000) falls back to the bound connection session', async function ()
|
|
157
|
+
{
|
|
158
|
+
const tmpInstance = { settings: serverSettings(), headers: {}, cookies: [ 'UserSession=machine-bound' ] };
|
|
159
|
+
await readAnimalsWithSession(buildDAL(tmpInstance), { SessionID: '0x0000' });
|
|
160
|
+
Expect(_LastRequest.Cookie).to.equal('UserSession=machine-bound', 'an anonymous/placeholder session is not a real identity — use the machine session');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('no override present → bound connection session (backward compatible)', async function ()
|
|
164
|
+
{
|
|
165
|
+
const tmpInstance = { settings: serverSettings(), headers: {}, cookies: [ 'UserSession=machine-bound' ] };
|
|
166
|
+
await readAnimals(buildDAL(tmpInstance));
|
|
167
|
+
Expect(_LastRequest.Cookie).to.equal('UserSession=machine-bound');
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
suite('MeadowEndpoints provider request timeout', function ()
|
|
172
|
+
{
|
|
173
|
+
suiteSetup(async function () { await startStubAPI(); });
|
|
174
|
+
suiteTeardown(function () { if (_Server) { _Server.close(); } });
|
|
175
|
+
|
|
176
|
+
test('an explicit request timeout is always set (Node 20+ globalAgent ~5s default workaround)', function (fDone)
|
|
177
|
+
{
|
|
178
|
+
// Intercept the socket-level options by reading from a slow-but-fine
|
|
179
|
+
// stub: the request must carry a timeout >= the configured value, so
|
|
180
|
+
// the platform default never applies.
|
|
181
|
+
const libHTTP = require('http');
|
|
182
|
+
const tmpOriginalRequest = libHTTP.request;
|
|
183
|
+
let tmpCapturedOptions = null;
|
|
184
|
+
libHTTP.request = function (pOptions, fResponseHandler)
|
|
185
|
+
{
|
|
186
|
+
tmpCapturedOptions = pOptions;
|
|
187
|
+
return tmpOriginalRequest.call(libHTTP, pOptions, fResponseHandler);
|
|
188
|
+
};
|
|
189
|
+
const tmpDAL = buildDAL(null, serverSettings());
|
|
190
|
+
readAnimals(tmpDAL).then((pOutcome) =>
|
|
191
|
+
{
|
|
192
|
+
libHTTP.request = tmpOriginalRequest;
|
|
193
|
+
Expect(tmpCapturedOptions).to.be.an('object');
|
|
194
|
+
Expect(tmpCapturedOptions.timeout).to.equal(60000, 'default 60s');
|
|
195
|
+
fDone();
|
|
196
|
+
}).catch((pError) => { libHTTP.request = tmpOriginalRequest; fDone(pError); });
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('the connection settings RequestTimeout overrides the default', function (fDone)
|
|
200
|
+
{
|
|
201
|
+
const libHTTP = require('http');
|
|
202
|
+
const tmpOriginalRequest = libHTTP.request;
|
|
203
|
+
let tmpCapturedOptions = null;
|
|
204
|
+
libHTTP.request = function (pOptions, fResponseHandler)
|
|
205
|
+
{
|
|
206
|
+
tmpCapturedOptions = pOptions;
|
|
207
|
+
return tmpOriginalRequest.call(libHTTP, pOptions, fResponseHandler);
|
|
208
|
+
};
|
|
209
|
+
const tmpSettings = Object.assign(serverSettings(), { RequestTimeout: 120000 });
|
|
210
|
+
const tmpDAL = buildDAL(null, tmpSettings);
|
|
211
|
+
readAnimals(tmpDAL).then(() =>
|
|
212
|
+
{
|
|
213
|
+
libHTTP.request = tmpOriginalRequest;
|
|
214
|
+
Expect(tmpCapturedOptions.timeout).to.equal(120000);
|
|
215
|
+
fDone();
|
|
216
|
+
}).catch((pError) => { libHTTP.request = tmpOriginalRequest; fDone(pError); });
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
suite('MeadowEndpoints provider additional query string', function ()
|
|
221
|
+
{
|
|
222
|
+
suiteSetup(async function () { await startStubAPI(); });
|
|
223
|
+
suiteTeardown(function () { if (_Server) { _Server.close(); } });
|
|
224
|
+
|
|
225
|
+
test('AdditionalQueryString is appended to read URLs (e.g. skipDecoration=true)', function (fDone)
|
|
226
|
+
{
|
|
227
|
+
const libHTTP = require('http');
|
|
228
|
+
const tmpOriginalRequest = libHTTP.request;
|
|
229
|
+
let tmpCapturedPath = null;
|
|
230
|
+
libHTTP.request = function (pOptions, fResponseHandler)
|
|
231
|
+
{
|
|
232
|
+
tmpCapturedPath = pOptions.path;
|
|
233
|
+
return tmpOriginalRequest.call(libHTTP, pOptions, fResponseHandler);
|
|
234
|
+
};
|
|
235
|
+
const tmpSettings = Object.assign(serverSettings(), { AdditionalQueryString: 'skipDecoration=true' });
|
|
236
|
+
const tmpDAL = buildDAL(null, tmpSettings);
|
|
237
|
+
readAnimals(tmpDAL).then(() =>
|
|
238
|
+
{
|
|
239
|
+
libHTTP.request = tmpOriginalRequest;
|
|
240
|
+
Expect(tmpCapturedPath).to.contain('?skipDecoration=true');
|
|
241
|
+
fDone();
|
|
242
|
+
}).catch((pError) => { libHTTP.request = tmpOriginalRequest; fDone(pError); });
|
|
243
|
+
});
|
|
244
|
+
});
|