1
1
import { addNode , createSite , deleteSite } from '@jahia/cypress' ;
2
2
import {
3
+ addConfig ,
4
+ disableHtmlFiltering ,
3
5
enableHtmlFiltering ,
4
6
getContent ,
5
7
installConfig ,
@@ -11,6 +13,8 @@ describe('HTML rich text filtering', () => {
11
13
const textName = 'myText' ;
12
14
const path = `/sites/${ siteKey } /contents/${ textName } ` ;
13
15
16
+ // TODO Need to clean up configuration manually (delete in file system) for local re-runs
17
+
14
18
before ( ( ) => {
15
19
createSite ( siteKey ) ;
16
20
addNode ( {
@@ -25,40 +29,55 @@ describe('HTML rich text filtering', () => {
25
29
deleteSite ( siteKey ) ;
26
30
} ) ;
27
31
28
- it ( 'does not apply html filtering when disabled (default)' , ( ) => {
29
- modifyContent ( path , '<iframe title="My iframe"></iframe>' ) ;
32
+ it ( 'does not apply html filtering to tag when disabled (default)' , ( ) => {
33
+ modifyContent ( path , '<iframe title="My iframe"></iframe><script> var today= new Date(); </script> ' ) ;
30
34
getContent ( path ) . then ( result => {
31
35
expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'iframe' ) ;
36
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( '<script>' ) ;
32
37
} ) ;
33
38
} ) ;
34
39
35
40
it ( 'does not apply html filtering to attribute when disabled (default)' , ( ) => {
36
41
modifyContent ( path , '<img src="stub.jpg" loading="lazy">' ) ;
37
42
getContent ( path ) . then ( result => {
38
- expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'img' ) ;
43
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( '< img' ) ;
39
44
expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'src' ) ;
40
45
expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'loading' ) ;
41
46
} ) ;
42
47
} ) ;
43
48
44
49
it ( 'applies default html filtering when enabled' , ( ) => {
45
50
enableHtmlFiltering ( siteKey ) ;
46
- modifyContent ( path , '<iframe title="My iframe"></iframe>' ) ;
51
+ modifyContent ( path , '<iframe title="My iframe"></iframe><a title="My link"></a><script> var today= new Date(); </script> ' ) ;
47
52
getContent ( path ) . then ( result => {
48
53
expect ( result . data . jcr . nodeByPath . property . value ) . to . not . contain ( 'iframe' ) ;
54
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . not . contain ( 'script' ) ;
55
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( '<a' ) ;
56
+ } ) ;
57
+ } ) ;
58
+
59
+ it ( 'applies default html filtering when enabled' , ( ) => {
60
+ enableHtmlFiltering ( siteKey ) ;
61
+ modifyContent ( path , '<a title="My iframe"></a>' ) ;
62
+ getContent ( path ) . then ( result => {
63
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'a' ) ;
49
64
} ) ;
50
65
} ) ;
51
66
52
67
it ( 'applies default filtering to html element when enabled' , ( ) => {
53
- modifyContent ( path , '<iframe title="My iframe"></iframe>' ) ;
68
+ modifyContent ( path , '<iframe title="My iframe"></iframe><p>This is a <u>nested</u>tag</p> ' ) ;
54
69
getContent ( path ) . then ( result => {
55
- expect ( result . data . jcr . nodeByPath . property . value ) . to . not . contain ( 'iframe' ) ;
70
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . not . contain ( '<iframe>' ) ;
71
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( '<p>' ) ;
72
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( '<u>' ) ;
56
73
} ) ;
57
74
} ) ;
58
75
59
76
it ( 'applies default filtering to html attributes when enabled' , ( ) => {
60
- modifyContent ( path , '<img src="stub.jpg" loading="lazy">' ) ;
77
+ modifyContent ( path , '<img src="stub.jpg" loading="lazy"><a href="https://localhost:8080"> ' ) ;
61
78
getContent ( path ) . then ( result => {
79
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'a' ) ;
80
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'href' ) ;
62
81
expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'img' ) ;
63
82
expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'src' ) ;
64
83
expect ( result . data . jcr . nodeByPath . property . value ) . to . not . contain ( 'loading' , 'filtered attribute' ) ;
@@ -75,11 +94,30 @@ describe('HTML rich text filtering', () => {
75
94
76
95
it ( 'can override filtering config for specified site' , ( ) => {
77
96
installConfig ( 'configs/org.jahia.modules.richtext.config-filteringSite.yml' ) ;
78
- modifyContent ( path , '<strong >This text is important!</strong>' ) ;
97
+ modifyContent ( path , '<p >This text<strong> is important!</strong> but not this one</p >' ) ;
79
98
getContent ( path ) . then ( result => {
99
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( '<p>' ) ;
80
100
expect ( result . data . jcr . nodeByPath . property . value ) . to . not . contain ( 'strong' ) ;
101
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'important' , 'Tag removed but data remains' ) ;
102
+ } ) ;
103
+ } ) ;
104
+
105
+ it ( 'can update config and filter using updated rules' , ( ) => {
106
+ addConfig ( 'htmlFiltering.disallow.elements[1].name' , 'i' , 'filteringSite' ) ;
107
+ modifyContent ( path , '<p>This text<i>is important!</i> but not this one</p>' ) ;
108
+ getContent ( path ) . then ( result => {
109
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( '<p>' ) ;
110
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . not . contain ( '<i>' ) ;
111
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'important' , 'Tag removed but data remains' ) ;
81
112
} ) ;
82
113
} ) ;
83
114
84
- // TODO Need to clean up configuration manually (delete in file system) for re-runs
115
+ it ( 'does not override filtering config for specified site when filtering is disabled' , ( ) => {
116
+ disableHtmlFiltering ( siteKey ) ;
117
+ installConfig ( 'configs/org.jahia.modules.richtext.config-filteringSite.yml' ) ;
118
+ modifyContent ( path , '<p>This text<strong>is important!</strong> but not this one</p>' ) ;
119
+ getContent ( path ) . then ( result => {
120
+ expect ( result . data . jcr . nodeByPath . property . value ) . to . contain ( 'strong' ) ;
121
+ } ) ;
122
+ } ) ;
85
123
} ) ;
0 commit comments