Added session length option for session tokens to server configuration
This commit is contained in:
committed by
Florent Vilmart
parent
51664c8f33
commit
f99b5588ab
@@ -26,6 +26,7 @@ function verifyACL(user) {
|
||||
}
|
||||
|
||||
describe('Parse.User testing', () => {
|
||||
|
||||
it("user sign up class method", (done) => {
|
||||
Parse.User.signUp("asdf", "zxcv", null, {
|
||||
success: function(user) {
|
||||
@@ -2160,4 +2161,44 @@ describe('Parse.User testing', () => {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should fail to become user with expired token', (done) => {
|
||||
Parse.User.signUp("auser", "somepass", null, {
|
||||
success: function(user) {
|
||||
request.get({
|
||||
url: 'http://localhost:8378/1/classes/_Session',
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
}, (error, response, body) => {
|
||||
var id = body.results[0].objectId;
|
||||
var expiresAt = new Date((new Date()).setYear(2015));
|
||||
var token = body.results[0].sessionToken;
|
||||
request.put({
|
||||
url: "http://localhost:8378/1/classes/_Session/" + id,
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': 'test',
|
||||
'X-Parse-Master-Key': 'test',
|
||||
},
|
||||
body: {
|
||||
expiresAt: { __type: "Date", iso: expiresAt.toISOString() },
|
||||
},
|
||||
}, (error, response, body) => {
|
||||
Parse.User.become(token)
|
||||
.then(() => { fail("Should not have succeded"); })
|
||||
.fail((err) => {
|
||||
expect(err.code).toEqual(209);
|
||||
expect(err.message).toEqual("Session token is expired.");
|
||||
Parse.User.logOut() // Logout to prevent polluting CLI with messages
|
||||
.then(done());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -284,4 +284,72 @@ describe('rest create', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("test default session length", (done) => {
|
||||
var user = {
|
||||
username: 'asdf',
|
||||
password: 'zxcv',
|
||||
foo: 'bar',
|
||||
};
|
||||
var now = new Date();
|
||||
|
||||
rest.create(config, auth.nobody(config), '_User', user)
|
||||
.then((r) => {
|
||||
expect(Object.keys(r.response).length).toEqual(3);
|
||||
expect(typeof r.response.objectId).toEqual('string');
|
||||
expect(typeof r.response.createdAt).toEqual('string');
|
||||
expect(typeof r.response.sessionToken).toEqual('string');
|
||||
return rest.find(config, auth.master(config),
|
||||
'_Session', {sessionToken: r.response.sessionToken});
|
||||
})
|
||||
.then((r) => {
|
||||
expect(r.results.length).toEqual(1);
|
||||
|
||||
var session = r.results[0];
|
||||
var actual = new Date(session.expiresAt.iso);
|
||||
var expected = new Date(now.getTime() + (1000 * 3600 * 24 * 365));
|
||||
|
||||
expect(actual.getFullYear()).toEqual(expected.getFullYear());
|
||||
expect(actual.getMonth()).toEqual(expected.getMonth());
|
||||
expect(actual.getDate()).toEqual(expected.getDate());
|
||||
expect(actual.getMinutes()).toEqual(expected.getMinutes());
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("test specified session length", (done) => {
|
||||
var user = {
|
||||
username: 'asdf',
|
||||
password: 'zxcv',
|
||||
foo: 'bar',
|
||||
};
|
||||
var sessionLength = 3600, // 1 Hour ahead
|
||||
now = new Date(); // For reference later
|
||||
config.sessionLength = sessionLength;
|
||||
|
||||
rest.create(config, auth.nobody(config), '_User', user)
|
||||
.then((r) => {
|
||||
expect(Object.keys(r.response).length).toEqual(3);
|
||||
expect(typeof r.response.objectId).toEqual('string');
|
||||
expect(typeof r.response.createdAt).toEqual('string');
|
||||
expect(typeof r.response.sessionToken).toEqual('string');
|
||||
return rest.find(config, auth.master(config),
|
||||
'_Session', {sessionToken: r.response.sessionToken});
|
||||
})
|
||||
.then((r) => {
|
||||
expect(r.results.length).toEqual(1);
|
||||
|
||||
var session = r.results[0];
|
||||
var actual = new Date(session.expiresAt.iso);
|
||||
var expected = new Date(now.getTime() + (sessionLength*1000));
|
||||
|
||||
expect(actual.getFullYear()).toEqual(expected.getFullYear());
|
||||
expect(actual.getMonth()).toEqual(expected.getMonth());
|
||||
expect(actual.getDate()).toEqual(expected.getDate());
|
||||
expect(actual.getHours()).toEqual(expected.getHours());
|
||||
expect(actual.getMinutes()).toEqual(expected.getMinutes());
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -280,4 +280,37 @@ describe('server', () => {
|
||||
}) ).toThrow("publicServerURL should be a valid HTTPS URL starting with https://");
|
||||
done();
|
||||
});
|
||||
|
||||
it('fails if the session length is not a number', (done) => {
|
||||
expect(() => setServerConfiguration({
|
||||
serverURL: 'http://localhost:8378/1',
|
||||
appId: 'test',
|
||||
appName: 'unused',
|
||||
javascriptKey: 'test',
|
||||
masterKey: 'test',
|
||||
sessionLength: 'test'
|
||||
})).toThrow('Session length must be a valid number.');
|
||||
done();
|
||||
});
|
||||
|
||||
it('fails if the session length is less than or equal to 0', (done) => {
|
||||
expect(() => setServerConfiguration({
|
||||
serverURL: 'http://localhost:8378/1',
|
||||
appId: 'test',
|
||||
appName: 'unused',
|
||||
javascriptKey: 'test',
|
||||
masterKey: 'test',
|
||||
sessionLength: '-33'
|
||||
})).toThrow('Session length must be a value greater than 0.');
|
||||
|
||||
expect(() => setServerConfiguration({
|
||||
serverURL: 'http://localhost:8378/1',
|
||||
appId: 'test',
|
||||
appName: 'unused',
|
||||
javascriptKey: 'test',
|
||||
masterKey: 'test',
|
||||
sessionLength: '0'
|
||||
})).toThrow('Session length must be a value greater than 0.');
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user