Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-74126

[atlassian-jira-software-cloud] Extract inline script block in com/atlassian/jira/cloud/jenkins/config/JiraCloudPluginConfig/config.js.test.html

      Problem

      == Inline Script Block
      Line: 25
      ----
      <script>
      
      function isErrorVisible() {
          return document.getElementById('errorDiv').style.display == 'block';
      }
      
      function isSuccessVisible() {
          return document.getElementById('successDiv').style.display == 'block';
      }
      
      function setTestRegex(regexStr) {
          document.getElementById('textRegexInput').value = regexStr;
      }
      
      function getErrorMessage() {
          return document.getElementById('errorDiv').innerHTML;
      }
      
      function getSuccessMessage() {
          return document.getElementById('successDiv').innerHTML;
      }
      
      function assertTrue(bool) {
          if (!bool) {
              throw new Error("Assertion error");
          } else {
              console.log("check!");
          }
      }
      
      function checkStarted(message) {
          console.warn("Running test: " + message);
      }
      
      function checkFinished() {
          console.warn("OK!");
      }
      
      {
          checkStarted("Test browser not supported case");
      
          const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
          testObj._isCapturingGroupsSupported = function() { return false; };
      
          assertTrue(!testObj.test("blah", ["a"]));
          assertTrue(isErrorVisible());
          assertTrue(!isSuccessVisible());
          assertTrue(getErrorMessage().indexOf("Your browser does not support") >= 0);
      
          checkFinished();
      }
      
      {
          checkStarted("Happy path no groups");
      
          setTestRegex("^Hello .*$")
          const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
          testObj._getUserInput = function(question) {
              assertTrue(question === "TheQuestion");
              return "Hello World";
          }
      
          assertTrue(!testObj.test("TheQuestion", []));
          assertTrue(!isErrorVisible());
          assertTrue(isSuccessVisible());
          assertTrue(getSuccessMessage() === "Matches!");
      
          checkFinished();
      }
      
      {
          checkStarted("Happy path no groups");
      
          setTestRegex("^Hello .*$")
          const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
          testObj._getUserInput = function(question) {
              assertTrue(question === "TheQuestion");
              return "Hello World";
          }
      
          assertTrue(!testObj.test("TheQuestion", []));
          assertTrue(!isErrorVisible());
          assertTrue(isSuccessVisible());
          assertTrue(getSuccessMessage() === "Matches!");
      
          checkFinished();
      }
      
      {
          checkStarted("Invalid regex");
      
          setTestRegex("^Hello (?<")
          const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
      
          assertTrue(!testObj.test("TheQuestion", []));
          assertTrue(isErrorVisible());
          assertTrue(!isSuccessVisible());
          assertTrue(getErrorMessage() === '"^Hello (?&lt;" is not a valid RegEx string. SyntaxError: Invalid regular expression: /^Hello (?&lt;/: Invalid capture group name');
      
          checkFinished();
      }
      
      {
          checkStarted("Empty regex");
      
          setTestRegex("")
          const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
      
          assertTrue(!testObj.test("TheQuestion", []));
          assertTrue(isErrorVisible());
          assertTrue(!isSuccessVisible());
          assertTrue(getErrorMessage() === 'Empty RegEx, nothing to test');
      
          checkFinished();
      }
      
      {
          checkStarted("Happy path with groups");
      
          setTestRegex("^Hello (?<group1>.*) (?<group2>.*)$")
          const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
          testObj._getUserInput = function(question) {
              assertTrue(question === "TheQuestion");
              return "Hello WorldFirst WorldSecond";
          }
      
          assertTrue(!testObj.test("TheQuestion", ["group1", "group2"]));
          assertTrue(!isErrorVisible());
          assertTrue(isSuccessVisible());
          assertTrue(getSuccessMessage() === "Matches: group1=WorldFirst, group2=WorldSecond");
      
          checkFinished();
      }
      
      {
          checkStarted("Error path not all groups");
      
          setTestRegex("^Hello (?<group1>.*) (?<group2>.*)$")
          const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
          testObj._getUserInput = function(question) {
              assertTrue(question === "TheQuestion");
              return "Hello WorldFirst ";
          }
      
          assertTrue(!testObj.test("TheQuestion", ["group1", "group2"]));
          assertTrue(isErrorVisible());
          assertTrue(!isSuccessVisible());
          assertTrue(getErrorMessage() === "Error: the values for the following groups were not found: group2");
      
          checkFinished();
      }
      
      {
          checkStarted("setTestRegex")
      
          atlWatchNotEmpty("textRegexInput", "errorDiv", "<notempty>");
          setTestRegex("");
      
          setTimeout(function() {
              assertTrue(isErrorVisible());
              console.log(getErrorMessage());
              assertTrue(getErrorMessage() === "&lt;notempty&gt;");
      
              setTestRegex("blah");
      
              setTimeout(function() {
                  assertTrue(!isErrorVisible());
      
                  checkFinished();
              }, 500);
          }, 500);
      
      }
      
      console.warn("All checks are passing!")
      
      </script>
      ----
      

      Solution

      https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks

          [JENKINS-74126] [atlassian-jira-software-cloud] Extract inline script block in com/atlassian/jira/cloud/jenkins/config/JiraCloudPluginConfig/config.js.test.html

          Basil Crow created issue -
          Basil Crow made changes -
          Assignee Original: Boris Gvozdev [ bgvozdev ]
          Basil Crow made changes -
          Description Original: h4. Problems

          {noformat}
          == Inline Script Block
          Line: 25
          ----
          <script>

          function isErrorVisible() {
              return document.getElementById('errorDiv').style.display == 'block';
          }

          function isSuccessVisible() {
              return document.getElementById('successDiv').style.display == 'block';
          }

          function setTestRegex(regexStr) {
              document.getElementById('textRegexInput').value = regexStr;
          }

          function getErrorMessage() {
              return document.getElementById('errorDiv').innerHTML;
          }

          function getSuccessMessage() {
              return document.getElementById('successDiv').innerHTML;
          }

          function assertTrue(bool) {
              if (!bool) {
                  throw new Error("Assertion error");
              } else {
                  console.log("check!");
              }
          }

          function checkStarted(message) {
              console.warn("Running test: " + message);
          }

          function checkFinished() {
              console.warn("OK!");
          }

          {
              checkStarted("Test browser not supported case");

              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._isCapturingGroupsSupported = function() { return false; };

              assertTrue(!testObj.test("blah", ["a"]));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage().indexOf("Your browser does not support") >= 0);

              checkFinished();
          }

          {
              checkStarted("Happy path no groups");

              setTestRegex("^Hello .*$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello World";
              }

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(!isErrorVisible());
              assertTrue(isSuccessVisible());
              assertTrue(getSuccessMessage() === "Matches!");

              checkFinished();
          }

          {
              checkStarted("Happy path no groups");

              setTestRegex("^Hello .*$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello World";
              }

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(!isErrorVisible());
              assertTrue(isSuccessVisible());
              assertTrue(getSuccessMessage() === "Matches!");

              checkFinished();
          }

          {
              checkStarted("Invalid regex");

              setTestRegex("^Hello (?<")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage() === '"^Hello (?&lt;" is not a valid RegEx string. SyntaxError: Invalid regular expression: /^Hello (?&lt;/: Invalid capture group name');

              checkFinished();
          }

          {
              checkStarted("Empty regex");

              setTestRegex("")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage() === 'Empty RegEx, nothing to test');

              checkFinished();
          }

          {
              checkStarted("Happy path with groups");

              setTestRegex("^Hello (?<group1>.*) (?<group2>.*)$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello WorldFirst WorldSecond";
              }

              assertTrue(!testObj.test("TheQuestion", ["group1", "group2"]));
              assertTrue(!isErrorVisible());
              assertTrue(isSuccessVisible());
              assertTrue(getSuccessMessage() === "Matches: group1=WorldFirst, group2=WorldSecond");

              checkFinished();
          }

          {
              checkStarted("Error path not all groups");

              setTestRegex("^Hello (?<group1>.*) (?<group2>.*)$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello WorldFirst ";
              }

              assertTrue(!testObj.test("TheQuestion", ["group1", "group2"]));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage() === "Error: the values for the following groups were not found: group2");

              checkFinished();
          }

          {
              checkStarted("setTestRegex")

              atlWatchNotEmpty("textRegexInput", "errorDiv", "<notempty>");
              setTestRegex("");

              setTimeout(function() {
                  assertTrue(isErrorVisible());
                  console.log(getErrorMessage());
                  assertTrue(getErrorMessage() === "&lt;notempty&gt;");

                  setTestRegex("blah");

                  setTimeout(function() {
                      assertTrue(!isErrorVisible());

                      checkFinished();
                  }, 500);
              }, 500);

          }

          console.warn("All checks are passing!")

          </script>
          ----

          == Inline Script Block
          Line: 25
          ----
          <script>

          function isErrorVisible() {
              return document.getElementById('errorDiv').style.display == 'block';
          }

          function isSuccessVisible() {
              return document.getElementById('successDiv').style.display == 'block';
          }

          function setTestRegex(regexStr) {
              document.getElementById('textRegexInput').value = regexStr;
          }

          function getErrorMessage() {
              return document.getElementById('errorDiv').innerHTML;
          }

          function getSuccessMessage() {
              return document.getElementById('successDiv').innerHTML;
          }

          function assertTrue(bool) {
              if (!bool) {
                  throw new Error("Assertion error");
              } else {
                  console.log("check!");
              }
          }

          function checkStarted(message) {
              console.warn("Running test: " + message);
          }

          function checkFinished() {
              console.warn("OK!");
          }

          {
              checkStarted("Test browser not supported case");

              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._isCapturingGroupsSupported = function() { return false; };

              assertTrue(!testObj.test("blah", ["a"]));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage().indexOf("Your browser does not support") >= 0);

              checkFinished();
          }

          {
              checkStarted("Happy path no groups");

              setTestRegex("^Hello .*$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello World";
              }

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(!isErrorVisible());
              assertTrue(isSuccessVisible());
              assertTrue(getSuccessMessage() === "Matches!");

              checkFinished();
          }

          {
              checkStarted("Happy path no groups");

              setTestRegex("^Hello .*$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello World";
              }

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(!isErrorVisible());
              assertTrue(isSuccessVisible());
              assertTrue(getSuccessMessage() === "Matches!");

              checkFinished();
          }

          {
              checkStarted("Invalid regex");

              setTestRegex("^Hello (?<")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage() === '"^Hello (?&lt;" is not a valid RegEx string. SyntaxError: Invalid regular expression: /^Hello (?&lt;/: Invalid capture group name');

              checkFinished();
          }

          {
              checkStarted("Empty regex");

              setTestRegex("")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage() === 'Empty RegEx, nothing to test');

              checkFinished();
          }

          {
              checkStarted("Happy path with groups");

              setTestRegex("^Hello (?<group1>.*) (?<group2>.*)$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello WorldFirst WorldSecond";
              }

              assertTrue(!testObj.test("TheQuestion", ["group1", "group2"]));
              assertTrue(!isErrorVisible());
              assertTrue(isSuccessVisible());
              assertTrue(getSuccessMessage() === "Matches: group1=WorldFirst, group2=WorldSecond");

              checkFinished();
          }

          {
              checkStarted("Error path not all groups");

              setTestRegex("^Hello (?<group1>.*) (?<group2>.*)$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello WorldFirst ";
              }

              assertTrue(!testObj.test("TheQuestion", ["group1", "group2"]));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage() === "Error: the values for the following groups were not found: group2");

              checkFinished();
          }

          {
              checkStarted("setTestRegex")

              atlWatchNotEmpty("textRegexInput", "errorDiv", "<notempty>");
              setTestRegex("");

              setTimeout(function() {
                  assertTrue(isErrorVisible());
                  console.log(getErrorMessage());
                  assertTrue(getErrorMessage() === "&lt;notempty&gt;");

                  setTestRegex("blah");

                  setTimeout(function() {
                      assertTrue(!isErrorVisible());

                      checkFinished();
                  }, 500);
              }, 500);

          }

          console.warn("All checks are passing!")

          </script>
          ----
          {noformat}

          h4. Solution

          [https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks]
          New: h4. Problem

          {noformat}
          == Inline Script Block
          Line: 25
          ----
          <script>

          function isErrorVisible() {
              return document.getElementById('errorDiv').style.display == 'block';
          }

          function isSuccessVisible() {
              return document.getElementById('successDiv').style.display == 'block';
          }

          function setTestRegex(regexStr) {
              document.getElementById('textRegexInput').value = regexStr;
          }

          function getErrorMessage() {
              return document.getElementById('errorDiv').innerHTML;
          }

          function getSuccessMessage() {
              return document.getElementById('successDiv').innerHTML;
          }

          function assertTrue(bool) {
              if (!bool) {
                  throw new Error("Assertion error");
              } else {
                  console.log("check!");
              }
          }

          function checkStarted(message) {
              console.warn("Running test: " + message);
          }

          function checkFinished() {
              console.warn("OK!");
          }

          {
              checkStarted("Test browser not supported case");

              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._isCapturingGroupsSupported = function() { return false; };

              assertTrue(!testObj.test("blah", ["a"]));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage().indexOf("Your browser does not support") >= 0);

              checkFinished();
          }

          {
              checkStarted("Happy path no groups");

              setTestRegex("^Hello .*$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello World";
              }

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(!isErrorVisible());
              assertTrue(isSuccessVisible());
              assertTrue(getSuccessMessage() === "Matches!");

              checkFinished();
          }

          {
              checkStarted("Happy path no groups");

              setTestRegex("^Hello .*$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello World";
              }

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(!isErrorVisible());
              assertTrue(isSuccessVisible());
              assertTrue(getSuccessMessage() === "Matches!");

              checkFinished();
          }

          {
              checkStarted("Invalid regex");

              setTestRegex("^Hello (?<")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage() === '"^Hello (?&lt;" is not a valid RegEx string. SyntaxError: Invalid regular expression: /^Hello (?&lt;/: Invalid capture group name');

              checkFinished();
          }

          {
              checkStarted("Empty regex");

              setTestRegex("")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");

              assertTrue(!testObj.test("TheQuestion", []));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage() === 'Empty RegEx, nothing to test');

              checkFinished();
          }

          {
              checkStarted("Happy path with groups");

              setTestRegex("^Hello (?<group1>.*) (?<group2>.*)$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello WorldFirst WorldSecond";
              }

              assertTrue(!testObj.test("TheQuestion", ["group1", "group2"]));
              assertTrue(!isErrorVisible());
              assertTrue(isSuccessVisible());
              assertTrue(getSuccessMessage() === "Matches: group1=WorldFirst, group2=WorldSecond");

              checkFinished();
          }

          {
              checkStarted("Error path not all groups");

              setTestRegex("^Hello (?<group1>.*) (?<group2>.*)$")
              const testObj = new AtlassianRegexTester("textRegexInput", "errorDiv", "successDiv");
              testObj._getUserInput = function(question) {
                  assertTrue(question === "TheQuestion");
                  return "Hello WorldFirst ";
              }

              assertTrue(!testObj.test("TheQuestion", ["group1", "group2"]));
              assertTrue(isErrorVisible());
              assertTrue(!isSuccessVisible());
              assertTrue(getErrorMessage() === "Error: the values for the following groups were not found: group2");

              checkFinished();
          }

          {
              checkStarted("setTestRegex")

              atlWatchNotEmpty("textRegexInput", "errorDiv", "<notempty>");
              setTestRegex("");

              setTimeout(function() {
                  assertTrue(isErrorVisible());
                  console.log(getErrorMessage());
                  assertTrue(getErrorMessage() === "&lt;notempty&gt;");

                  setTestRegex("blah");

                  setTimeout(function() {
                      assertTrue(!isErrorVisible());

                      checkFinished();
                  }, 500);
              }, 500);

          }

          console.warn("All checks are passing!")

          </script>
          ----
          {noformat}

          h4. Solution

          [https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks]
          Summary Original: [atlassian-jira-software-cloud] Extract inline script blocks in com/atlassian/jira/cloud/jenkins/config/JiraCloudPluginConfig/config.js.test.html New: [atlassian-jira-software-cloud] Extract inline script block in com/atlassian/jira/cloud/jenkins/config/JiraCloudPluginConfig/config.js.test.html
          Yaroslav Afenkin made changes -
          Assignee New: Yaroslav Afenkin [ yafenkin ]
          Yaroslav Afenkin made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Yaroslav Afenkin made changes -
          Resolution New: Won't Fix [ 2 ]
          Status Original: In Progress [ 3 ] New: Closed [ 6 ]

            yafenkin Yaroslav Afenkin
            basil Basil Crow
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: