feat: migrate unit tests to Jest (#6353)
* config(jest): updated setup * config(jest): update testMatch to include jsx files * config(jest): add transformIgnorePatterns * config(jest): update ignore files that do not work in jest yet * config: add test:unit-jest to test script * fix(jest): lint with eslint-plugin-jest * refactor(jest): move unit test directory * refactor(mocha): restore mocha tests that fail in jest * docs(jest): update helpful scripts with test:unit-jest
This commit is contained in:
34
test/unit/xss/markdown-script-sanitization.jsx
Normal file
34
test/unit/xss/markdown-script-sanitization.jsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import React from "react"
|
||||
import { render } from "enzyme"
|
||||
import Markdown from "components/providers/markdown"
|
||||
import { Markdown as OAS3Markdown } from "corePlugins/oas3/wrap-components/markdown.jsx"
|
||||
|
||||
describe("Markdown Script Sanitization", function() {
|
||||
describe("Swagger 2.0", function() {
|
||||
it("sanitizes <script> elements", function() {
|
||||
const str = `script <script>alert(1)</script>`
|
||||
const el = render(<Markdown source={str} />)
|
||||
expect(el.html()).toEqual(`<div class="markdown"><p>script </p>\n</div>`)
|
||||
})
|
||||
|
||||
it("sanitizes <img> elements", function() {
|
||||
const str = `<img src=x onerror="alert('img-in-description')">`
|
||||
const el = render(<Markdown source={str} />)
|
||||
expect(el.html()).toEqual(`<div class="markdown"><p><img src="x"></p>\n</div>`)
|
||||
})
|
||||
})
|
||||
|
||||
describe("OAS 3", function() {
|
||||
it("sanitizes <script> elements", function() {
|
||||
const str = `script <script>alert(1)</script>`
|
||||
const el = render(<OAS3Markdown source={str} />)
|
||||
expect(el.html()).toEqual(`<div class="renderedMarkdown"><p>script </p></div>`)
|
||||
})
|
||||
|
||||
it("sanitizes <img> elements", function() {
|
||||
const str = `<img src=x onerror="alert('img-in-description')">`
|
||||
const el = render(<OAS3Markdown source={str} />)
|
||||
expect(el.html()).toEqual(`<div class="renderedMarkdown"><p><img src="x"></p></div>`)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user