mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
fix(db): read every request row id through toRowId, at the trip guards and the repository lookups
toRowId moves to src/db/row-id.ts so repositories can use it (src/db sits below src/nest), together with a new withRowId helper; src/nest/common/row-id.ts re-exports both. Its docstring is rewritten to state the rule plainly. TripsRepository read its number | string trip ids raw: SQLite matched '0x1' against nothing, Postgres 14 and 15 refused the cast with a 500, and 16 and later read it as trip 1. Its access reads, DaysRepository.existsInTrip and the packing template lookups now parse the id first, so an id toRowId refuses is no row on every engine. TripAccessGuard, TripOwnerGuard and JourneyAssistantGuard used Number(), which read '0x1' and '1e0' as row 1; they now use toRowId.
This commit is contained in:
@@ -458,7 +458,7 @@ describe('Assignment participants', () => {
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('H1 — trip id parsed once at the gate (rule 21)', () => {
|
||||
it('POST create-assignment by the hex-spelled trip id 404s "Day not found" (legacy: 404, not 201)', async () => {
|
||||
it('POST create-assignment by the hex-spelled trip id 404s "Trip not found" at the guard (legacy: 404, not 201)', async () => {
|
||||
const { user } = await makeUser(orm);
|
||||
const { trip, day, place } = await setupAssignmentFixtures(user.id);
|
||||
const hexTripId = '0x' + trip.id.toString(16);
|
||||
@@ -467,8 +467,9 @@ describe('H1 — trip id parsed once at the gate (rule 21)', () => {
|
||||
.post(`/api/trips/${hexTripId}/days/${day.id}/assignments`)
|
||||
.set('Cookie', authCookie(user.id))
|
||||
.send({ place_id: place.id });
|
||||
// TripAccessGuard reads :tripId through toRowId, so the hex spelling is no trip.
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.body).toEqual({ error: 'Day not found' });
|
||||
expect(res.body).toEqual({ error: 'Trip not found' });
|
||||
expect(await countRows(orm, DayAssignments, { day: day.id })).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -670,17 +670,17 @@ describe('Accommodations', () => {
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('A-H2 — DaysService trip id parsed once, threaded to every survivor (Task 9 fix wave)', () => {
|
||||
it("GET /days by the hex-spelled trip id answers the legacy-shaped miss ({ days: [] }), not the real trip's days", async () => {
|
||||
it("GET /days by the hex-spelled trip id answers the guard's 404, not the real trip's days (TripAccessGuard reads :tripId through toRowId)", async () => {
|
||||
const { user } = await makeUser(orm());
|
||||
const trip = await makeTrip(orm(), user.id, { title: 'Trip', start_date: '2026-09-01', end_date: '2026-09-03' });
|
||||
const hexTripId = '0x' + trip.id.toString(16);
|
||||
|
||||
const res = await request(app).get(`/api/trips/${hexTripId}/days`).set('Cookie', authCookie(user.id));
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual({ days: [] });
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.body).toEqual({ error: 'Trip not found' });
|
||||
});
|
||||
|
||||
it('PUT /days/:id by the hex-spelled trip id 404s "Day not found" (getDay\'s own toRowId gate), not the real trip\'s day', async () => {
|
||||
it('PUT /days/:id by the hex-spelled trip id 404s "Trip not found" at the guard, not the real trip\'s day', async () => {
|
||||
const { user } = await makeUser(orm());
|
||||
const trip = await makeTrip(orm(), user.id, { title: 'Trip' });
|
||||
const day = await makeDay(orm(), trip.id, { title: 'Original' });
|
||||
@@ -691,7 +691,7 @@ describe('A-H2 — DaysService trip id parsed once, threaded to every survivor (
|
||||
.set('Cookie', authCookie(user.id))
|
||||
.send({ title: 'Renamed' });
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.body).toEqual({ error: 'Day not found' });
|
||||
expect(res.body).toEqual({ error: 'Trip not found' });
|
||||
const row = await findRow(orm(), Days, { id: day.id });
|
||||
expect(row?.title).toBe('Original');
|
||||
});
|
||||
@@ -841,7 +841,7 @@ describe('A-H2 — DaysService trip id parsed once, threaded to every survivor (
|
||||
expect(after).toBe(before);
|
||||
});
|
||||
|
||||
it('PUT /days/reorder by the hex-spelled trip id 400s "orderedIds must be a permutation…" and writes NOTHING — the live H2 bug: it used to 200 and invert a real accommodation', async () => {
|
||||
it('PUT /days/reorder by the hex-spelled trip id 404s "Trip not found" at the guard and writes NOTHING, where it used to answer 200 and invert a real accommodation', async () => {
|
||||
const { user } = await makeUser(orm());
|
||||
const trip = await makeTrip(orm(), user.id, { title: 'Trip', start_date: '2026-06-01', end_date: '2026-06-03' });
|
||||
const days = await dayList(trip.id);
|
||||
@@ -859,8 +859,8 @@ describe('A-H2 — DaysService trip id parsed once, threaded to every survivor (
|
||||
.put(`/api/trips/${hexTripId}/days/reorder`)
|
||||
.set('Cookie', authCookie(user.id))
|
||||
.send({ orderedIds: [d2.id, d1.id, d3.id] });
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body).toEqual({ error: 'orderedIds must be a permutation of the trip day ids.' });
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.body).toEqual({ error: 'Trip not found' });
|
||||
|
||||
// Nothing renumbered.
|
||||
const after = await dayList(trip.id);
|
||||
|
||||
@@ -464,7 +464,7 @@ describe('Search places', () => {
|
||||
expect(res.body.places[0].name).toBe('Scenic Place');
|
||||
});
|
||||
|
||||
it('PLACE-017c — GET ?category= or ?tag= with an id that is not a number matches nothing', async () => {
|
||||
it('PLACE-017c: GET ?category= or ?tag= with an id that is not a number matches nothing', async () => {
|
||||
const { user } = await makeUser(orm);
|
||||
const trip = await makeTrip(orm, user.id);
|
||||
await makePlace(orm, trip.id, { name: 'Somewhere' });
|
||||
@@ -1065,8 +1065,9 @@ describe('H1 — trip id parsed once at the gate (rule 21)', () => {
|
||||
const hexTripId = '0x' + trip.id.toString(16);
|
||||
|
||||
const res = await request(app).get(`/api/trips/${hexTripId}/places/${place.id}`).set('Cookie', authCookie(user.id));
|
||||
// TripAccessGuard reads :tripId through toRowId, so the hex spelling is no trip.
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.body).toEqual({ error: 'Place not found' });
|
||||
expect(res.body).toEqual({ error: 'Trip not found' });
|
||||
});
|
||||
|
||||
it('PUT with tags by the hex-spelled trip id 404s "Trip not found" (Task 9 fix wave: `verifyTripAccess` now gates BEFORE the place-id read, so the string changed from "Place not found") and leaves the tags untouched (H1 live: they used to be wiped)', async () => {
|
||||
@@ -1135,7 +1136,7 @@ describe('H1 — trip id parsed once at the gate (rule 21)', () => {
|
||||
.delete(`/api/trips/${hexTripId}/places/${place.id}`)
|
||||
.set('Cookie', authCookie(user.id));
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.body).toEqual({ error: 'Place not found' });
|
||||
expect(res.body).toEqual({ error: 'Trip not found' });
|
||||
expect(await findRow(orm, Places, { id: place.id })).toBeTruthy();
|
||||
expect(await findRow(orm, BudgetItems, { place: place.id })).toBeTruthy();
|
||||
expect(broadcast).not.toHaveBeenCalled();
|
||||
@@ -1303,18 +1304,17 @@ describe('A-H1 / A-M1 / B-H1 — verifyTripAccess parses once with toRowId (Task
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// M1 / program rule 22 (task-4-review.md) — control characters in a user
|
||||
// string round-trip on every engine. The NUL byte, which neither engine
|
||||
// Control characters in a user string round-trip on every engine. The NUL byte, which neither engine
|
||||
// stores, has its own suite: places-nul.test.ts.
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('M1 — control characters in a place name (rule 22)', () => {
|
||||
describe('control characters in a place name', () => {
|
||||
it('fuzzes every 0x01-0x1F control character in a created place name: none 500 and every one round-trips', async () => {
|
||||
const { user } = await makeUser(orm);
|
||||
const trip = await makeTrip(orm, user.id);
|
||||
|
||||
// 0x00 is covered by places-nul.test.ts; this sweeps the rest
|
||||
// of the control-character range the review's fuzz asked for.
|
||||
// of the control-character range.
|
||||
for (let code = 0x01; code <= 0x1f; code++) {
|
||||
const name = `ctrl${String.fromCharCode(code)}char`;
|
||||
const res = await request(app)
|
||||
|
||||
Reference in New Issue
Block a user