|
| 1 | +describe('Authentication Redirects', () => { |
| 2 | + beforeEach(() => { |
| 3 | + cy.clearCookies(); |
| 4 | + cy.clearLocalStorage(); |
| 5 | + }); |
| 6 | + |
| 7 | + it('should redirect to profile page after login', () => { |
| 8 | + cy.visit('http://localhost:3007'); |
| 9 | + cy.wait(3000); |
| 10 | + |
| 11 | + cy.contains('Sign in').click(); |
| 12 | + |
| 13 | + let user; |
| 14 | + let challenge; |
| 15 | + let token; |
| 16 | + let info; |
| 17 | + |
| 18 | + cy.fixture('nodes.json').then((json) => { |
| 19 | + user = json[0]; |
| 20 | + const userAlias = user.alias; |
| 21 | + |
| 22 | + cy.get('[data-challenge]') |
| 23 | + .invoke('attr', 'data-challenge') |
| 24 | + .then((value) => { |
| 25 | + const array = value?.split('&'); |
| 26 | + if (array && array.length === 4) { |
| 27 | + challenge = array[2].substring(10); |
| 28 | + } |
| 29 | + }); |
| 30 | + |
| 31 | + cy.request({ |
| 32 | + method: 'POST', |
| 33 | + url: `${user.external_ip}/verify_external`, |
| 34 | + headers: { |
| 35 | + 'x-user-token': `${user.authToken}` |
| 36 | + } |
| 37 | + }).then((response) => { |
| 38 | + ({ token } = response.body.response); |
| 39 | + ({ info } = response.body.response); |
| 40 | + }); |
| 41 | + |
| 42 | + cy.request({ |
| 43 | + method: 'GET', |
| 44 | + url: `${user.external_ip}/signer/U98BoaW54IFZlcmlmaWNhdGlvbg==`, |
| 45 | + headers: { |
| 46 | + 'x-user-token': `${user.authToken}` |
| 47 | + } |
| 48 | + }).then((response) => { |
| 49 | + info.url = `${user.external_ip}`; |
| 50 | + info['verification_signature'] = response.body.response.sig; |
| 51 | + |
| 52 | + cy.request({ |
| 53 | + method: 'POST', |
| 54 | + url: `http://localhost:13000/verify/${challenge}?token=${token}`, |
| 55 | + body: info |
| 56 | + }); |
| 57 | + |
| 58 | + cy.url().should('include', '/p/').and('include', '/workspaces'); |
| 59 | + cy.contains(userAlias).should('exist'); |
| 60 | + }); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should redirect to homepage after logout', () => { |
| 65 | + cy.fixture('nodes.json').then((json) => { |
| 66 | + const user = json[0]; |
| 67 | + cy.login(user.alias); |
| 68 | + |
| 69 | + cy.visit(`http://localhost:3007/p/${user.pubkey}/workspaces`); |
| 70 | + |
| 71 | + cy.contains(user.alias).click(); |
| 72 | + |
| 73 | + cy.contains('Sign out').click(); |
| 74 | + |
| 75 | + cy.url().should('eq', 'http://localhost:3007/'); |
| 76 | + |
| 77 | + cy.contains('Sign in').should('be.visible'); |
| 78 | + }); |
| 79 | + }); |
| 80 | +}); |
0 commit comments