Skip to content

Commit

Permalink
test TOS hash is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
finn-block committed Nov 17, 2023
1 parent 01b27fc commit 2e88e2c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/http-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,45 @@ describe('http api', function () {
expect(response.body.id).to.equal(requestId);
expect(response.body.result.reply.status.code).to.equal(401);
});

it('rejects TOS acceptance with incorrect hash', async function () {
const hash = createHash('sha256');
hash.update('i do not agree');

const p = await createProfile();

const acceptResponse = await fetch('http://localhost:3000/register/tos', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
did: p.did,
tosHash: hash.digest('hex'),
}),
});
expect(acceptResponse.status).to.equal(400);
await tenantGate.authorizeTenantPOW(p.did);

const recordsQuery = await RecordsQuery.create({
filter: { schema: 'woosa' },
signer: p.signer,
});

const requestId = uuidv4();
const dwnRequest = createJsonRpcRequest(requestId, 'dwn.processMessage', {
message: recordsQuery.toJSON(),
target: p.did,
});

const rpcResponse = await request(httpApi.api)
.post('/')
.set('dwn-request', JSON.stringify(dwnRequest))
.send();

console.log(rpcResponse.body.result.reply.status);
expect(rpcResponse.statusCode).to.equal(200);
expect(rpcResponse.body.id).to.equal(requestId);
expect(rpcResponse.body.result.reply.status.code).to.equal(401);
});
});

describe('/ (rpc)', function () {
Expand Down

0 comments on commit 2e88e2c

Please sign in to comment.