Handle non-url-safe chars in context api

This commit is contained in:
Nick O'Leary
2023-09-01 16:06:05 +01:00
parent 2478a7194e
commit 18bd318da2
2 changed files with 43 additions and 4 deletions

View File

@@ -126,6 +126,26 @@ describe("api/admin/context", function () {
});
});
it('should call context.getValue to get a node context value - url unsafe keyname', function (done) {
stub.returns(Promise.resolve(nContext));
request(app)
.get('/context/node/5678/foo%23123?store=file')
.set('Accept', 'application/json')
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
stub.args[0][0].should.have.property('user', undefined);
stub.args[0][0].should.have.property('scope', 'node');
stub.args[0][0].should.have.property('id', '5678');
stub.args[0][0].should.have.property('key', 'foo#123');
stub.args[0][0].should.have.property('store', 'file');
var body = res.body;
body.should.eql(nContext);
done();
});
});
it('should handle error which context.getValue causes', function (done) {
var stubbedResult = Promise.reject('error');
stubbedResult.catch(function() {});
@@ -214,6 +234,24 @@ describe("api/admin/context", function () {
});
});
it('should call context.delete to delete a node context - url unsafe keyname', function (done) {
stub.returns(Promise.resolve());
request(app)
.delete('/context/node/5678/foo%23123?store=file')
.expect(204)
.end(function (err, res) {
if (err) {
return done(err);
}
stub.args[0][0].should.have.property('user', undefined);
stub.args[0][0].should.have.property('scope', 'node');
stub.args[0][0].should.have.property('id', '5678');
stub.args[0][0].should.have.property('key', 'foo#123');
stub.args[0][0].should.have.property('store', 'file');
done();
});
});
it('should handle error which context.delete causes', function (done) {
var stubbedResult = Promise.reject('error');
stubbedResult.catch(function() {});