-
-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: url encode client_id returned in registration responses
- Loading branch information
Showing
3 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const cloneDeep = require('lodash/cloneDeep'); | ||
const merge = require('lodash/merge'); | ||
|
||
const nanoid = require('../../lib/helpers/nanoid'); | ||
const config = cloneDeep(require('../default.config')); | ||
|
||
merge(config.features, { | ||
registration: { | ||
enabled: true, | ||
rotateRegistrationAccessToken: false, | ||
idFactory() { | ||
return new URL(`https://repo.clients.com/path?id=${nanoid()}`).href; | ||
}, | ||
}, | ||
registrationManagement: { | ||
enabled: true, | ||
}, | ||
}); | ||
|
||
module.exports = { | ||
config, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const { expect } = require('chai'); | ||
|
||
const bootstrap = require('../test_helper'); | ||
|
||
describe('registration management with client_id as URI', () => { | ||
before(bootstrap(__dirname)); | ||
|
||
it('returns client_id as a URI string', async function () { | ||
let client_id; | ||
let registration_client_uri; | ||
let registration_access_token; | ||
|
||
await this.agent.post('/reg') | ||
.send({ | ||
redirect_uris: ['https://client.example.com/cb'], | ||
}) | ||
.expect(201) | ||
.expect((response) => { | ||
({ client_id, registration_access_token, registration_client_uri } = response.body); | ||
|
||
const parsed = new URL(registration_client_uri); | ||
expect(parsed.search).to.be.empty; | ||
const i = parsed.pathname.indexOf('/reg/'); | ||
expect(parsed.pathname.slice(i + 5)).to.equal(encodeURIComponent(client_id)); | ||
}); | ||
|
||
await this.agent.get(new URL(registration_client_uri).pathname) | ||
.auth(registration_access_token, { type: 'bearer' }) | ||
.expect(200) | ||
.expect((response) => { | ||
({ registration_client_uri } = response.body); | ||
|
||
const parsed = new URL(registration_client_uri); | ||
expect(parsed.search).to.be.empty; | ||
const i = parsed.pathname.indexOf('/reg/'); | ||
expect(parsed.pathname.slice(i + 5)).to.equal(encodeURIComponent(client_id)); | ||
}); | ||
|
||
await this.agent.put(new URL(registration_client_uri).pathname) | ||
.auth(registration_access_token, { type: 'bearer' }) | ||
.send({ | ||
client_id, | ||
redirect_uris: ['https://client.example.com/cb2'], | ||
}) | ||
.expect(200) | ||
.expect((response) => { | ||
({ registration_client_uri } = response.body); | ||
|
||
const parsed = new URL(registration_client_uri); | ||
expect(parsed.search).to.be.empty; | ||
const i = parsed.pathname.indexOf('/reg/'); | ||
expect(parsed.pathname.slice(i + 5)).to.equal(encodeURIComponent(client_id)); | ||
}); | ||
|
||
await this.agent.delete(new URL(registration_client_uri).pathname) | ||
.auth(registration_access_token, { type: 'bearer' }) | ||
.expect(204); | ||
}); | ||
}); |