Skip to content

Commit

Permalink
chore: Removes ajv validation of attribute set
Browse files Browse the repository at this point in the history
- We aren't doing attribute validation elsewhere
- This is less necessary after the switch to typescript
- the library is heavy and doesn't play well with our esm based tooling
  • Loading branch information
dmihalcik-virtru committed May 3, 2024
1 parent 13936cf commit 13a335f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 41 deletions.
1 change: 0 additions & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"watch": "(trap 'kill 0' SIGINT; npm run build && (npm run build:watch & npm run test -- --watch))"
},
"dependencies": {
"ajv": "^8.12.0",
"axios": "^1.6.1",
"axios-retry": "^3.9.0",
"base64-js": "^1.5.1",
Expand Down
36 changes: 0 additions & 36 deletions lib/tdf3/src/models/attribute-set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Ajv, { JSONSchemaType } from 'ajv';
import { decodeJwt } from 'jose';

const verbose = false;
Expand All @@ -13,32 +12,6 @@ export type AttributeObject = {
jwt?: string;
};

const ATTRIBUTE_OBJECT_SCHEMA: JSONSchemaType<AttributeObject> = {
$id: '/AttributeObject',
type: 'object',
properties: {
attribute: { type: 'string' },
displayName: { type: 'string', nullable: true },
isDefault: { type: 'boolean', nullable: true },
pubKey: { type: 'string' },
kasUrl: { type: 'string' },
kid: { type: 'string', nullable: true },
jwt: { type: 'string', nullable: true },
},
required: ['attribute', 'pubKey', 'kasUrl'],
additionalProperties: false,
};

const validator = (() => {
try {
//@ts-expect-error: Ajv not a constructor
return new Ajv();
} catch (e) {
console.log(e);
}
return new Ajv.default();
})();

export class AttributeSet {
attributes: AttributeObject[];

Expand Down Expand Up @@ -97,15 +70,6 @@ export class AttributeSet {
* @return the attribute object if successful, or null
*/
addAttribute(attrObj: AttributeObject): AttributeObject | null {
// Check shape of object. Reject semi-silently if malformed.
const validate = validator.compile(ATTRIBUTE_OBJECT_SCHEMA);
const result = validate(attrObj);
if (!result) {
// TODO: Determine if an error should be thrown
// console.log("WARNING - AttributeSet.addAttribute: AttributeObject is malformed. AddAttribute failed:");
if (verbose) console.log(attrObj);
return null;
}
// Check for duplicate entries to assure idempotency.
if (this.has(attrObj.attribute)) {
// This may be a common occurance, so only un-comment this log message
Expand Down
8 changes: 4 additions & 4 deletions lib/tests/mocha/unit/attribute-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('AttributeSet', function () {
assert.equal(aSet.attributes[0], expected);
});

it('should not add one with additional fields (malformed)', () => {
it.skip('should not add one with additional fields (malformed)', () => {
const aSet = new AttributeSet();
const expected = Mocks.createAttribute({});
expected.addedField = 'Potential mallware';
Expand Down Expand Up @@ -134,23 +134,23 @@ describe('AttributeSet', function () {
assert.equal(aSet.attributes[0], expected);
});

it('should not add an attribute object with "attribute" missing ', () => {
it.skip('should not add an attribute object with "attribute" missing ', () => {
const aSet = new AttributeSet();
const expected = Mocks.createAttribute({});
delete expected.attribute;
aSet.addAttribute(expected);
assert.equal(aSet.attributes.length, 0);
});

it('should not add an attribute object with "pubKey" missing ', () => {
it.skip('should not add an attribute object with "pubKey" missing ', () => {
const aSet = new AttributeSet();
const expected = Mocks.createAttribute({});
delete expected.pubKey;
aSet.addAttribute(expected);
assert.equal(aSet.attributes.length, 0);
});

it('should not add an attribute object with "kasUrl" missing ', () => {
it.skip('should not add an attribute object with "kasUrl" missing ', () => {
const aSet = new AttributeSet();
const expected = Mocks.createAttribute({});
delete expected.kasUrl;
Expand Down

0 comments on commit 13a335f

Please sign in to comment.