Skip to content

Commit

Permalink
test: use cypress fetchers
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Mar 24, 2021
1 parent d8ad323 commit 2aa0980
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 35 deletions.
32 changes: 9 additions & 23 deletions cypress/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,9 @@ export const revokeEndUserAuthorization = (subject) =>
).then(isStatusOk)

export const createClient = (client) =>
fetch(Cypress.env('admin_url') + '/clients', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(client)
})
.then(isStatusOk)
.then((res) => {
return res.json()
})
.then((body) =>
cy
.request('POST', Cypress.env('admin_url') + '/clients', client)
.then(({ body }) =>
getClient(client.client_id).then((actual) => {
if (actual.client_id !== body.client_id) {
return Promise.reject(
Expand All @@ -52,21 +45,14 @@ export const createClient = (client) =>
)

export const deleteClients = () =>
fetch(Cypress.env('admin_url') + '/clients', {
method: 'GET'
cy.request(Cypress.env('admin_url') + '/clients').then(({ body = [] }) => {
;(body || []).forEach(({ client_id }) => deleteClient(client_id))
})
.then(isStatusOk)
.then((res) => res.json())
.then((body = []) => {
;(body || []).forEach(({ client_id }) => deleteClient(client_id))
})

const deleteClient = (client_id) =>
fetch(Cypress.env('admin_url') + '/clients/' + client_id, {
method: 'DELETE'
}).then(isStatusOk)
cy.request('DELETE', Cypress.env('admin_url') + '/clients/' + client_id)

const getClient = (id) =>
fetch(Cypress.env('admin_url') + '/clients/' + id)
.then(isStatusOk)
.then((res) => res.json())
cy
.request(Cypress.env('admin_url') + '/clients/' + id)
.then(({ body }) => body)
8 changes: 4 additions & 4 deletions cypress/integration/oauth2/authorize_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('OAuth 2.0 Authorization Endpoint Error Handling', () => {
redirect_uris: [`${Cypress.env('client_url')}/oauth2/callback`],
grant_types: ['authorization_code']
}
cy.wrap(createClient(c))
createClient(c)

cy.visit(
`${Cypress.env('client_url')}/oauth2/code?client_id=${
Expand All @@ -115,7 +115,7 @@ describe('OAuth 2.0 Authorization Endpoint Error Handling', () => {
redirect_uris: [`${Cypress.env('client_url')}/oauth2/callback`],
response_types: ['token'] // disallows Authorization Code Grant
}
cy.wrap(createClient(c))
createClient(c)

cy.visit(
`${Cypress.env('client_url')}/oauth2/code?client_id=${
Expand All @@ -134,7 +134,7 @@ describe('OAuth 2.0 Authorization Endpoint Error Handling', () => {
redirect_uris: [`${Cypress.env('client_url')}/oauth2/callback`],
grant_types: ['client_credentials']
}
cy.wrap(createClient(c))
createClient(c)

cy.visit(
`${Cypress.env('client_url')}/oauth2/code?client_id=${
Expand All @@ -158,7 +158,7 @@ describe('OAuth 2.0 Authorization Endpoint Error Handling', () => {
redirect_uris: ['http://some-other-domain/not-callback'],
grant_types: ['client_credentials']
}
cy.wrap(createClient(c))
createClient(c)

cy.visit(
`${Cypress.env('client_url')}/oauth2/code?client_id=${
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/oauth2/client_creds.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('The OAuth 2.0 Authorization Code Grant', function () {

it('should return an Access Token but not Refresh or ID Token for client_credentials flow', function () {
const client = nc()
cy.wrap(createClient(client))
createClient(client)

cy.request(
`${Cypress.env('client_url')}/oauth2/cc?client_id=${
Expand Down
12 changes: 8 additions & 4 deletions cypress/integration/openid/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ const nc = () => ({
})

describe('OpenID Connect Logout', () => {
before(() => {
cy.clearCookies({ domain: null })
})

after(() => {
cy.wrap(deleteClients())
deleteClients()
})

describe('logout without id_token_hint', () => {
Expand All @@ -24,7 +28,7 @@ describe('OpenID Connect Logout', () => {
})

before(() => {
cy.wrap(deleteClients())
deleteClients()
})

const client = {
Expand Down Expand Up @@ -91,7 +95,7 @@ describe('OpenID Connect Logout', () => {
})

before(() => {
cy.wrap(deleteClients())
deleteClients()
})

const client = {
Expand Down Expand Up @@ -151,7 +155,7 @@ describe('OpenID Connect Logout', () => {
})

before(() => {
cy.wrap(deleteClients())
deleteClients()
})

const client = {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/openid/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('OpenID Connect Prompt', () => {

it('should fail prompt=none when no session exists', function () {
const client = nc()
cy.wrap(createClient(client))
createClient(client)

cy.visit(
`${Cypress.env('client_url')}/openid/code?client_id=${
Expand Down
4 changes: 2 additions & 2 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Cypress.Commands.add(
path = 'oauth2'
) => {
if (doCreateClient) {
cy.wrap(createClient(client))
createClient(client)
}

cy.visit(
Expand Down Expand Up @@ -117,7 +117,7 @@ Cypress.Commands.add(
} = {}
) => {
if (doCreateClient) {
cy.wrap(createClient(client))
createClient(client)
}

const codeChallenge = 'QeNVR-BHuB6I2d0HycQzp2qUNNKi_-5QoR4fQSifLH0'
Expand Down

0 comments on commit 2aa0980

Please sign in to comment.