<commit_before>(ns backtype.storm.ui-test
  (:use [backtype.storm.ui core])
  (:use [clojure test])
  (:use [hiccup.core :only (html)])
)

(deftest test-javascript-escaped-in-action-buttons
  (let [expected-s "confirmAction('XX\\\"XX\\'XX\\\\XX\\/XX\\nXX', 'XX\\\"XX\\'XX\\\\XX\\/XX\\nXX', 'activate', false, 0)"
        malicious-js "XX\"XX'XX\\XX/XX
XX"
        result (topology-action-button malicious-js malicious-js
                                "Activate" "activate" false 0 true)
        onclick (:onclick (second result))]

    (is (= expected-s onclick)
        "Escapes quotes, slashes, back-slashes, and new-lines.")
  )
)

(deftest test-topology-link-escapes-content-html
  (let [topo-name "BOGUSTOPO"]
    (is (= (str "<a href=\"/topology/" topo-name "\">&lt;BLINK&gt;foobar</a>")
           (html (topology-link topo-name "<BLINK>foobar"))))
  )
)

(deftest test-component-link-escapes-content-html
  (let [topo-name "BOGUSTOPO"]
    (is (= (str "<a href=\"/topology/" topo-name "/component/%3CBLINK%3Ecomp-id\">&lt;BLINK&gt;comp-id</a>")
           (html (component-link topo-name "<BLINK>comp-id"))))
  )
)

; main-topology-summary-table
; submit topo name like "<BLINK>foobar"
; Load / and visually confirm the 'id' column does not blink for the topo.

; topology-summary-table
; submit topo name like "<BLINK>foobar"
; Load / and visually confirm the 'id' column does not blink for the topo or the name

; topology-summary-table
; submit topo name like "<BLINK>foobar"
; Load / and visually confirm the 'id' column does not blink for the topo or the name

; component-page
; recompile a topology (such as the ExclamationTopology from storm-starter) and hardcode bolt/spout names with '<blink>' 
; Load the bolt or spout component page and visually confirm the 'id' column does not blink the component name.

; bolt-input-summary-table
; recompile a topology (such as the ExclamationTopology from storm-starter) and hardcode bolt/spout names with '<blink>' 
;<commit_msg>Clarify test for component summ. input stats test<commit_after>(ns backtype.storm.ui-test
  (:use [backtype.storm.ui core])
  (:use [clojure test])
  (:use [hiccup.core :only (html)])
)

(deftest test-javascript-escaped-in-action-buttons
  (let [expected-s "confirmAction('XX\\\"XX\\'XX\\\\XX\\/XX\\nXX', 'XX\\\"XX\\'XX\\\\XX\\/XX\\nXX', 'activate', false, 0)"
        malicious-js "XX\"XX'XX\\XX/XX
XX"
        result (topology-action-button malicious-js malicious-js
                                "Activate" "activate" false 0 true)
        onclick (:onclick (second result))]

    (is (= expected-s onclick)
        "Escapes quotes, slashes, back-slashes, and new-lines.")
  )
)

(deftest test-topology-link-escapes-content-html
  (let [topo-name "BOGUSTOPO"]
    (is (= (str "<a href=\"/topology/" topo-name "\">&lt;BLINK&gt;foobar</a>")
           (html (topology-link topo-name "<BLINK>foobar"))))
  )
)

(deftest test-component-link-escapes-content-html
  (let [topo-name "BOGUSTOPO"]
    (is (= (str "<a href=\"/topology/" topo-name "/component/%3CBLINK%3Ecomp-id\">&lt;BLINK&gt;comp-id</a>")
           (html (component-link topo-name "<BLINK>comp-id"))))
  )
)

; main-topology-summary-table
; submit topo name like "<BLINK>foobar"
; Load / and visually confirm the 'id' column does not blink for the topo.

; topology-summary-table
; submit topo name like "<BLINK>foobar"
; Load / and visually confirm the 'id' column does not blink for the topo or the name

; topology-summary-table
; submit topo name like "<BLINK>foobar"
; Load / and visually confirm the 'id' column does not blink for the topo or the name

; component-page
; recompile a topology (such as the ExclamationTopology from storm-starter) and hardcode bolt/spout names with '<blink>' 
; Load the bolt or spout component page and visually confirm the 'id' column does not blink the component name.

; bolt-input-summary-table
; recompile a topology (such as the ExclamationTopology from storm-starter) and hardcode bolt names with '<blink>' 
; A bolt component page and visually confirm the 'component' column of the Input stats does not blink the component name.
{'fraction_non_alphanumeric': 0.14745762711864407, 'fraction_numerical': 0.001937046004842615, 'mean_word_length': 3.4467168998923574, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2346888', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1367, 'n_words': 407}