2024-08-29 11:56:28 +02:00
|
|
|
import { auth } from '../support'
|
2021-02-04 10:53:00 +01:00
|
|
|
|
2024-08-29 11:56:28 +02:00
|
|
|
describe('Auth', () => {
|
2020-05-22 18:34:48 +02:00
|
|
|
it('Logout', () => {
|
2024-08-29 11:56:28 +02:00
|
|
|
auth.logout()
|
2020-05-22 18:34:48 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Logout and login', () => {
|
2024-08-29 11:56:28 +02:00
|
|
|
auth.logout()
|
2020-05-22 18:34:48 +02:00
|
|
|
|
2022-11-02 15:57:29 +01:00
|
|
|
cy.get('[data-attr=login-email]').type('test@posthog.com').should('have.value', 'test@posthog.com').blur()
|
2022-03-23 18:58:08 +01:00
|
|
|
cy.get('[data-attr=password]', { timeout: 5000 }).should('be.visible') // Wait for login precheck (note blur above)
|
2020-05-22 18:34:48 +02:00
|
|
|
|
2021-03-25 15:40:20 +01:00
|
|
|
cy.get('[data-attr=password]').type('12345678').should('have.value', '12345678')
|
2020-05-22 18:34:48 +02:00
|
|
|
|
2021-03-25 15:40:20 +01:00
|
|
|
cy.get('[type=submit]').click()
|
2022-11-02 15:57:29 +01:00
|
|
|
// Login should have succeeded
|
2024-01-15 10:31:54 +01:00
|
|
|
cy.location('pathname').should('eq', '/')
|
2020-05-22 18:34:48 +02:00
|
|
|
})
|
|
|
|
|
2023-03-10 11:15:42 +01:00
|
|
|
it('Logout and verify that Google login button has correct link', () => {
|
2024-08-29 11:56:28 +02:00
|
|
|
auth.logout()
|
2023-03-10 11:15:42 +01:00
|
|
|
|
|
|
|
cy.window().then((win) => {
|
|
|
|
win.POSTHOG_APP_CONTEXT.preflight.available_social_auth_providers = {
|
|
|
|
'google-oauth2': true,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.get('a[href="/login/google-oauth2/"').should('exist') // As of March 2023, the trailing slash really matters!
|
|
|
|
})
|
|
|
|
|
2022-11-02 15:57:29 +01:00
|
|
|
it('Try logging in improperly and then properly', () => {
|
2024-08-29 11:56:28 +02:00
|
|
|
auth.logout()
|
2020-05-22 18:34:48 +02:00
|
|
|
|
2022-11-02 15:57:29 +01:00
|
|
|
cy.get('[data-attr=login-email]').type('test@posthog.com').should('have.value', 'test@posthog.com').blur()
|
2022-03-23 18:58:08 +01:00
|
|
|
cy.get('[data-attr=password]', { timeout: 5000 }).should('be.visible') // Wait for login precheck (note blur above)
|
2021-03-25 15:40:20 +01:00
|
|
|
cy.get('[data-attr=password]').type('wrong password').should('have.value', 'wrong password')
|
|
|
|
cy.get('[type=submit]').click()
|
2022-11-02 15:57:29 +01:00
|
|
|
// There should be an error message now
|
2023-04-14 11:03:33 +02:00
|
|
|
cy.get('.LemonBanner').should('contain', 'Invalid email or password.')
|
2022-11-02 15:57:29 +01:00
|
|
|
// Now try with the right password
|
|
|
|
cy.get('[data-attr=password]').clear().type('12345678')
|
|
|
|
cy.get('[type=submit]').click()
|
|
|
|
// Login should have succeeded
|
2024-01-15 10:31:54 +01:00
|
|
|
cy.location('pathname').should('eq', '/')
|
2021-03-25 15:40:20 +01:00
|
|
|
})
|
2020-05-22 18:34:48 +02:00
|
|
|
|
2021-03-25 15:40:20 +01:00
|
|
|
it('Redirect to appropriate place after login', () => {
|
2024-08-29 11:56:28 +02:00
|
|
|
auth.logout()
|
2020-05-22 18:34:48 +02:00
|
|
|
|
2024-06-04 13:33:42 +02:00
|
|
|
cy.visit('/activity/explore')
|
2021-03-25 15:40:20 +01:00
|
|
|
cy.location('pathname').should('include', '/login') // Should be redirected to login because we're now logged out
|
|
|
|
|
2022-03-23 18:58:08 +01:00
|
|
|
cy.get('[data-attr=login-email]').type('test@posthog.com').blur()
|
|
|
|
cy.get('[data-attr=password]', { timeout: 5000 }).should('be.visible') // Wait for login precheck (note blur above)
|
2021-03-25 15:40:20 +01:00
|
|
|
cy.get('[data-attr=password]').type('12345678')
|
|
|
|
cy.get('[type=submit]').click()
|
|
|
|
|
2024-06-04 13:33:42 +02:00
|
|
|
cy.location('pathname').should('include', '/activity/explore')
|
2021-03-25 15:40:20 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Redirect to appropriate place after login with complex URL', () => {
|
2024-08-29 11:56:28 +02:00
|
|
|
auth.logout()
|
2021-03-25 15:40:20 +01:00
|
|
|
|
2022-03-11 15:06:23 +01:00
|
|
|
cy.visit('/insights?search=testString')
|
2021-03-25 15:40:20 +01:00
|
|
|
cy.location('pathname').should('include', '/login') // Should be redirected to login because we're now logged out
|
|
|
|
|
2022-03-23 18:58:08 +01:00
|
|
|
cy.get('[data-attr=login-email]').type('test@posthog.com').blur()
|
|
|
|
cy.get('[data-attr=password]', { timeout: 5000 }).should('be.visible') // Wait for login precheck (note blur above)
|
2021-03-25 15:40:20 +01:00
|
|
|
cy.get('[data-attr=password]').type('12345678')
|
|
|
|
cy.get('[type=submit]').click()
|
|
|
|
|
2022-03-11 15:06:23 +01:00
|
|
|
cy.location('search').should('include', 'testString')
|
|
|
|
cy.get('.saved-insight-empty-state').should('contain', 'testString') // Ensure the URL was properly parsed and components shown correctly
|
2021-03-25 15:40:20 +01:00
|
|
|
})
|
2020-05-22 18:34:48 +02:00
|
|
|
|
2021-03-25 15:40:20 +01:00
|
|
|
it('Cannot access signup page if authenticated', () => {
|
|
|
|
cy.visit('/signup')
|
2024-01-15 10:31:54 +01:00
|
|
|
cy.location('pathname').should('eq', '/project/1')
|
2020-05-22 18:34:48 +02:00
|
|
|
})
|
|
|
|
})
|