Skip to content

Commit b6b51f1

Browse files
committed
Fix Hapi Issue hapijs#2501, pass on auth artifacts object in the server.inject method, add test, update documentation
1 parent 22b87a3 commit b6b51f1

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

API.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,9 @@ for performing injections, with some additional options and response properties:
10291029
- `credentials` - an optional credentials object containing authentication information. The
10301030
`credentials` are used to bypass the default authentication strategies, and are validated
10311031
directly as if they were received via an authentication scheme. Defaults to no credentials.
1032+
- `artifacts` - an optional artifacts object containing authentication artifact information. The
1033+
`artifacts` are used to bypass the default authentication strategies, and are validated
1034+
directly as if they were received via an authentication scheme. Defaults to no artifacts.
10321035
- `simulate` - an object with options used to simulate client request stream conditions for
10331036
testing:
10341037
- `error` - if `true`, emits an `'error'` event after payload transmission (if any).

lib/connection.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,16 @@ internals.Connection.prototype._dispatch = function (options) {
237237
internals.Connection.prototype.inject = function (options, callback) {
238238

239239
var settings = options;
240-
if (settings.credentials) {
240+
if (settings.credentials || settings.artifacts) {
241241
settings = Hoek.shallow(options); // options can be reused
242242
delete settings.credentials;
243+
delete settings.artifacts;
243244
}
244245

245-
var needle = this._dispatch({ credentials: options.credentials });
246+
var needle = this._dispatch({
247+
credentials: options.credentials,
248+
artifacts: options.artifacts
249+
});
246250
Shot.inject(needle, settings, function (res) {
247251

248252
if (res.raw.res._hapi) {

lib/request.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ exports = module.exports = internals.Request = function (connection, req, res, o
8989
if (options.credentials) {
9090
this.auth.credentials = options.credentials;
9191
}
92+
if (options.artifacts) {
93+
this.auth.artifacts = options.artifacts;
94+
}
95+
9296

9397
// Assigned elsewhere:
9498

test/connection.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,31 @@ describe('Connection', function () {
635635
});
636636
});
637637

638+
it('passes the options.artifacts object', function (done) {
639+
640+
var handler = function (request, reply) {
641+
return reply(request.auth.artifacts);
642+
};
643+
644+
var server = new Hapi.Server();
645+
server.connection();
646+
server.route({ method: 'GET', path: '/', config: { handler: handler } });
647+
648+
var options = {
649+
url: '/',
650+
credentials: { foo: 'bar' },
651+
artifacts: { bar: 'baz' }
652+
};
653+
654+
server.connections[0].inject(options, function (res) {
655+
656+
expect(res.statusCode).to.equal(200);
657+
expect(res.result.bar).to.equal('baz');
658+
expect(options.artifacts).to.exist();
659+
done();
660+
});
661+
});
662+
638663
it('returns the request object', function (done) {
639664

640665
var handler = function (request, reply) {

0 commit comments

Comments
 (0)