-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds settings endpoint to configure loglevel
- Loading branch information
1 parent
4072734
commit 5e9ca02
Showing
5 changed files
with
97 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
var request = require('request'); | ||
|
||
var headers = { | ||
'X-Parse-Application-Id': 'test', | ||
'X-Parse-Master-Key': 'test' | ||
}; | ||
|
||
|
||
describe('SettingsRouter', () => { | ||
|
||
it('should set the loglevel', (done) => { | ||
request.post({ | ||
headers: headers, | ||
json: { | ||
'logLevel': 'silly' | ||
}, | ||
url: 'http://localhost:8378/1/settings' | ||
}, (err, res, body) => { | ||
request.get({ | ||
url: 'http://localhost:8378/1/settings', | ||
headers: headers | ||
}, (err, res, body)=> { | ||
body = JSON.parse(body); | ||
expect(body.logLevel).toBe('silly'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should not access without masterKey', (done) => { | ||
request.post({ | ||
headers: { | ||
'X-Parse-Application-Id': 'test', | ||
'X-Parse-Master-Key': 'invalid' | ||
}, | ||
json: { | ||
'logLevel': 'silly' | ||
}, | ||
url: 'http://localhost:8378/1/settings' | ||
}, (err, res, body) => { | ||
expect(body.error).not.toBeUndefined(); | ||
expect(body.error).toBe('unauthorized'); | ||
request.get({ | ||
url: 'http://localhost:8378/1/settings', | ||
headers: { | ||
'X-Parse-Application-Id': 'test', | ||
'X-Parse-Master-Key': 'invalid' | ||
} | ||
}, (err, res, body)=> { | ||
body = JSON.parse(body); | ||
expect(body.error).toBe('unauthorized'); | ||
done(); | ||
}); | ||
}); | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import PromiseRouter from '../PromiseRouter'; | ||
import * as middleware from "../middlewares"; | ||
import { logger, configureLogger } from '../logger'; | ||
import winston from 'winston'; | ||
|
||
export class SettingsRouter extends PromiseRouter { | ||
mountRoutes() { | ||
this.route('GET', '/settings', middleware.promiseEnforceMasterKeyAccess, (req) => { | ||
return Promise.resolve({ | ||
response: { | ||
logLevel: winston.level | ||
} | ||
}) | ||
}); | ||
this.route('POST','/settings', middleware.promiseEnforceMasterKeyAccess, (req) => { | ||
let body = req.body; | ||
let logLevel = body.logLevel; | ||
if (logLevel) { | ||
configureLogger({level: logLevel}); | ||
} | ||
return Promise.resolve({ | ||
response: body | ||
}) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters