Skip to content

Commit

Permalink
ActionAssertion: Add test cases for generating v1 and v2 assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
cyraxx committed Jan 15, 2025
1 parent fbb3d17 commit d9c9f9b
Showing 1 changed file with 78 additions and 14 deletions.
92 changes: 78 additions & 14 deletions tests/manifest/assertions/ActionAssertion.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import assert from 'node:assert/strict';
import * as bin from 'typed-binary';
import { CBORBox, SuperBox } from '../../../src/jumbf';
import { ActionAssertion, Assertion, Claim } from '../../../src/manifest';
import {
ActionAssertion,
ActionType,
Assertion,
AssertionLabels,
Claim,
DigitalSourceType,
} from '../../../src/manifest';
import * as raw from '../../../src/manifest/rawTypes';
import { BinaryHelper } from '../../../src/util';

Expand All @@ -10,12 +17,12 @@ describe('ActionAssertion Tests', function () {

const claim = new Claim();

const serializedString =
const serializedStringV1 =
'000000846a756d62000000266a756d6463626f7200110010800000aa00389b7103633270612e616374696f6e73000000005663626f72a167616374696f6e7382a166616374696f6e6c633270612e63726561746564a266616374696f6e6c633270612e64726177696e676a706172616d6574657273a1646e616d65686772616469656e74';

let superBox: SuperBox;
it('read a JUMBF box', function () {
const buffer = BinaryHelper.fromHexString(serializedString);
it('read a v1 JUMBF box', function () {
const buffer = BinaryHelper.fromHexString(serializedStringV1);

// fetch schema from the box class
const schema = SuperBox.schema;
Expand Down Expand Up @@ -49,7 +56,7 @@ describe('ActionAssertion Tests', function () {
});

let assertion: Assertion;
it('construct an assertion from the JUMBF box', function () {
it('construct an assertion from the v1 JUMBF box', function () {
if (!superBox) this.skip();

const actionAssertion = new ActionAssertion();
Expand All @@ -62,27 +69,19 @@ describe('ActionAssertion Tests', function () {
assert.equal(actionAssertion.actions.length, 2);
assert.deepEqual(actionAssertion.actions[0], {
action: 'c2pa.created',
reason: undefined,
instanceID: undefined,
parameters: undefined,
digitalSourceType: undefined,
});
assert.deepEqual(actionAssertion.actions[1], {
action: 'c2pa.drawing',
reason: undefined,
instanceID: undefined,
parameters: {
name: 'gradient',
ingredients: [],
ingredient: undefined,
},
digitalSourceType: undefined,
});

assertion = actionAssertion;
});

it('construct a JUMBF box from the assertion', function () {
it('construct a JUMBF box from the v1 assertion', function () {
if (!assertion) this.skip();

const box = assertion.generateJUMBFBox(claim);
Expand Down Expand Up @@ -111,4 +110,69 @@ describe('ActionAssertion Tests', function () {
],
});
});

const constructedAssertion = new ActionAssertion();
constructedAssertion.actions.push({
action: ActionType.C2paOpened,
digitalSourceType: DigitalSourceType.DigitalArt,
reason: 'Opened the media',
instanceID: 'Dummy-Instance-ID',
});

it('create and read back a v2 assertion', function () {
const box = constructedAssertion.generateJUMBFBox();

assert.equal(box.descriptionBox?.label, 'c2pa.actions.v2');
assert.deepEqual(box.descriptionBox?.uuid, raw.UUIDs.cborAssertion);
assert.equal(box.contentBoxes.length, 1);
assert.ok(box.contentBoxes[0] instanceof CBORBox);
assert.deepEqual(box.contentBoxes[0].content, {
actions: [
{
action: 'c2pa.opened',
digitalSourceType: 'http://cv.iptc.org/newscodes/digitalsourcetype/digitalArt',
reason: 'Opened the media',
},
],
});

const readBackAssertion = new ActionAssertion();
readBackAssertion.readFromJUMBF(box, claim);

assert.equal(readBackAssertion.label, 'c2pa.actions.v2');
assert.deepEqual(readBackAssertion.actions[0], {
action: ActionType.C2paOpened,
digitalSourceType: DigitalSourceType.DigitalArt,
reason: 'Opened the media',
});
});

it('create and read back a v1 assertion', function () {
constructedAssertion.label = AssertionLabels.actions;
const box = constructedAssertion.generateJUMBFBox();

assert.equal(box.descriptionBox?.label, 'c2pa.actions');
assert.deepEqual(box.descriptionBox?.uuid, raw.UUIDs.cborAssertion);
assert.equal(box.contentBoxes.length, 1);
assert.ok(box.contentBoxes[0] instanceof CBORBox);
assert.deepEqual(box.contentBoxes[0].content, {
actions: [
{
action: 'c2pa.opened',
digitalSourceType: 'http://cv.iptc.org/newscodes/digitalsourcetype/digitalArt',
instanceID: 'Dummy-Instance-ID',
},
],
});

const readBackAssertion = new ActionAssertion();
readBackAssertion.readFromJUMBF(box, claim);

assert.equal(readBackAssertion.label, 'c2pa.actions');
assert.deepEqual(readBackAssertion.actions[0], {
action: ActionType.C2paOpened,
digitalSourceType: DigitalSourceType.DigitalArt,
instanceID: 'Dummy-Instance-ID',
});
});
});

0 comments on commit d9c9f9b

Please sign in to comment.