|
7 | 7 | const InvalidArgumentError = require('../../../lib/errors/invalid-argument-error'); |
8 | 8 | const InvalidGrantError = require('../../../lib/errors/invalid-grant-error'); |
9 | 9 | const InvalidRequestError = require('../../../lib/errors/invalid-request-error'); |
| 10 | +const InvalidScopeError = require('../../../lib/errors/invalid-scope-error'); |
10 | 11 | const RefreshTokenGrantType = require('../../../lib/grant-types/refresh-token-grant-type'); |
11 | 12 | const Request = require('../../../lib/request'); |
12 | 13 | const ServerError = require('../../../lib/errors/server-error'); |
@@ -182,6 +183,34 @@ describe('RefreshTokenGrantType integration', function() { |
182 | 183 |
|
183 | 184 | grantType.handle(request, client).should.be.an.instanceOf(Promise); |
184 | 185 | }); |
| 186 | + |
| 187 | + it('should throw an error if extra `scope` is requested', async function() { |
| 188 | + const client = { id: 123 }; |
| 189 | + const token = { |
| 190 | + accessToken: 'foo', |
| 191 | + client: { id: 123 }, |
| 192 | + user: { name: 'foo' }, |
| 193 | + refreshTokenExpiresAt: new Date(new Date() * 2) |
| 194 | + }; |
| 195 | + const model = { |
| 196 | + getRefreshToken: async function() { |
| 197 | + return token; |
| 198 | + }, |
| 199 | + revokeToken: () => should.fail(), |
| 200 | + saveToken: () => should.fail() |
| 201 | + }; |
| 202 | + const grantType = new RefreshTokenGrantType({ accessTokenLifetime: 123, model }); |
| 203 | + const request = new Request({ body: { refresh_token: 'foobar', scope: 'read' }, headers: {}, method: {}, query: {} }); |
| 204 | + |
| 205 | + try { |
| 206 | + await grantType.handle(request, client); |
| 207 | + |
| 208 | + should.fail(); |
| 209 | + } catch (e) { |
| 210 | + e.should.be.an.instanceOf(InvalidScopeError); |
| 211 | + e.message.should.equal('Invalid scope: Unable to add extra scopes'); |
| 212 | + } |
| 213 | + }); |
185 | 214 | }); |
186 | 215 |
|
187 | 216 | describe('getRefreshToken()', function() { |
|
0 commit comments