Skip to content

Commit

Permalink
Remove did from signature submission in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Jan 10, 2025
1 parent e7adda8 commit 13d6b2d
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 180 deletions.
115 changes: 54 additions & 61 deletions tests/resource/02-createResource.spec.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,69 @@
import { test, expect } from '@playwright/test';
import { sign } from '@stablelib/ed25519';
import { toString, fromString } from 'uint8arrays';
import { toString } from 'uint8arrays';
import { getDidDocument, privKeyBytes, setResourceId } from 'fixtures';

let didUrlState;
let resourceJobId;
test.describe('Resource creat workflow', () => {
let didUrlState;
let resourceJobId;

test('resource-create. Initiate Resource creation procedure', async ({ request }) => {
const didPayload = getDidDocument();
const payload = await request.post(`/1.0/createResource`, {
data: {
did: didPayload.id,
content: 'SGVsbG8gV29ybGQ=',
name: 'ResourceName',
type: 'TextDocument',
version: '1.0',
options: {
network: 'testnet',
test('resource-create. Initiate Resource creation procedure', async ({ request }) => {
const didPayload = getDidDocument();
const payload = await request.post(`/1.0/createResource`, {
data: {
did: didPayload.id,
content: 'SGVsbG8gV29ybGQ=',
name: 'ResourceName',
type: 'TextDocument',
version: '1.0',
options: {
network: 'testnet',
},
},
},
});
});

expect(payload.status()).toBe(200);
expect(payload.status()).toBe(200);

const body = await payload.json();
expect(body.didUrlState).toBeDefined();
expect(body.didUrlState.didUrl).toBeDefined();
expect(body.didUrlState.state).toBeDefined();
expect(body.didUrlState.signingRequest).toBeDefined();
const body = await payload.json();
expect(body.didUrlState).toBeDefined();
expect(body.didUrlState.didUrl).toBeDefined();
expect(body.didUrlState.state).toBeDefined();
expect(body.didUrlState.signingRequest).toBeDefined();

didUrlState = body.didUrlState;
resourceJobId = body.jobId;
});
didUrlState = body.didUrlState;
resourceJobId = body.jobId;
});

test('resource-create. Send the final request for Resource creation', async ({ request }) => {
const didPayload = getDidDocument();
const serializedPayload = didUrlState.signingRequest[0].serializedPayload;
const serializedBytes = Buffer.from(serializedPayload, 'base64');
const signature = sign(privKeyBytes, serializedBytes);
test('resource-create. Send the final request for Resource creation', async ({ request }) => {
const serializedPayload = didUrlState.signingRequest[0].serializedPayload;

Check failure on line 38 in tests/resource/02-createResource.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Integration tests] › resource/02-createResource.spec.ts:37:2 › Resource creat workflow › resource-create. Send the final request for Resource creation

1) [Integration tests] › resource/02-createResource.spec.ts:37:2 › Resource creat workflow › resource-create. Send the final request for Resource creation Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TypeError: Cannot read properties of undefined (reading 'signingRequest') 36 | 37 | test('resource-create. Send the final request for Resource creation', async ({ request }) => { > 38 | const serializedPayload = didUrlState.signingRequest[0].serializedPayload; | ^ 39 | const serializedBytes = Buffer.from(serializedPayload, 'base64'); 40 | const signature = sign(privKeyBytes, serializedBytes); 41 | at /home/runner/work/did-registrar/did-registrar/tests/resource/02-createResource.spec.ts:38:41

Check failure on line 38 in tests/resource/02-createResource.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Integration tests] › resource/02-createResource.spec.ts:37:2 › Resource creat workflow › resource-create. Send the final request for Resource creation

1) [Integration tests] › resource/02-createResource.spec.ts:37:2 › Resource creat workflow › resource-create. Send the final request for Resource creation Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TypeError: Cannot read properties of undefined (reading 'signingRequest') 36 | 37 | test('resource-create. Send the final request for Resource creation', async ({ request }) => { > 38 | const serializedPayload = didUrlState.signingRequest[0].serializedPayload; | ^ 39 | const serializedBytes = Buffer.from(serializedPayload, 'base64'); 40 | const signature = sign(privKeyBytes, serializedBytes); 41 | at /home/runner/work/did-registrar/did-registrar/tests/resource/02-createResource.spec.ts:38:41
const serializedBytes = Buffer.from(serializedPayload, 'base64');
const signature = sign(privKeyBytes, serializedBytes);

const secret = {
signingResponse: [
{
kid: didUrlState.signingRequest[0].kid,
signature: toString(signature, 'base64'),
},
],
};
const secret = {
signingResponse: [
{
kid: didUrlState.signingRequest[0].kid,
signature: toString(signature, 'base64'),
},
],
};

const resourceCreate = await request.post(`/1.0/createResource`, {
data: {
did: didPayload.id,
content: 'SGVsbG8gV29ybGQ=',
name: 'ResourceName',
type: 'TextDocument',
version: '1.0',
jobId: resourceJobId,
secret: secret,
options: {
network: 'testnet',
const resourceCreate = await request.post(`/1.0/createResource`, {
data: {
jobId: resourceJobId,
secret: secret,
},
},
});
const response = await resourceCreate.json();
expect(resourceCreate.status()).toBe(201);

Check failure on line 58 in tests/resource/02-createResource.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Integration tests] › resource/02-createResource.spec.ts:37:2 › Resource creat workflow › resource-create. Send the final request for Resource creation

1) [Integration tests] › resource/02-createResource.spec.ts:37:2 › Resource creat workflow › resource-create. Send the final request for Resource creation Error: expect(received).toBe(expected) // Object.is equality Expected: 201 Received: 400 56 | }); 57 | const response = await resourceCreate.json(); > 58 | expect(resourceCreate.status()).toBe(201); | ^ 59 | expect(response.didUrlState).toBeDefined(); 60 | expect(response.didUrlState.didUrl).toBeDefined(); 61 | expect(response.didUrlState.state).toBeDefined(); at /home/runner/work/did-registrar/did-registrar/tests/resource/02-createResource.spec.ts:58:35
expect(response.didUrlState).toBeDefined();
expect(response.didUrlState.didUrl).toBeDefined();
expect(response.didUrlState.state).toBeDefined();
expect(response.didUrlState.state).toEqual('finished');
expect(response.didUrlState.name).toEqual('ResourceName');
expect(response.didUrlState.type).toEqual('TextDocument');
expect(response.didUrlState.version).toEqual('1.0');
console.log('DIDUrl:' + response.didUrlState.didUrl);
setResourceId(response.didUrlState.didUrl.split('/resources/')[1]);
});
const response = await resourceCreate.json();
expect(resourceCreate.status()).toBe(201);
expect(response.didUrlState).toBeDefined();
expect(response.didUrlState.didUrl).toBeDefined();
expect(response.didUrlState.state).toBeDefined();
expect(response.didUrlState.state).toEqual('finished');
expect(response.didUrlState.name).toEqual('ResourceName');
expect(response.didUrlState.type).toEqual('TextDocument');
expect(response.didUrlState.version).toEqual('1.0');
console.log('DIDUrl:' + response.didUrlState.didUrl);
setResourceId(response.didUrlState.didUrl.split('/resources/')[1]);
});
229 changes: 110 additions & 119 deletions tests/resource/03-updateResource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,139 +3,130 @@ import { sign } from '@stablelib/ed25519';
import { toString, fromString } from 'uint8arrays';
import { getDidDocument, getResourceId, privKeyBytes } from 'fixtures';

let didUrlState;
let resourceJobId;

test('resource-update. Initiate Resource update procedure', async ({ request }) => {
const didPayload = getDidDocument();
const resourceId = getResourceId();
const payload = await request.post(`/1.0/updateResource`, {
data: {
did: didPayload.id,
name: 'ResourceName',
type: 'TextDocument',
content: ['SGVsbG8gV29ybGQ='],
version: '2.0',
relativeDidUrl: '/resources/' + resourceId,
options: {
network: 'testnet',
test.describe('Resource update using relative url', () => {
let didUrlState;
let resourceJobId;

test('resource-update. Initiate Resource update procedure', async ({ request }) => {
const didPayload = getDidDocument();
const resourceId = getResourceId();
const payload = await request.post(`/1.0/updateResource`, {
data: {
did: didPayload.id,

Check failure on line 15 in tests/resource/03-updateResource.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Integration tests] › resource/03-updateResource.spec.ts:10:2 › Resource update using relative url › resource-update. Initiate Resource update procedure

2) [Integration tests] › resource/03-updateResource.spec.ts:10:2 › Resource update using relative url › resource-update. Initiate Resource update procedure TypeError: Cannot read properties of undefined (reading 'id') 13 | const payload = await request.post(`/1.0/updateResource`, { 14 | data: { > 15 | did: didPayload.id, | ^ 16 | name: 'ResourceName', 17 | type: 'TextDocument', 18 | content: ['SGVsbG8gV29ybGQ='], at /home/runner/work/did-registrar/did-registrar/tests/resource/03-updateResource.spec.ts:15:21

Check failure on line 15 in tests/resource/03-updateResource.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Integration tests] › resource/03-updateResource.spec.ts:10:2 › Resource update using relative url › resource-update. Initiate Resource update procedure

2) [Integration tests] › resource/03-updateResource.spec.ts:10:2 › Resource update using relative url › resource-update. Initiate Resource update procedure Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TypeError: Cannot read properties of undefined (reading 'id') 13 | const payload = await request.post(`/1.0/updateResource`, { 14 | data: { > 15 | did: didPayload.id, | ^ 16 | name: 'ResourceName', 17 | type: 'TextDocument', 18 | content: ['SGVsbG8gV29ybGQ='], at /home/runner/work/did-registrar/did-registrar/tests/resource/03-updateResource.spec.ts:15:21

Check failure on line 15 in tests/resource/03-updateResource.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Integration tests] › resource/03-updateResource.spec.ts:10:2 › Resource update using relative url › resource-update. Initiate Resource update procedure

2) [Integration tests] › resource/03-updateResource.spec.ts:10:2 › Resource update using relative url › resource-update. Initiate Resource update procedure Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TypeError: Cannot read properties of undefined (reading 'id') 13 | const payload = await request.post(`/1.0/updateResource`, { 14 | data: { > 15 | did: didPayload.id, | ^ 16 | name: 'ResourceName', 17 | type: 'TextDocument', 18 | content: ['SGVsbG8gV29ybGQ='], at /home/runner/work/did-registrar/did-registrar/tests/resource/03-updateResource.spec.ts:15:21
name: 'ResourceName',
type: 'TextDocument',
content: ['SGVsbG8gV29ybGQ='],
version: '2.0',
relativeDidUrl: '/resources/' + resourceId,
options: {
network: 'testnet',
},
},
},
});
});

expect(payload.status()).toBe(200);
expect(payload.status()).toBe(200);

const body = await payload.json();
expect(body.didUrlState).toBeDefined();
expect(body.didUrlState.didUrl).toBeDefined();
expect(body.didUrlState.state).toBeDefined();
expect(body.didUrlState.signingRequest).toBeDefined();
const body = await payload.json();
expect(body.didUrlState).toBeDefined();
expect(body.didUrlState.didUrl).toBeDefined();
expect(body.didUrlState.state).toBeDefined();
expect(body.didUrlState.signingRequest).toBeDefined();

didUrlState = body.didUrlState;
resourceJobId = body.jobId;
});
didUrlState = body.didUrlState;
resourceJobId = body.jobId;
});

test('resource-update. Send the final request for Resource update', async ({ request }) => {
const didPayload = getDidDocument();
const resourceId = getResourceId();
const serializedPayload = didUrlState.signingRequest[0].serializedPayload;
const serializedBytes = Buffer.from(serializedPayload, 'base64');
const signature = sign(privKeyBytes, serializedBytes);

const secret = {
signingResponse: [
{
kid: didUrlState.signingRequest[0].kid,
signature: toString(signature, 'base64'),
},
],
};

const resourceUpdate = await request.post(`/1.0/updateResource`, {
data: {
did: didPayload.id,
content: ['SGVsbG8gV29ybGQ='],
name: 'ResourceName',
type: 'TextDocument',
version: '1.0',
jobId: resourceJobId,
relativeDidUrl: '/resources/' + resourceId,
secret: secret,
options: {
network: 'testnet',
test('resource-update. Send the final request for Resource update', async ({ request }) => {
const serializedPayload = didUrlState.signingRequest[0].serializedPayload;

Check failure on line 40 in tests/resource/03-updateResource.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Integration tests] › resource/03-updateResource.spec.ts:39:2 › Resource update using relative url › resource-update. Send the final request for Resource update

3) [Integration tests] › resource/03-updateResource.spec.ts:39:2 › Resource update using relative url › resource-update. Send the final request for Resource update TypeError: Cannot read properties of undefined (reading 'signingRequest') 38 | 39 | test('resource-update. Send the final request for Resource update', async ({ request }) => { > 40 | const serializedPayload = didUrlState.signingRequest[0].serializedPayload; | ^ 41 | const serializedBytes = Buffer.from(serializedPayload, 'base64'); 42 | const signature = sign(privKeyBytes, serializedBytes); 43 | at /home/runner/work/did-registrar/did-registrar/tests/resource/03-updateResource.spec.ts:40:41

Check failure on line 40 in tests/resource/03-updateResource.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Integration tests] › resource/03-updateResource.spec.ts:39:2 › Resource update using relative url › resource-update. Send the final request for Resource update

3) [Integration tests] › resource/03-updateResource.spec.ts:39:2 › Resource update using relative url › resource-update. Send the final request for Resource update Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TypeError: Cannot read properties of undefined (reading 'signingRequest') 38 | 39 | test('resource-update. Send the final request for Resource update', async ({ request }) => { > 40 | const serializedPayload = didUrlState.signingRequest[0].serializedPayload; | ^ 41 | const serializedBytes = Buffer.from(serializedPayload, 'base64'); 42 | const signature = sign(privKeyBytes, serializedBytes); 43 | at /home/runner/work/did-registrar/did-registrar/tests/resource/03-updateResource.spec.ts:40:41

Check failure on line 40 in tests/resource/03-updateResource.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Integration tests] › resource/03-updateResource.spec.ts:39:2 › Resource update using relative url › resource-update. Send the final request for Resource update

3) [Integration tests] › resource/03-updateResource.spec.ts:39:2 › Resource update using relative url › resource-update. Send the final request for Resource update Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TypeError: Cannot read properties of undefined (reading 'signingRequest') 38 | 39 | test('resource-update. Send the final request for Resource update', async ({ request }) => { > 40 | const serializedPayload = didUrlState.signingRequest[0].serializedPayload; | ^ 41 | const serializedBytes = Buffer.from(serializedPayload, 'base64'); 42 | const signature = sign(privKeyBytes, serializedBytes); 43 | at /home/runner/work/did-registrar/did-registrar/tests/resource/03-updateResource.spec.ts:40:41
const serializedBytes = Buffer.from(serializedPayload, 'base64');
const signature = sign(privKeyBytes, serializedBytes);

const secret = {
signingResponse: [
{
kid: didUrlState.signingRequest[0].kid,
signature: toString(signature, 'base64'),
},
],
};

const resourceUpdate = await request.post(`/1.0/updateResource`, {
data: {
jobId: resourceJobId,
secret: secret,
},
},
});
const response = await resourceUpdate.json();
expect(resourceUpdate.status()).toBe(201);
expect(response.didUrlState).toBeDefined();
expect(response.didUrlState.didUrl).toBeDefined();
expect(response.didUrlState.state).toBeDefined();
expect(response.didUrlState.state).toEqual('finished');
expect(response.didUrlState.name).toEqual('ResourceName');
expect(response.didUrlState.type).toEqual('TextDocument');
expect(response.didUrlState.version).toEqual('2.0');
});
const response = await resourceUpdate.json();
expect(resourceUpdate.status()).toBe(201);
expect(response.didUrlState).toBeDefined();
expect(response.didUrlState.didUrl).toBeDefined();
expect(response.didUrlState.state).toBeDefined();
expect(response.didUrlState.state).toEqual('finished');
expect(response.didUrlState.name).toEqual('ResourceName');
expect(response.didUrlState.type).toEqual('TextDocument');
expect(response.didUrlState.version).toEqual('2.0');
});

test('resource-update. Resource update without relativeDidUrl', async ({ request }) => {
const didPayload = getDidDocument();
const payload = await request.post(`/1.0/updateResource`, {
data: {
did: didPayload.id,
name: 'ResourceName',
type: 'TextDocument',
content: ['SGVsbG8gV29ybGQ='],
version: '3.0',
options: {
network: 'testnet',
test.describe('Resource update with resource name and resource type', () => {
let didUrlState;
let resourceJobId;

test('resource-update. Resource update without relativeDidUrl', async ({ request }) => {
const didPayload = getDidDocument();
const payload = await request.post(`/1.0/updateResource`, {
data: {
did: didPayload.id,
name: 'ResourceName',
type: 'TextDocument',
content: ['SGVsbG8gV29ybGQ='],
version: '3.0',
options: {
network: 'testnet',
},
},
},
});
});

expect(payload.status()).toBe(200);
expect(payload.status()).toBe(200);

const body = await payload.json();
expect(body.didUrlState).toBeDefined();
expect(body.didUrlState.didUrl).toBeDefined();
expect(body.didUrlState.state).toBeDefined();
expect(body.didUrlState.signingRequest).toBeDefined();
const body = await payload.json();
expect(body.didUrlState).toBeDefined();
expect(body.didUrlState.didUrl).toBeDefined();
expect(body.didUrlState.state).toBeDefined();
expect(body.didUrlState.signingRequest).toBeDefined();

didUrlState = body.didUrlState;
resourceJobId = body.jobId;
});
didUrlState = body.didUrlState;
resourceJobId = body.jobId;
});

test('resource-update. Send the final update without relativeDidUrl', async ({ request }) => {
const didPayload = getDidDocument();
const serializedPayload = didUrlState.signingRequest[0].serializedPayload;
const serializedBytes = Buffer.from(serializedPayload, 'base64');
const signature = sign(privKeyBytes, serializedBytes);

const secret = {
signingResponse: [
{
kid: didUrlState.signingRequest[0].kid,
signature: toString(signature, 'base64'),
},
],
};

const resourceUpdate = await request.post(`/1.0/updateResource`, {
data: {
did: didPayload.id,
jobId: resourceJobId,
secret: secret,
options: {
network: 'testnet',
test('resource-update. Send the final update without relativeDidUrl', async ({ request }) => {
const serializedPayload = didUrlState.signingRequest[0].serializedPayload;
const serializedBytes = Buffer.from(serializedPayload, 'base64');
const signature = sign(privKeyBytes, serializedBytes);

const secret = {
signingResponse: [
{
kid: didUrlState.signingRequest[0].kid,
signature: toString(signature, 'base64'),
},
],
};

const resourceUpdate = await request.post(`/1.0/updateResource`, {
data: {
jobId: resourceJobId,
secret: secret,
},
},
});
const response = await resourceUpdate.json();
expect(resourceUpdate.status()).toBe(201);
expect(response.didUrlState).toBeDefined();
expect(response.didUrlState.didUrl).toBeDefined();
expect(response.didUrlState.state).toBeDefined();
expect(response.didUrlState.state).toEqual('finished');
expect(response.didUrlState.name).toEqual('ResourceName');
expect(response.didUrlState.type).toEqual('TextDocument');
expect(response.didUrlState.version).toEqual('3.0');
});
const response = await resourceUpdate.json();
expect(resourceUpdate.status()).toBe(201);
expect(response.didUrlState).toBeDefined();
expect(response.didUrlState.didUrl).toBeDefined();
expect(response.didUrlState.state).toBeDefined();
expect(response.didUrlState.state).toEqual('finished');
expect(response.didUrlState.name).toEqual('ResourceName');
expect(response.didUrlState.type).toEqual('TextDocument');
expect(response.didUrlState.version).toEqual('3.0');
});

0 comments on commit 13d6b2d

Please sign in to comment.