mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-13 22:40:01 -04:00
fix websockets, add unit test for tls socket
This commit is contained in:
parent
5fedc4b1ca
commit
9504f9d167
4 changed files with 42 additions and 4 deletions
|
@ -49,5 +49,8 @@ class JSTest(unittest.TestCase):
|
|||
def test_redirect_out(self):
|
||||
self.run_test("redirect_out.js")
|
||||
|
||||
def test_tls_socket(self):
|
||||
self.run_test("test_tls_socket.js")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
27
client/tests/scripts/test_tls_socket.js
Normal file
27
client/tests/scripts/test_tls_socket.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
function test() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let socket = new libcurl.TLSSocket("cloudflare.com", 443, {verbose: 1});
|
||||
|
||||
socket.onopen = () => {
|
||||
let str = "GET /cdn-cgi/trace HTTP/1.1\r\nHost: cloudflare.com\r\nConnection: close\r\n\r\n";
|
||||
socket.send(new TextEncoder().encode(str));
|
||||
};
|
||||
|
||||
socket.onmessage = (data) => {
|
||||
let text = new TextDecoder().decode(data);
|
||||
if (!text.includes("tls=TLSv1.3")) {
|
||||
reject("cloudflare reported tls version mismatch");
|
||||
return;
|
||||
}
|
||||
if (!text.includes("HTTP/1.1 200 OK")) {
|
||||
reject("cloudflare reported http error");
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
};
|
||||
|
||||
socket.onerror = (error) => {
|
||||
reject("socket error occurred " + error);
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue