-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: if POST /validate-email?mode=authorize catches error w/ too big…
- Loading branch information
Showing
3 changed files
with
74 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { context } from './helpers/context.js' | ||
import * as assert from 'assert' | ||
import { Delegation } from '@ucanto/core' | ||
import { Access } from '@web3-storage/capabilities' | ||
import { delegationToString } from '@web3-storage/access/encoding' | ||
import { getRandomValues } from 'crypto' | ||
|
||
describe('validate-email', () => { | ||
it('can POST /validate-email?mode=authorize', async () => { | ||
const { mf, service, issuer: agent } = await context() | ||
const accountDid = /** @type {const} */ (`did:mailto:dag.house:foo`) | ||
// add extra bytes to make it really big | ||
// and maybe trigger errors encoding big things | ||
const extraBytes = getRandomValues(new Uint8Array(10 * 1024)) | ||
const ucan = await Delegation.delegate({ | ||
issuer: service, | ||
audience: agent, | ||
capabilities: [ | ||
Access.confirm.create({ | ||
with: service.did(), | ||
nb: { | ||
iss: accountDid, | ||
aud: agent.did(), | ||
att: [ | ||
{ can: '*' }, | ||
// validate-email may pass this value unmodified into qr | ||
{ | ||
can: `data:text/plain;base64,${btoa( | ||
String.fromCodePoint(...extraBytes) | ||
)}`, | ||
}, | ||
], | ||
}, | ||
}), | ||
], | ||
}) | ||
const validateEmailUrl = (() => { | ||
const url = new URL(`http://localhost:8787/validate-email`) | ||
url.searchParams.set('mode', 'authorize') | ||
url.searchParams.set('ucan', delegationToString(ucan)) | ||
return url | ||
})() | ||
const response = await mf.dispatchFetch(validateEmailUrl, { | ||
method: 'post', | ||
}) | ||
assert.deepEqual(response.status, 200) | ||
}) | ||
}) |