@@ -14,28 +14,34 @@ component extends="testbox.system.BaseSpec" {
1414
1515 it ( " can serialize to a memento" , function () {
1616 expect ( variables .req .getMemento () ).toBe ( {
17- " requestID" : variables .req .getRequestID (),
18- " baseUrl" : variables .req .getBaseUrl (),
19- " url" : variables .req .getUrl (),
20- " fullUrl" : variables .req .getFullUrl (),
21- " method" : variables .req .getMethod (),
22- " queryParams" : variables .req .getQueryParams (),
23- " headers" : variables .req .getHeaders (),
24- " cookies" : variables .req .getCookies (),
25- " files" : variables .req .getFiles (),
26- " bodyFormat" : variables .req .getBodyFormat (),
27- " body" : variables .req .getBody (),
28- " referrerId" : " " ,
29- " throwOnError" : variables .req .getThrowOnError (),
30- " timeout" : variables .req .getTimeout (),
31- " maximumRedirects" : variables .req .getMaximumRedirects (),
32- " authType" : variables .req .getAuthType (),
33- " username" : variables .req .getUsername (),
34- " password" : variables .req .getPassword (),
35- " clientCert" : " " ,
36- " clientCertPassword" : " " ,
37- " domain" : variables .req .getDomain (),
38- " workstation" : variables .req .getWorkstation (),
17+ " requestID" : variables .req .getRequestID (),
18+ " baseUrl" : variables .req .getBaseUrl (),
19+ " url" : variables .req .getUrl (),
20+ " fullUrl" : variables .req .getFullUrl (),
21+ " method" : variables .req .getMethod (),
22+ " queryParams" : variables .req .getQueryParams (),
23+ " headers" : variables .req .getHeaders (),
24+ " cookies" : variables .req .getCookies (),
25+ " files" : variables .req .getFiles (),
26+ " bodyFormat" : variables .req .getBodyFormat (),
27+ " body" : variables .req .getBody (),
28+ " referrerId" : " " ,
29+ " throwOnError" : variables .req .getThrowOnError (),
30+ " timeout" : variables .req .getTimeout (),
31+ " maximumRedirects" : variables .req .getMaximumRedirects (),
32+ " authType" : variables .req .getAuthType (),
33+ " username" : variables .req .getUsername (),
34+ " password" : variables .req .getPassword (),
35+ " clientCert" : " " ,
36+ " clientCertPassword" : " " ,
37+ " domain" : variables .req .getDomain (),
38+ " workstation" : variables .req .getWorkstation (),
39+ " proxy" : {
40+ " proxyServer" : variables .req .getProxyServer (),
41+ " proxyPort" : variables .req .getProxyPort (),
42+ " proxyUser" : variables .req .getProxyUser (),
43+ " proxyPassword" : variables .req .getProxyPassword ()
44+ },
3945 " resolveUrls" : variables .req .getResolveUrls (),
4046 " encodeUrl" : variables .req .getEncodeUrl (),
4147 " retries" : variables .req .getRetries (),
@@ -166,6 +172,83 @@ component extends="testbox.system.BaseSpec" {
166172 expect ( req .getClientCertPassword () ).toBe ( " mypassword" );
167173 } );
168174
175+ it ( " can set proxy settings via throughProxy method" , function () {
176+ expect ( req .getProxyServer () ).toBe ( " " );
177+ expect ( req .getProxyPort () ).toBe ( 80 );
178+ expect ( req .getProxyUser () ).toBe ( " " );
179+ expect ( req .getProxyPassword () ).toBe ( " " );
180+ req .throughProxy (
181+ proxyHost = " proxy.example.com" ,
182+ proxyUser = " proxyuser" ,
183+ proxyPassword = " proxypass" ,
184+ proxyPort = 8080
185+ );
186+ expect ( req .getProxyServer () ).toBe ( " proxy.example.com" );
187+ expect ( req .getProxyPort () ).toBe ( 8080 );
188+ expect ( req .getProxyUser () ).toBe ( " proxyuser" );
189+ expect ( req .getProxyPassword () ).toBe ( " proxypass" );
190+ } );
191+
192+ it ( " can set proxy settings with default port" , function () {
193+ expect ( req .getProxyPort () ).toBe ( 80 );
194+ req .throughProxy (
195+ proxyHost = " proxy.example.com" ,
196+ proxyUser = " proxyuser" ,
197+ proxyPassword = " proxypass"
198+ );
199+ expect ( req .getProxyServer () ).toBe ( " proxy.example.com" );
200+ expect ( req .getProxyPort () ).toBe ( 80 );
201+ expect ( req .getProxyUser () ).toBe ( " proxyuser" );
202+ expect ( req .getProxyPassword () ).toBe ( " proxypass" );
203+ } );
204+
205+ it ( " can set proxy settings without authentication" , function () {
206+ req .throughProxy ( proxyHost = " proxy.example.com" );
207+ expect ( req .getProxyServer () ).toBe ( " proxy.example.com" );
208+ expect ( req .getProxyPort () ).toBe ( 80 );
209+ expect ( req .getProxyUser () ).toBe ( " " );
210+ expect ( req .getProxyPassword () ).toBe ( " " );
211+ } );
212+
213+ it ( " can set proxy settings with custom port but no authentication" , function () {
214+ req .throughProxy ( proxyHost = " proxy.example.com" , proxyPort = 8080 );
215+ expect ( req .getProxyServer () ).toBe ( " proxy.example.com" );
216+ expect ( req .getProxyPort () ).toBe ( 8080 );
217+ expect ( req .getProxyUser () ).toBe ( " " );
218+ expect ( req .getProxyPassword () ).toBe ( " " );
219+ } );
220+
221+ it ( " includes proxy settings in memento" , function () {
222+ req .throughProxy (
223+ proxyHost = " proxy.example.com" ,
224+ proxyUser = " proxyuser" ,
225+ proxyPassword = " proxypass" ,
226+ proxyPort = 8080
227+ );
228+ var memento = req .getMemento ();
229+ expect ( memento ).toHaveKey ( " proxy" );
230+ expect ( memento .proxy ).toBe ( {
231+ " proxyServer" : " proxy.example.com" ,
232+ " proxyPort" : 8080 ,
233+ " proxyUser" : " proxyuser" ,
234+ " proxyPassword" : " proxypass"
235+ } );
236+ } );
237+
238+ it ( " clones proxy settings to new request" , function () {
239+ req .throughProxy (
240+ proxyHost = " proxy.example.com" ,
241+ proxyUser = " proxyuser" ,
242+ proxyPassword = " proxypass" ,
243+ proxyPort = 8080
244+ );
245+ var clonedReq = req .clone ();
246+ expect ( clonedReq .getProxyServer () ).toBe ( " proxy.example.com" );
247+ expect ( clonedReq .getProxyPort () ).toBe ( 8080 );
248+ expect ( clonedReq .getProxyUser () ).toBe ( " proxyuser" );
249+ expect ( clonedReq .getProxyPassword () ).toBe ( " proxypass" );
250+ } );
251+
169252 it ( " can define onRequest callback hooks" , function () {
170253 var method = " not set yet" ;
171254 var headers = {};
0 commit comments