Independent-of-prod quality debt from PENDIENTE.md §2: - test: migrate broken Jest -> meteortesting:mocha. Tests rewritten to chai + Meteor 3 async APIs, moved to test/server/ (server-only). test/server/ 00-setup.test.js re-runs the collection2/accounts init that `meteor test` skips (no server/main.js). New comments method + mediaAnalyzers coverage. Dropped rest.test.js (removed meteor/http; covered by smoke/). 36 passing. - fix: scope FireContainer read by the URL _id on the archive route instead of a selector-less FiresCollection.findOne() (imports/ui/pages/Fires/Fires.js). - feat: rate-limit abusable publications via rateLimitSubscriptions (fireFrom* and comments.forReference 5/1000ms; geo subs 10/1000ms). - perf: append loading=async to the Google Maps loader URL (Gkeys.js). - deps: meteor-accounts-t9n 2.0 -> 2.6 (no gl build -> keep gl->es fallback, documented); add 3 missing gl/common.json keys (0 missing now). - deps: drop jest/babel/enzyme, add chai.
63 lines
2.9 KiB
JavaScript
63 lines
2.9 KiB
JavaScript
/* eslint-env mocha */
|
|
/* eslint-disable func-names, prefer-arrow-callback */
|
|
/* eslint-disable import/no-absolute-path */
|
|
|
|
import { expect } from 'chai';
|
|
import urlEnc from '/imports/modules/url-encode';
|
|
|
|
// NOTE: the old suite also seeded ActiveFires via @cleverbeagle/seeder and
|
|
// round-tripped whole docs. Those cases were documented-broken (Date fields came
|
|
// back as strings) and depended on a dev-only seeder package that is no longer
|
|
// installed, so they were dropped. The crypto round-trip below is the real
|
|
// contract this module owes.
|
|
|
|
describe('url encoding', () => {
|
|
it('should encrypt and decrypt basic objects', async () => {
|
|
const obj = { lat: 2 };
|
|
const sealed = await urlEnc.encrypt(obj);
|
|
const unsealed = await urlEnc.decrypt(sealed);
|
|
expect(unsealed).to.deep.equal(obj);
|
|
});
|
|
|
|
it('should encrypt and decrypt objects with date', async () => {
|
|
const obj = { lat: 40.234503, lon: -3.350386, when: (new Date()).toString() };
|
|
const sealed = await urlEnc.encrypt(obj);
|
|
const unsealed = await urlEnc.decrypt(sealed);
|
|
expect(unsealed).to.deep.equal(obj);
|
|
});
|
|
|
|
it('should encrypt complete objects and produce url-safe, salted output', async () => {
|
|
const obj = {
|
|
ourid: { type: 'Point', coordinates: [24.813, 9.223] },
|
|
type: 'modis',
|
|
lat: 9.223,
|
|
lon: 24.813,
|
|
when: new Date('2017-12-13T00:00:00.000Z').toISOString(),
|
|
scan: 1,
|
|
track: 1,
|
|
satellite: 'A',
|
|
confidence: 'nominal',
|
|
version: '6.0NRT',
|
|
frp: 6.5,
|
|
daynight: null,
|
|
brightness: 305.9,
|
|
bright_t31: 292.6
|
|
};
|
|
|
|
const sealed = await urlEnc.encrypt(obj);
|
|
const sealed2 = await urlEnc.encrypt(obj);
|
|
const unsealed = await urlEnc.decrypt(sealed);
|
|
|
|
expect(unsealed).to.deep.equal(obj);
|
|
expect(sealed).to.equal(encodeURI(sealed)); // already url-safe
|
|
expect(sealed).to.not.equal(sealed2); // salted: same input, different output
|
|
expect(sealed).to.not.include('/');
|
|
expect(sealed).to.not.include('%');
|
|
});
|
|
|
|
it('should decrypt a node-red produced blob without throwing', async () => {
|
|
const sealed = 'Fe26.2**7ae64199b871901d16a6ba031198c57b43b4a9231e15b851ff80014a8de230ca*RkB3_Uu_oJnTefyzB-Ocqg*2Z9rXYf--GxLJnYESHvdK5rC6lOMlSbMJ6YQyR2Mgpl57iBYopAHPWRLNTBgNkbUHFYa0IlEjdyeEz5VvLDtVvlSr1Sam-Cx8GUai4mharZO5-Wkze0dTr7M56WofSC9jpkv3kANrpsrit3HASE_E-5Z1JVYQVQqehw-VbSZTorrYj0GCJiAgXE5I0iY4boXRDYCv7fm_pzcuAbHlnNkKT1GbMFEPjyVViP4mVMRI5PDUhcWb0f62goMX4UnYLZXum4oYOIr84DG8AxqIdW2L94yslt0EZkD3yVhvKEGoauMpy6ry2illpSgaMaj4sU3AKWIjfAsJXvM6bHwbNh6G1_BJfCapuu3KijBBQPQMAnhYuwLAlY56WN-Y2efNIBJkp__kO6ak2nFqu8PufpxE-cv0uW7x6GWUtCpnFO2SeUJWVVMddUgJjLiM8Hkdl1v9huB0WdIvsoPEV0ZOwHZaC3jtdKFSO7Xe6LdqTXjXmdBMwtOv-HefyaB8LnEN6dAeKWwJuDu7g03QFTryDIiuwtpQ8mcLWTJGHcxoaluNhUESOBULkWSv_E1vOM1_fFv**1e41101b27c5da58bc11177448e91d88d7801bf911088a895844db0c542dfa7c*dPlOhtXJcyR47ezuL7CEgC2Z8d6C1asNOiqZmhD5TXY';
|
|
const unsealed = await urlEnc.decrypt(sealed);
|
|
expect(unsealed).to.be.an('object');
|
|
});
|
|
});
|