Skip to content

Commit bfdfa3c

Browse files
committed
Added improved JavaScript port coverage to CI and fixed port security alerts
1 parent d03e8e6 commit bfdfa3c

File tree

4 files changed

+100
-7
lines changed

4 files changed

+100
-7
lines changed

.github/workflows/parparvm-tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ on:
44
pull_request:
55
paths:
66
- 'vm/**'
7+
- 'Ports/JavaScriptPort/**'
78
- '!vm/**/README.md'
89
- '!vm/**/readme.md'
910
- '!vm/**/docs/**'
1011
push:
1112
branches: [ master, main ]
1213
paths:
1314
- 'vm/**'
15+
- 'Ports/JavaScriptPort/**'
1416
- '!vm/**/README.md'
1517
- '!vm/**/readme.md'
1618
- '!vm/**/docs/**'
@@ -79,6 +81,11 @@ jobs:
7981
java-version: '8'
8082
cache: 'maven'
8183

84+
- name: Set up Node
85+
uses: actions/setup-node@v4
86+
with:
87+
node-version: '20'
88+
8289
- name: Run ParparVM JVM tests
8390
working-directory: vm
8491
run: mvn -B clean package -pl JavaAPI -am -DskipTests && mvn -B test -pl tests -am -DexcludedGroups=benchmark

.github/workflows/pr.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ jobs:
7272
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
7373
restore-keys: |
7474
${{ runner.os }}-m2
75+
- name: Set up Node
76+
if: ${{ matrix.java-version == 8 }}
77+
uses: actions/setup-node@v4
78+
with:
79+
node-version: '20'
7580
- name: Run Unit Tests
7681
run: |
7782
MVN_ARGS=""
@@ -110,6 +115,10 @@ jobs:
110115
- name: Run SpotBugs for ByteCodeTranslator
111116
if: ${{ matrix.java-version == 8 }}
112117
run: mvn -B -DskipTests=true -f vm/ByteCodeTranslator/pom.xml verify
118+
- name: Run JavaScript Port smoke integration
119+
if: ${{ matrix.java-version == 8 }}
120+
working-directory: vm
121+
run: mvn -B test -pl tests -am -Dtest=JavaScriptPortSmokeIntegrationTest
113122
- name: Generate static analysis HTML summaries
114123
if: ${{ always() && matrix.java-version == 8 }}
115124
env:

Ports/JavaScriptPort/src/main/webapp/js/fontmetrics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ setTimeout(function() {
2929
})();
3030

3131
window.cn1_escape_single_quotes = function(str) {
32-
return str.replace(/'/g, "\\'");
32+
return String(str).replace(/\\/g, "\\\\").replace(/'/g, "\\'");
3333
};
3434
window.cn1NativeBacksideHooks = [];
3535
window.cn1RunOnMainThread = function(callback) {
@@ -3119,4 +3119,4 @@ window.virtualKeyboardDetector = ( function( window, undefined ) {
31193119
}
31203120

31213121
window.CN1AudioRecorder = AudioRecorder;
3122-
})();
3122+
})();

Ports/JavaScriptPort/src/main/webapp/js/videojs/adapter.js

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4535,10 +4535,88 @@ module.exports = function(window, edgeVersion) {
45354535
// SDP helpers.
45364536
var SDPUtils = {};
45374537

4538+
SDPUtils.getCrypto = function() {
4539+
if (typeof globalThis !== 'undefined' && globalThis.crypto &&
4540+
typeof globalThis.crypto.getRandomValues === 'function') {
4541+
return globalThis.crypto;
4542+
}
4543+
if (typeof self !== 'undefined' && self.crypto &&
4544+
typeof self.crypto.getRandomValues === 'function') {
4545+
return self.crypto;
4546+
}
4547+
if (typeof window !== 'undefined' && window.crypto &&
4548+
typeof window.crypto.getRandomValues === 'function') {
4549+
return window.crypto;
4550+
}
4551+
return null;
4552+
};
4553+
4554+
SDPUtils._fallbackCounter = 0;
4555+
4556+
SDPUtils.generateFallbackDigits = function(length) {
4557+
var seed = String(Date.now()) +
4558+
String(typeof performance !== 'undefined' &&
4559+
typeof performance.now === 'function'
4560+
? performance.now() : 0) +
4561+
String(SDPUtils._fallbackCounter++);
4562+
var chars = '';
4563+
var i;
4564+
for (i = 0; chars.length < length; i++) {
4565+
chars += seed.charAt(i % seed.length);
4566+
}
4567+
return chars.substr(0, length);
4568+
};
4569+
4570+
SDPUtils.generateFallbackIdentifier = function(length) {
4571+
var alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789';
4572+
var seed = SDPUtils.generateFallbackDigits(length * 2);
4573+
var chars = '';
4574+
var i;
4575+
for (i = 0; i < length; i++) {
4576+
chars += alphabet.charAt(parseInt(seed.charAt(i), 10) % alphabet.length);
4577+
}
4578+
return chars;
4579+
};
4580+
4581+
SDPUtils.generateSecureDigits = function(length) {
4582+
var crypto = SDPUtils.getCrypto();
4583+
var chars = '';
4584+
var values;
4585+
var i;
4586+
4587+
if (crypto) {
4588+
values = new Uint32Array(length);
4589+
crypto.getRandomValues(values);
4590+
for (i = 0; i < length; i++) {
4591+
chars += (values[i] % 10).toString();
4592+
}
4593+
return chars;
4594+
}
4595+
return SDPUtils.generateFallbackDigits(length);
4596+
};
4597+
4598+
SDPUtils.generateSecureIdentifier = function(length) {
4599+
var crypto = SDPUtils.getCrypto();
4600+
var alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789';
4601+
var chars = '';
4602+
var values;
4603+
var i;
4604+
4605+
if (crypto) {
4606+
values = new Uint8Array(length);
4607+
crypto.getRandomValues(values);
4608+
for (i = 0; i < length; i++) {
4609+
chars += alphabet.charAt(values[i] % alphabet.length);
4610+
}
4611+
return chars;
4612+
}
4613+
return SDPUtils.generateFallbackIdentifier(length);
4614+
};
4615+
45384616
// Generate an alphanumeric identifier for cname or mids.
45394617
// TODO: use UUIDs instead? https://gist.github.com/jed/982883
45404618
SDPUtils.generateIdentifier = function() {
4541-
return Math.random().toString(36).substr(2, 10);
4619+
return SDPUtils.generateSecureIdentifier(10);
45424620
};
45434621

45444622
// The RTCP CNAME used by all peerconnections from the same JS.
@@ -5084,10 +5162,9 @@ SDPUtils.parseMsid = function(mediaSection) {
50845162

50855163
// Generate a session ID for SDP.
50865164
// https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-20#section-5.2.1
5087-
// recommends using a cryptographically random +ve 64-bit value
5088-
// but right now this should be acceptable and within the right range
5165+
// recommends using a cryptographically random +ve 64-bit value.
50895166
SDPUtils.generateSessionId = function() {
5090-
return Math.random().toString().substr(2, 21);
5167+
return SDPUtils.generateSecureDigits(21);
50915168
};
50925169

50935170
// Write boilder plate for start of SDP
@@ -5242,4 +5319,4 @@ if (typeof module === 'object') {
52425319
}
52435320

52445321
},{}]},{},[1])(1)
5245-
});
5322+
});

0 commit comments

Comments
 (0)