Skip to content

Commit

Permalink
Merge pull request #12 from r-peck/fix-client-secret-post
Browse files Browse the repository at this point in the history
fix(TokenRequest): Fix client lookup
  • Loading branch information
dmitrizagidulin authored Oct 15, 2018
2 parents e1d7ad2 + d405654 commit 460d09c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/handlers/TokenRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class TokenRequest extends BaseRequest {
}

return new Promise((resolve, reject) => {
provider.backend.get(id).then(client => {
provider.backend.get('clients', id).then(client => {

// UNKNOWN CLIENT
if (!client) {
Expand All @@ -292,6 +292,8 @@ class TokenRequest extends BaseRequest {
})
}

request.client = client

resolve(request)
})
})
Expand Down
24 changes: 19 additions & 5 deletions test/handlers/TokenRequestSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,39 +935,53 @@ describe('TokenRequest', () => {
})

describe('with valid credentials', () => {
let request, promise
let client, request, promise

before(() => {
sinon.stub(TokenRequest.prototype, 'badRequest')
sinon.stub(TokenRequest.prototype, 'unauthorized')

let client_id = 'uuid'
let req = {
method: 'POST',
body: {
client_id: 'uuid',
client_id: client_id,
client_secret: 'secret'
}
}

client = { client_id, client_secret: 'secret' }

let res = {}
let provider = {
host: {},
backend: { get: () => Promise.resolve({ client_secret: 'secret' }) }
backend: {
get: (collection, id) => {
return Promise.resolve(collection == 'clients' && id == client_id ? client : undefined)
}
}
}

request = new TokenRequest(req, res, provider)
promise = request.clientSecretPost(request)
})

after(() => {
TokenRequest.prototype.badRequest.restore()
TokenRequest.prototype.unauthorized.restore()
})

it('should return a promise', () => {
promise.should.be.instanceof(Promise)
})

it('should resolve request', () => {
promise.then(result => result.should.equal(request))
it('should resolve request with client added', () => {
request.badRequest.should.not.have.been.called()
request.unauthorized.should.not.have.been.called()
return promise.then(result => {
result.client.should.equal(client)
result.should.equal(request)
})
})
})
})
Expand Down

0 comments on commit 460d09c

Please sign in to comment.