mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-27 06:13:06 +00:00
fix(int): scope access-memo leadership find to fixture ids
Unscoped depth-1 finds could pick up other suites' leaderships with a campaignUser relation and inflate the SQL count without breaking the memo.
This commit is contained in:
parent
224eaf5c47
commit
8331ae0452
1 changed files with 8 additions and 2 deletions
|
|
@ -68,13 +68,15 @@ describe('access-control per-request memo', () => {
|
||||||
const coordinator = await fixtures.createCampaignUser('coordinator')
|
const coordinator = await fixtures.createCampaignUser('coordinator')
|
||||||
const municipality = await fixtures.getMunicipality()
|
const municipality = await fixtures.getMunicipality()
|
||||||
|
|
||||||
|
const leadershipIds: number[] = []
|
||||||
for (let index = 0; index < 3; index += 1) {
|
for (let index = 0; index < 3; index += 1) {
|
||||||
const contact = await fixtures.createContact()
|
const contact = await fixtures.createContact()
|
||||||
await fixtures.createLeadership({
|
const leadership = await fixtures.createLeadership({
|
||||||
contact: contact.id,
|
contact: contact.id,
|
||||||
municipalities: [municipality.id],
|
municipalities: [municipality.id],
|
||||||
supportStatus: 'engajado',
|
supportStatus: 'engajado',
|
||||||
})
|
})
|
||||||
|
leadershipIds.push(leadership.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { result, count } = await countStatements('from "campaign_user"', () =>
|
const { result, count } = await countStatements('from "campaign_user"', () =>
|
||||||
|
|
@ -84,12 +86,16 @@ describe('access-control per-request memo', () => {
|
||||||
// field-level access checks across every populated relation.
|
// field-level access checks across every populated relation.
|
||||||
depth: 1,
|
depth: 1,
|
||||||
limit: 25,
|
limit: 25,
|
||||||
|
// Scope to this test's rows — an unscoped find can pick up other suites'
|
||||||
|
// leaderships with `user` set and inflate the campaign_user SQL count via
|
||||||
|
// populate (not via the actor memo).
|
||||||
|
where: { id: { in: leadershipIds } },
|
||||||
user: coordinator,
|
user: coordinator,
|
||||||
overrideAccess: false,
|
overrideAccess: false,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(result.docs.length).toBeGreaterThan(0)
|
expect(result.docs).toHaveLength(3)
|
||||||
// One read for the whole operation. Before the fix this was in the hundreds
|
// One read for the whole operation. Before the fix this was in the hundreds
|
||||||
// and grew with rows × populated fields.
|
// and grew with rows × populated fields.
|
||||||
expect(count).toBe(1)
|
expect(count).toBe(1)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue