Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/api-tokens.spec.js
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | it('should report error when not logged in and visiting a token generation URL', function() { | ||||
cy.get('.swh-http-error') | cy.get('.swh-http-error') | ||||
.should('be.visible'); | .should('be.visible'); | ||||
cy.get('.swh-http-error-code') | cy.get('.swh-http-error-code') | ||||
.should('contain', 403); | .should('contain', 403); | ||||
cy.get('.swh-http-error-desc') | cy.get('.swh-http-error-desc') | ||||
.should('contain', 'You are not allowed to generate bearer tokens'); | .should('contain', 'You are not allowed to generate bearer tokens'); | ||||
}); | }); | ||||
function displayToken(Urls, status, tokenValue = '') { | function displayToken(Urls, status, body = '') { | ||||
cy.intercept('POST', `${Urls.oidc_get_bearer_token()}/**`, { | cy.intercept('POST', `${Urls.oidc_get_bearer_token()}/**`, { | ||||
body: tokenValue, | body: body, | ||||
statusCode: status | statusCode: status | ||||
}).as('getTokenRequest'); | }).as('getTokenRequest'); | ||||
cy.contains('Display token') | cy.contains('Display token') | ||||
.click({force: true}); | .click({force: true}); | ||||
cy.get('.modal-dialog') | cy.get('.modal-dialog') | ||||
.should('be.visible'); | .should('be.visible'); | ||||
cy.get('.modal-header') | cy.get('.modal-header') | ||||
.should('contain', 'Display bearer token'); | .should('contain', 'Display bearer token'); | ||||
} | } | ||||
it('should show a token when requested', function() { | it('should show a token when requested', function() { | ||||
initTokensPage(this.Urls, [{id: 1, creation_date: new Date().toISOString()}]); | initTokensPage(this.Urls, [{id: 1, creation_date: new Date().toISOString()}]); | ||||
const tokenValue = 'token-value'; | const tokenValue = 'token-value'; | ||||
displayToken(this.Urls, 200, tokenValue); | displayToken(this.Urls, 200, tokenValue); | ||||
cy.get('#swh-bearer-token') | cy.get('#swh-bearer-token') | ||||
.should('contain', tokenValue); | .should('contain', tokenValue); | ||||
}); | }); | ||||
it('should report errors when token display failed', function() { | it('should report error when token display failed', function() { | ||||
initTokensPage(this.Urls, [{id: 1, creation_date: new Date().toISOString()}]); | initTokensPage(this.Urls, [{id: 1, creation_date: new Date().toISOString()}]); | ||||
displayToken(this.Urls, 500); | const errorMessage = 'Internal server error'; | ||||
displayToken(this.Urls, 500, errorMessage); | |||||
cy.get('.modal-body') | cy.get('.modal-body') | ||||
.should('contain', 'Internal server error'); | .should('contain', errorMessage); | ||||
}); | |||||
it('should report error when token expired', function() { | |||||
initTokensPage(this.Urls, [{id: 1, creation_date: new Date().toISOString()}]); | |||||
const errorMessage = 'Bearer token has expired'; | |||||
displayToken(this.Urls, 400, errorMessage); | |||||
cy.get('.modal-body') | |||||
.should('contain', errorMessage); | |||||
}); | }); | ||||
function revokeToken(Urls, status) { | function revokeToken(Urls, status) { | ||||
cy.intercept('POST', `${Urls.oidc_revoke_bearer_tokens()}/**`, { | cy.intercept('POST', `${Urls.oidc_revoke_bearer_tokens()}/**`, { | ||||
body: '', | body: '', | ||||
statusCode: status | statusCode: status | ||||
}).as('revokeTokenRequest'); | }).as('revokeTokenRequest'); | ||||
Show All 35 Lines |