Skip to content

Commit 2533a8c

Browse files
imwissflovilmart
authored andcommitted
Do not create user if username or password is empty (#3650)
1 parent ea94ae7 commit 2533a8c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

spec/ParseServerRESTController.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const ParseServerRESTController = require('../src/ParseServerRESTController').ParseServerRESTController;
22
const ParseServer = require('../src/ParseServer').default;
3+
const Parse = require('parse/node').Parse;
4+
35
let RESTController;
46

57
describe('ParseServerRESTController', () => {
@@ -103,6 +105,28 @@ describe('ParseServerRESTController', () => {
103105
});
104106
});
105107

108+
it('ensures no user is created when passing an empty username', (done) => {
109+
RESTController.request("POST", "/classes/_User", {username: "", password: "world"}).then(() => {
110+
jfail(new Error('Success callback should not be called when passing an empty username.'));
111+
done();
112+
}, (err) => {
113+
expect(err.code).toBe(Parse.Error.USERNAME_MISSING);
114+
expect(err.message).toBe('bad or missing username');
115+
done();
116+
});
117+
});
118+
119+
it('ensures no user is created when passing an empty password', (done) => {
120+
RESTController.request("POST", "/classes/_User", {username: "hello", password: ""}).then(() => {
121+
jfail(new Error('Success callback should not be called when passing an empty password.'));
122+
done();
123+
}, (err) => {
124+
expect(err.code).toBe(Parse.Error.PASSWORD_MISSING);
125+
expect(err.message).toBe('password is required');
126+
done();
127+
});
128+
});
129+
106130
it('ensures no session token is created on creating users', (done) => {
107131
RESTController.request("POST", "/classes/_User", {username: "hello", password: "world"}).then((user) => {
108132
expect(user.sessionToken).toBeUndefined();

src/RestWrite.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ RestWrite.prototype.validateAuthData = function() {
204204
}
205205

206206
if (!this.query && !this.data.authData) {
207-
if (typeof this.data.username !== 'string') {
207+
if (typeof this.data.username !== 'string' || _.isEmpty(this.data.username)) {
208208
throw new Parse.Error(Parse.Error.USERNAME_MISSING,
209209
'bad or missing username');
210210
}
211-
if (typeof this.data.password !== 'string') {
211+
if (typeof this.data.password !== 'string' || _.isEmpty(this.data.password)) {
212212
throw new Parse.Error(Parse.Error.PASSWORD_MISSING,
213213
'password is required');
214214
}

0 commit comments

Comments
 (0)