-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BACKLOG-22157 Update api, add dry run property, add tests (#6)
* BACKLOG-22157 Update api, add dry run property, add tests * BACKLOG-22157 Fix test
- Loading branch information
Showing
11 changed files
with
227 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/org/jahia/modules/richtext/graphql/models/GqlRichTextDisallowedConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.jahia.modules.richtext.graphql.models; | ||
|
||
import graphql.annotations.annotationTypes.GraphQLDescription; | ||
import graphql.annotations.annotationTypes.GraphQLField; | ||
import graphql.annotations.annotationTypes.GraphQLName; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@GraphQLDescription("Model for disallowed richtext configuration") | ||
public class GqlRichTextDisallowedConfig implements RichTextConfigInterface { | ||
|
||
private Set<String> protocols = new HashSet<>(); | ||
private Set<String> elements = new HashSet<>(); | ||
private List<GqlRichTextConfigAttribute> attributes = new ArrayList<>(); | ||
|
||
@GraphQLField | ||
@GraphQLName("protocols") | ||
@GraphQLDescription("Protocols") | ||
public Set<String> getProtocols() { | ||
return protocols; | ||
} | ||
|
||
@GraphQLField | ||
@GraphQLName("elements") | ||
@GraphQLDescription("HTML elements") | ||
public Set<String> getElements() { | ||
return elements; | ||
} | ||
|
||
@GraphQLField | ||
@GraphQLName("attributes") | ||
@GraphQLDescription("HTML attributes") | ||
public List<GqlRichTextConfigAttribute> getAttributes() { | ||
return attributes; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/jahia/modules/richtext/graphql/models/RichTextConfigInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.jahia.modules.richtext.graphql.models; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public interface RichTextConfigInterface { | ||
|
||
public Set<String> getProtocols(); | ||
public Set<String> getElements(); | ||
public List<GqlRichTextConfigAttribute> getAttributes(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...in/resources/META-INF/configuration-default/org.jahia.modules.richtext.config-default.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
htmlFiltering: | ||
htmlSanitizerDryRun: false | ||
protocols: | ||
- http | ||
- https | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import {createSite, deleteSite} from '@jahia/cypress'; | ||
import {DocumentNode} from 'graphql'; | ||
import {enableHtmlFiltering, installConfig} from '../fixtures/utils'; | ||
|
||
describe('HTML rich text filtering API', () => { | ||
const siteKey = 'filteringSite'; | ||
const text = '<div id="myId" role="myRole" removed-attribute="removed">Testing <h1>Testing</h1><p><strong>Testing</strong></p></div>'; | ||
let previewMutation: DocumentNode; | ||
let configQuery: DocumentNode; | ||
|
||
before(() => { | ||
createSite(siteKey); | ||
installConfig('configs/org.jahia.modules.richtext.config-filteringSite.yml'); | ||
enableHtmlFiltering(siteKey); | ||
previewMutation = require('graphql-tag/loader!../fixtures/filteringAPI/preview.graphql'); | ||
configQuery = require('graphql-tag/loader!../fixtures/filteringAPI/config.graphql'); | ||
}); | ||
|
||
after(() => { | ||
deleteSite(siteKey); | ||
}); | ||
|
||
it('filters via API and reports on removed elements/attributes', () => { | ||
cy.apollo({ | ||
mutation: previewMutation, | ||
variables: { | ||
text: text, | ||
siteKey: siteKey | ||
} | ||
}).then(response => { | ||
expect(response.data.richtextConfiguration.htmlFiltering.testFiltering.removedAttributes).length(1); | ||
expect(response.data.richtextConfiguration.htmlFiltering.testFiltering.removedAttributes[0].attributes[0]).to.equal('removed-attribute'); | ||
expect(response.data.richtextConfiguration.htmlFiltering.testFiltering.removedAttributes[0].element).to.equal('div'); | ||
expect(response.data.richtextConfiguration.htmlFiltering.testFiltering.removedElements).length(1); | ||
expect(response.data.richtextConfiguration.htmlFiltering.testFiltering.removedElements).contain('strong'); | ||
expect(response.data.richtextConfiguration.htmlFiltering.testFiltering.html).contain('role="myRole"'); | ||
expect(response.data.richtextConfiguration.htmlFiltering.testFiltering.html).contain('id="myId"'); | ||
expect(response.data.richtextConfiguration.htmlFiltering.testFiltering.html).contain('<p>Testing</p>'); | ||
}); | ||
}); | ||
|
||
it('returns a list of configured elements and attributes', () => { | ||
cy.apollo({ | ||
query: configQuery, | ||
variables: { | ||
siteKey: siteKey | ||
} | ||
}).then(response => { | ||
expect(response.data.richtextConfiguration.htmlFiltering.richtextConfiguration.attributes).length(37); | ||
expect(response.data.richtextConfiguration.htmlFiltering.richtextConfiguration.attributes.find(a => a.attribute === 'class')).to.deep.equal({ | ||
attribute: 'class', | ||
elements: [], | ||
isGlobal: true, | ||
pattern: '(myclass1|myclass2)', | ||
__typename: 'GqlRichTextConfigAttribute' | ||
}); | ||
expect(response.data.richtextConfiguration.htmlFiltering.richtextConfiguration.attributes.find(a => a.attribute === 'autoplay')).to.deep.equal({ | ||
attribute: 'autoplay', | ||
elements: [ | ||
'audio', | ||
'video' | ||
], | ||
isGlobal: false, | ||
pattern: null, | ||
__typename: 'GqlRichTextConfigAttribute' | ||
}); | ||
expect(response.data.richtextConfiguration.htmlFiltering.richtextConfiguration.elements).length(70); | ||
expect(response.data.richtextConfiguration.htmlFiltering.richtextConfiguration.protocols).length(3); | ||
expect(response.data.richtextConfiguration.htmlFiltering.richtextConfiguration.disallow.elements).length(1); | ||
expect(response.data.richtextConfiguration.htmlFiltering.richtextConfiguration.disallow.elements).contain('strong'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
query Config($siteKey: String!) { | ||
richtextConfiguration { | ||
htmlFiltering { | ||
richtextConfiguration(siteKey: $siteKey) { | ||
elements | ||
protocols | ||
attributes { | ||
attribute | ||
elements | ||
isGlobal | ||
pattern | ||
} | ||
disallow { | ||
elements | ||
protocols | ||
attributes { | ||
attribute | ||
elements | ||
isGlobal | ||
pattern | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
mutation PreviewFiltering($text: String!, $siteKey: String!) { | ||
richtextConfiguration { | ||
htmlFiltering { | ||
testFiltering( | ||
siteKey: $siteKey | ||
html: $text | ||
) { | ||
html | ||
removedElements | ||
removedAttributes { | ||
element | ||
attributes | ||
} | ||
} | ||
} | ||
} | ||
} |