You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ra...@apache.org on 2022/05/18 19:31:07 UTC
[trafficcontrol] branch master updated: Cdnjs integrity hashes (#6826)
This is an automated email from the ASF dual-hosted git repository.
rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 77d88c387a Cdnjs integrity hashes (#6826)
77d88c387a is described below
commit 77d88c387aa8398bec5858434644b9f92bb65dfc
Author: ocket8888 <oc...@apache.org>
AuthorDate: Wed May 18 13:31:03 2022 -0600
Cdnjs integrity hashes (#6826)
* Add crossorigin=anonymous and SHA384 integrity hashes to CDN resources
This doesn't really matter because these are just (unused afaik) tests,
but it's really easy to do.
* Eliminate prototype pollution in load-test react script
---
test/router/index.html | 49 +++++++++++++++++++++++++++++------
test/router/js/load-test.jsx | 61 +++++++++++++++++++++++++-------------------
2 files changed, 76 insertions(+), 34 deletions(-)
diff --git a/test/router/index.html b/test/router/index.html
index e4dbdee012..33ea561351 100644
--- a/test/router/index.html
+++ b/test/router/index.html
@@ -24,14 +24,47 @@ under the License.
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Traffic Router Loadtest</title>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.6/d3.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
- <script src="https://unpkg.com/babel-core@5.8.38/browser.min.js"></script>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
+ <script
+ integrity="sha384-HERpnF+tlZ/PxhCuxaUfTFrU8tKctj33vfD60o0LCNaYDxhrZsk45o1QG9L8GV1y"
+ crossorigin="anonymous"
+ src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.6/d3.min.js"
+ ></script>
+ <script
+ integrity="sha384-7pfELK0arQ3VANqV4kiPWPh5wOsrfitjFGF/NdyHXUJ3JJPy/rNhasPtdkaNKhul"
+ crossorigin="anonymous"
+ src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"
+ ></script>
+ <script
+ integrity="sha384-bQIyvl+8Ufi5KiKZPG9VItNWmhcAXA1pa5nHIEoBGob+rdbjJnpNV3s288Mz2yZu"
+ crossorigin="anonymous"
+ src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"
+ ></script>
+ <script
+ integrity="sha384-ZzFfcTbsRst34N23lWs6TtlfonXwDgpeALh+ObwYXav5BSo0j7KsaAtcdn+xrnS1"
+ crossorigin="anonymous"
+ src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"
+ ></script>
+ <script
+ integrity="sha384-Fw04PJPC6ayYz0V6lPpRaiQxouxskHt/AjlelA2NWboTMnn5niXpXMyN4hftijud"
+ crossorigin="anonymous"
+ src="https://unpkg.com/babel-core@5.8.38/browser.min.js"
+ ></script>
+ <link
+ integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
+ crossorigin="anonymous"
+ rel="stylesheet"
+ href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
+ >
+ <script
+ integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ"
+ crossorigin="anonymous"
+ src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"
+ ></script>
+ <script
+ integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
+ crossorigin="anonymous"
+ src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
+ ></script>
<link href="css/loadtest.css" rel="stylesheet">
<script src="js/load-test.jsx" type="text/babel"></script>
</head>
diff --git a/test/router/js/load-test.jsx b/test/router/js/load-test.jsx
index f06a6dd7a7..32888a7edb 100644
--- a/test/router/js/load-test.jsx
+++ b/test/router/js/load-test.jsx
@@ -12,29 +12,41 @@
limitations under the License.
*/}
-if ( ! Array.prototype.groupBy) {
- Array.prototype.groupBy = function (f)
- {
- var groups = {};
- this.forEach(function(o) {
- var group = JSON.stringify(f(o));
- groups[group] = groups[group] || [];
- groups[group].push(o);
- });
-
- return Object.keys(groups).map(function (group) {
- return groups[group];
- });
- };
+/**
+ * Creates an array of arrays of elements that return the same value from the
+ * given function.
+ *
+ * @template T
+ * @param {Array<T>} a The array to group.
+ * @param {(e: T) => string} f The grouping function; values in `a` that return
+ * the same value from this function will be grouped together.
+ * @returns {Array<Array<T>>} All of the elements of `a`, grouped by `f`.
+ */
+function groupBy(a, f) {
+ /** @type Record<string, Array<T>> */
+ const groups = {};
+ for (const element of a) {
+ const group = f(element);
+ if (group in groups) {
+ groups[group].push(element);
+ } else {
+ groups[group] = [element];
+ }
+ }
+ return Object.keys(groups).map(g=>groups[g]);
}
-if (!Array.prototype.unique) {
- Array.prototype.unique = function(a){
- return function() {
- return this.filter(a);
- }
- }(function (a,b,c) { return c.indexOf(a, b + 1) < 0; }
- );
+/**
+ * Gets the unique elements of an Array as a new Array. Does not modify Arrays
+ * in-place.
+ *
+ * @template T
+ * @param {Array<T>} a The array to be unique'd.
+ * @returns {Array<T>} A new array with all of the values in `a`, but without
+ * any duplicate values. Duplicates are determined with `===`.
+ */
+function unique(a) {
+ return Array.from(new Set(a));
}
var CdnTestForm = React.createClass({
@@ -315,8 +327,7 @@ var LabBox = React.createClass({
if (this.deliveryServices != null) {
- var cdnNames = this.deliveryServices.map(function (item) { return item.cdnName})
- .unique()
+ var cdnNames = unique(this.deliveryServices.map(function (item) { return item.cdnName}))
.filter(function(item) { return item.toLowerCase() != 'all'});
cdnNames.forEach(function (cdnName) {
@@ -514,9 +525,7 @@ var ResultsList = React.createClass({
}
histogram(this.props.data.map(function (r, i) { return (r.latency / 1000.0).toFixed(3)}));
- var groupedResults = this.props.data.groupBy(function (result) {
- return [result.host];
- });
+ var groupedResults = groupBy(this.props.data, result => JSON.stringify([result.host]));
for (var i = 0; i < groupedResults.length; i++) {
groupedResults[i].host = groupedResults[i][0].host;