Skip to content

Commit 7c02787

Browse files
fix(auth): add regression guard for data-integrity anomaly on signin (#3709)
Add E2E test verifying signin returns 200 (not 500) when currentOrganization points to a non-existent org ID (pre-existing corruption scenario). Tasks 1+2 already fix the root cause; this test is the belt-and-suspenders regression guard.
1 parent 6bce74b commit 7c02787

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

modules/auth/tests/auth.e2e.tests.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,42 @@ describe('Auth E2E tests:', () => {
237237
expect(err).toBeFalsy();
238238
}
239239
});
240+
241+
test('should return 200 on signin even when autoSetCurrentOrganization would encounter a data-integrity anomaly', async () => {
242+
config.organizations = { enabled: true, autoCreate: true, domainMatching: false };
243+
244+
// Signup user, then directly corrupt their currentOrganization to a non-existent ObjectId
245+
// to simulate a pre-existing dangling ref in prod
246+
try {
247+
const signupRes = await agent
248+
.post('/api/auth/signup')
249+
.send({
250+
firstName: 'Danglingref',
251+
lastName: 'User',
252+
email: 'e2e-dangling-ref-3709@test.com',
253+
password: 'W@os.jsI$Aw3$0m3',
254+
provider: 'local',
255+
})
256+
.expect(200);
257+
258+
user = signupRes.body.user;
259+
// Directly write a bogus ObjectId as currentOrganization (simulates pre-existing corruption)
260+
const mongoose = (await import('mongoose')).default;
261+
const User = mongoose.model('User');
262+
await User.updateOne({ _id: user.id }, { currentOrganization: new mongoose.Types.ObjectId() });
263+
264+
// Signin must NOT 500
265+
const signinRes = await agent
266+
.post('/api/auth/signin')
267+
.send({ email: 'e2e-dangling-ref-3709@test.com', password: 'W@os.jsI$Aw3$0m3' })
268+
.expect(200);
269+
270+
expect(signinRes.body.type).toBe('success');
271+
} catch (err) {
272+
console.log(err);
273+
expect(err).toBeFalsy();
274+
}
275+
});
240276
});
241277

242278
// Mongoose disconnect

0 commit comments

Comments
 (0)