@7365admin1/core 3.119.0 → 3.120.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.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +29 -1
- package/dist/index.js +64 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/ounitech-timestamp-probe.test.mjs +57 -0
package/package.json
CHANGED
|
@@ -110,3 +110,60 @@ test("probe: refuses non-Ounitech robots and robots with no credentials, without
|
|
|
110
110
|
await assert.rejects(fleetFor("none").probeTimestampFormat({ ...robotRow("a4"), appKey: "", appToken: "" }), (e) => e.statusCode === 400);
|
|
111
111
|
assert.equal(calls.length, 0);
|
|
112
112
|
});
|
|
113
|
+
|
|
114
|
+
/* ------------------------------------------------------- the offset probe */
|
|
115
|
+
|
|
116
|
+
// A mock Ounitech whose clock runs 30 s ahead and which accepts yyyyMMddHHmmss
|
|
117
|
+
// only at its own clock + 8 h (within 2 s), checking the sign server-side.
|
|
118
|
+
let offServer;
|
|
119
|
+
let offBase;
|
|
120
|
+
const offCalls = [];
|
|
121
|
+
const SKEW_MS = 30_000;
|
|
122
|
+
const parseCompact = (t) =>
|
|
123
|
+
Date.UTC(+t.slice(0, 4), +t.slice(4, 6) - 1, +t.slice(6, 8), +t.slice(8, 10), +t.slice(10, 12), +t.slice(12, 14));
|
|
124
|
+
|
|
125
|
+
before(async () => {
|
|
126
|
+
offServer = http.createServer((req, res) => {
|
|
127
|
+
let raw = "";
|
|
128
|
+
req.on("data", (c) => (raw += c));
|
|
129
|
+
req.on("end", () => {
|
|
130
|
+
const [, mode, ...rest] = req.url.split("/");
|
|
131
|
+
const path = "/" + rest.join("/");
|
|
132
|
+
const body = JSON.parse(raw);
|
|
133
|
+
offCalls.push({ path, body });
|
|
134
|
+
const vendorNow = Date.now() + SKEW_MS;
|
|
135
|
+
const signOk = body.sign === sha1(`appid=${body.appid},timestamp=${body.timestamp},url=${path},secret=${SECRET}`);
|
|
136
|
+
const want = mode === "plus8" ? vendorNow + 8 * 3600_000 : NaN;
|
|
137
|
+
const ok = signOk && /^\d{14}$/.test(body.timestamp) && Math.abs(parseCompact(body.timestamp) - want) < 2000;
|
|
138
|
+
res.writeHead(200, { "content-type": "application/json", date: new Date(vendorNow).toUTCString() });
|
|
139
|
+
res.end(JSON.stringify(ok ? { robotList: [] } : { ok: false, msg: "bad timestamp" }));
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
offServer.listen(0, "127.0.0.1");
|
|
143
|
+
await once(offServer, "listening");
|
|
144
|
+
offBase = `http://127.0.0.1:${offServer.address().port}`;
|
|
145
|
+
});
|
|
146
|
+
after(() => offServer.close());
|
|
147
|
+
|
|
148
|
+
const offFleet = (mode) => useRobotFleetService({ cloudOptions: { baseUrl: `${offBase}/${mode}`, timeoutMs: 1000 } });
|
|
149
|
+
|
|
150
|
+
test("offset probe: learns the vendor clock, tries offsets in order, stops at the first accepted (+8 h)", async () => {
|
|
151
|
+
offCalls.length = 0;
|
|
152
|
+
const r = await offFleet("plus8").probeTimestampOffset(robotRow("o1"));
|
|
153
|
+
assert.equal(r.acceptedOffsetMinutes, 480);
|
|
154
|
+
assert.deepEqual(r.attempts.map((a) => a.offsetMinutes), [0, 120, 60, 480]);
|
|
155
|
+
assert.ok(Math.abs(r.vendorSkewSeconds - 30) <= 1);
|
|
156
|
+
assert.ok(offCalls.every((c) => c.path === PATH), "only the robot list is called");
|
|
157
|
+
assert.ok(r.attempts.every((a) => /^\d{14}$/.test(a.sent)));
|
|
158
|
+
const text = JSON.stringify(r);
|
|
159
|
+
assert.equal(text.includes(SECRET) || text.includes(APPID), false);
|
|
160
|
+
assert.equal(/"sign"|[0-9a-f]{40}/.test(text), false);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("offset probe: none accepted tries all 8; its own once-a-minute limit, separate from the format probe", async () => {
|
|
164
|
+
const fleet = offFleet("none");
|
|
165
|
+
const r = await fleet.probeTimestampOffset(robotRow("o2"));
|
|
166
|
+
assert.equal(r.acceptedOffsetMinutes, null);
|
|
167
|
+
assert.equal(r.attempts.length, 8);
|
|
168
|
+
await assert.rejects(fleet.probeTimestampOffset(robotRow("o2")), (e) => e.statusCode === 429);
|
|
169
|
+
});
|