info-sanitization.jsx 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import React from "react"
  2. import { render } from "enzyme"
  3. import { fromJS } from "immutable"
  4. import Info from "components/info"
  5. import Markdown from "components/providers/markdown"
  6. describe("<Info/> Sanitization", function(){
  7. const dummyComponent = () => null
  8. const components = {
  9. Markdown
  10. }
  11. const props = {
  12. getComponent: c => components[c] || dummyComponent,
  13. info: fromJS({
  14. title: "Test Title **strong** <script>alert(1)</script>",
  15. description: "Description *with* <script>Markdown</script>"
  16. }),
  17. host: "example.test",
  18. basePath: "/api",
  19. selectedServer: "https://example.test",
  20. }
  21. it("renders sanitized .title content", function(){
  22. let wrapper = render(<Info {...props}/>)
  23. expect(wrapper.find(".title").html()).toEqual("Test Title **strong** &lt;script&gt;alert(1)&lt;/script&gt;")
  24. })
  25. it("renders sanitized .description content", function() {
  26. let wrapper = render(<Info {...props}/>)
  27. expect(wrapper.find(".description").html()).toEqual("<div class=\"markdown\"><p>Description <em>with</em> </p>\n</div>")
  28. })
  29. })