Skip to content

Commit

Permalink
Allow api3 behind reverse proxy (nightscout#5631)
Browse files Browse the repository at this point in the history
* Allow api3 behind reverse proxy

* fix test

Co-authored-by: Sulka Haro <sulka@sulka.net>
  • Loading branch information
2 people authored and arnaudlimbourg committed Jul 4, 2021
1 parent 3a7036c commit bd7996a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions lib/api3/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ function authenticate (opCtx) {
return resolve({ shiros: [ adminShiro ] });
}

if (req.protocol !== 'https') {
return reject(
opTools.sendJSONStatus(res, apiConst.HTTP.FORBIDDEN, apiConst.MSG.HTTP_403_NOT_USING_HTTPS));
}
// if (req.protocol !== 'https') {
// return reject(
// opTools.sendJSONStatus(res, apiConst.HTTP.FORBIDDEN, apiConst.MSG.HTTP_403_NOT_USING_HTTPS));
// }

const checkDateResult = checkDateHeader(opCtx);
if (checkDateResult !== true) {
Expand Down Expand Up @@ -123,4 +123,4 @@ module.exports = {
authenticate,
checkPermission,
demandPermission
};
};
22 changes: 11 additions & 11 deletions tests/api3.security.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ describe('Security of REST API3', function() {
});


it('should require HTTPS', async () => {
if (semver.gte(process.version, '10.0.0')) {
let res = await request(self.http.baseUrl) // hangs on 8.x.x (no reason why)
.get('/api/v3/test')
.expect(403);

res.body.status.should.equal(403);
res.body.message.should.equal(apiConst.MSG.HTTP_403_NOT_USING_HTTPS);
}
});
// it('should require HTTPS', async () => {
// if (semver.gte(process.version, '10.0.0')) {
// let res = await request(self.http.baseUrl) // hangs on 8.x.x (no reason why)
// .get('/api/v3/test')
// .expect(403);
//
// res.body.status.should.equal(403);
// res.body.message.should.equal(apiConst.MSG.HTTP_403_NOT_USING_HTTPS);
// }
// });


it('should require Date header', async () => {
Expand Down Expand Up @@ -186,4 +186,4 @@ describe('Security of REST API3', function() {
.expect(200);
});

});
});

0 comments on commit bd7996a

Please sign in to comment.