|
| 1 | +%%% % DO NOT EDIT: this file was generated by 'just codegen' |
| 2 | +%%% % @generated SignedSource<<dfbe93f4dfbf1c353aff0952ab1d06ad>> |
| 3 | +%%% % @format |
| 4 | +%%%----------------------------------------------------------------------------- |
| 5 | +%%% Copyright (c) Meta Platforms, Inc. and affiliates. |
| 6 | +%%% Copyright (c) WhatsApp LLC |
| 7 | +%%% |
| 8 | +%%% This source code is licensed under the MIT license found in the |
| 9 | +%%% LICENSE.md file in the root directory of this source tree. |
| 10 | +%%%----------------------------------------------------------------------------- |
| 11 | +-module(markdown_misc_dangerous_html_SUITE). |
| 12 | +-moduledoc """ |
| 13 | + |
| 14 | +""". |
| 15 | +- moduledoc #{ author => [ "Andrew Bennett <[email protected]>"]}. |
| 16 | +-moduledoc #{created => "", modified => ""}. |
| 17 | +-moduledoc #{copyright => "Meta Platforms, Inc. and affiliates."}. |
| 18 | +-compile(warn_missing_spec_all). |
| 19 | +-oncall("whatsapp_clr"). |
| 20 | + |
| 21 | +-include_lib("markdown/include/markdown_mdast.hrl"). |
| 22 | +-include_lib("markdown/include/markdown_util.hrl"). |
| 23 | +-include_lib("stdlib/include/assert.hrl"). |
| 24 | + |
| 25 | +-behaviour(ct_suite). |
| 26 | + |
| 27 | +%% ct_suite callbacks |
| 28 | +-export([ |
| 29 | + all/0, |
| 30 | + groups/0, |
| 31 | + init_per_suite/1, |
| 32 | + end_per_suite/1, |
| 33 | + init_per_group/2, |
| 34 | + end_per_group/2 |
| 35 | +]). |
| 36 | + |
| 37 | +%% Test Cases |
| 38 | +-export([ |
| 39 | + test_misc_dangerous_html_case_1/1, |
| 40 | + test_misc_dangerous_html_case_2/1, |
| 41 | + test_misc_dangerous_html_case_3/1 |
| 42 | +]). |
| 43 | + |
| 44 | +%% Macros |
| 45 | +-define(danger, markdown_options:new(#{compile => #{allow_dangerous_html => true, allow_dangerous_protocol => true}})). |
| 46 | + |
| 47 | +%%%============================================================================= |
| 48 | +%%% ct_suite callbacks |
| 49 | +%%%============================================================================= |
| 50 | + |
| 51 | +-spec all() -> markdown_test:all(). |
| 52 | +all() -> |
| 53 | + [ |
| 54 | + {group, static} |
| 55 | + ]. |
| 56 | + |
| 57 | +-spec groups() -> markdown_test:groups(). |
| 58 | +groups() -> |
| 59 | + [ |
| 60 | + {static, [parallel], [ |
| 61 | + test_misc_dangerous_html_case_1, |
| 62 | + test_misc_dangerous_html_case_2, |
| 63 | + test_misc_dangerous_html_case_3 |
| 64 | + ]} |
| 65 | + ]. |
| 66 | + |
| 67 | +-spec init_per_suite(Config :: ct_suite:ct_config()) -> markdown_test:init_per_suite(). |
| 68 | +init_per_suite(Config) -> |
| 69 | + Config. |
| 70 | + |
| 71 | +-spec end_per_suite(Config :: ct_suite:ct_config()) -> markdown_test:end_per_suite(). |
| 72 | +end_per_suite(_Config) -> |
| 73 | + ok. |
| 74 | + |
| 75 | +-spec init_per_group(GroupName :: ct_suite:ct_groupname(), Config :: ct_suite:ct_config()) -> |
| 76 | + markdown_test:init_per_group(). |
| 77 | +init_per_group(_Group, Config) -> |
| 78 | + Config. |
| 79 | + |
| 80 | +-spec end_per_group(GroupName :: ct_suite:ct_groupname(), Config :: ct_suite:ct_config()) -> |
| 81 | + markdown_test:end_per_group(). |
| 82 | +end_per_group(_Group, _Config) -> |
| 83 | + ok. |
| 84 | + |
| 85 | +%%%============================================================================= |
| 86 | +%%% Test Cases |
| 87 | +%%%============================================================================= |
| 88 | + |
| 89 | +-spec test_misc_dangerous_html_case_1(Config) -> markdown_test:testcase() when |
| 90 | + Config :: ct_suite:ct_config(). |
| 91 | +test_misc_dangerous_html_case_1(_Config) -> |
| 92 | + ?assertMatch( |
| 93 | + {ok, <<"<x>"/utf8>>}, |
| 94 | + markdown:to_html(<<"<x>"/utf8>>), |
| 95 | + "should be safe by default for flow" |
| 96 | + ), |
| 97 | + ok. |
| 98 | + |
| 99 | +-spec test_misc_dangerous_html_case_2(Config) -> markdown_test:testcase() when |
| 100 | + Config :: ct_suite:ct_config(). |
| 101 | +test_misc_dangerous_html_case_2(_Config) -> |
| 102 | + ?assertMatch( |
| 103 | + {ok, <<"<p>a<b></p>"/utf8>>}, |
| 104 | + markdown:to_html(<<"a<b>"/utf8>>), |
| 105 | + "should be safe by default for text" |
| 106 | + ), |
| 107 | + ok. |
| 108 | + |
| 109 | +-spec test_misc_dangerous_html_case_3(Config) -> markdown_test:testcase() when |
| 110 | + Config :: ct_suite:ct_config(). |
| 111 | +test_misc_dangerous_html_case_3(_Config) -> |
| 112 | + ?assertMatch( |
| 113 | + {ok, <<"<x>"/utf8>>}, |
| 114 | + markdown:to_html_with_options(<<"<x>"/utf8>>, ?danger), |
| 115 | + "should be unsafe w/ `allowDangerousHtml`" |
| 116 | + ), |
| 117 | + ok. |
0 commit comments