Skip to content

Ignore _RevoableSession "header" that is sent by JS SDK. Fixes #1548. #1627

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

Merged
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
34 changes: 30 additions & 4 deletions spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ describe('miscellaneous', function() {
});
})
});

it('properly returns incremented values (#1554)', (done) => {
let headers = {
'Content-Type': 'application/json',
Expand All @@ -1312,12 +1312,12 @@ describe('miscellaneous', function() {
json: true
};
let object = new Parse.Object('AnObject');;

function runIncrement(amount) {
let options = Object.assign({}, requestOptions, {
body: {
"key": {
__op: 'Increment',
__op: 'Increment',
amount: amount
}
},
Expand All @@ -1333,7 +1333,7 @@ describe('miscellaneous', function() {
});
})
}

object.save().then(() => {
return runIncrement(1);
}).then((res) => {
Expand All @@ -1345,4 +1345,30 @@ describe('miscellaneous', function() {
})
})

it('ignores _RevocableSession "header" send by JS SDK', (done) => {
let object = new Parse.Object('AnObject');
object.set('a', 'b');
object.save().then(() => {
request.post({
headers: {'Content-Type': 'application/json'},
url: 'http://localhost:8378/1/classes/AnObject',
body: {
_method: 'GET',
_ApplicationId: 'test',
_JavaScriptKey: 'test',
_ClientVersion: 'js1.8.3',
_InstallationId: 'iid',
_RevocableSession: "1",
},
json: true
}, (err, res, body) => {
expect(body.error).toBeUndefined();
expect(body.results).not.toBeUndefined();
expect(body.results.length).toBe(1);
let result = body.results[0];
expect(result.a).toBe('b');
done();
})
});
});
});
2 changes: 0 additions & 2 deletions spec/RestQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ describe('rest query', () => {
expect(error).toBe(null);
var b = JSON.parse(body);
expect(b.code).toEqual(Parse.Error.INVALID_QUERY);
expect(b.error).toEqual('Improper encode of parameter');
done();
});
}).then(() => {
Expand All @@ -185,7 +184,6 @@ describe('rest query', () => {
expect(error).toBe(null);
var b = JSON.parse(body);
expect(b.code).toEqual(Parse.Error.INVALID_QUERY);
expect(b.error).toEqual('Improper encode of parameter');
done();
});
});
Expand Down
20 changes: 10 additions & 10 deletions src/Routers/ClassesRouter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

import PromiseRouter from '../PromiseRouter';
import rest from '../rest';
import rest from '../rest';

import url from 'url';
import url from 'url';

const ALLOWED_GET_QUERY_KEYS = ['keys', 'include'];

export class ClassesRouter extends PromiseRouter {

handleFind(req) {
let body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
let options = {};
Expand All @@ -16,7 +16,7 @@ export class ClassesRouter extends PromiseRouter {

for (let key of Object.keys(body)) {
if (allowConstraints.indexOf(key) === -1) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Improper encode of parameter');
throw new Parse.Error(Parse.Error.INVALID_QUERY, `Invalid paramater for query: ${key}`);
}
}

Expand Down Expand Up @@ -82,18 +82,18 @@ export class ClassesRouter extends PromiseRouter {
if (!response.results || response.results.length == 0) {
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
}

if (req.params.className === "_User") {

delete response.results[0].sessionToken;

const user = response.results[0];

if (req.auth.user && user.objectId == req.auth.user.id) {
// Force the session token
response.results[0].sessionToken = req.info.sessionToken;
}
}
}
return { response: response.results[0] };
});
}
Expand Down Expand Up @@ -124,7 +124,7 @@ export class ClassesRouter extends PromiseRouter {
}
return json
}

mountRoutes() {
this.route('GET', '/classes/:className', (req) => { return this.handleFind(req); });
this.route('GET', '/classes/:className/:objectId', (req) => { return this.handleGet(req); });
Expand Down
4 changes: 4 additions & 0 deletions src/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function handleParseHeaders(req, res, next) {
fileViaJSON = true;
}

if (req.body) {
delete req.body._RevocableSession;
}

if (req.body &&
req.body._ApplicationId &&
cache.apps.get(req.body._ApplicationId) &&
Expand Down