Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Removes ajv validation of attribute set #270

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 8 additions & 52 deletions lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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';

export type AttributeObject = {
Expand All @@ -11,32 +10,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 (this.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
36 changes: 5 additions & 31 deletions remote-store/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading