mirror of
https://github.com/denoland/deno.git
synced 2025-02-02 04:38:21 -05:00
fix: createSecKey logic (#4063)
This commit is contained in:
parent
f4fd433e1a
commit
79c6e052ed
3 changed files with 10 additions and 1 deletions
|
@ -20,6 +20,7 @@ mod tests {
|
||||||
cwd.push("std");
|
cwd.push("std");
|
||||||
let mut deno = deno_cmd
|
let mut deno = deno_cmd
|
||||||
.current_dir(cwd) // note: std tests expect to run from "std" dir
|
.current_dir(cwd) // note: std tests expect to run from "std" dir
|
||||||
|
.arg("--seed=86") // Some tests rely on specific random numbers.
|
||||||
.arg("-A")
|
.arg("-A")
|
||||||
// .arg("-Ldebug")
|
// .arg("-Ldebug")
|
||||||
.arg("./testing/runner.ts")
|
.arg("./testing/runner.ts")
|
||||||
|
|
|
@ -457,7 +457,7 @@ const kSecChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.~_";
|
||||||
export function createSecKey(): string {
|
export function createSecKey(): string {
|
||||||
let key = "";
|
let key = "";
|
||||||
for (let i = 0; i < 16; i++) {
|
for (let i = 0; i < 16; i++) {
|
||||||
const j = Math.round(Math.random() * kSecChars.length);
|
const j = Math.floor(Math.random() * kSecChars.length);
|
||||||
key += kSecChars[j];
|
key += kSecChars[j];
|
||||||
}
|
}
|
||||||
return btoa(key);
|
return btoa(key);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
acceptable,
|
acceptable,
|
||||||
connectWebSocket,
|
connectWebSocket,
|
||||||
createSecAccept,
|
createSecAccept,
|
||||||
|
createSecKey,
|
||||||
handshake,
|
handshake,
|
||||||
OpCode,
|
OpCode,
|
||||||
readFrame,
|
readFrame,
|
||||||
|
@ -328,6 +329,13 @@ test("WebSocket.send(), WebSocket.ping() should be exclusive", async (): Promise
|
||||||
assertEquals(bytes.equal(third.payload, new Uint8Array([3])), true);
|
assertEquals(bytes.equal(third.payload, new Uint8Array([3])), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(function createSecKeyHasCorrectLength(): void {
|
||||||
|
// Note: relies on --seed=86 being passed to deno to reproduce failure in
|
||||||
|
// #4063.
|
||||||
|
const secKey = createSecKey();
|
||||||
|
assertEquals(atob(secKey).length, 16);
|
||||||
|
});
|
||||||
|
|
||||||
test("WebSocket should throw SocketClosedError when peer closed connection without close frame", async () => {
|
test("WebSocket should throw SocketClosedError when peer closed connection without close frame", async () => {
|
||||||
const buf = new Buffer();
|
const buf = new Buffer();
|
||||||
const eofReader: Deno.Reader = {
|
const eofReader: Deno.Reader = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue