2021-03-09 17:00:14 -05:00
|
|
|
/*
|
2023-09-24 17:37:03 -04:00
|
|
|
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
|
2021-03-09 17:00:14 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
2022-04-15 17:03:15 -04:00
|
|
|
import type { AuthProvider } from '../../src/api/config/types'
|
|
|
|
import { AuthProviderType } from '../../src/api/config/types'
|
2021-03-09 17:00:14 -05:00
|
|
|
|
2022-04-15 17:03:15 -04:00
|
|
|
const initLoggedOutTestWithCustomAuthProviders = (cy: Cypress.cy, enabledProviders: AuthProvider[]) => {
|
2023-09-10 02:54:03 -04:00
|
|
|
cy.logOut()
|
2021-03-09 17:00:14 -05:00
|
|
|
cy.loadConfig({
|
2022-04-15 17:03:15 -04:00
|
|
|
authProviders: enabledProviders
|
2021-03-09 17:00:14 -05:00
|
|
|
})
|
2023-09-10 02:54:03 -04:00
|
|
|
cy.visitHistory()
|
2021-03-09 17:00:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('When logged-in, ', () => {
|
|
|
|
it('sign-in button is hidden', () => {
|
2023-09-10 02:54:03 -04:00
|
|
|
cy.visitHistory()
|
|
|
|
cy.getByCypressId('base-app-bar').should('be.visible')
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('sign-in-button').should('not.exist')
|
2021-03-09 17:00:14 -05:00
|
|
|
})
|
2023-09-10 02:54:03 -04:00
|
|
|
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')
|
|
|
|
})
|
|
|
|
})
|
2021-03-09 17:00:14 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When logged-out ', () => {
|
|
|
|
describe('and no auth-provider is enabled, ', () => {
|
|
|
|
it('sign-in button is hidden', () => {
|
2022-04-15 17:03:15 -04:00
|
|
|
initLoggedOutTestWithCustomAuthProviders(cy, [])
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('sign-in-button').should('not.exist')
|
2021-03-09 17:00:14 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('and an interactive auth-provider is enabled, ', () => {
|
|
|
|
it('sign-in button points to login route: internal', () => {
|
2022-04-15 17:03:15 -04:00
|
|
|
initLoggedOutTestWithCustomAuthProviders(cy, [
|
|
|
|
{
|
|
|
|
type: AuthProviderType.LOCAL
|
|
|
|
}
|
|
|
|
])
|
2023-09-24 17:37:03 -04:00
|
|
|
cy.getByCypressId('sign-in-button')
|
|
|
|
.should('be.visible')
|
|
|
|
.parent()
|
|
|
|
.should('have.attr', 'href', '/login?redirectBackTo=/history')
|
2021-03-09 17:00:14 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('sign-in button points to login route: ldap', () => {
|
2022-04-15 17:03:15 -04:00
|
|
|
initLoggedOutTestWithCustomAuthProviders(cy, [
|
|
|
|
{
|
|
|
|
type: AuthProviderType.LDAP,
|
|
|
|
identifier: 'cy-ldap',
|
|
|
|
providerName: 'cy LDAP'
|
|
|
|
}
|
|
|
|
])
|
2023-09-24 17:37:03 -04:00
|
|
|
cy.getByCypressId('sign-in-button')
|
|
|
|
.should('be.visible')
|
|
|
|
.parent()
|
|
|
|
.should('have.attr', 'href', '/login?redirectBackTo=/history')
|
2021-03-09 17:00:14 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('and only one one-click auth-provider is enabled, ', () => {
|
|
|
|
it('sign-in button points to auth-provider', () => {
|
2022-04-15 17:03:15 -04:00
|
|
|
initLoggedOutTestWithCustomAuthProviders(cy, [
|
|
|
|
{
|
|
|
|
type: AuthProviderType.GITHUB
|
|
|
|
}
|
|
|
|
])
|
2021-12-25 10:44:24 -05:00
|
|
|
cy.getByCypressId('sign-in-button')
|
2021-03-09 17:00:14 -05:00
|
|
|
.should('be.visible')
|
2022-12-09 13:35:40 -05:00
|
|
|
.parent()
|
2021-03-09 17:00:14 -05:00
|
|
|
// The absolute URL is used because it is defined as API base URL absolute.
|
2022-04-15 17:03:15 -04:00
|
|
|
.should('have.attr', 'href', '/auth/github')
|
2021-03-09 17:00:14 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('and multiple one-click auth-providers are enabled, ', () => {
|
|
|
|
it('sign-in button points to login route', () => {
|
2022-04-15 17:03:15 -04:00
|
|
|
initLoggedOutTestWithCustomAuthProviders(cy, [
|
|
|
|
{
|
|
|
|
type: AuthProviderType.GITHUB
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: AuthProviderType.GOOGLE
|
|
|
|
}
|
|
|
|
])
|
2023-09-24 17:37:03 -04:00
|
|
|
cy.getByCypressId('sign-in-button')
|
|
|
|
.should('be.visible')
|
|
|
|
.parent()
|
|
|
|
.should('have.attr', 'href', '/login?redirectBackTo=/history')
|
2021-03-09 17:00:14 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('and one-click- as well as interactive auth-providers are enabled, ', () => {
|
|
|
|
it('sign-in button points to login route', () => {
|
2022-04-15 17:03:15 -04:00
|
|
|
initLoggedOutTestWithCustomAuthProviders(cy, [
|
|
|
|
{
|
|
|
|
type: AuthProviderType.GITHUB
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: AuthProviderType.LOCAL
|
|
|
|
}
|
|
|
|
])
|
2023-09-24 17:37:03 -04:00
|
|
|
cy.getByCypressId('sign-in-button')
|
|
|
|
.should('be.visible')
|
|
|
|
.parent()
|
|
|
|
.should('have.attr', 'href', '/login?redirectBackTo=/history')
|
2021-03-09 17:00:14 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|