Skip to content

Commit 7d7b234

Browse files
committed
Assert missing credentials Error
1 parent 173117d commit 7d7b234

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

plugins/BasicAuthHandler/src/plugin.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module.exports = (req, res, next) => {
1212
const password = basicAuth?.password;
1313

1414
if (!username || !password) {
15-
/* istanbul ignore next */
1615
throw new Error('Missing Basic Auth credentials');
1716
}
1817

plugins/BasicAuthHandler/test/unit.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,41 @@ describe('BasicAuthHandler', function() {
115115
expect(result.body).to.equal('Unauthorized');
116116
});
117117
});
118+
119+
describe('error', function() {
120+
const stack = new Stack();
121+
122+
const dependency = function(req, res, next) {
123+
const config = {
124+
basicAuth: {
125+
username: '',
126+
password: ''
127+
}
128+
};
129+
130+
req.plugin('config', config);
131+
next();
132+
};
133+
134+
Utils.setFuncName(dependency, 'middleware');
135+
Utils.setFuncName(middleware, 'middleware');
136+
137+
const route = function(req, res) {
138+
res.status(200).send();
139+
};
140+
141+
Utils.setFuncName(route, 'route:index');
142+
143+
stack.middleware = [dependency, middleware];
144+
stack.routes = route;
145+
146+
const req = new Request(event.Records[0].cf.request, {});
147+
const res = new Response({});
148+
149+
const result = () => stack.exec(req, res);
150+
151+
it ('should throw Error', function() {
152+
expect(result).to.throw(Error, /Missing Basic Auth credentials/);
153+
});
154+
});
118155
});

0 commit comments

Comments
 (0)