Skip to content

Commit

Permalink
test: add refresh narrowing and broadening e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-elliott committed Jan 2, 2023
1 parent 7fa97d9 commit d4115e2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cypress/integration/oauth2/refresh_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,48 @@ describe("The OAuth 2.0 Refresh Token Grant", function () {
})
})
})

it("should narrow Refresh Token scopes correctly", function () {
const referrer = `${Cypress.env("client_url")}/empty`
cy.visit(referrer, {
failOnStatusCode: false,
})

createClient({
scope: "offline_access openid foo bar baz",
redirect_uris: [referrer],
grant_types: ["authorization_code", "refresh_token"],
response_types: ["code"],
token_endpoint_auth_method: "none",
}).then((client) => {
cy.authCodeFlowBrowser(client, {
consent: { scope: ["offline_access openid foo bar baz"] },
createClient: false,
}).then((originalResponse) => {
expect(originalResponse.status).to.eq(200)
expect(originalResponse.body.refresh_token).to.not.be.empty
expect(originalResponse.body.scope).to.eq("offline_access openid foo bar baz")

const originalToken = originalResponse.body.refresh_token

cy.refreshTokenBrowserScope(client, originalToken, "offline_access openid foo").then(
(refreshedResponse) => {
expect(refreshedResponse.status).to.eq(200)
expect(refreshedResponse.body.refresh_token).to.not.be.empty
expect(refreshedResponse.body.scope).to.eq("offline_access openid foo")

const refreshedToken = refreshedResponse.body.refresh_token

cy.refreshTokenBrowserScope(client, refreshedToken, "offline_access openid foo bar baz").then(
(finalRefreshedResponse) => {
expect(finalRefreshedResponse.status).to.eq(200)
expect(finalRefreshedResponse.body.refresh_token).to.not.be.empty
expect(finalRefreshedResponse.body.scope).to.eq("offline_access openid foo bar baz")
},
)
},
)
})
})
})
})
15 changes: 15 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,18 @@ Cypress.Commands.add("refreshTokenBrowser", (client, token) =>
failOnStatusCode: false,
}),
)

Cypress.Commands.add("refreshTokenBrowserScope", (client, token, scope) =>
cy.request({
url: `${Cypress.env("public_url")}/oauth2/token`,
method: "POST",
form: true,
body: {
grant_type: "refresh_token",
client_id: client.client_id,
refresh_token: token,
scope: scope,
},
failOnStatusCode: false,
}),
)

0 comments on commit d4115e2

Please sign in to comment.