Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(directAccess/cloud-code): Pass installationId with LogIn #6903

Merged
merged 1 commit into from
Sep 17, 2020
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
31 changes: 31 additions & 0 deletions spec/ParseServerRESTController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,35 @@ describe('ParseServerRESTController', () => {
}
);
});

it('ensures logIn is saved with installationId', async () => {
const installationId = 'installation123';
const user = await RESTController.request(
'POST',
'/classes/_User',
{ username: 'hello', password: 'world' },
{ installationId }
);
expect(user.sessionToken).not.toBeUndefined();
const query = new Parse.Query('_Session');
let sessions = await query.find({ useMasterKey: true });

expect(sessions.length).toBe(1);
expect(sessions[0].get('installationId')).toBe(installationId);
expect(sessions[0].get('sessionToken')).toBe(user.sessionToken);

const loggedUser = await RESTController.request(
'POST',
'/login',
{ username: 'hello', password: 'world' },
{ installationId }
);
expect(loggedUser.sessionToken).not.toBeUndefined();
sessions = await query.find({ useMasterKey: true });

// Should clean up old sessions with this installationId
expect(sessions.length).toBe(1);
expect(sessions[0].get('installationId')).toBe(installationId);
expect(sessions[0].get('sessionToken')).toBe(loggedUser.sessionToken);
});
});
1 change: 1 addition & 0 deletions src/ParseServerRESTController.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function ParseServerRESTController(applicationId, router) {
info: {
applicationId: applicationId,
sessionToken: options.sessionToken,
installationId: options.installationId,
context: options.context || {}, // Add context
},
query,
Expand Down
4 changes: 2 additions & 2 deletions src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class UsersRouter extends ClassesRouter {
// Use query parameters instead if provided in url
let payload = req.body;
if (
(!payload.username && req.query.username) ||
(!payload.email && req.query.email)
(!payload.username && req.query && req.query.username) ||
(!payload.email && req.query && req.query.email)
) {
payload = req.query;
}
Expand Down