Skip to content

Commit

Permalink
refactor(auth): code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
duncdrum committed Dec 20, 2023
1 parent 1a9ad15 commit 9dc97c9
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions cypress/e2e/auth_old.spec.js → cypress/e2e/auth.spec.js
Original file line number Diff line number Diff line change
@@ -1,102 +1,102 @@
const indexPage = 'http://localhost:8080/exist/apps/eXide/index.html'
const loginPage = 'http://localhost:8080/exist/apps/eXide/login.html'

describe.skip('with guest=yes (default)', function() {
before(function () {
describe('with guest=yes (default)', () => {
before(() => {
cy.setConf(true, true);
})

describe('as guest user', function() {
it('login page should redirect guest to index.html', function() {
cy.visit('/eXide/login.html')
describe('as guest user', () => {
it('login page should redirect guest to index.html', () => {
cy.visit('/login.html')
cy.url().should('eq', indexPage)
})

it('index page should show editor', function () {
cy.visit('/eXide/index.html')
it('index page should show editor', () => {
cy.visit('/index.html')
cy.url().should('eq', indexPage)
})
})

describe('as admin user', function() {
it('login page should redirect admin to index.html', function() {
describe('as admin user', () => {
it('login page should redirect admin to index.html', () => {
cy.loginXHR('admin', '')
cy.visit('/eXide/login.html')
cy.visit('/login.html')
cy.url().should('eq', indexPage)
})

it('index page should show editor', function () {
it('index page should show editor', () => {
cy.loginXHR('admin', '')
cy.visit('/eXide/index.html')
cy.visit('/index.html')
cy.url().should('eq', indexPage)
})

it('reload after logout still shows editor', function () {
it('reload after logout still shows editor', () => {
cy.loginXHR('guest', 'guest')
cy.visit('/eXide/index.html')
cy.visit('/index.html')
cy.url().should('eq', indexPage)
})
})
})

describe('with guest=no', function() {
before(function () {
describe('with guest=no', () => {
before(() => {
cy.setConf(true, false);
})
after(function () {
after(() => {
cy.setConf(true, true);
})

describe('as guest', function() {
before(function () { cy.loginXHR('guest', 'guest') })
it('login page should show', function() {
cy.visit('/eXide/login.html')
describe('as guest', () => {
before(() => { cy.loginXHR('guest', 'guest') })
it('login page should show', () => {
cy.visit('/login.html')
// cy.reload(true)
cy.url().should('eq', loginPage)
})

it('index page should redirect to login', function () {
cy.visit('/eXide/index.html')
it('index page should redirect to login', () => {
cy.visit('/index.html')
cy.url().should('eq', loginPage)
})
})

describe('as admin', function() {
it('login page should redirect admin to index.html', function() {
describe('as admin', () => {
it('login page should redirect admin to index.html', () => {
cy.loginXHR('admin', '')
cy.visit('/eXide/login.html')
cy.visit('/login.html')
cy.url().should('eq', indexPage)
})

it('index page should show editor', function () {
it('index page should show editor', () => {
cy.loginXHR('admin', '')
cy.visit('/eXide/index.html')
cy.visit('/index.html')
cy.url().should('eq', indexPage)
})
})
})

describe('login using form', function () {
before(function () {
describe('login using form', () => {
before(() => {
cy.setConf(true, false);
})
beforeEach(function () {
beforeEach(() => {
cy.loginXHR('guest', 'guest')
})
after(function () {
after(() => {
cy.setConf(true, true);
cy.loginXHR('guest', 'guest')
})

it('login page should show', function() {
cy.visit('/eXide/login.html')
it('login page should show', () => {
cy.visit('/login.html')
cy.url().should('eq', loginPage)
})

describe('with valid admin credentials', function () {
it('should login in', function() {
describe('with valid admin credentials', () => {
it('should login in', () => {
cy.session(['form', 'admin', ''], () => {
cy.visit('/eXide/login.html')
cy.visit('/login.html')
cy.get('[name=user]').type('admin')
// this will throw an error as .type cannot handle an empty string
// cy.get('[name=password]').type('')
Expand All @@ -105,10 +105,10 @@ describe('login using form', function () {
})
})
})
describe('with invalid admin credentials', function () {
it('should not allow access', function() {
describe('with invalid admin credentials', () => {
it('should not allow access', () => {
cy.session(['form', 'admin', 'nimda'], () => {
cy.visit('/eXide/login.html')
cy.visit('/login.html')
cy.get('[name=user]').type('admin')
// this will throw an error as .type cannot handle an empty string
cy.get('[name=password]').type('nimda')
Expand All @@ -117,10 +117,10 @@ describe('login using form', function () {
})
})
})
describe('with valid guest credentials', function () {
it('should still not allow guest', function() {
describe('with valid guest credentials', () => {
it('should still not allow guest', () => {
cy.session(['form', 'guest', 'guest'], () => {
cy.visit('/eXide/login.html')
cy.visit('/login.html')
cy.get('[name=user]').type('guest')
// this will throw an error as .type cannot handle an empty string
cy.get('[name=password]').type('guest')
Expand Down

0 comments on commit 9dc97c9

Please sign in to comment.