Skip to content

Commit

Permalink
Test cases for passing locals to grants.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed May 18, 2016
1 parent 7858ec8 commit 40982f0
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/grant/code.test.js
Expand Up @@ -638,6 +638,48 @@ describe('grant.code', function() {
});
});

describe('decision handling with user response, client request, and server locals', function() {
function issue(client, redirectURI, user, ares, areq, locals, done) {
if (client.id !== 'c123') { return done(new Error('incorrect client argument')); }
if (redirectURI !== 'http://example.com/auth/callback') { return done(new Error('incorrect redirectURI argument')); }
if (user.id !== 'u123') { return done(new Error('incorrect user argument')); }
if (ares.scope !== 'foo') { return done(new Error('incorrect ares argument')); }
if (areq.codeChallenge !== 'hashed-s3cr1t') { return done(new Error('incorrect areq argument')); }
if (locals.service.jwksURL !== 'http://www.example.com/.well-known/jwks') { return done(new Error('incorrect locals argument')); }

return done(null, 'xyz');
}

describe('transaction with response scope', function() {
var response;

before(function(done) {
chai.oauth2orize.grant(code(issue))
.txn(function(txn) {
txn.client = { id: 'c123', name: 'Example' };
txn.redirectURI = 'http://www.example.com/auth/callback';
txn.req = {
redirectURI: 'http://example.com/auth/callback',
codeChallenge: 'hashed-s3cr1t'
};
txn.user = { id: 'u123', name: 'Bob' };
txn.res = { allow: true, scope: 'foo' };
txn.locals = { service: { jwksURL: 'http://www.example.com/.well-known/jwks' } };
})
.end(function(res) {
response = res;
done();
})
.decide();
});

it('should respond', function() {
expect(response.statusCode).to.equal(302);
expect(response.getHeader('Location')).to.equal('http://www.example.com/auth/callback?code=xyz');
});
});
});

describe('decision handling with response mode', function() {
function issue(client, redirectURI, user, done) {
return done(null, 'xyz');
Expand Down
41 changes: 41 additions & 0 deletions test/grant/token.test.js
Expand Up @@ -700,6 +700,47 @@ describe('grant.token', function() {
});
});

describe('decision handling with user response, client request, and server locals', function() {
function issue(client, user, ares, areq, locals, done) {
if (client.id !== 'c123') { return done(new Error('incorrect client argument')); }
if (user.id !== 'u123') { return done(new Error('incorrect user argument')); }
if (ares.scope !== 'foo') { return done(new Error('incorrect ares argument')); }
if (areq.state !== 'f1o1o1') { return done(new Error('incorrect areq argument')); }
if (locals.service.jwksURL !== 'http://www.example.com/.well-known/jwks') { return done(new Error('incorrect locals argument')); }

return done(null, 'xyz');
}

describe('transaction with response scope', function() {
var response;

before(function(done) {
chai.oauth2orize.grant(token(issue))
.txn(function(txn) {
txn.client = { id: 'c123', name: 'Example' };
txn.redirectURI = 'http://example.com/auth/callback';
txn.req = {
redirectURI: 'http://example.com/auth/callback',
state: 'f1o1o1'
};
txn.user = { id: 'u123', name: 'Bob' };
txn.res = { allow: true, scope: 'foo' };
txn.locals = { service: { jwksURL: 'http://www.example.com/.well-known/jwks' } };
})
.end(function(res) {
response = res;
done();
})
.decide();
});

it('should respond', function() {
expect(response.statusCode).to.equal(302);
expect(response.getHeader('Location')).to.equal('http://example.com/auth/callback#access_token=xyz&token_type=Bearer&state=f1o1o1');
});
});
});

describe('decision handling with response mode', function() {
function issue(client, user, done) {
return done(null, 'xyz');
Expand Down

0 comments on commit 40982f0

Please sign in to comment.