aboutsummaryrefslogtreecommitdiffhomepage
path: root/node_modules/xmlhttprequest-ssl/tests
diff options
context:
space:
mode:
authorYaroslav De La Peña Smirnov <yaros.rus_89@live.com.mx>2017-11-29 11:44:34 +0300
committerYaroslav De La Peña Smirnov <yaros.rus_89@live.com.mx>2017-11-29 11:44:34 +0300
commit67fdec20726e48ba3a934cb25bb30d47ec4a4f29 (patch)
tree37fd9f4f0b0c20103e1646fc83021e4765de3680 /node_modules/xmlhttprequest-ssl/tests
downloadspanish-checkers-67fdec20726e48ba3a934cb25bb30d47ec4a4f29.tar.gz
spanish-checkers-67fdec20726e48ba3a934cb25bb30d47ec4a4f29.zip
Initial commit, version 0.5.3
Diffstat (limited to 'node_modules/xmlhttprequest-ssl/tests')
-rw-r--r--node_modules/xmlhttprequest-ssl/tests/test-constants.js13
-rw-r--r--node_modules/xmlhttprequest-ssl/tests/test-events.js50
-rw-r--r--node_modules/xmlhttprequest-ssl/tests/test-exceptions.js59
-rw-r--r--node_modules/xmlhttprequest-ssl/tests/test-headers.js76
-rw-r--r--node_modules/xmlhttprequest-ssl/tests/test-redirect-302.js41
-rw-r--r--node_modules/xmlhttprequest-ssl/tests/test-redirect-303.js41
-rw-r--r--node_modules/xmlhttprequest-ssl/tests/test-redirect-307.js43
-rw-r--r--node_modules/xmlhttprequest-ssl/tests/test-request-methods.js62
-rw-r--r--node_modules/xmlhttprequest-ssl/tests/test-request-protocols.js32
-rw-r--r--node_modules/xmlhttprequest-ssl/tests/testdata.txt1
10 files changed, 418 insertions, 0 deletions
diff --git a/node_modules/xmlhttprequest-ssl/tests/test-constants.js b/node_modules/xmlhttprequest-ssl/tests/test-constants.js
new file mode 100644
index 0000000..372e46c
--- /dev/null
+++ b/node_modules/xmlhttprequest-ssl/tests/test-constants.js
@@ -0,0 +1,13 @@
+var sys = require("util")
+ , assert = require("assert")
+ , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
+ , xhr = new XMLHttpRequest();
+
+// Test constant values
+assert.equal(0, xhr.UNSENT);
+assert.equal(1, xhr.OPENED);
+assert.equal(2, xhr.HEADERS_RECEIVED);
+assert.equal(3, xhr.LOADING);
+assert.equal(4, xhr.DONE);
+
+sys.puts("done");
diff --git a/node_modules/xmlhttprequest-ssl/tests/test-events.js b/node_modules/xmlhttprequest-ssl/tests/test-events.js
new file mode 100644
index 0000000..c72f001
--- /dev/null
+++ b/node_modules/xmlhttprequest-ssl/tests/test-events.js
@@ -0,0 +1,50 @@
+var sys = require("util")
+ , assert = require("assert")
+ , http = require("http")
+ , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
+ , xhr;
+
+// Test server
+var server = http.createServer(function (req, res) {
+ var body = (req.method != "HEAD" ? "Hello World" : "");
+
+ res.writeHead(200, {
+ "Content-Type": "text/plain",
+ "Content-Length": Buffer.byteLength(body)
+ });
+ // HEAD has no body
+ if (req.method != "HEAD") {
+ res.write(body);
+ }
+ res.end();
+ assert.equal(onreadystatechange, true);
+ assert.equal(readystatechange, true);
+ assert.equal(removed, true);
+ sys.puts("done");
+ this.close();
+}).listen(8000);
+
+xhr = new XMLHttpRequest();
+
+// Track event calls
+var onreadystatechange = false;
+var readystatechange = false;
+var removed = true;
+var removedEvent = function() {
+ removed = false;
+};
+
+xhr.onreadystatechange = function() {
+ onreadystatechange = true;
+};
+
+xhr.addEventListener("readystatechange", function() {
+ readystatechange = true;
+});
+
+// This isn't perfect, won't guarantee it was added in the first place
+xhr.addEventListener("readystatechange", removedEvent);
+xhr.removeEventListener("readystatechange", removedEvent);
+
+xhr.open("GET", "http://localhost:8000");
+xhr.send();
diff --git a/node_modules/xmlhttprequest-ssl/tests/test-exceptions.js b/node_modules/xmlhttprequest-ssl/tests/test-exceptions.js
new file mode 100644
index 0000000..10eaea2
--- /dev/null
+++ b/node_modules/xmlhttprequest-ssl/tests/test-exceptions.js
@@ -0,0 +1,59 @@
+var sys = require("util")
+ , assert = require("assert")
+ , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
+ , xhr = new XMLHttpRequest();
+
+// Test request methods that aren't allowed
+try {
+ xhr.open("TRACK", "http://localhost:8000/");
+ console.log("ERROR: TRACK should have thrown exception");
+} catch(e) {}
+try {
+ xhr.open("TRACE", "http://localhost:8000/");
+ console.log("ERROR: TRACE should have thrown exception");
+} catch(e) {}
+try {
+ xhr.open("CONNECT", "http://localhost:8000/");
+ console.log("ERROR: CONNECT should have thrown exception");
+} catch(e) {}
+// Test valid request method
+try {
+ xhr.open("GET", "http://localhost:8000/");
+} catch(e) {
+ console.log("ERROR: Invalid exception for GET", e);
+}
+
+// Test forbidden headers
+var forbiddenRequestHeaders = [
+ "accept-charset",
+ "accept-encoding",
+ "access-control-request-headers",
+ "access-control-request-method",
+ "connection",
+ "content-length",
+ "content-transfer-encoding",
+ "cookie",
+ "cookie2",
+ "date",
+ "expect",
+ "host",
+ "keep-alive",
+ "origin",
+ "referer",
+ "te",
+ "trailer",
+ "transfer-encoding",
+ "upgrade",
+ "via"
+];
+
+for (var i in forbiddenRequestHeaders) {
+ if(xhr.setRequestHeader(forbiddenRequestHeaders[i], "Test") !== false) {
+ console.log("ERROR: " + forbiddenRequestHeaders[i] + " should have thrown exception");
+ }
+}
+
+// Try valid header
+xhr.setRequestHeader("X-Foobar", "Test");
+
+console.log("Done");
diff --git a/node_modules/xmlhttprequest-ssl/tests/test-headers.js b/node_modules/xmlhttprequest-ssl/tests/test-headers.js
new file mode 100644
index 0000000..76454f1
--- /dev/null
+++ b/node_modules/xmlhttprequest-ssl/tests/test-headers.js
@@ -0,0 +1,76 @@
+var sys = require("util")
+ , assert = require("assert")
+ , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
+ , xhr = new XMLHttpRequest()
+ , http = require("http");
+
+// Test server
+var server = http.createServer(function (req, res) {
+ // Test setRequestHeader
+ assert.equal("Foobar", req.headers["x-test"]);
+ // Test non-conforming allowed header
+ assert.equal("node-XMLHttpRequest-test", req.headers["user-agent"]);
+ // Test header set with blacklist disabled
+ assert.equal("http://github.com", req.headers["referer"]);
+
+ var body = "Hello World";
+ res.writeHead(200, {
+ "Content-Type": "text/plain",
+ "Content-Length": Buffer.byteLength(body),
+ // Set cookie headers to see if they're correctly suppressed
+ // Actual values don't matter
+ "Set-Cookie": "foo=bar",
+ "Set-Cookie2": "bar=baz",
+ "Date": "Thu, 30 Aug 2012 18:17:53 GMT",
+ "Connection": "close"
+ });
+ res.write("Hello World");
+ res.end();
+
+ this.close();
+}).listen(8000);
+
+xhr.onreadystatechange = function() {
+ if (this.readyState == 4) {
+ // Test getAllResponseHeaders()
+ var headers = "content-type: text/plain\r\ncontent-length: 11\r\ndate: Thu, 30 Aug 2012 18:17:53 GMT\r\nconnection: close";
+ assert.equal(headers, this.getAllResponseHeaders());
+
+ // Test case insensitivity
+ assert.equal('text/plain', this.getResponseHeader('Content-Type'));
+ assert.equal('text/plain', this.getResponseHeader('Content-type'));
+ assert.equal('text/plain', this.getResponseHeader('content-Type'));
+ assert.equal('text/plain', this.getResponseHeader('content-type'));
+
+ // Test aborted getAllResponseHeaders
+ this.abort();
+ assert.equal("", this.getAllResponseHeaders());
+ assert.equal(null, this.getResponseHeader("Connection"));
+
+ sys.puts("done");
+ }
+};
+
+assert.equal(null, xhr.getResponseHeader("Content-Type"));
+try {
+ xhr.open("GET", "http://localhost:8000/");
+ // Valid header
+ xhr.setRequestHeader("X-Test", "Foobar");
+ // Invalid header
+ xhr.setRequestHeader("Content-Length", 0);
+ // Allowed header outside of specs
+ xhr.setRequestHeader("user-agent", "node-XMLHttpRequest-test");
+ // Test getRequestHeader
+ assert.equal("Foobar", xhr.getRequestHeader("X-Test"));
+ // Test invalid header
+ assert.equal("", xhr.getRequestHeader("Content-Length"));
+
+ // Test allowing all headers
+ xhr.setDisableHeaderCheck(true);
+ xhr.setRequestHeader("Referer", "http://github.com");
+ assert.equal("http://github.com", xhr.getRequestHeader("Referer"));
+
+ xhr.send();
+} catch(e) {
+ console.log("ERROR: Exception raised", e);
+}
diff --git a/node_modules/xmlhttprequest-ssl/tests/test-redirect-302.js b/node_modules/xmlhttprequest-ssl/tests/test-redirect-302.js
new file mode 100644
index 0000000..d884f78
--- /dev/null
+++ b/node_modules/xmlhttprequest-ssl/tests/test-redirect-302.js
@@ -0,0 +1,41 @@
+var sys = require("util")
+ , assert = require("assert")
+ , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
+ , xhr = new XMLHttpRequest()
+ , http = require("http");
+
+// Test server
+var server = http.createServer(function (req, res) {
+ if (req.url === '/redirectingResource') {
+ res.writeHead(302, {'Location': 'http://localhost:8000/'});
+ res.end();
+ return;
+ }
+
+ var body = "Hello World";
+ res.writeHead(200, {
+ "Content-Type": "text/plain",
+ "Content-Length": Buffer.byteLength(body),
+ "Date": "Thu, 30 Aug 2012 18:17:53 GMT",
+ "Connection": "close"
+ });
+ res.write("Hello World");
+ res.end();
+
+ this.close();
+}).listen(8000);
+
+xhr.onreadystatechange = function() {
+ if (this.readyState == 4) {
+ assert.equal(xhr.getRequestHeader('Location'), '');
+ assert.equal(xhr.responseText, "Hello World");
+ sys.puts("done");
+ }
+};
+
+try {
+ xhr.open("GET", "http://localhost:8000/redirectingResource");
+ xhr.send();
+} catch(e) {
+ console.log("ERROR: Exception raised", e);
+}
diff --git a/node_modules/xmlhttprequest-ssl/tests/test-redirect-303.js b/node_modules/xmlhttprequest-ssl/tests/test-redirect-303.js
new file mode 100644
index 0000000..60d9343
--- /dev/null
+++ b/node_modules/xmlhttprequest-ssl/tests/test-redirect-303.js
@@ -0,0 +1,41 @@
+var sys = require("util")
+ , assert = require("assert")
+ , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
+ , xhr = new XMLHttpRequest()
+ , http = require("http");
+
+// Test server
+var server = http.createServer(function (req, res) {
+ if (req.url === '/redirectingResource') {
+ res.writeHead(303, {'Location': 'http://localhost:8000/'});
+ res.end();
+ return;
+ }
+
+ var body = "Hello World";
+ res.writeHead(200, {
+ "Content-Type": "text/plain",
+ "Content-Length": Buffer.byteLength(body),
+ "Date": "Thu, 30 Aug 2012 18:17:53 GMT",
+ "Connection": "close"
+ });
+ res.write("Hello World");
+ res.end();
+
+ this.close();
+}).listen(8000);
+
+xhr.onreadystatechange = function() {
+ if (this.readyState == 4) {
+ assert.equal(xhr.getRequestHeader('Location'), '');
+ assert.equal(xhr.responseText, "Hello World");
+ sys.puts("done");
+ }
+};
+
+try {
+ xhr.open("POST", "http://localhost:8000/redirectingResource");
+ xhr.send();
+} catch(e) {
+ console.log("ERROR: Exception raised", e);
+}
diff --git a/node_modules/xmlhttprequest-ssl/tests/test-redirect-307.js b/node_modules/xmlhttprequest-ssl/tests/test-redirect-307.js
new file mode 100644
index 0000000..3abc906
--- /dev/null
+++ b/node_modules/xmlhttprequest-ssl/tests/test-redirect-307.js
@@ -0,0 +1,43 @@
+var sys = require("util")
+ , assert = require("assert")
+ , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
+ , xhr = new XMLHttpRequest()
+ , http = require("http");
+
+// Test server
+var server = http.createServer(function (req, res) {
+ if (req.url === '/redirectingResource') {
+ res.writeHead(307, {'Location': 'http://localhost:8000/'});
+ res.end();
+ return;
+ }
+
+ assert.equal(req.method, 'POST');
+
+ var body = "Hello World";
+ res.writeHead(200, {
+ "Content-Type": "text/plain",
+ "Content-Length": Buffer.byteLength(body),
+ "Date": "Thu, 30 Aug 2012 18:17:53 GMT",
+ "Connection": "close"
+ });
+ res.write("Hello World");
+ res.end();
+
+ this.close();
+}).listen(8000);
+
+xhr.onreadystatechange = function() {
+ if (this.readyState == 4) {
+ assert.equal(xhr.getRequestHeader('Location'), '');
+ assert.equal(xhr.responseText, "Hello World");
+ sys.puts("done");
+ }
+};
+
+try {
+ xhr.open("POST", "http://localhost:8000/redirectingResource");
+ xhr.send();
+} catch(e) {
+ console.log("ERROR: Exception raised", e);
+}
diff --git a/node_modules/xmlhttprequest-ssl/tests/test-request-methods.js b/node_modules/xmlhttprequest-ssl/tests/test-request-methods.js
new file mode 100644
index 0000000..fa1b1be
--- /dev/null
+++ b/node_modules/xmlhttprequest-ssl/tests/test-request-methods.js
@@ -0,0 +1,62 @@
+var sys = require("util")
+ , assert = require("assert")
+ , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
+ , http = require("http")
+ , xhr;
+
+// Test server
+var server = http.createServer(function (req, res) {
+ // Check request method and URL
+ assert.equal(methods[curMethod], req.method);
+ assert.equal("/" + methods[curMethod], req.url);
+
+ var body = (req.method != "HEAD" ? "Hello World" : "");
+
+ res.writeHead(200, {
+ "Content-Type": "text/plain",
+ "Content-Length": Buffer.byteLength(body)
+ });
+ // HEAD has no body
+ if (req.method != "HEAD") {
+ res.write(body);
+ }
+ res.end();
+
+ if (curMethod == methods.length - 1) {
+ this.close();
+ sys.puts("done");
+ }
+}).listen(8000);
+
+// Test standard methods
+var methods = ["GET", "POST", "HEAD", "PUT", "DELETE"];
+var curMethod = 0;
+
+function start(method) {
+ // Reset each time
+ xhr = new XMLHttpRequest();
+
+ xhr.onreadystatechange = function() {
+ if (this.readyState == 4) {
+ if (method == "HEAD") {
+ assert.equal("", this.responseText);
+ } else {
+ assert.equal("Hello World", this.responseText);
+ }
+
+ curMethod++;
+
+ if (curMethod < methods.length) {
+ sys.puts("Testing " + methods[curMethod]);
+ start(methods[curMethod]);
+ }
+ }
+ };
+
+ var url = "http://localhost:8000/" + method;
+ xhr.open(method, url);
+ xhr.send();
+}
+
+sys.puts("Testing " + methods[curMethod]);
+start(methods[curMethod]);
diff --git a/node_modules/xmlhttprequest-ssl/tests/test-request-protocols.js b/node_modules/xmlhttprequest-ssl/tests/test-request-protocols.js
new file mode 100644
index 0000000..543917d
--- /dev/null
+++ b/node_modules/xmlhttprequest-ssl/tests/test-request-protocols.js
@@ -0,0 +1,32 @@
+var sys = require("util")
+ , assert = require("assert")
+ , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
+ , xhr;
+
+xhr = new XMLHttpRequest();
+
+xhr.onreadystatechange = function() {
+ if (this.readyState == 4) {
+ assert.equal("Hello World", this.responseText);
+ runSync();
+ }
+};
+
+// Async
+var url = "file://" + __dirname + "/testdata.txt";
+xhr.open("GET", url);
+xhr.send();
+
+// Sync
+var runSync = function() {
+ xhr = new XMLHttpRequest();
+
+ xhr.onreadystatechange = function() {
+ if (this.readyState == 4) {
+ assert.equal("Hello World", this.responseText);
+ sys.puts("done");
+ }
+ };
+ xhr.open("GET", url, false);
+ xhr.send();
+}
diff --git a/node_modules/xmlhttprequest-ssl/tests/testdata.txt b/node_modules/xmlhttprequest-ssl/tests/testdata.txt
new file mode 100644
index 0000000..5e1c309
--- /dev/null
+++ b/node_modules/xmlhttprequest-ssl/tests/testdata.txt
@@ -0,0 +1 @@
+Hello World \ No newline at end of file