Skip to content

Commit

Permalink
Add test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 23, 2017
1 parent 2683554 commit d7527e3
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions test/middleware/authorization.immediate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,86 @@ describe('authorization', function() {

});

describe('using non-legacy transaction store', function() {
var server, validate, immediate;

before(function() {
var MockStore = require('../mock/store');
server = new Server({ store: new MockStore() });

server.grant('code', function(req) {
return {
clientID: req.query['client_id'],
redirectURI: req.query['redirect_uri'],
scope: req.query['scope']
};
});
});

before(function() {
validate = function(clientID, redirectURI, done) {
return done(null, { id: clientID }, 'http://example.com/auth/callback');
};
});

describe('based on client, user, and scope, with result that supplies info and locals', function() {
var immediate, request, err;

before(function() {
immediate = function(client, user, scope, done) {
if (client.id !== '1234') { return done(new Error('incorrect client argument')); }
if (user.id !== 'u123') { return done(new Error('incorrect user argument')); }
if (scope !== 'profile') { return done(new Error('incorrect scope argument')); }

return done(null, false, { scope: 'read', confidential: true }, { beep: 'boop' });
};
});

before(function(done) {
chai.connect.use('express', authorization(server, validate, immediate))
.req(function(req) {
request = req;
req.query = { response_type: 'code', client_id: '1234', redirect_uri: 'http://example.com/auth/callback', scope: 'profile' };
req.user = { id: 'u123' };
})
.next(function(e) {
err = e;
done();
})
.dispatch();
});

it('should not error', function() {
expect(err).to.be.undefined;
});

it('should add transaction', function() {
expect(request.oauth2).to.be.an('object');
expect(request.oauth2.res).to.be.undefined;
expect(request.oauth2.info).to.be.an('object');
expect(request.oauth2.info.confidential).to.equal(true);
expect(request.oauth2.info.scope).to.equal('read');
expect(request.oauth2.locals).to.be.an('object');
expect(request.oauth2.locals.beep).to.equal('boop');
});

it('should serialize transaction', function() {
expect(request.__mock_store__.txn).to.be.an('object');
expect(Object.keys(request.__mock_store__.txn)).to.have.length(7);
expect(request.__mock_store__.txn.transactionID).to.equal('mocktxn-1');
expect(request.__mock_store__.txn.client.id).to.equal('1234');
expect(request.__mock_store__.txn.redirectURI).to.equal('http://example.com/auth/callback');
expect(request.__mock_store__.txn.req.type).to.equal('code');
expect(request.__mock_store__.txn.req.clientID).to.equal('1234');
expect(request.__mock_store__.txn.req.redirectURI).to.equal('http://example.com/auth/callback');
expect(request.__mock_store__.txn.user.id).to.equal('u123');
expect(request.__mock_store__.txn.info.confidential).to.equal(true);
expect(request.__mock_store__.txn.info.scope).to.equal('read');
expect(request.__mock_store__.txn.locals.beep).to.equal('boop');
});
});
});

});

});

0 comments on commit d7527e3

Please sign in to comment.