diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /services/sync/tests/unit/test_utils_makeGUID.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'services/sync/tests/unit/test_utils_makeGUID.js')
-rw-r--r-- | services/sync/tests/unit/test_utils_makeGUID.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/services/sync/tests/unit/test_utils_makeGUID.js b/services/sync/tests/unit/test_utils_makeGUID.js new file mode 100644 index 0000000000..b1104c1114 --- /dev/null +++ b/services/sync/tests/unit/test_utils_makeGUID.js @@ -0,0 +1,44 @@ +const base64url = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; + +function run_test() { + _("Make sure makeGUID makes guids of the right length/characters"); + _("Create a bunch of guids to make sure they don't conflict"); + let guids = []; + for (let i = 0; i < 1000; i++) { + let newGuid = Utils.makeGUID(); + _("Generated " + newGuid); + + // Verify that the GUID's length is correct, even when it's URL encoded. + Assert.equal(newGuid.length, 12); + Assert.equal(encodeURIComponent(newGuid).length, 12); + + // Verify that the GUID only contains base64url characters + Assert.ok( + Array.prototype.every.call(newGuid, function (chr) { + return base64url.includes(chr); + }) + ); + + // Verify that Utils.checkGUID() correctly identifies them as valid. + Assert.ok(Utils.checkGUID(newGuid)); + + // Verify uniqueness within our sample of 1000. This could cause random + // failures, but they should be extremely rare. Otherwise we'd have a + // problem with GUID collisions. + Assert.ok( + guids.every(function (g) { + return g != newGuid; + }) + ); + guids.push(newGuid); + } + + _("Make sure checkGUID fails for invalid GUIDs"); + Assert.ok(!Utils.checkGUID(undefined)); + Assert.ok(!Utils.checkGUID(null)); + Assert.ok(!Utils.checkGUID("")); + Assert.ok(!Utils.checkGUID("blergh")); + Assert.ok(!Utils.checkGUID("ThisGUIDisWayTooLong")); + Assert.ok(!Utils.checkGUID("Invalid!!!!!")); +} |