First Commit
This commit is contained in:
391
html/sternwarte/checkfuehrung/node_modules/nodemailer-fetch/test/cookies-test.js
generated
vendored
Executable file
391
html/sternwarte/checkfuehrung/node_modules/nodemailer-fetch/test/cookies-test.js
generated
vendored
Executable file
@@ -0,0 +1,391 @@
|
||||
/* eslint no-unused-expressions:0 */
|
||||
/* globals beforeEach, describe, it */
|
||||
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai');
|
||||
var expect = chai.expect;
|
||||
|
||||
//var http = require('http');
|
||||
var Cookies = require('../lib/cookies');
|
||||
|
||||
chai.config.includeStack = true;
|
||||
|
||||
describe('Cookies Unit Tests', function () {
|
||||
var biskviit;
|
||||
|
||||
beforeEach(function () {
|
||||
biskviit = new Cookies();
|
||||
});
|
||||
|
||||
describe('#getPath', function () {
|
||||
|
||||
it('should return root path', function () {
|
||||
expect(biskviit.getPath('/')).to.equal('/');
|
||||
expect(biskviit.getPath('')).to.equal('/');
|
||||
expect(biskviit.getPath('/index.php')).to.equal('/');
|
||||
});
|
||||
|
||||
it('should return without file', function () {
|
||||
expect(biskviit.getPath('/path/to/file')).to.equal('/path/to/');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#isExpired', function () {
|
||||
it('should match expired cookie', function () {
|
||||
expect(biskviit.isExpired({
|
||||
name: 'a',
|
||||
value: 'b',
|
||||
expires: new Date(Date.now() + 10000)
|
||||
})).to.be.false;
|
||||
|
||||
expect(biskviit.isExpired({
|
||||
name: 'a',
|
||||
value: '',
|
||||
expires: new Date(Date.now() + 10000)
|
||||
})).to.be.true;
|
||||
|
||||
expect(biskviit.isExpired({
|
||||
name: 'a',
|
||||
value: 'b',
|
||||
expires: new Date(Date.now() - 10000)
|
||||
})).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#compare', function () {
|
||||
it('should match similar cookies', function () {
|
||||
expect(biskviit.compare({
|
||||
name: 'zzz',
|
||||
path: '/',
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
}, {
|
||||
name: 'zzz',
|
||||
path: '/',
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
})).to.be.true;
|
||||
|
||||
expect(biskviit.compare({
|
||||
name: 'zzz',
|
||||
path: '/',
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
}, {
|
||||
name: 'yyy',
|
||||
path: '/',
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
})).to.be.false;
|
||||
|
||||
expect(biskviit.compare({
|
||||
name: 'zzz',
|
||||
path: '/',
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
}, {
|
||||
name: 'zzz',
|
||||
path: '/amp',
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
})).to.be.false;
|
||||
|
||||
expect(biskviit.compare({
|
||||
name: 'zzz',
|
||||
path: '/',
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
}, {
|
||||
name: 'zzz',
|
||||
path: '/',
|
||||
domain: 'examples.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
})).to.be.false;
|
||||
|
||||
expect(biskviit.compare({
|
||||
name: 'zzz',
|
||||
path: '/',
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
}, {
|
||||
name: 'zzz',
|
||||
path: '/',
|
||||
domain: 'example.com',
|
||||
secure: true,
|
||||
httponly: false
|
||||
})).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#add', function () {
|
||||
it('should append new cookie', function () {
|
||||
expect(biskviit.cookies.length).to.equal(0);
|
||||
biskviit.add({
|
||||
name: 'zzz',
|
||||
value: 'abc',
|
||||
path: '/',
|
||||
expires: new Date(Date.now() + 10000),
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
});
|
||||
expect(biskviit.cookies.length).to.equal(1);
|
||||
expect(biskviit.cookies[0].name).to.equal('zzz');
|
||||
expect(biskviit.cookies[0].value).to.equal('abc');
|
||||
});
|
||||
|
||||
it('should update existing cookie', function () {
|
||||
expect(biskviit.cookies.length).to.equal(0);
|
||||
biskviit.add({
|
||||
name: 'zzz',
|
||||
value: 'abc',
|
||||
path: '/',
|
||||
expires: new Date(Date.now() + 10000),
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
});
|
||||
biskviit.add({
|
||||
name: 'zzz',
|
||||
value: 'def',
|
||||
path: '/',
|
||||
expires: new Date(Date.now() + 10000),
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
});
|
||||
expect(biskviit.cookies.length).to.equal(1);
|
||||
expect(biskviit.cookies[0].name).to.equal('zzz');
|
||||
expect(biskviit.cookies[0].value).to.equal('def');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#match', function () {
|
||||
it('should check if a cookie matches particular domain and path', function () {
|
||||
var cookie = {
|
||||
name: 'zzz',
|
||||
value: 'abc',
|
||||
path: '/def/',
|
||||
expires: new Date(Date.now() + 10000),
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
};
|
||||
expect(biskviit.match(cookie, 'http://example.com/def/')).to.be.true;
|
||||
expect(biskviit.match(cookie, 'http://example.com/bef/')).to.be.false;
|
||||
});
|
||||
|
||||
it('should check if a cookie matches particular domain and path', function () {
|
||||
var cookie = {
|
||||
name: 'zzz',
|
||||
value: 'abc',
|
||||
path: '/def',
|
||||
expires: new Date(Date.now() + 10000),
|
||||
domain: 'example.com',
|
||||
secure: false,
|
||||
httponly: false
|
||||
};
|
||||
expect(biskviit.match(cookie, 'http://example.com/def/')).to.be.true;
|
||||
expect(biskviit.match(cookie, 'http://example.com/bef/')).to.be.false;
|
||||
});
|
||||
|
||||
it('should check if a cookie is secure', function () {
|
||||
var cookie = {
|
||||
name: 'zzz',
|
||||
value: 'abc',
|
||||
path: '/def/',
|
||||
expires: new Date(Date.now() + 10000),
|
||||
domain: 'example.com',
|
||||
secure: true,
|
||||
httponly: false
|
||||
};
|
||||
expect(biskviit.match(cookie, 'https://example.com/def/')).to.be.true;
|
||||
expect(biskviit.match(cookie, 'http://example.com/def/')).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#parse', function () {
|
||||
it('should parse Set-Cookie value', function () {
|
||||
|
||||
expect(biskviit.parse('theme=plain')).to.deep.equal({
|
||||
name: 'theme',
|
||||
value: 'plain'
|
||||
});
|
||||
|
||||
expect(biskviit.parse('SSID=Ap4P….GTEq; Domain=foo.com; Path=/; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly')).to.deep.equal({
|
||||
name: 'ssid',
|
||||
value: 'Ap4P….GTEq',
|
||||
domain: '.foo.com',
|
||||
path: '/',
|
||||
httponly: true,
|
||||
secure: true,
|
||||
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should ignore invalid expire header', function () {
|
||||
expect(biskviit.parse('theme=plain; Expires=Wed, 13 Jan 2021 22:23:01 GMT')).to.deep.equal({
|
||||
name: 'theme',
|
||||
value: 'plain',
|
||||
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
|
||||
});
|
||||
|
||||
expect(biskviit.parse('theme=plain; Expires=ZZZZZZZZ GMT')).to.deep.equal({
|
||||
name: 'theme',
|
||||
value: 'plain'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Listing', function () {
|
||||
beforeEach(function () {
|
||||
biskviit.cookies = [{
|
||||
name: 'ssid1',
|
||||
value: 'Ap4P….GTEq1',
|
||||
domain: '.foo.com',
|
||||
path: '/',
|
||||
httponly: true,
|
||||
secure: true,
|
||||
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
|
||||
}, {
|
||||
name: 'ssid2',
|
||||
value: 'Ap4P….GTEq2',
|
||||
domain: '.foo.com',
|
||||
path: '/',
|
||||
httponly: true,
|
||||
secure: true,
|
||||
expires: new Date('Wed, 13 Jan 1900 22:23:01 GMT')
|
||||
}, {
|
||||
name: 'ssid3',
|
||||
value: 'Ap4P….GTEq3',
|
||||
domain: 'foo.com',
|
||||
path: '/',
|
||||
httponly: true,
|
||||
secure: true,
|
||||
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
|
||||
}, {
|
||||
name: 'ssid4',
|
||||
value: 'Ap4P….GTEq4',
|
||||
domain: 'www.foo.com',
|
||||
path: '/',
|
||||
httponly: true,
|
||||
secure: true,
|
||||
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
|
||||
}, {
|
||||
name: 'ssid5',
|
||||
value: 'Ap4P….GTEq5',
|
||||
domain: 'broo.com',
|
||||
path: '/',
|
||||
httponly: true,
|
||||
secure: true,
|
||||
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
|
||||
}];
|
||||
});
|
||||
|
||||
|
||||
describe('#list', function () {
|
||||
it('should return matching cookies for an URL', function () {
|
||||
expect(biskviit.list('https://www.foo.com')).to.deep.equal([{
|
||||
name: 'ssid1',
|
||||
value: 'Ap4P….GTEq1',
|
||||
domain: '.foo.com',
|
||||
path: '/',
|
||||
httponly: true,
|
||||
secure: true,
|
||||
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
|
||||
}, {
|
||||
name: 'ssid4',
|
||||
value: 'Ap4P….GTEq4',
|
||||
domain: 'www.foo.com',
|
||||
path: '/',
|
||||
httponly: true,
|
||||
secure: true,
|
||||
expires: new Date('Wed, 13 Jan 2021 22:23:01 GMT')
|
||||
}]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#get', function () {
|
||||
it('should return matching cookies for an URL', function () {
|
||||
expect(biskviit.get('https://www.foo.com')).to.equal('ssid1=Ap4P….GTEq1; ssid4=Ap4P….GTEq4');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#set', function () {
|
||||
it('should set cookie', function () {
|
||||
// short
|
||||
biskviit.set('theme=plain', 'https://foo.com/');
|
||||
// long
|
||||
biskviit.set('SSID=Ap4P….GTEq; Domain=foo.com; Path=/test; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly', 'https://foo.com/');
|
||||
// subdomains
|
||||
biskviit.set('SSID=Ap4P….GTEq; Domain=.foo.com; Path=/; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly', 'https://www.foo.com/');
|
||||
// invalid cors
|
||||
biskviit.set('invalid_1=cors; domain=example.com', 'https://foo.com/');
|
||||
biskviit.set('invalid_2=cors; domain=www.foo.com', 'https://foo.com/');
|
||||
// invalid date
|
||||
biskviit.set('invalid_3=date; Expires=zzzz', 'https://foo.com/');
|
||||
// invalid tld
|
||||
biskviit.set('invalid_4=cors; domain=.co.uk', 'https://foo.co.uk/');
|
||||
// should not be added
|
||||
biskviit.set('expired_1=date; Expires=1999-01-01 01:01:01 GMT', 'https://foo.com/');
|
||||
|
||||
expect(biskviit.cookies.map(function (cookie) {
|
||||
delete cookie.expires;
|
||||
return cookie;
|
||||
})).to.deep.equal([{
|
||||
name: 'theme',
|
||||
value: 'plain',
|
||||
domain: 'foo.com',
|
||||
path: '/'
|
||||
}, {
|
||||
name: 'ssid',
|
||||
value: 'Ap4P….GTEq',
|
||||
domain: 'foo.com',
|
||||
path: '/test',
|
||||
secure: true,
|
||||
httponly: true
|
||||
}, {
|
||||
name: 'ssid',
|
||||
value: 'Ap4P….GTEq',
|
||||
domain: 'www.foo.com',
|
||||
path: '/',
|
||||
secure: true,
|
||||
httponly: true
|
||||
}, {
|
||||
name: 'invalid_1',
|
||||
value: 'cors',
|
||||
domain: 'foo.com',
|
||||
path: '/'
|
||||
}, {
|
||||
name: 'invalid_2',
|
||||
value: 'cors',
|
||||
domain: 'foo.com',
|
||||
path: '/'
|
||||
}, {
|
||||
name: 'invalid_3',
|
||||
value: 'date',
|
||||
domain: 'foo.com',
|
||||
path: '/'
|
||||
}, {
|
||||
name: 'invalid_4',
|
||||
value: 'cors',
|
||||
domain: 'foo.co.uk',
|
||||
path: '/'
|
||||
}]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
486
html/sternwarte/checkfuehrung/node_modules/nodemailer-fetch/test/fetch-test.js
generated
vendored
Executable file
486
html/sternwarte/checkfuehrung/node_modules/nodemailer-fetch/test/fetch-test.js
generated
vendored
Executable file
@@ -0,0 +1,486 @@
|
||||
/* eslint no-unused-expressions:0 */
|
||||
/* globals afterEach, beforeEach, describe, it */
|
||||
|
||||
'use strict';
|
||||
|
||||
var chai = require('chai');
|
||||
var expect = chai.expect;
|
||||
|
||||
//var http = require('http');
|
||||
var fetch = require('../lib/fetch');
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var zlib = require('zlib');
|
||||
var PassThrough = require('stream').PassThrough;
|
||||
|
||||
chai.config.includeStack = true;
|
||||
|
||||
var HTTP_PORT = 9998;
|
||||
var HTTPS_PORT = 9993;
|
||||
|
||||
var httpsOptions = {
|
||||
key: '-----BEGIN RSA PRIVATE KEY-----\n' +
|
||||
'MIIEpAIBAAKCAQEA6Z5Qqhw+oWfhtEiMHE32Ht94mwTBpAfjt3vPpX8M7DMCTwHs\n' +
|
||||
'1xcXvQ4lQ3rwreDTOWdoJeEEy7gMxXqH0jw0WfBx+8IIJU69xstOyT7FRFDvA1yT\n' +
|
||||
'RXY2yt9K5s6SKken/ebMfmZR+03ND4UFsDzkz0FfgcjrkXmrMF5Eh5UXX/+9YHeU\n' +
|
||||
'xlp0gMAt+/SumSmgCaysxZLjLpd4uXz+X+JVxsk1ACg1NoEO7lWJC/3WBP7MIcu2\n' +
|
||||
'wVsMd2XegLT0gWYfT1/jsIH64U/mS/SVXC9QhxMl9Yfko2kx1OiYhDxhHs75RJZh\n' +
|
||||
'rNRxgfiwgSb50Gw4NAQaDIxr/DJPdLhgnpY6UQIDAQABAoIBAE+tfzWFjJbgJ0ql\n' +
|
||||
's6Ozs020Sh4U8TZQuonJ4HhBbNbiTtdDgNObPK1uNadeNtgW5fOeIRdKN6iDjVeN\n' +
|
||||
'AuXhQrmqGDYVZ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\n' +
|
||||
'zLgx2ZNZzVhBz0odCU4JVhOCEks/OzSyKeGwjIb4JAY7dh+Kju1+6MNfQJ4r1Hza\n' +
|
||||
'SVXH0+JlpJDaJ73NQ2JyfqELmJ1mTcptkA/N6rQWhlzycTBSlfogwf9xawgVPATP\n' +
|
||||
'4AuwgjHl12JI2HVVs1gu65Y3slvaHRCr0B4+Kg1GYNLLcbFcK+NEHrHmPxy9TnTh\n' +
|
||||
'Zwp1dsNQU+Xkylz8IUANWSLHYZOMtN2e5SKIdwTtl5C8YxveuY8YKb1gDExnMraT\n' +
|
||||
'VGXQDqPleug=\n' +
|
||||
'-----END CERTIFICATE-----'
|
||||
};
|
||||
|
||||
describe('fetch tests', function () {
|
||||
var httpServer, httpsServer;
|
||||
|
||||
beforeEach(function (done) {
|
||||
httpServer = http.createServer(function (req, res) {
|
||||
switch (req.url) {
|
||||
|
||||
case '/redirect6':
|
||||
res.writeHead(302, {
|
||||
Location: '/redirect5'
|
||||
});
|
||||
res.end();
|
||||
break;
|
||||
|
||||
case '/redirect5':
|
||||
res.writeHead(302, {
|
||||
Location: '/redirect4'
|
||||
});
|
||||
res.end();
|
||||
break;
|
||||
|
||||
case '/redirect4':
|
||||
res.writeHead(302, {
|
||||
Location: '/redirect3'
|
||||
});
|
||||
res.end();
|
||||
break;
|
||||
|
||||
case '/redirect3':
|
||||
res.writeHead(302, {
|
||||
Location: '/redirect2'
|
||||
});
|
||||
res.end();
|
||||
break;
|
||||
|
||||
case '/redirect2':
|
||||
res.writeHead(302, {
|
||||
Location: '/redirect1'
|
||||
});
|
||||
res.end();
|
||||
break;
|
||||
|
||||
case '/redirect1':
|
||||
res.writeHead(302, {
|
||||
Location: '/'
|
||||
});
|
||||
res.end();
|
||||
break;
|
||||
|
||||
case '/forever':
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
res.write('This connection is never closed');
|
||||
// never end the request
|
||||
break;
|
||||
|
||||
case '/gzip':
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/plain',
|
||||
'Content-Encoding': 'gzip'
|
||||
});
|
||||
|
||||
var stream = zlib.createGzip();
|
||||
stream.pipe(res);
|
||||
stream.end('Hello World HTTP\n');
|
||||
break;
|
||||
|
||||
case '/invalid':
|
||||
res.writeHead(500, {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
res.end('Hello World HTTP\n');
|
||||
break;
|
||||
|
||||
case '/auth':
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
res.end(new Buffer(req.headers.authorization.split(' ').pop(), 'base64'));
|
||||
break;
|
||||
|
||||
case '/cookie':
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
res.end(req.headers.cookie);
|
||||
break;
|
||||
|
||||
case '/ua':
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
res.end(req.headers['user-agent']);
|
||||
break;
|
||||
|
||||
case '/post':
|
||||
var body = [];
|
||||
req.on('readable', function () {
|
||||
var chunk;
|
||||
while ((chunk = req.read()) !== null) {
|
||||
body.push(chunk);
|
||||
}
|
||||
});
|
||||
req.on('end', function () {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
res.end(Buffer.concat(body));
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
res.end('Hello World HTTP\n');
|
||||
}
|
||||
});
|
||||
|
||||
httpsServer = https.createServer(httpsOptions, function (req, res) {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
res.end('Hello World HTTPS\n');
|
||||
});
|
||||
|
||||
httpServer.listen(HTTP_PORT, function () {
|
||||
httpsServer.listen(HTTPS_PORT, done);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
httpServer.close(function () {
|
||||
httpsServer.close(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should fetch HTTP data', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT);
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('end', function () {
|
||||
expect(Buffer.concat(buf).toString()).to.equal('Hello World HTTP\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fetch HTTPS data', function (done) {
|
||||
var req = fetch('https://localhost:' + HTTPS_PORT);
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('end', function () {
|
||||
expect(Buffer.concat(buf).toString()).to.equal('Hello World HTTPS\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fetch HTTP data with redirects', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/redirect3');
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('end', function () {
|
||||
expect(Buffer.concat(buf).toString()).to.equal('Hello World HTTP\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error for too many redirects', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/redirect6');
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('error', function (err) {
|
||||
expect(err).to.exist;
|
||||
done();
|
||||
});
|
||||
req.on('end', function () {});
|
||||
});
|
||||
|
||||
it('should fetch HTTP data with custom redirect limit', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/redirect3', {
|
||||
maxRedirects: 3
|
||||
});
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('end', function () {
|
||||
expect(Buffer.concat(buf).toString()).to.equal('Hello World HTTP\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error for custom redirect limit', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/redirect3', {
|
||||
maxRedirects: 2
|
||||
});
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('error', function (err) {
|
||||
expect(err).to.exist;
|
||||
done();
|
||||
});
|
||||
req.on('end', function () {});
|
||||
});
|
||||
|
||||
it('should return disable redirects', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/redirect1', {
|
||||
maxRedirects: 0
|
||||
});
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('error', function (err) {
|
||||
expect(err).to.exist;
|
||||
done();
|
||||
});
|
||||
req.on('end', function () {});
|
||||
});
|
||||
|
||||
it('should unzip compressed HTTP data', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/gzip');
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('end', function () {
|
||||
expect(Buffer.concat(buf).toString()).to.equal('Hello World HTTP\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error for unresolved host', function (done) {
|
||||
var req = fetch('http://asfhaskhhgbjdsfhgbsdjgk');
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('error', function (err) {
|
||||
expect(err).to.exist;
|
||||
done();
|
||||
});
|
||||
req.on('end', function () {});
|
||||
});
|
||||
|
||||
it('should return error for invalid status', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/invalid');
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('error', function (err) {
|
||||
expect(err).to.exist;
|
||||
done();
|
||||
});
|
||||
req.on('end', function () {});
|
||||
});
|
||||
|
||||
it('should return error for invalid url', function (done) {
|
||||
var req = fetch('http://localhost:99999999/');
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('error', function (err) {
|
||||
expect(err).to.exist;
|
||||
done();
|
||||
});
|
||||
req.on('end', function () {});
|
||||
});
|
||||
|
||||
it('should return timeout error', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/forever', {
|
||||
timeout: 1000
|
||||
});
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('error', function (err) {
|
||||
expect(err).to.exist;
|
||||
done();
|
||||
});
|
||||
req.on('end', function () {});
|
||||
});
|
||||
|
||||
it('should handle basic HTTP auth', function (done) {
|
||||
var req = fetch('http://user:pass@localhost:' + HTTP_PORT + '/auth');
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('end', function () {
|
||||
expect(Buffer.concat(buf).toString()).to.equal('user:pass');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
if (!/^0\.10\./.test(process.versions.node)) {
|
||||
// disabled for node 0.10
|
||||
it('should return error for invalid protocol', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTPS_PORT);
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('error', function (err) {
|
||||
expect(err).to.exist;
|
||||
done();
|
||||
});
|
||||
req.on('end', function () {});
|
||||
});
|
||||
}
|
||||
|
||||
it('should set cookie value', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/cookie', {
|
||||
cookie: 'test=pest'
|
||||
});
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('end', function () {
|
||||
expect(Buffer.concat(buf).toString()).to.equal('test=pest');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should set user agent', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/ua', {
|
||||
userAgent: 'nodemailer-fetch'
|
||||
});
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('end', function () {
|
||||
expect(Buffer.concat(buf).toString()).to.equal('nodemailer-fetch');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should post data', function (done) {
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/post', {
|
||||
method: 'post',
|
||||
body: {
|
||||
hello: 'world 😭',
|
||||
another: 'value'
|
||||
}
|
||||
});
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('end', function () {
|
||||
expect(Buffer.concat(buf).toString()).to.equal('hello=world%20%F0%9F%98%AD&another=value');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should post stream data', function (done) {
|
||||
var body = new PassThrough();
|
||||
var data = new Buffer('hello=world%20%F0%9F%98%AD&another=value');
|
||||
|
||||
var req = fetch('http://localhost:' + HTTP_PORT + '/post', {
|
||||
method: 'post',
|
||||
body: body
|
||||
});
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('end', function () {
|
||||
expect(Buffer.concat(buf).toString()).to.equal(data.toString());
|
||||
done();
|
||||
});
|
||||
|
||||
var pos = 0;
|
||||
var writeNext = function () {
|
||||
if (pos >= data.length) {
|
||||
return body.end();
|
||||
}
|
||||
var char = data.slice(pos++, pos);
|
||||
body.write(char);
|
||||
setImmediate(writeNext);
|
||||
};
|
||||
|
||||
setImmediate(writeNext);
|
||||
});
|
||||
|
||||
it('should return error for invalid cert', function (done) {
|
||||
var req = fetch('https://localhost:' + HTTPS_PORT, {
|
||||
tls: {
|
||||
rejectUnauthorized: true
|
||||
}
|
||||
});
|
||||
var buf = [];
|
||||
req.on('data', function (chunk) {
|
||||
buf.push(chunk);
|
||||
});
|
||||
req.on('error', function (err) {
|
||||
expect(err).to.exist;
|
||||
done();
|
||||
});
|
||||
req.on('end', function () {});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user