Skip to content

Commit

Permalink
chore: apply ory-prettier-styles to cypress tests (ory#2179)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik authored Nov 17, 2020
1 parent 6da7cf4 commit e972bcb
Show file tree
Hide file tree
Showing 21 changed files with 557 additions and 542 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ jobs:
- checkout
- golangci/lint
- docs/check-format
- run: |
bash <(curl -s https://raw.githubusercontent.com/ory/ci/master/src/scripts/install/prettier.sh)
npm run format:check
workflows:
bdt:
Expand Down
24 changes: 12 additions & 12 deletions cypress/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ export const prng = () =>
.toString(36)
.substring(2)}${Math.random()
.toString(36)
.substring(2)}`;
.substring(2)}`

const isStatusOk = res =>
res.ok
? Promise.resolve(res)
: Promise.reject(
new Error(`Received unexpected status code ${res.statusCode}`)
);
)

export const findEndUserAuthorization = subject =>
fetch(
Expand All @@ -19,15 +19,15 @@ export const findEndUserAuthorization = subject =>
subject
)
.then(isStatusOk)
.then(res => res.json());
.then(res => res.json())

export const revokeEndUserAuthorization = subject =>
fetch(
Cypress.env('admin_url') +
'/oauth2/auth/sessions/consent?subject=' +
subject,
{ method: 'DELETE' }
).then(isStatusOk);
).then(isStatusOk)

export const createClient = client =>
fetch(Cypress.env('admin_url') + '/clients', {
Expand All @@ -37,7 +37,7 @@ export const createClient = client =>
})
.then(isStatusOk)
.then(res => {
return res.json();
return res.json()
})
.then(body =>
getClient(client.client_id).then(actual => {
Expand All @@ -48,12 +48,12 @@ export const createClient = client =>
body.client
}`
)
);
)
}

return Promise.resolve(body);
return Promise.resolve(body)
})
);
)

export const deleteClients = () =>
fetch(Cypress.env('admin_url') + '/clients', {
Expand All @@ -62,15 +62,15 @@ export const deleteClients = () =>
.then(isStatusOk)
.then(res => res.json())
.then((body = []) => {
(body || []).forEach(({ client_id }) => deleteClient(client_id));
});
;(body || []).forEach(({ client_id }) => deleteClient(client_id))
})

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

const getClient = id =>
fetch(Cypress.env('admin_url') + '/clients/' + id)
.then(isStatusOk)
.then(res => res.json());
.then(res => res.json())
16 changes: 8 additions & 8 deletions cypress/integration/admin/client_create.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { prng } from '../../helpers';
import { prng } from '../../helpers'

describe('The Clients Admin Interface', function() {
const nc = () => ({
scope: 'foo openid offline_access',
grant_types: ['client_credentials']
});
})

it('should return client_secret with length 26 for newly created clients without client_secret specified', function() {
const client = nc();
const client = nc()

cy.request(
'POST',
Cypress.env('admin_url') + '/clients',
JSON.stringify(client)
).then(response => {
console.log(response.body, client);
expect(response.body.client_secret.length).to.equal(26);
});
});
});
console.log(response.body, client)
expect(response.body.client_secret.length).to.equal(26)
})
})
})
78 changes: 39 additions & 39 deletions cypress/integration/oauth2/authorize_code.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { prng } from '../../helpers';
import { prng } from '../../helpers'

describe('The OAuth 2.0 Authorization Code Grant', function() {
const nc = () => ({
Expand All @@ -9,83 +9,83 @@ describe('The OAuth 2.0 Authorization Code Grant', function() {
token_endpoint_auth_method: 'client_secret_basic',
redirect_uris: [`${Cypress.env('client_url')}/oauth2/callback`],
grant_types: ['authorization_code', 'refresh_token']
});
})

it('should return an Access, Refresh, and ID Token when scope offline_access and openid are granted', function() {
const client = nc();
const client = nc()
cy.authCodeFlow(client, {
consent: { scope: ['offline_access', 'openid'] }
});
})

cy.get('body')
.invoke('text')
.then(content => {
const {
result,
token: { access_token, id_token, refresh_token }
} = JSON.parse(content);
} = JSON.parse(content)

expect(result).to.equal('success');
expect(access_token).to.not.be.empty;
expect(id_token).to.not.be.empty;
expect(refresh_token).to.not.be.empty;
});
});
expect(result).to.equal('success')
expect(access_token).to.not.be.empty
expect(id_token).to.not.be.empty
expect(refresh_token).to.not.be.empty
})
})

it('should return an Access and Refresh Token when scope offline_access is granted', function() {
const client = nc();
cy.authCodeFlow(client, { consent: { scope: ['offline_access'] } });
const client = nc()
cy.authCodeFlow(client, { consent: { scope: ['offline_access'] } })

cy.get('body')
.invoke('text')
.then(content => {
const {
result,
token: { access_token, id_token, refresh_token }
} = JSON.parse(content);
} = JSON.parse(content)

expect(result).to.equal('success');
expect(access_token).to.not.be.empty;
expect(id_token).to.be.empty;
expect(refresh_token).to.not.be.empty;
});
});
expect(result).to.equal('success')
expect(access_token).to.not.be.empty
expect(id_token).to.be.empty
expect(refresh_token).to.not.be.empty
})
})

it('should return an Access and ID Token when scope offline_access is granted', function() {
const client = nc();
cy.authCodeFlow(client, { consent: { scope: ['openid'] } });
const client = nc()
cy.authCodeFlow(client, { consent: { scope: ['openid'] } })

cy.get('body')
.invoke('text')
.then(content => {
const {
result,
token: { access_token, id_token, refresh_token }
} = JSON.parse(content);
} = JSON.parse(content)

expect(result).to.equal('success');
expect(access_token).to.not.be.empty;
expect(id_token).to.not.be.empty;
expect(refresh_token).to.be.empty;
});
});
expect(result).to.equal('success')
expect(access_token).to.not.be.empty
expect(id_token).to.not.be.empty
expect(refresh_token).to.be.empty
})
})

it('should return an Access Token when no scope is granted', function() {
const client = nc();
cy.authCodeFlow(client, { consent: { scope: [] } });
const client = nc()
cy.authCodeFlow(client, { consent: { scope: [] } })

cy.get('body')
.invoke('text')
.then(content => {
const {
result,
token: { access_token, id_token, refresh_token }
} = JSON.parse(content);
} = JSON.parse(content)

expect(result).to.equal('success');
expect(access_token).to.not.be.empty;
expect(id_token).to.be.empty;
expect(refresh_token).to.be.empty;
});
});
});
expect(result).to.equal('success')
expect(access_token).to.not.be.empty
expect(id_token).to.be.empty
expect(refresh_token).to.be.empty
})
})
})
Loading

0 comments on commit e972bcb

Please sign in to comment.