mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-09 13:51:57 -04:00

Some checks are pending
Docker / build-and-push (frontend) (push) Waiting to run
Docker / build-and-push (backend) (push) Waiting to run
Deploy HD2 docs to Netlify / Deploys to netlify (push) Waiting to run
E2E Tests / backend-sqlite (push) Waiting to run
E2E Tests / backend-mariadb (push) Waiting to run
E2E Tests / backend-postgres (push) Waiting to run
E2E Tests / Build test build of frontend (push) Waiting to run
E2E Tests / frontend-cypress (1) (push) Blocked by required conditions
E2E Tests / frontend-cypress (2) (push) Blocked by required conditions
E2E Tests / frontend-cypress (3) (push) Blocked by required conditions
Lint and check format / Lint files and check formatting (push) Waiting to run
REUSE Compliance Check / reuse (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Static Analysis / Njsscan code scanning (push) Waiting to run
Static Analysis / CodeQL analysis (push) Waiting to run
Run tests & build / Test and build with NodeJS 20 (push) Waiting to run
Thanks to all HedgeDoc team members for the time discussing, helping with weird Nest issues, providing feedback and suggestions! Co-authored-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Erik Michelson <github@erik.michelson.eu>
135 lines
4.1 KiB
TypeScript
135 lines
4.1 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
import type { AuthProvider } from '../../src/api/config/types'
|
|
import { AuthProviderType } from '../../src/api/config/types'
|
|
|
|
const initLoggedOutTestWithCustomAuthProviders = (cy: Cypress.cy, enabledProviders: AuthProvider[]) => {
|
|
cy.logOut()
|
|
cy.loadConfig({
|
|
authProviders: enabledProviders
|
|
})
|
|
cy.visitHistory()
|
|
}
|
|
|
|
describe('When logged-in, ', () => {
|
|
it('sign-in button is hidden', () => {
|
|
cy.visitHistory()
|
|
cy.getByCypressId('base-app-bar').should('be.visible')
|
|
cy.getByCypressId('sign-in-button').should('not.exist')
|
|
})
|
|
describe('login page route will redirect', () => {
|
|
it('to /history if no redirect url has been provided', () => {
|
|
cy.visit('/login')
|
|
cy.url().should('contain', '/history')
|
|
})
|
|
it('to any page if a redirect url has been provided', () => {
|
|
cy.visit('/login?redirectBackTo=/profile')
|
|
cy.url().should('contain', '/profile')
|
|
})
|
|
it('to /history if a external redirect url has been provided', () => {
|
|
cy.visit('/login?redirectBackTo=https://example.org')
|
|
cy.url().should('contain', '/history')
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('When logged-out ', () => {
|
|
describe('and no auth-provider is enabled, ', () => {
|
|
it('sign-in button is hidden', () => {
|
|
initLoggedOutTestWithCustomAuthProviders(cy, [])
|
|
cy.getByCypressId('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, [
|
|
{
|
|
type: AuthProviderType.LOCAL
|
|
}
|
|
])
|
|
cy.getByCypressId('sign-in-button')
|
|
.should('be.visible')
|
|
.parent()
|
|
.should('have.attr', 'href', '/login?redirectBackTo=/history')
|
|
})
|
|
|
|
it('sign-in button points to login route: ldap', () => {
|
|
initLoggedOutTestWithCustomAuthProviders(cy, [
|
|
{
|
|
type: AuthProviderType.LDAP,
|
|
identifier: 'cy-ldap',
|
|
providerName: 'cy LDAP'
|
|
}
|
|
])
|
|
cy.getByCypressId('sign-in-button')
|
|
.should('be.visible')
|
|
.parent()
|
|
.should('have.attr', 'href', '/login?redirectBackTo=/history')
|
|
})
|
|
})
|
|
|
|
describe('and only one one-click auth-provider is enabled, ', () => {
|
|
it('sign-in button points to auth-provider', () => {
|
|
initLoggedOutTestWithCustomAuthProviders(cy, [
|
|
{
|
|
type: AuthProviderType.OIDC,
|
|
identifier: 'github',
|
|
providerName: 'GitHub',
|
|
theme: 'github'
|
|
}
|
|
])
|
|
cy.getByCypressId('sign-in-button')
|
|
.should('be.visible')
|
|
.parent()
|
|
// The absolute URL is used because it is defined as API base URL absolute.
|
|
.should('have.attr', 'href', '/api/private/auth/oidc/github')
|
|
})
|
|
})
|
|
|
|
describe('and multiple one-click auth-providers are enabled, ', () => {
|
|
it('sign-in button points to login route', () => {
|
|
initLoggedOutTestWithCustomAuthProviders(cy, [
|
|
{
|
|
type: AuthProviderType.OIDC,
|
|
identifier: 'github',
|
|
providerName: 'GitHub',
|
|
theme: 'github'
|
|
},
|
|
{
|
|
type: AuthProviderType.OIDC,
|
|
identifier: 'gitlab',
|
|
providerName: 'GitLab',
|
|
theme: 'gitlab'
|
|
}
|
|
])
|
|
cy.getByCypressId('sign-in-button')
|
|
.should('be.visible')
|
|
.parent()
|
|
.should('have.attr', 'href', '/login?redirectBackTo=/history')
|
|
})
|
|
})
|
|
|
|
describe('and one-click- as well as interactive auth-providers are enabled, ', () => {
|
|
it('sign-in button points to login route', () => {
|
|
initLoggedOutTestWithCustomAuthProviders(cy, [
|
|
{
|
|
type: AuthProviderType.OIDC,
|
|
identifier: 'github',
|
|
providerName: 'GitHub',
|
|
theme: 'github'
|
|
},
|
|
{
|
|
type: AuthProviderType.LOCAL
|
|
}
|
|
])
|
|
cy.getByCypressId('sign-in-button')
|
|
.should('be.visible')
|
|
.parent()
|
|
.should('have.attr', 'href', '/login?redirectBackTo=/history')
|
|
})
|
|
})
|
|
})
|