diff --git a/src/index.ts b/src/index.ts index 9e7d8b5..326ff88 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,7 +70,11 @@ export class IntegrityMetadata implements IntegrityMetadataLike { }); } - match({ alg, val }: IntegrityMetadataLike): boolean { + match(integrity: IntegrityMetadataLike | string | null | undefined): boolean { + const { alg, val } = new IntegrityMetadata(integrity); + if (!alg) return false; + if (!val) return false; + if (!(alg in supportedHashAlgorithms)) return false; return alg === this.alg && val === this.val; } diff --git a/test/integrity-metadata/match.js b/test/integrity-metadata/match.js index de6ceb5..e265268 100644 --- a/test/integrity-metadata/match.js +++ b/test/integrity-metadata/match.js @@ -44,7 +44,7 @@ test("if the hash values are different, return false", function () { ); }); -test.todo("if the hash algorithm is unsupported, return false", function () { +test("if the hash algorithm is unsupported, return false", function () { const integrityMetadata = new IntegrityMetadata( "sha1-lDpwLQbzRZmu4fjajvn3KWAx1pk=", ); @@ -57,7 +57,7 @@ test.todo("if the hash algorithm is unsupported, return false", function () { ); }); -test.todo("if null, return false", function () { +test("if null, return false", function () { const integrityMetadata = new IntegrityMetadata(null); assert.strictEqual( @@ -66,13 +66,13 @@ test.todo("if null, return false", function () { ); }); -test.todo("if empty, return false", function () { +test("if empty, return false", function () { const integrityMetadata = new IntegrityMetadata(""); assert.strictEqual(integrityMetadata.match(new IntegrityMetadata("")), false); }); -test.todo("if invalid value, return false", function () { +test("if invalid value, return false", function () { const integrityMetadata = new IntegrityMetadata("md5\0/..invalid-value"); assert.strictEqual(