Skip to content

Commit

Permalink
fix: don't require a parameter in /address, add tests
Browse files Browse the repository at this point in the history
`addressAndNetworkUrl` was removed in 60296ef
  • Loading branch information
davidyuk committed Feb 14, 2025
1 parent b6277aa commit 5fbf38e
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/store/plugins/ui/urlRequestHandler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { times } from 'lodash-es';
import { ensureLoggedIn, mergeEnterHandlers } from '../../../router/utils';

const urlRequestMethods = ['address', 'addressAndNetworkUrl', 'sign', 'signTransaction'];
const urlRequestMethods = ['address', 'sign', 'signTransaction'];

export default (store) => {
const handleUrlRequest = async (url) => {
Expand All @@ -10,7 +10,8 @@ export default (store) => {
const lastParamIdx = Math.max(
-1,
...Array.from(Object.keys(url.query))
.map((key) => key.startsWith('param') && +key.replace('param', '')),
.filter((key) => key.startsWith('param'))
.map((key) => +key.replace('param', '')),
);
const params = times(
lastParamIdx + 1,
Expand Down
125 changes: 125 additions & 0 deletions tests/e2e/specs/deep-links.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { verify } from '@aeternity/aepp-sdk-next';

describe('Deep links', () => {
const signer = 'ak_2ujJ8N4GdKapdE2a7aEy4Da3pfPdV7EtJdaA7BUpJ8uqgkQdEB';

describe('Get address', () => {
it('returns', () => {
const url = new URL('http://localhost/address');
url.searchParams.append('callback', 'http://faucet.aepps.com');
cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), {
login: 'wallet-empty',
});
const button = cy.get('button').contains('Allow').should('be.visible');
cy.matchImage();
button.click();

cy.url()
.should('contain', 'faucet.aepps.com')
.then((u) => {
const resultUrl = new URL(u);
const result = JSON.parse(decodeURIComponent(resultUrl.searchParams.get('result')));
expect(result).to.equal(signer);
});
});

it('returns if allowed before', () => {
const url = new URL('http://localhost/address');
url.searchParams.append('callback', 'http://faucet.aepps.com');
cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), {
login: 'wallet-empty',
state: {
apps: [
{
host: 'faucet.aepps.com',
permissions: {
accessToAccounts: [signer],
},
},
],
},
});

cy.url()
.should('contain', 'faucet.aepps.com')
.then((u) => {
const resultUrl = new URL(u);
const result = JSON.parse(decodeURIComponent(resultUrl.searchParams.get('result')));
expect(result).to.equal(signer);
});
});

it('redirects if selected correct account', () => {
const url = new URL('http://localhost/address');
const signer2 = 'ak_2Mz7EqTRdmGfns7fvLYfLFLoKyXj8jbfHbfwERfwFZgoZs4Z3T';
url.searchParams.append('callback', 'http://faucet.aepps.com');
cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), {
login: 'wallet-empty',
state: {
apps: [
{
host: 'faucet.aepps.com',
permissions: {
accessToAccounts: [signer2],
},
},
],
},
});
cy.get('button').contains('Allow').should('be.visible');
cy.get('.tab-bar .ae-identicon').last().click();
cy.get('.account-switcher-modal .list-item').contains('Account #2').click();

cy.url()
.should('contain', 'faucet.aepps.com')
.then((u) => {
const resultUrl = new URL(u);
const result = JSON.parse(decodeURIComponent(resultUrl.searchParams.get('result')));
expect(result).to.equal(signer2);
});
});

it('cancels', () => {
const url = new URL('http://localhost/address');
url.searchParams.append('callback', 'about:blank');
cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), { login: true });
cy.get('button').contains('Deny').click();
cy.url().should('equal', 'about:blank?error=Rejected+by+user');
});
});

describe('Sign raw data', () => {
const data = 'test';

it('signs', () => {
const url = new URL('http://localhost/sign');
url.searchParams.append('param0', `"${data}"`);
url.searchParams.append('callback', 'about:blank');
cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), {
login: 'wallet-empty',
});
const button = cy.get('button').contains('Confirm').should('be.visible');
cy.matchImage();
button.click();

cy.url()
.should('contain', 'about:blank')
.then((u) => {
const resultUrl = new URL(u);
const signature = Buffer.from(
Object.values(JSON.parse(decodeURIComponent(resultUrl.searchParams.get('result')))),
);
expect(verify(Buffer.from(data), signature, signer)).to.equal(true);
});
});

it('cancels', () => {
const url = new URL('http://localhost/sign');
url.searchParams.append('param0', `"${data}"`);
url.searchParams.append('callback', 'about:blank');
cy.viewport('iphone-se2').visit(url.href.replace('http://localhost', ''), { login: true });
cy.get('button').contains('Cancel').click();
cy.url().should('equal', 'about:blank?error=Rejected+by+user');
});
});
});

0 comments on commit 5fbf38e

Please sign in to comment.