Skip to content

Commit 5384b8e

Browse files
committed
BACKLOG-22218: Add more test scenarios
1 parent 7eee63f commit 5384b8e

File tree

2 files changed

+67
-10
lines changed

2 files changed

+67
-10
lines changed

tests/cypress/e2e/filtering.cy.ts

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {addNode, createSite, deleteSite} from '@jahia/cypress';
22
import {
3+
addConfig,
4+
disableHtmlFiltering,
35
enableHtmlFiltering,
46
getContent,
57
installConfig,
@@ -11,6 +13,8 @@ describe('HTML rich text filtering', () => {
1113
const textName = 'myText';
1214
const path = `/sites/${siteKey}/contents/${textName}`;
1315

16+
// TODO Need to clean up configuration manually (delete in file system) for local re-runs
17+
1418
before(() => {
1519
createSite(siteKey);
1620
addNode({
@@ -25,40 +29,55 @@ describe('HTML rich text filtering', () => {
2529
deleteSite(siteKey);
2630
});
2731

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>');
3034
getContent(path).then(result => {
3135
expect(result.data.jcr.nodeByPath.property.value).to.contain('iframe');
36+
expect(result.data.jcr.nodeByPath.property.value).to.contain('<script>');
3237
});
3338
});
3439

3540
it('does not apply html filtering to attribute when disabled (default)', () => {
3641
modifyContent(path, '<img src="stub.jpg" loading="lazy">');
3742
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');
3944
expect(result.data.jcr.nodeByPath.property.value).to.contain('src');
4045
expect(result.data.jcr.nodeByPath.property.value).to.contain('loading');
4146
});
4247
});
4348

4449
it('applies default html filtering when enabled', () => {
4550
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>');
4752
getContent(path).then(result => {
4853
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');
4964
});
5065
});
5166

5267
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>');
5469
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>');
5673
});
5774
});
5875

5976
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">');
6178
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');
6281
expect(result.data.jcr.nodeByPath.property.value).to.contain('img');
6382
expect(result.data.jcr.nodeByPath.property.value).to.contain('src');
6483
expect(result.data.jcr.nodeByPath.property.value).to.not.contain('loading', 'filtered attribute');
@@ -75,11 +94,30 @@ describe('HTML rich text filtering', () => {
7594

7695
it('can override filtering config for specified site', () => {
7796
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>');
7998
getContent(path).then(result => {
99+
expect(result.data.jcr.nodeByPath.property.value).to.contain('<p>');
80100
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');
81112
});
82113
});
83114

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+
});
85123
});

tests/cypress/fixtures/utils/configuration.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import gql from 'graphql-tag';
22

3+
const pid = 'org.jahia.modules.richtext.config';
4+
35
export const installConfig = configFilePath => {
46
return cy.runProvisioningScript(
57
{fileContent: `- installConfiguration: "${configFilePath}"`, type: 'application/yaml'},
@@ -8,7 +10,6 @@ export const installConfig = configFilePath => {
810
};
911

1012
export const getConfig = siteKey => {
11-
const pid = 'org.jahia.modules.richtext.config';
1213
const getConfigGql = gql`
1314
query getConfig($pid: String!, $siteKey: String!) {
1415
admin {
@@ -25,3 +26,21 @@ export const getConfig = siteKey => {
2526
variables: {pid, siteKey}
2627
});
2728
};
29+
30+
export const addConfig = (key, value, siteKey = 'default') => {
31+
const addConfigGql = gql`
32+
mutation addConfig($pid: String!, $identifier: String!, $key: String!, $value: String!) {
33+
admin {
34+
jahia {
35+
configuration(pid: $pid, identifier: $identifier) {
36+
value(name: $key value: $value)
37+
}
38+
}
39+
}
40+
}
41+
`;
42+
return cy.apollo({
43+
mutation: addConfigGql,
44+
variables: {pid, identifier: siteKey, key, value}
45+
});
46+
};

0 commit comments

Comments
 (0)