feat: extendSessionOnUse to automatically renew Parse Sessions (#8505)

This commit is contained in:
Daniel
2023-05-18 03:49:25 +10:00
committed by GitHub
parent 559b1de828
commit 6f885d36b9
7 changed files with 108 additions and 2 deletions

View File

@@ -94,6 +94,35 @@ describe('Auth', () => {
});
});
it('can use extendSessionOnUse', async () => {
await reconfigureServer({
extendSessionOnUse: true,
});
const user = new Parse.User();
await user.signUp({
username: 'hello',
password: 'password',
});
const session = await new Parse.Query(Parse.Session).first();
const updatedAt = new Date('2010');
const expiry = new Date();
expiry.setHours(expiry.getHours() + 1);
await Parse.Server.database.update(
'_Session',
{ objectId: session.id },
{
expiresAt: { __type: 'Date', iso: expiry.toISOString() },
updatedAt: updatedAt.toISOString(),
}
);
await session.fetch();
await new Promise(resolve => setTimeout(resolve, 1000));
await session.fetch();
expect(session.get('expiresAt') > expiry).toBeTrue();
});
it('should load auth without a config', async () => {
const user = new Parse.User();
await user.signUp({

View File

@@ -367,6 +367,22 @@ describe('server', () => {
});
});
it('should throw when extendSessionOnUse is invalid', async () => {
await expectAsync(
reconfigureServer({
extendSessionOnUse: 'yolo',
})
).toBeRejectedWith('extendSessionOnUse must be a boolean value');
});
it('should throw when revokeSessionOnPasswordReset is invalid', async () => {
await expectAsync(
reconfigureServer({
revokeSessionOnPasswordReset: 'yolo',
})
).toBeRejectedWith('revokeSessionOnPasswordReset must be a boolean value');
});
it('fails if the session length is not a number', done => {
reconfigureServer({ sessionLength: 'test' })
.then(done.fail)