Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/dom/security/test/csp/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 4 kB image not shown  

Quelle  test_CSP.html   Sprache: HTML

 
 products/Sources/formale Sprachen/C/Firefox/dom/security/test/csp/test_CSP.html


<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Content Security Policy Connections</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<iframe style="width:200px;height:200px;" id='cspframe'></iframe>
<script class="testbody" type="text/javascript">

// These are test results: -1 means it hasn't run,
// true/false is the pass/fail result.
window.tests = {
  img_good: -1,
  img_bad: -1,
  style_good: -1,
  style_bad: -1,
  frame_good: -1,
  frame_bad: -1,
  script_good: -1,
  script_bad: -1,
  xhr_good: -1,
  xhr_bad: -1,
  fetch_good: -1,
  fetch_bad: -1,
  beacon_good: -1,
  beacon_bad: -1,
  media_good: -1,
  media_bad: -1,
  font_good: -1,
  font_bad: -1,
  object_good: -1,
  object_bad: -1,
};

SpecialPowers.registerObservers("csp-on-violate-policy");

// This is used to watch the blocked data bounce off CSP and allowed data
// get sent out to the wire.
function examiner() {
  SpecialPowers.addObserver(this, "csp-on-violate-policy");
  SpecialPowers.addObserver(this, "specialpowers-csp-on-violate-policy");
  SpecialPowers.addObserver(this, "specialpowers-http-notify-request");
}
examiner.prototype  = {
  observe(subject, topic, data) {
    var testpat = new RegExp("testid=([a-z0-9_]+)");

    //_good things better be allowed!
    //_bad things better be stopped!

    // This is a special observer topic that is proxied from
    // http-on-modify-request in the parent process to inform us when a URI is
    // loaded
    if (topic === "specialpowers-http-notify-request") {
      var uri = data;
      if (!testpat.test(uri)) return;
      var testid = testpat.exec(uri)[1];

      window.testResult(testid,
                        /_good/.test(testid),
                        uri + " allowed by csp");
    }

    if (topic === "csp-on-violate-policy" ||
        topic === "specialpowers-csp-on-violate-policy") {
      // these were blocked... record that they were blocked
      var asciiSpec = SpecialPowers.getPrivilegedProps(SpecialPowers.do_QueryInterface(subject, "nsIURI"), "asciiSpec");
      if (!testpat.test(asciiSpec)) return;
      var testid = testpat.exec(asciiSpec)[1];
      window.testResult(testid,
                        /_bad/.test(testid),
                        asciiSpec + " blocked by \"" + data + "\"");
    }
  },

  // must eventually call this to remove the listener,
  // or mochitests might get borked.
  remove() {
    SpecialPowers.removeObserver(this, "csp-on-violate-policy");
    SpecialPowers.removeObserver(this, "specialpowers-csp-on-violate-policy");
    SpecialPowers.removeObserver(this, "specialpowers-http-notify-request");
  }
}

window.examiner = new examiner();

window.testResult = function(testname, result, msg) {
  // test already complete.... forget it... remember the first result.
  if (window.tests[testname] != -1)
    return;

  ok(testname in window.tests, "It's a real test");
  window.tests[testname] = result;
  is(result, true, testname + ' test: ' + msg);

  // if any test is incomplete, keep waiting
  for (var v in window.tests)
    if(tests[v] == -1)
      return;

  // ... otherwise, finish
  window.examiner.remove();
  SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();

SpecialPowers.pushPrefEnv(
  {'set':[// On a cellular connection the default preload value is 0 ("preload
          // none"). Our Android emulators emulate a cellular connection, and
          // so by default preload no media data. This causes the media_* tests
          // to timeout. We set the default used by cellular connections to the
          // same as used by non-cellular connections in order to get
          // consistent behavior across platforms/devices.
          ["media.preload.default", 2],
          ["media.preload.default.cellular", 2]]},
    function() {
      // save this for last so that our listeners are registered.
      // ... this loads the testbed of good and bad requests.
      document.getElementById('cspframe').src = 'file_main.html';
    });
</script>
</pre>
</body>
</html>

Messung V0.5
C=97 H=100 G=98

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.