|
| 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 parserOptions = { |
| 15 | + ecmaVersion: 2018, |
| 16 | + sourceType: 'module', |
| 17 | + ecmaFeatures: { |
| 18 | + jsx: true |
| 19 | + } |
| 20 | +}; |
| 21 | + |
| 22 | +// ------------------------------------------------------------------------------ |
| 23 | +// Tests |
| 24 | +// ------------------------------------------------------------------------------ |
| 25 | + |
| 26 | +const ruleTester = new RuleTester({parserOptions}); |
| 27 | +ruleTester.run('iframe-missing-sandbox', rule, { |
| 28 | + valid: [ |
| 29 | + {code: '<div sandbox="__unknown__" />;'}, |
| 30 | + {code: '<iframe sandbox="" />;'}, |
| 31 | + {code: '<iframe src="foo.htm" sandbox></iframe>'}, |
| 32 | + {code: '<iframe src="foo.htm" sandbox sandbox></iframe>'}, |
| 33 | + {code: '<iframe sandbox={""} />'}, |
| 34 | + {code: '<iframe sandbox="allow-forms"></iframe>'}, |
| 35 | + {code: '<iframe sandbox="allow-modals"></iframe>'}, |
| 36 | + {code: '<iframe sandbox="allow-orientation-lock"></iframe>'}, |
| 37 | + {code: '<iframe sandbox="allow-pointer-lock"></iframe>'}, |
| 38 | + {code: '<iframe sandbox="allow-popups"></iframe>'}, |
| 39 | + {code: '<iframe sandbox="allow-popups-to-escape-sandbox"></iframe>'}, |
| 40 | + {code: '<iframe sandbox="allow-presentation"></iframe>'}, |
| 41 | + {code: '<iframe sandbox="allow-same-origin"></iframe>'}, |
| 42 | + {code: '<iframe sandbox="allow-scripts"></iframe>'}, |
| 43 | + {code: '<iframe sandbox="allow-top-navigation"></iframe>'}, |
| 44 | + {code: '<iframe sandbox="allow-top-navigation-by-user-activation"></iframe>'}, |
| 45 | + {code: '<iframe sandbox="allow-forms allow-modals"></iframe>'}, |
| 46 | + {code: '<iframe sandbox="allow-popups allow-popups-to-escape-sandbox allow-pointer-lock allow-same-origin allow-top-navigation"></iframe>'} |
| 47 | + ], |
| 48 | + invalid: [{ |
| 49 | + code: '<iframe></iframe>;', |
| 50 | + errors: [{messageId: 'attributeMissing'}] |
| 51 | + }, |
| 52 | + { |
| 53 | + code: '<iframe/>;', |
| 54 | + errors: [{messageId: 'attributeMissing'}] |
| 55 | + }, |
| 56 | + { |
| 57 | + code: '<iframe sandbox="__unknown__"></iframe>', |
| 58 | + errors: [{messageId: 'invalidValue', data: {value: '__unknown__'}}] |
| 59 | + }, |
| 60 | + { |
| 61 | + code: '<iframe sandbox="allow-popups __unknown__"/>', |
| 62 | + errors: [{messageId: 'invalidValue', data: {value: '__unknown__'}}] |
| 63 | + }, |
| 64 | + { |
| 65 | + code: '<iframe sandbox="__unknown__ allow-popups"/>', |
| 66 | + errors: [{messageId: 'invalidValue', data: {value: '__unknown__'}}] |
| 67 | + }, |
| 68 | + { |
| 69 | + code: '<iframe sandbox=" allow-forms __unknown__ allow-popups __unknown__ "/>', |
| 70 | + errors: [ |
| 71 | + {messageId: 'invalidValue', data: {value: '__unknown__'}}, |
| 72 | + {messageId: 'invalidValue', data: {value: '__unknown__'}} |
| 73 | + ] |
| 74 | + }, |
| 75 | + { |
| 76 | + code: '<iframe sandbox="allow-scripts allow-same-origin"></iframe>;', |
| 77 | + errors: [{messageId: 'invalidCombination'}] |
| 78 | + }, |
| 79 | + { |
| 80 | + code: '<iframe sandbox="allow-same-origin allow-scripts"/>;', |
| 81 | + errors: [{messageId: 'invalidCombination'}] |
| 82 | + }] |
| 83 | +}); |
0 commit comments