1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | 'use strict';
|
19 |
|
20 | var http = require('http'),
|
21 | url = require('url');
|
22 |
|
23 | var Browser = require('..').Browser,
|
24 | promise = require('..').promise,
|
25 | firefox = require('../firefox'),
|
26 | proxy = require('../proxy'),
|
27 | assert = require('../testing/assert'),
|
28 | test = require('../lib/test'),
|
29 | Server = require('../lib/test/httpserver').Server,
|
30 | Pages = test.Pages;
|
31 |
|
32 | test.suite(function(env) {
|
33 | function writeResponse(res, body, encoding, contentType) {
|
34 | res.writeHead(200, {
|
35 | 'Content-Length': Buffer.byteLength(body, encoding),
|
36 | 'Content-Type': contentType
|
37 | });
|
38 | res.end(body);
|
39 | }
|
40 |
|
41 | function writePacFile(res) {
|
42 | writeResponse(res, [
|
43 | 'function FindProxyForURL(url, host) {',
|
44 | ' if (shExpMatch(url, "' + goodbyeServer.url('*') + '")) {',
|
45 | ' return "DIRECT";',
|
46 | ' }',
|
47 | ' return "PROXY ' + proxyServer.host() + '";',
|
48 | '}'
|
49 | ].join('\n'), 'ascii', 'application/x-javascript-config');
|
50 | }
|
51 |
|
52 | var proxyServer = new Server(function(req, res) {
|
53 | var pathname = url.parse(req.url).pathname;
|
54 | if (pathname === '/proxy.pac') {
|
55 | return writePacFile(res);
|
56 | }
|
57 |
|
58 | writeResponse(res, [
|
59 | '<!DOCTYPE html>',
|
60 | '<title>Proxy page</title>',
|
61 | '<h3>This is the proxy landing page</h3>'
|
62 | ].join(''), 'utf8', 'text/html; charset=UTF-8');
|
63 | });
|
64 |
|
65 | var helloServer = new Server(function(req, res) {
|
66 | writeResponse(res, [
|
67 | '<!DOCTYPE html>',
|
68 | '<title>Hello</title>',
|
69 | '<h3>Hello, world!</h3>'
|
70 | ].join(''), 'utf8', 'text/html; charset=UTF-8');
|
71 | });
|
72 |
|
73 | var goodbyeServer = new Server(function(req, res) {
|
74 | writeResponse(res, [
|
75 | '<!DOCTYPE html>',
|
76 | '<title>Goodbye</title>',
|
77 | '<h3>Goodbye, world!</h3>'
|
78 | ].join(''), 'utf8', 'text/html; charset=UTF-8');
|
79 | });
|
80 |
|
81 |
|
82 |
|
83 | function mkStartFunc(server) {
|
84 | return function() {
|
85 | return server.start();
|
86 | };
|
87 | }
|
88 |
|
89 | test.before(mkStartFunc(proxyServer));
|
90 | test.before(mkStartFunc(helloServer));
|
91 | test.before(mkStartFunc(goodbyeServer));
|
92 |
|
93 | test.after(proxyServer.stop.bind(proxyServer));
|
94 | test.after(helloServer.stop.bind(helloServer));
|
95 | test.after(goodbyeServer.stop.bind(goodbyeServer));
|
96 |
|
97 | var driver;
|
98 | test.beforeEach(function() { driver = null; });
|
99 | test.afterEach(function() { return driver && driver.quit(); });
|
100 |
|
101 | function createDriver(proxy) {
|
102 |
|
103 |
|
104 | let profile = new firefox.Profile();
|
105 | profile.setPreference('network.proxy.no_proxies_on', '');
|
106 |
|
107 | return driver = env.builder()
|
108 | .setFirefoxOptions(new firefox.Options().setProfile(profile))
|
109 | .setProxy(proxy)
|
110 | .build();
|
111 | }
|
112 |
|
113 |
|
114 | test.ignore(env.browsers(Browser.IE, Browser.OPERA, Browser.SAFARI)).
|
115 | describe('manual proxy settings', function() {
|
116 |
|
117 |
|
118 | test.ignore(env.browsers(Browser.PHANTOM_JS)).
|
119 | it('can configure HTTP proxy host', function*() {
|
120 | yield createDriver(proxy.manual({
|
121 | http: proxyServer.host()
|
122 | }));
|
123 |
|
124 | yield driver.get(helloServer.url());
|
125 | yield assert(driver.getTitle()).equalTo('Proxy page');
|
126 | yield assert(driver.findElement({tagName: 'h3'}).getText()).
|
127 | equalTo('This is the proxy landing page');
|
128 | });
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | test.ignore(env.browsers(
|
134 | Browser.FIREFOX,
|
135 | 'legacy-' + Browser.FIREFOX,
|
136 | Browser.PHANTOM_JS)).
|
137 | it('can bypass proxy for specific hosts', function*() {
|
138 | yield createDriver(proxy.manual({
|
139 | http: proxyServer.host(),
|
140 | bypass: helloServer.host()
|
141 | }));
|
142 |
|
143 | yield driver.get(helloServer.url());
|
144 | yield assert(driver.getTitle()).equalTo('Hello');
|
145 | yield assert(driver.findElement({tagName: 'h3'}).getText()).
|
146 | equalTo('Hello, world!');
|
147 |
|
148 | yield driver.get(goodbyeServer.url());
|
149 | yield assert(driver.getTitle()).equalTo('Proxy page');
|
150 | yield assert(driver.findElement({tagName: 'h3'}).getText()).
|
151 | equalTo('This is the proxy landing page');
|
152 | });
|
153 |
|
154 |
|
155 | });
|
156 |
|
157 |
|
158 |
|
159 | test.ignore(env.browsers(
|
160 | Browser.IE, Browser.OPERA, Browser.PHANTOM_JS, Browser.SAFARI)).
|
161 | describe('pac proxy settings', function() {
|
162 | test.it('can configure proxy through PAC file', function*() {
|
163 | yield createDriver(proxy.pac(proxyServer.url('/proxy.pac')));
|
164 |
|
165 | yield driver.get(helloServer.url());
|
166 | yield assert(driver.getTitle()).equalTo('Proxy page');
|
167 | yield assert(driver.findElement({tagName: 'h3'}).getText()).
|
168 | equalTo('This is the proxy landing page');
|
169 |
|
170 | yield driver.get(goodbyeServer.url());
|
171 | yield assert(driver.getTitle()).equalTo('Goodbye');
|
172 | yield assert(driver.findElement({tagName: 'h3'}).getText()).
|
173 | equalTo('Goodbye, world!');
|
174 | });
|
175 | });
|
176 |
|
177 |
|
178 | describe.skip('direct proxy settings', function() {});
|
179 | describe.skip('system proxy settings', function() {});
|
180 | });
|