Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- **Reader access: re-verifying on a registered device no longer hits the device limit** — `createSession` counted the reader's existing session on the same device towards `MAX_CONCURRENT_DEVICES`. A reader already signed in on two devices therefore got `409 device_limit_exceeded` when re-verifying on one of them, even though that session is replaced in place under the same storage key. The same-device session is now left out of the count. A regression test is in `tests/session/device-limit-tests.test.ts`. (The wider session test-suite repair landed separately in PR #653.)
- **Corrupted package-lock.json** — The merge in `161ed46` truncated `package-lock.json` into invalid JSON, so `npm ci` failed with `EUSAGE` in every workflow. Regenerated the lockfile from the last valid copy (`7db390c`) with `npm install --package-lock-only --ignore-scripts`; `package.json` is unchanged.
- **CI: Removed unused Playwright browser install from Vitest job** — The `Install Playwright browsers` step in `tests.yml` stalled on the runner's apt mirror (~20 s per package, 49 packages), causing both matrix jobs to time out at 20 minutes and the "No new test failures" comparison to fail closed. The Vitest suite runs in a plain Node environment and needs no browser binaries. Removing the step unblocks the Tests workflow without affecting test coverage.
- **Netlify deployment configuration** — Removed duplicate `public/_redirects` file that conflicted with redirect rules defined in `netlify.toml`, resolving validation failures for header rules, redirect rules, and pages changed checks
Expand Down
7 changes: 5 additions & 2 deletions netlify/lib/reader-access/session-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ async function createSessionUnserialised(
// Generate device fingerprint hash
const deviceId = generateDeviceFingerprint(deviceFingerprint);

// Check concurrent device limit (T006b)
// Check concurrent device limit (T006b).
// A session for this same device is stored under the same key and is
// replaced by the new one, so it must not count towards the limit:
// re-verifying on a device the reader already uses is not a new device.
const activeSessions = await listSessionsByEmail(email);
const activeCount = activeSessions.filter(
(s) => s.status === 'active' && s.terminatedAt === null
(s) => s.status === 'active' && s.terminatedAt === null && s.deviceId !== deviceId
).length;

if (activeCount >= MAX_CONCURRENT_DEVICES) {
Expand Down
23 changes: 23 additions & 0 deletions tests/session/device-limit-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,29 @@ describe('Device Limit Enforcement - T099-T102 (US4)', () => {
});
});

describe('T100: Re-verifying on a registered device', () => {
it('should allow a new session on an already-registered device at the limit', async () => {
const testEmail = `${testEmailBase}-reverify`;
const devices = Array.from({ length: MAX_CONCURRENT_DEVICES }, (_, i) => ({
userAgent: `Device${i + 1}`,
ipAddress: `192.168.1.${i + 1}`,
timezone: 'UTC',
}));

const sessions = [];
for (const device of devices) {
sessions.push(await createSession(testEmail, testCode, device));
}

// Same device again: replaces its own session, so it is not a new device
const replacement = await createSession(testEmail, testCode, devices[0]);

expect(replacement.deviceId).toBe(sessions[0].deviceId);
expect(replacement.sessionId).not.toBe(sessions[0].sessionId);
expect(await getActiveSessionCount(testEmail)).toBe(MAX_CONCURRENT_DEVICES);
});
});

describe('T101: Device termination and freeing slots', () => {
it('should allow creation after terminating a device', async () => {
const testEmail = `${testEmailBase}-free-slot`;
Expand Down
Loading