From 3cd709f6b395394924a70322298cfd66962453db Mon Sep 17 00:00:00 2001 From: Guillaume Weghsteen Date: Thu, 19 Dec 2024 01:04:09 -0800 Subject: [PATCH] No public description PiperOrigin-RevId: 707820349 --- .../html_sanitizer/html_sanitizer_test.ts | 49 +- test/testing/testvectors/html_test_vectors.ts | 24485 ---------------- 2 files changed, 39 insertions(+), 24495 deletions(-) delete mode 100644 test/testing/testvectors/html_test_vectors.ts diff --git a/test/builders/html_sanitizer/html_sanitizer_test.ts b/test/builders/html_sanitizer/html_sanitizer_test.ts index b6ca4254..4fd66597 100644 --- a/test/builders/html_sanitizer/html_sanitizer_test.ts +++ b/test/builders/html_sanitizer/html_sanitizer_test.ts @@ -5,7 +5,6 @@ */ import {secretToken} from '../../../src/internals/secrets'; -import {HTML_TEST_VECTORS} from '../../testing/testvectors/html_test_vectors'; import { CssSanitizationFn, @@ -51,16 +50,46 @@ function sanitizeAssertUnchanged(table: SanitizerTable, html: string): string { .toString(); } -describe('HtmlSanitizer', () => { - describe('using test vectors', () => { - for (const v of HTML_TEST_VECTORS) { - it(`passes testVector[${v.name}]`, () => { - const sanitized = sanitizeHtml(v.input).toString(); - expect(v.acceptable).toContain(sanitized); - }); - } - }); +describe('sanitizeHtml', () => { + interface TestCase { + html: string; + expected: string; + } + const testCases: TestCase[] = [ + { + html: '', + expected: '', + }, + { + html: 'abcd', + expected: 'abcd', + }, + { + html: 'abcd', + expected: 'abcd', + }, + { + html: '', + expected: '', + }, + { + html: '', + expected: '', + }, + { + html: '', + expected: '', + }, + ]; + for (const testCase of testCases) { + it(`sanitizes ${JSON.stringify(testCase.html)} correctly`, () => { + const sanitized = sanitizeHtml(testCase.html).toString(); + expect(sanitized).toEqual(testCase.expected); + }); + } +}); +describe('HtmlSanitizer', () => { it('drops unknown elements', () => { const emptyTable = new SanitizerTable( new Set(), diff --git a/test/testing/testvectors/html_test_vectors.ts b/test/testing/testvectors/html_test_vectors.ts deleted file mode 100644 index 76c6e633..00000000 --- a/test/testing/testvectors/html_test_vectors.ts +++ /dev/null @@ -1,24485 +0,0 @@ -/** - * @license - * Copyright Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -interface TestVector { - readonly input: string; - readonly acceptable: string[]; - readonly name: string; -} - -/** - * AUTOGENERATED. DO NOT EDIT. - * Test vectors for HTML sanitizer. - */ -export const HTML_TEST_VECTORS: TestVector[] = [ - { - input: 'foo', - acceptable: [ - 'foo', - 'foo', - 'foo', - 'foo', - 'foo', - 'foo', - 'foo', - ], - name: 'a', - }, - { - input: 'foo', - acceptable: [ - 'foo', - 'foo', - 'foo', - 'foo', - 'foo', - 'foo', - ], - name: 'a_quot', - }, - { - input: 'foo', - acceptable: [ - 'foo', - 'foo', - 'foo', - 'foo', - 'foo', - 'foo', - 'foo', - ], - name: 'a_tab', - }, - {input: "", acceptable: [''], name: 'body_onload'}, - { - input: '
', - acceptable: ['', '
', '
'], - name: 'clobbering_children', - }, - { - input: '
', - acceptable: ['', '
', '
'], - name: 'clobbering_firstchild', - }, - { - input: '
', - acceptable: ['', '
', '
'], - name: 'clobbering_proto', - }, - { - input: '
', - acceptable: ['', '
'], - name: 'clobbering_tagname', - }, - { - input: '
', - acceptable: [ - '', - '
', - '
', - '
', - '
', - '
', - ], - name: 'details', - }, - { - input: '', '', '', '', - acceptable: [ - '', - '', - '', - '', - '', - '', - '', - ], - name: 'contract_iframe_action', - }, - { - input: '', - '
', - '', - '', - '', - '', - ], - name: 'contract_iframe_method', - }, - { - input: '', - '
', - '', - '', - '', - '', - ], - name: 'contract_iframe_formaction', - }, - { - input: '', - '
', - '', - '', - '', - '', - ], - name: 'contract_iframe_formmethod', - }, - { - input: '', - '
', - '', - '', - '', - '', - ], - name: 'contract_iframe_pattern', - }, - { - input: '', - '
', - '', - '', - '', - '', - ], - name: 'contract_iframe_readonly', - }, - { - input: '', - '
', - '', - '', - '', - '', - ], - name: 'contract_iframe_accept', - }, - { - input: '', - '
', - '', - '', - '', - '', - ], - name: 'contract_iframe_defer', - }, - { - input: '', - acceptable: ['', '', ''], - name: 'contract_embed_plain', - }, - { - input: '', - acceptable: ['', '', ''], - name: 'contract_embed_scriptinside', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_embed_srcdoc', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_embed_action', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_embed_method', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_embed_formaction', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_embed_formmethod', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_embed_pattern', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_embed_readonly', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_embed_accept', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_embed_defer', - }, - { - input: '', - acceptable: ['', '', ''], - name: 'contract_object_plain', - }, - { - input: '', - acceptable: ['', '', ''], - name: 'contract_object_scriptinside', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_object_srcdoc', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_object_action', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_object_method', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_object_formaction', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_object_formmethod', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_object_pattern', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_object_readonly', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_object_accept', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_object_defer', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '', - '', - '
', - '', - '', - '', - ], - name: 'contract_param_plain', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '', - '', - '
', - '', - '', - '', - '
', - ], - name: 'contract_param_scriptinside', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_param_srcdoc', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_param_action', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_param_method', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_param_formaction', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_param_formmethod', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_param_pattern', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_param_readonly', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_param_accept', - }, - { - input: '', - acceptable: [ - '', - '', - '', - '', - '
', - '
', - '', - '', - '', - '', - '', - ], - name: 'contract_param_defer', - }, - { - input: '', - acceptable: [ - '