-
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-22207: Fix href pattern to allow ref and external links (#10)
* BACKLOG-22207: Fix ONSITE_URL pattern to allow asset links * Fix lint * Remove .DS_Store * Fix issue adding external links * Add invalid links test
- Loading branch information
1 parent
95a83f8
commit 7759f0d
Showing
3 changed files
with
87 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import {addNode, deleteNode} from '@jahia/cypress'; | ||
import { | ||
disableHtmlFiltering, | ||
enableHtmlFiltering, | ||
getContent, | ||
modifyContent | ||
} from '../fixtures/utils'; | ||
|
||
/** | ||
* Test scenarios for default filtering cases | ||
*/ | ||
describe('Default HTML filtering', () => { | ||
const siteKey = 'digitall'; | ||
const textName = 'myText'; | ||
const path = `/sites/${siteKey}/contents/${textName}`; | ||
|
||
before(() => { | ||
addNode({ | ||
parentPathOrId: `/sites/${siteKey}/contents`, | ||
primaryNodeType: 'jnt:bigText', | ||
name: textName, | ||
properties: [{name: 'text', value: '<p>hello there</p>', language: 'en'}] | ||
}); | ||
enableHtmlFiltering(siteKey); | ||
}); | ||
|
||
after(() => { | ||
disableHtmlFiltering(siteKey); | ||
deleteNode(path); | ||
}); | ||
|
||
it('allows internal links', () => { | ||
// Note that the actual href text being sent over to the sanitizer is '##doc-context##/{workspace}/##ref:link1##' | ||
const text = '<p><a href="/files/{workspace}/sites/digitall/files/images/pdf/Conference%20Guide.pdf" ' + | ||
'title="Conference Guide.pdf">/files/{workspace}/sites/digitall/files/images/pdf/Conference%20Guide.pdf</a></p>'; | ||
modifyContent(path, text); | ||
getContent(path).then(result => { | ||
const value = result.data.jcr.nodeByPath.property.value; | ||
expect(value).to.contain('<p>'); | ||
expect(value).to.contain('<a'); | ||
expect(value).to.contain('href'); | ||
expect(value).to.contain('title'); | ||
}); | ||
}); | ||
|
||
it('allows external links', () => { | ||
const text = '<p>This is a <a href="http://google.com" title="My google link">google link</a></p>'; | ||
modifyContent(path, text); | ||
getContent(path).then(result => { | ||
const value = result.data.jcr.nodeByPath.property.value; | ||
expect(value).to.contain('<p>'); | ||
expect(value).to.contain('<a'); | ||
expect(value).to.contain('href'); | ||
expect(value).to.contain('title'); | ||
}); | ||
}); | ||
|
||
it('rejects invalid protocol links', () => { | ||
const text = '<p>This is an <a href="javascript://%0aalert(document.location)">xss test</a></p>'; | ||
modifyContent(path, text); | ||
getContent(path).then(result => { | ||
const value = result.data.jcr.nodeByPath.property.value; | ||
expect(value).to.contain('<p>'); | ||
expect(value).to.not.contain('<a'); | ||
expect(value).to.not.contain('href'); | ||
}); | ||
}); | ||
|
||
it('rejects invalid href links', () => { | ||
const text = '<p>This is an <a href="#javascript:alert(\'hello\')" target="_blank">xss test</a></p>'; | ||
modifyContent(path, text); | ||
getContent(path).then(result => { | ||
const value = result.data.jcr.nodeByPath.property.value; | ||
expect(value).to.contain('<p>'); | ||
expect(value).to.contain('<a'); | ||
expect(value).to.not.contain('href'); | ||
expect(value).to.contain('target'); | ||
}); | ||
}); | ||
}); |