fix(app): grant expiry ends the chosen day in Paris; species order 0..9999 (V1-2.5 L2)
Owner checkpoint 2026-11-02: expiry 23:59:59.999 Europe/Paris (picker, validation, display), tests under non-Paris zones and DST days; M7 redefines create_species and update_inactive_species with the range check; pgTAP 015 and 022; « Relecteur ou relectrice »; object_conflict EN; setup key selectable, no Copy.
This commit is contained in:
1 parent
4111efa1d1
commit
51225cacf6
17 files changed
+437
-61
No files matched your search
@@ -0,0 +1,102 @@
|
||||
import { createElement } from 'react'
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
||||
import { cleanup, render, screen } from '@testing-library/react'
|
||||
import type { CatalogGrant } from '@faunosteo/supabase'
|
||||
import GrantList from '@/components/admin/GrantList'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { parseGrant } from '@/admin/validation'
|
||||
|
||||
const GRANT = {
|
||||
kind: 'catalog_reader' as const,
|
||||
reason: ' Lecture ',
|
||||
verification_note: '',
|
||||
}
|
||||
|
||||
const EXPIRING: CatalogGrant = {
|
||||
id: 'g-1',
|
||||
user_id: 'user-2',
|
||||
display_name: 'Paul',
|
||||
email: 'paul@example.test',
|
||||
kind: 'catalog_reader',
|
||||
reason: 'Essai',
|
||||
verification_note: null,
|
||||
granted_by: 'user-1',
|
||||
granted_by_name: 'Alice',
|
||||
granted_at: '2026-11-01T10:00:00Z',
|
||||
expires_at: '2026-12-31T22:59:59.999Z',
|
||||
revoked_at: null,
|
||||
revoked_by: null,
|
||||
revocation_reason: null,
|
||||
state: 'active',
|
||||
effective: true,
|
||||
}
|
||||
|
||||
// Zones on both sides of Paris: the expiry never follows the device.
|
||||
describe.each(['America/Los_Angeles', 'Pacific/Kiritimati'])(
|
||||
'grant expiry under the device zone %s',
|
||||
(zone) => {
|
||||
const previous = process.env.TZ
|
||||
beforeAll(() => {
|
||||
process.env.TZ = zone
|
||||
expect(Intl.DateTimeFormat().resolvedOptions().timeZone).toBe(zone)
|
||||
})
|
||||
afterAll(() => {
|
||||
if (previous === undefined) delete process.env.TZ
|
||||
else process.env.TZ = previous
|
||||
})
|
||||
|
||||
it('the reader needs no note; the expiry is the end of the Paris day', () => {
|
||||
expect(
|
||||
parseGrant({ ...GRANT, expires_on: '2026-12-31' }, '2026-11-02'),
|
||||
).toEqual({
|
||||
ok: true,
|
||||
value: {
|
||||
kind: 'catalog_reader',
|
||||
reason: 'Lecture',
|
||||
expires_at: '2026-12-31T22:59:59.999Z',
|
||||
},
|
||||
})
|
||||
expect(
|
||||
parseGrant({ ...GRANT, expires_on: '2026-07-15' }, '2026-07-01'),
|
||||
).toMatchObject({
|
||||
ok: true,
|
||||
value: { expires_at: '2026-07-15T21:59:59.999Z' },
|
||||
})
|
||||
})
|
||||
|
||||
it('refuses today, accepts tomorrow', () => {
|
||||
expect(
|
||||
parseGrant({ ...GRANT, expires_on: '2026-11-02' }, '2026-11-02'),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
errors: { expires_on: 'admin.access.error.expiry' },
|
||||
})
|
||||
expect(
|
||||
parseGrant({ ...GRANT, expires_on: '2026-11-03' }, '2026-11-02'),
|
||||
).toMatchObject({ ok: true })
|
||||
})
|
||||
|
||||
it('refuses a day that does not exist', () => {
|
||||
expect(
|
||||
parseGrant({ ...GRANT, expires_on: '2026-02-30' }, '2026-01-01'),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
errors: { expires_on: 'admin.access.error.expiry' },
|
||||
})
|
||||
})
|
||||
|
||||
it('the grant list shows the Paris expiry day', () => {
|
||||
// 23:59:59.999 Paris on 31 December; the device day would be 1 January east of Paris.
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
render(
|
||||
createElement(GrantList, {
|
||||
grants: [EXPIRING],
|
||||
onChanged: () => undefined,
|
||||
}),
|
||||
)
|
||||
expect(screen.getByText(/31 décembre 2026/)).toBeInTheDocument()
|
||||
expect(screen.queryByText(/1 janvier 2027/)).toBeNull()
|
||||
cleanup()
|
||||
})
|
||||
},
|
||||
)
|
||||
@@ -96,6 +96,17 @@ describe('Security, factors', () => {
|
||||
expect(JSON.stringify(useAuthStore.getState())).not.toContain(SECRET)
|
||||
})
|
||||
|
||||
it('shows the setup key in full as selectable text, with no Copy button', async () => {
|
||||
const user = userEvent.setup()
|
||||
mount()
|
||||
await startEnrolment(user)
|
||||
const key = await screen.findByText(SECRET)
|
||||
expect(key.textContent).toBe(SECRET)
|
||||
expect(key.className).not.toMatch(/select-none/)
|
||||
expect((key as HTMLElement).style.userSelect).not.toBe('none')
|
||||
expect(screen.queryByRole('button', { name: /cop(y|ier)/i })).toBeNull()
|
||||
})
|
||||
|
||||
it('cancel removes the unverified factor it created and clears the secret', async () => {
|
||||
const user = userEvent.setup()
|
||||
mount()
|
||||
@@ -125,6 +136,21 @@ describe('Security, factors', () => {
|
||||
expect(fake.auth.mfa.enroll).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('refuses a 65-character name without calling GoTrue, accepts 64', async () => {
|
||||
const user = userEvent.setup()
|
||||
mount()
|
||||
await user.click(await screen.findByRole('button', { name: fr['mfa.enrol.start'] }))
|
||||
const field = screen.getByLabelText(fr['mfa.enrol.name'])
|
||||
await user.type(field, 'a'.repeat(65))
|
||||
await user.click(screen.getByRole('button', { name: fr['mfa.enrol.continue'] }))
|
||||
expect(screen.getByText(fr['mfa.error.name_too_long'].replace('{max}', '64'))).toBeInTheDocument()
|
||||
expect(fake.auth.mfa.enroll).not.toHaveBeenCalled()
|
||||
await user.clear(field)
|
||||
await user.type(field, 'b'.repeat(64))
|
||||
await user.click(screen.getByRole('button', { name: fr['mfa.enrol.continue'] }))
|
||||
expect(fake.auth.mfa.enroll).toHaveBeenCalledWith({ factorType: 'totp', friendlyName: 'b'.repeat(64) })
|
||||
})
|
||||
|
||||
it('a second factor at aal1 steps up first, then enrols again', async () => {
|
||||
const user = userEvent.setup()
|
||||
setMfa(fake, [fakeFactor({ id: 'f-1' })])
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { formatDate, todayIso, nowIso } from '@/lib/dates'
|
||||
import { afterAll, beforeAll, describe, it, expect } from 'vitest'
|
||||
import {
|
||||
endOfParisDayIso,
|
||||
formatDate,
|
||||
nowIso,
|
||||
parisDateIso,
|
||||
parisTomorrowIso,
|
||||
todayIso,
|
||||
} from '@/lib/dates'
|
||||
|
||||
describe('formatDate fr', () => {
|
||||
it('formats "2026-05-18" as "18 mai 2026"', () => {
|
||||
@@ -38,3 +45,47 @@ describe('nowIso', () => {
|
||||
expect(nowIso()).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)
|
||||
})
|
||||
})
|
||||
|
||||
// A zone west and a zone east of Paris: the Paris rules never follow the device.
|
||||
describe.each(['America/Los_Angeles', 'Pacific/Kiritimati'])(
|
||||
'Paris days under the device zone %s',
|
||||
(zone) => {
|
||||
const previous = process.env.TZ
|
||||
beforeAll(() => {
|
||||
process.env.TZ = zone
|
||||
expect(Intl.DateTimeFormat().resolvedOptions().timeZone).toBe(zone)
|
||||
})
|
||||
afterAll(() => {
|
||||
if (previous === undefined) delete process.env.TZ
|
||||
else process.env.TZ = previous
|
||||
})
|
||||
|
||||
it.each([
|
||||
['2026-01-15', '2026-01-15T22:59:59.999Z'],
|
||||
['2026-07-15', '2026-07-15T21:59:59.999Z'],
|
||||
['2026-03-28', '2026-03-28T22:59:59.999Z'],
|
||||
['2026-03-29', '2026-03-29T21:59:59.999Z'],
|
||||
['2026-10-25', '2026-10-25T22:59:59.999Z'],
|
||||
])('endOfParisDayIso(%s) is %s', (day, instant) => {
|
||||
expect(endOfParisDayIso(day)).toBe(instant)
|
||||
})
|
||||
|
||||
it('refuses an impossible or malformed day', () => {
|
||||
expect(() => endOfParisDayIso('2026-02-30')).toThrow()
|
||||
expect(() => endOfParisDayIso('2026-1-5')).toThrow()
|
||||
})
|
||||
|
||||
it('parisDateIso reads the Paris date', () => {
|
||||
expect(parisDateIso(new Date('2026-11-02T23:30:00Z'))).toBe('2026-11-03')
|
||||
})
|
||||
|
||||
it('parisTomorrowIso is the next Paris calendar day, DST included', () => {
|
||||
expect(parisTomorrowIso(new Date('2026-03-28T22:30:00Z'))).toBe(
|
||||
'2026-03-29',
|
||||
)
|
||||
expect(parisTomorrowIso(new Date('2026-03-28T23:30:00Z'))).toBe(
|
||||
'2026-03-30',
|
||||
)
|
||||
})
|
||||
},
|
||||
)
|
||||
@@ -33,7 +33,7 @@ import AdminSheetRoute from '@/app/routes/app/admin/AdminSheetRoute'
|
||||
import AdminSpeciesRoute from '@/app/routes/app/admin/AdminSpeciesRoute'
|
||||
import AdminAccessRoute from '@/app/routes/app/admin/AdminAccessRoute'
|
||||
import { NO_FILTER, filterSheets } from '@/admin/filters'
|
||||
import { parseGrant, proposeSlug } from '@/admin/validation'
|
||||
import { proposeSlug } from '@/admin/validation'
|
||||
import { setCoreRuntime } from '@/core/runtime'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
@@ -489,7 +489,7 @@ describe('Rights (A0, §5.2)', () => {
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Attribuer' }))
|
||||
expect(screen.getByText(fr['admin.access.error.kind'])).toBeInTheDocument()
|
||||
await user.click(screen.getByLabelText('Relecteur, relectrice'))
|
||||
await user.click(screen.getByLabelText('Relecteur ou relectrice'))
|
||||
await user.type(screen.getByLabelText('Motif'), 'Relecture')
|
||||
await user.type(screen.getByLabelText(/Échéance/), '2020-01-01')
|
||||
await user.click(screen.getByRole('button', { name: 'Attribuer' }))
|
||||
@@ -582,39 +582,6 @@ describe('Rights (A0, §5.2)', () => {
|
||||
)
|
||||
expect(await screen.findByText('Droit révoqué.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('parseGrant: the reader needs no note; the expiry is the end of the chosen day', () => {
|
||||
const parsed = parseGrant(
|
||||
{
|
||||
kind: 'catalog_reader',
|
||||
reason: ' Lecture ',
|
||||
verification_note: '',
|
||||
expires_on: '2026-12-31',
|
||||
},
|
||||
'2026-11-02',
|
||||
)
|
||||
expect(parsed).toEqual({
|
||||
ok: true,
|
||||
value: {
|
||||
kind: 'catalog_reader',
|
||||
reason: 'Lecture',
|
||||
expires_at: new Date('2026-12-31T23:59:59').toISOString(),
|
||||
},
|
||||
})
|
||||
const today = parseGrant(
|
||||
{
|
||||
kind: 'catalog_reader',
|
||||
reason: 'x',
|
||||
verification_note: '',
|
||||
expires_on: '2026-11-02',
|
||||
},
|
||||
'2026-11-02',
|
||||
)
|
||||
expect(today).toMatchObject({
|
||||
ok: false,
|
||||
errors: { expires_on: 'admin.access.error.expiry' },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Official sheets list (H1)', () => {
|
||||
|
||||
Reference in new issue
Block a user