|
| 1 | +import { verify } from '@aeternity/aepp-sdk-next'; |
| 2 | + |
| 3 | +describe('Deep links', () => { |
| 4 | + const signer = 'ak_2ujJ8N4GdKapdE2a7aEy4Da3pfPdV7EtJdaA7BUpJ8uqgkQdEB'; |
| 5 | + |
| 6 | + describe('Get address', () => { |
| 7 | + it('returns', () => { |
| 8 | + const url = new URL('http://localhost/address'); |
| 9 | + url.searchParams.append('callback', 'http://faucet.aepps.com'); |
| 10 | + cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), { |
| 11 | + login: 'wallet-empty', |
| 12 | + }); |
| 13 | + const button = cy.get('button').contains('Allow').should('be.visible'); |
| 14 | + cy.get('.confirm-account-access img').should(($img) => { |
| 15 | + expect($img[0].naturalWidth).to.be.greaterThan(0); |
| 16 | + }); |
| 17 | + cy.matchImage(); |
| 18 | + button.click(); |
| 19 | + |
| 20 | + cy.url() |
| 21 | + .should('contain', 'faucet.aepps.com') |
| 22 | + .then((u) => { |
| 23 | + const resultUrl = new URL(u); |
| 24 | + const result = JSON.parse(decodeURIComponent(resultUrl.searchParams.get('result'))); |
| 25 | + expect(result).to.equal(signer); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + it('returns if allowed before', () => { |
| 30 | + const url = new URL('http://localhost/address'); |
| 31 | + url.searchParams.append('callback', 'http://faucet.aepps.com'); |
| 32 | + cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), { |
| 33 | + login: 'wallet-empty', |
| 34 | + state: { |
| 35 | + apps: [ |
| 36 | + { |
| 37 | + host: 'faucet.aepps.com', |
| 38 | + permissions: { |
| 39 | + accessToAccounts: [signer], |
| 40 | + }, |
| 41 | + }, |
| 42 | + ], |
| 43 | + }, |
| 44 | + }); |
| 45 | + |
| 46 | + cy.url() |
| 47 | + .should('contain', 'faucet.aepps.com') |
| 48 | + .then((u) => { |
| 49 | + const resultUrl = new URL(u); |
| 50 | + const result = JSON.parse(decodeURIComponent(resultUrl.searchParams.get('result'))); |
| 51 | + expect(result).to.equal(signer); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it('redirects if selected correct account', () => { |
| 56 | + const url = new URL('http://localhost/address'); |
| 57 | + const signer2 = 'ak_2Mz7EqTRdmGfns7fvLYfLFLoKyXj8jbfHbfwERfwFZgoZs4Z3T'; |
| 58 | + url.searchParams.append('callback', 'http://faucet.aepps.com'); |
| 59 | + cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), { |
| 60 | + login: 'wallet-empty', |
| 61 | + state: { |
| 62 | + apps: [ |
| 63 | + { |
| 64 | + host: 'faucet.aepps.com', |
| 65 | + permissions: { |
| 66 | + accessToAccounts: [signer2], |
| 67 | + }, |
| 68 | + }, |
| 69 | + ], |
| 70 | + }, |
| 71 | + }); |
| 72 | + cy.get('button').contains('Allow').should('be.visible'); |
| 73 | + cy.get('.tab-bar .ae-identicon').last().click(); |
| 74 | + cy.get('.account-switcher-modal .list-item').contains('Account #2').click(); |
| 75 | + |
| 76 | + cy.url() |
| 77 | + .should('contain', 'faucet.aepps.com') |
| 78 | + .then((u) => { |
| 79 | + const resultUrl = new URL(u); |
| 80 | + const result = JSON.parse(decodeURIComponent(resultUrl.searchParams.get('result'))); |
| 81 | + expect(result).to.equal(signer2); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + it('cancels', () => { |
| 86 | + const url = new URL('http://localhost/address'); |
| 87 | + url.searchParams.append('callback', 'about:blank'); |
| 88 | + cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), { login: true }); |
| 89 | + cy.get('button').contains('Deny').click(); |
| 90 | + cy.url().should('equal', 'about:blank?error=Rejected+by+user'); |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + describe('Sign raw data', () => { |
| 95 | + const data = 'test'; |
| 96 | + |
| 97 | + it('signs', () => { |
| 98 | + const url = new URL('http://localhost/sign'); |
| 99 | + url.searchParams.append('param0', `"${data}"`); |
| 100 | + url.searchParams.append('callback', 'about:blank'); |
| 101 | + cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), { |
| 102 | + login: 'wallet-empty', |
| 103 | + }); |
| 104 | + const button = cy.get('button').contains('Confirm').should('be.visible'); |
| 105 | + cy.matchImage(); |
| 106 | + button.click(); |
| 107 | + |
| 108 | + cy.url() |
| 109 | + .should('contain', 'about:blank') |
| 110 | + .then((u) => { |
| 111 | + const resultUrl = new URL(u); |
| 112 | + const signature = Buffer.from( |
| 113 | + Object.values(JSON.parse(decodeURIComponent(resultUrl.searchParams.get('result')))), |
| 114 | + ); |
| 115 | + expect(verify(Buffer.from(data), signature, signer)).to.equal(true); |
| 116 | + }); |
| 117 | + }); |
| 118 | + |
| 119 | + it('cancels', () => { |
| 120 | + const url = new URL('http://localhost/sign'); |
| 121 | + url.searchParams.append('param0', `"${data}"`); |
| 122 | + url.searchParams.append('callback', 'about:blank'); |
| 123 | + cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), { login: true }); |
| 124 | + cy.get('button').contains('Cancel').click(); |
| 125 | + cy.url().should('equal', 'about:blank?error=Rejected+by+user'); |
| 126 | + }); |
| 127 | + }); |
| 128 | +}); |
0 commit comments