|
| 1 | +/** |
| 2 | + * @fileoverview TBD |
| 3 | + */ |
| 4 | + |
| 5 | +'use strict'; |
| 6 | + |
| 7 | +// ------------------------------------------------------------------------------ |
| 8 | +// Requirements |
| 9 | +// ------------------------------------------------------------------------------ |
| 10 | + |
| 11 | +const RuleTester = require('eslint').RuleTester; |
| 12 | +const rule = require('../../../lib/rules/iframe-missing-sandbox'); |
| 13 | + |
| 14 | +const parsers = require('../../helpers/parsers'); |
| 15 | + |
| 16 | +const parserOptions = { |
| 17 | + ecmaVersion: 2018, |
| 18 | + sourceType: 'module', |
| 19 | + ecmaFeatures: { |
| 20 | + jsx: true, |
| 21 | + }, |
| 22 | +}; |
| 23 | + |
| 24 | +// ------------------------------------------------------------------------------ |
| 25 | +// Tests |
| 26 | +// ------------------------------------------------------------------------------ |
| 27 | + |
| 28 | +const ruleTester = new RuleTester({ parserOptions }); |
| 29 | +ruleTester.run('iframe-missing-sandbox', rule, { |
| 30 | + valid: parsers.all([ |
| 31 | + { code: '<div sandbox="__unknown__" />;' }, |
| 32 | + |
| 33 | + { code: '<iframe sandbox="" />;' }, |
| 34 | + { code: '<iframe sandbox={""} />' }, |
| 35 | + { code: 'React.createElement("iframe", { sandbox: "" });' }, |
| 36 | + |
| 37 | + { code: '<iframe src="foo.htm" sandbox></iframe>' }, |
| 38 | + { code: 'React.createElement("iframe", { src: "foo.htm", sandbox: true })' }, |
| 39 | + |
| 40 | + { code: '<iframe src="foo.htm" sandbox sandbox></iframe>' }, |
| 41 | + |
| 42 | + { code: '<iframe sandbox="allow-forms"></iframe>' }, |
| 43 | + { code: '<iframe sandbox="allow-modals"></iframe>' }, |
| 44 | + { code: '<iframe sandbox="allow-orientation-lock"></iframe>' }, |
| 45 | + { code: '<iframe sandbox="allow-pointer-lock"></iframe>' }, |
| 46 | + { code: '<iframe sandbox="allow-popups"></iframe>' }, |
| 47 | + { code: '<iframe sandbox="allow-popups-to-escape-sandbox"></iframe>' }, |
| 48 | + { code: '<iframe sandbox="allow-presentation"></iframe>' }, |
| 49 | + { code: '<iframe sandbox="allow-same-origin"></iframe>' }, |
| 50 | + { code: '<iframe sandbox="allow-scripts"></iframe>' }, |
| 51 | + { code: '<iframe sandbox="allow-top-navigation"></iframe>' }, |
| 52 | + { code: '<iframe sandbox="allow-top-navigation-by-user-activation"></iframe>' }, |
| 53 | + { code: '<iframe sandbox="allow-forms allow-modals"></iframe>' }, |
| 54 | + { code: '<iframe sandbox="allow-popups allow-popups-to-escape-sandbox allow-pointer-lock allow-same-origin allow-top-navigation"></iframe>' }, |
| 55 | + { code: 'React.createElement("iframe", { sandbox: "allow-forms" })' }, |
| 56 | + { code: 'React.createElement("iframe", { sandbox: "allow-modals" })' }, |
| 57 | + { code: 'React.createElement("iframe", { sandbox: "allow-orientation-lock" })' }, |
| 58 | + { code: 'React.createElement("iframe", { sandbox: "allow-pointer-lock" })' }, |
| 59 | + { code: 'React.createElement("iframe", { sandbox: "allow-popups" })' }, |
| 60 | + { code: 'React.createElement("iframe", { sandbox: "allow-popups-to-escape-sandbox" })' }, |
| 61 | + { code: 'React.createElement("iframe", { sandbox: "allow-presentation" })' }, |
| 62 | + { code: 'React.createElement("iframe", { sandbox: "allow-same-origin" })' }, |
| 63 | + { code: 'React.createElement("iframe", { sandbox: "allow-scripts" })' }, |
| 64 | + { code: 'React.createElement("iframe", { sandbox: "allow-top-navigation" })' }, |
| 65 | + { code: 'React.createElement("iframe", { sandbox: "allow-top-navigation-by-user-activation" })' }, |
| 66 | + { code: 'React.createElement("iframe", { sandbox: "allow-forms allow-modals" })' }, |
| 67 | + { code: 'React.createElement("iframe", { sandbox: "allow-popups allow-popups-to-escape-sandbox allow-pointer-lock allow-same-origin allow-top-navigation" })' }, |
| 68 | + ]), |
| 69 | + invalid: parsers.all([ |
| 70 | + { |
| 71 | + code: '<iframe></iframe>;', |
| 72 | + errors: [{ messageId: 'attributeMissing' }], |
| 73 | + }, |
| 74 | + { |
| 75 | + code: '<iframe/>;', |
| 76 | + errors: [{ messageId: 'attributeMissing' }], |
| 77 | + }, |
| 78 | + { |
| 79 | + code: 'React.createElement("iframe");', |
| 80 | + errors: [{ messageId: 'attributeMissing' }], |
| 81 | + }, |
| 82 | + { |
| 83 | + code: 'React.createElement("iframe", {});', |
| 84 | + errors: [{ messageId: 'attributeMissing' }], |
| 85 | + }, |
| 86 | + { |
| 87 | + code: 'React.createElement("iframe", null);', |
| 88 | + errors: [{ messageId: 'attributeMissing' }], |
| 89 | + }, |
| 90 | + |
| 91 | + { |
| 92 | + code: '<iframe sandbox="__unknown__"></iframe>', |
| 93 | + errors: [{ messageId: 'invalidValue', data: { value: '__unknown__' } }], |
| 94 | + }, |
| 95 | + { |
| 96 | + code: 'React.createElement("iframe", { sandbox: "__unknown__" })', |
| 97 | + errors: [{ messageId: 'invalidValue', data: { value: '__unknown__' } }], |
| 98 | + }, |
| 99 | + |
| 100 | + { |
| 101 | + code: '<iframe sandbox="allow-popups __unknown__"/>', |
| 102 | + errors: [{ messageId: 'invalidValue', data: { value: '__unknown__' } }], |
| 103 | + }, |
| 104 | + { |
| 105 | + code: '<iframe sandbox="__unknown__ allow-popups"/>', |
| 106 | + errors: [{ messageId: 'invalidValue', data: { value: '__unknown__' } }], |
| 107 | + }, |
| 108 | + { |
| 109 | + code: '<iframe sandbox=" allow-forms __unknown__ allow-popups __unknown__ "/>', |
| 110 | + errors: [ |
| 111 | + { messageId: 'invalidValue', data: { value: '__unknown__' } }, |
| 112 | + { messageId: 'invalidValue', data: { value: '__unknown__' } }, |
| 113 | + ], |
| 114 | + }, |
| 115 | + { |
| 116 | + code: '<iframe sandbox="allow-scripts allow-same-origin"></iframe>;', |
| 117 | + errors: [{ messageId: 'invalidCombination' }], |
| 118 | + }, |
| 119 | + { |
| 120 | + code: '<iframe sandbox="allow-same-origin allow-scripts"/>;', |
| 121 | + errors: [{ messageId: 'invalidCombination' }], |
| 122 | + }, |
| 123 | + ]), |
| 124 | +}); |
0 commit comments