mirror of
https://github.com/kou029w/websri.git
synced 2025-01-18 08:05:13 +00:00
update match to return false for unsupported, null, empty, or invalid hash algorithms
This commit is contained in:
parent
f8aff38a6b
commit
47228186a0
2 changed files with 9 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Reference in a new issue