Skip to content

Commit 806800c

Browse files
committed
Use shared middleware to enforce master key on global config update API.
1 parent dacc22d commit 806800c

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

spec/ParseGlobalConfig.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ describe('a GlobalConfig', () => {
5353
'X-Parse-REST-API-Key': 'rest'
5454
},
5555
}, (error, response, body) => {
56-
expect(response.statusCode).toEqual(401);
57-
expect(body.error).toEqual('unauthorized');
56+
expect(response.statusCode).toEqual(403);
57+
expect(body.error).toEqual('unauthorized: master key is required');
5858
done();
5959
});
6060
});

src/Routers/GlobalConfigRouter.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var Parse = require('parse/node').Parse;
44

55
import PromiseRouter from '../PromiseRouter';
6+
import * as middleware from "../middlewares";
67

78
export class GlobalConfigRouter extends PromiseRouter {
89
getGlobalConfig(req) {
@@ -18,13 +19,6 @@ export class GlobalConfigRouter extends PromiseRouter {
1819
}));
1920
}
2021
updateGlobalConfig(req) {
21-
if (!req.auth.isMaster) {
22-
return Promise.resolve({
23-
status: 401,
24-
response: {error: 'unauthorized'},
25-
});
26-
}
27-
2822
return req.config.database.rawCollection('_GlobalConfig')
2923
.then(coll => coll.findOneAndUpdate({ _id: 1 }, { $set: req.body }))
3024
.then(response => {
@@ -41,7 +35,7 @@ export class GlobalConfigRouter extends PromiseRouter {
4135

4236
mountRoutes() {
4337
this.route('GET', '/config', req => { return this.getGlobalConfig(req) });
44-
this.route('PUT', '/config', req => { return this.updateGlobalConfig(req) });
38+
this.route('PUT', '/config', middleware.promiseEnforceMasterKeyAccess, req => { return this.updateGlobalConfig(req) });
4539
}
4640
}
4741

0 commit comments

Comments
 (0)