Add one-click login if possible (#1043)

This commit is contained in:
Erik Michelson 2021-03-09 23:00:14 +01:00 committed by GitHub
parent a6c80ac1f0
commit 6d2dde477c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 216 additions and 53 deletions

View file

@ -6,6 +6,7 @@
describe('Autocompletion', () => {
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
cy.get('.CodeMirror')
.click()

View file

@ -8,6 +8,7 @@ import { banner } from '../support/config'
describe('Banner', () => {
beforeEach(() => {
cy.loadConfig()
cy.visit('/')
expect(localStorage.getItem('bannerTimeStamp')).to.be.null
})

View file

@ -6,6 +6,7 @@
describe('Diagram codeblock ', () => {
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
})

View file

@ -9,6 +9,7 @@ import { branding } from '../support/config'
const title = 'This is a test title'
describe('Document Title', () => {
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
cy.get('.btn.active.btn-outline-secondary > i.fa-columns')
.should('exist')

View file

@ -5,6 +5,10 @@
*/
describe('Editor mode from URL parameter is used', () => {
beforeEach(() => {
cy.loadConfig()
})
it('mode view', () => {
cy.visitTestEditor('view')
cy.get('.splitter.left')

View file

@ -9,6 +9,7 @@ describe('Export', () => {
const testContent = `---\ntitle: ${ testTitle }\n---\nThis is some test content`
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
cy.codemirrorFill(testContent)
})

View file

@ -8,6 +8,7 @@ const imageUrl = 'http://example.com/non-existing.png'
describe('File upload', () => {
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
})

View file

@ -6,6 +6,7 @@
describe('Help Dialog', () => {
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
})

View file

@ -12,6 +12,7 @@ const findHljsCodeBlock = () => {
describe('Code', () => {
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
})

View file

@ -6,6 +6,7 @@
describe('History', () => {
beforeEach(() => {
cy.loadConfig()
cy.visit('/history')
})

View file

@ -6,6 +6,7 @@
describe('Import markdown file', () => {
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
})

View file

@ -7,6 +7,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
describe('Intro page', () => {
beforeEach(() => {
cy.loadConfig()
cy.intercept('/intro.md', 'test content')
cy.visit('/')
})

View file

@ -8,6 +8,7 @@ import { languages } from '../fixtures/languages'
describe('Languages', () => {
beforeEach(() => {
cy.loadConfig()
cy.visit('/')
})

View file

@ -8,6 +8,7 @@ import '../support/index'
describe('Links Intro', () => {
beforeEach(() => {
cy.loadConfig()
cy.visit('/')
})
@ -53,13 +54,6 @@ describe('Links Intro', () => {
cy.url()
.should('include', '/new')
})
it('Sign In', () => {
cy.get('.btn-success.btn-sm')
.click()
cy.url()
.should('include', '/login')
})
})
describe('Menu Buttons logged in', () => {
@ -83,7 +77,7 @@ describe('Links Intro', () => {
.should('include', '/features')
})
it('Features', () => {
it('Profile', () => {
cy.get('a.dropdown-item > i.fa-user')
.click()
cy.url()

View file

@ -6,6 +6,7 @@
describe('Link gets replaced with embedding: ', () => {
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
})

View file

@ -10,6 +10,7 @@ describe('The status bar text length info', () => {
const tooMuchTestContent = `${ dangerTestContent }a`
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
})

View file

@ -6,6 +6,7 @@
describe('profile page', () => {
beforeEach(() => {
cy.loadConfig()
cy.intercept({
url: '/api/v2/tokens',
method: 'GET'

View file

@ -6,6 +6,7 @@
describe('Quote extra tags', function () {
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
})

View file

@ -6,6 +6,7 @@
describe('Short code gets replaced or rendered: ', () => {
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
})

View file

@ -0,0 +1,114 @@
/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
const authProvidersDisabled = {
facebook: false,
github: false,
twitter: false,
gitlab: false,
dropbox: false,
ldap: false,
google: false,
saml: false,
oauth2: false,
internal: false,
openid: false
}
const initLoggedOutTestWithCustomAuthProviders = (cy: Cypress.cy, enabledProviders: Partial<typeof authProvidersDisabled>) => {
cy.loadConfig({
authProviders: {
...authProvidersDisabled,
...enabledProviders
}
})
cy.visit('/')
cy.logout()
}
describe('When logged-in, ', () => {
it('sign-in button is hidden', () => {
cy.loadConfig()
cy.visit('/')
cy.get('[data-cy=sign-in-button]')
.should('not.exist')
})
})
describe('When logged-out ', () => {
describe('and no auth-provider is enabled, ', () => {
it('sign-in button is hidden', () => {
initLoggedOutTestWithCustomAuthProviders(cy, {})
cy.get('[data-cy=sign-in-button]')
.should('not.exist')
})
})
describe('and an interactive auth-provider is enabled, ', () => {
it('sign-in button points to login route: internal', () => {
initLoggedOutTestWithCustomAuthProviders(cy, {
internal: true
})
cy.get('[data-cy=sign-in-button]')
.should('be.visible')
.should('have.attr', 'href', '/login')
})
it('sign-in button points to login route: ldap', () => {
initLoggedOutTestWithCustomAuthProviders(cy, {
ldap: true
})
cy.get('[data-cy=sign-in-button]')
.should('be.visible')
.should('have.attr', 'href', '/login')
})
it('sign-in button points to login route: openid', () => {
initLoggedOutTestWithCustomAuthProviders(cy, {
openid: true
})
cy.get('[data-cy=sign-in-button]')
.should('be.visible')
.should('have.attr', 'href', '/login')
})
})
describe('and only one one-click auth-provider is enabled, ', () => {
it('sign-in button points to auth-provider', () => {
initLoggedOutTestWithCustomAuthProviders(cy, {
saml: true
})
cy.get('[data-cy=sign-in-button]')
.should('be.visible')
// The absolute URL is used because it is defined as API base URL absolute.
.should('have.attr', 'href', 'http://127.0.0.1:3001/api/v2/auth/saml')
})
})
describe('and multiple one-click auth-providers are enabled, ', () => {
it('sign-in button points to login route', () => {
initLoggedOutTestWithCustomAuthProviders(cy, {
saml: true,
github: true
})
cy.get('[data-cy=sign-in-button]')
.should('be.visible')
.should('have.attr', 'href', '/login')
})
})
describe('and one-click- as well as interactive auth-providers are enabled, ', () => {
it('sign-in button points to login route', () => {
initLoggedOutTestWithCustomAuthProviders(cy, {
saml: true,
internal: true
})
cy.get('[data-cy=sign-in-button]')
.should('be.visible')
.should('have.attr', 'href', '/login')
})
})
})

View file

@ -9,6 +9,7 @@ describe('Toolbar Buttons', () => {
const testLink = 'http://hedgedoc.org'
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
cy.get('.CodeMirror')

View file

@ -6,6 +6,7 @@
describe('YAML Array for deprecated syntax of document tags in frontmatter', () => {
beforeEach(() => {
cy.loadConfig()
cy.visitTestEditor()
})