11'use strict' ;
2- /*jshint esnext:true, node:true */
2+ /* jshint esnext:true, node:true */
33const fs = require ( 'fs' ) ;
44const http = require ( 'http' ) ;
55const basicAuth = require ( 'basic-auth' ) ;
@@ -36,7 +36,7 @@ app.use(function(req, res, next) {
3636 } ) ;
3737 } ) ;
3838 req . busboy . on ( 'field' , function ( fieldname , val
39- /*, fieldnameTruncated, valTruncated, encoding, mimetype*/
39+ /* fieldnameTruncated, valTruncated, encoding, mimetype */
4040 ) {
4141 console . log ( 'Field [' + fieldname + ']: value: ' + val ) ;
4242 } ) ;
@@ -48,7 +48,7 @@ app.use(function(req, res, next) {
4848
4949app . use ( '/ntlm' , ntlm ( {
5050 debug : function ( ) {
51- var args = Array . prototype . slice . apply ( arguments ) ;
51+ const args = Array . prototype . slice . apply ( arguments ) ;
5252 console . log . apply ( null , args ) ;
5353 }
5454} ) ) ;
@@ -62,7 +62,7 @@ class TestServer {
6262 }
6363
6464 basicAuth ( req , res , next ) {
65- var user = basicAuth ( req ) ;
65+ const user = basicAuth ( req ) ;
6666 if ( ! user || ! user . name || ! user . pass ) {
6767 return this . unauthorized ( res ) ;
6868 }
@@ -75,14 +75,17 @@ class TestServer {
7575
7676 /**
7777 * To be called when the user is not basic authenticated.
78+ *
79+ * @param {Object } res
80+ * @return {Object }
7881 */
7982 unauthorized ( res ) {
8083 res . set ( 'WWW-Authenticate' , 'Basic realm=Authorization Required (test:test)' ) ;
8184 return res . sendStatus ( 401 ) ;
8285 }
8386
8487 createServer ( ) {
85- var httpServer = http . createServer ( app ) ;
88+ const httpServer = http . createServer ( app ) ;
8689 httpServer . listen ( this . post , ( ) => {
8790 console . log ( 'HTTP started (' + this . post + ').' ) ;
8891 } ) ;
@@ -147,60 +150,60 @@ class TestServer {
147150
148151 _setJson ( ) {
149152 app . get ( '/json' , ( req , res ) => {
150- var json = fs . readFileSync ( './tasks/test-data/json1.json' , 'utf8' ) ;
153+ const json = fs . readFileSync ( './tasks/test-data/json1.json' , 'utf8' ) ;
151154 // res.status(200).send('OK');
152155 res . set ( 'Content-Type' , 'application/json' ) ;
153156 res . send ( json ) ;
154157 } ) ;
155158 app . get ( '/json/2' , ( req , res ) => {
156- var json = fs . readFileSync ( './tasks/test-data/json2.json' , 'utf8' ) ;
159+ const json = fs . readFileSync ( './tasks/test-data/json2.json' , 'utf8' ) ;
157160 // res.status(200).send('OK');
158161 res . set ( 'Content-Type' , 'application/json' ) ;
159162 res . send ( json ) ;
160163 } ) ;
161164 app . get ( '/json/3' , ( req , res ) => {
162- var json = fs . readFileSync ( './tasks/test-data/quicker-response-export.json' , 'utf8' ) ;
165+ const json = fs . readFileSync ( './tasks/test-data/quicker-response-export.json' , 'utf8' ) ;
163166 // res.status(200).send('OK');
164167 res . set ( 'Content-Type' , 'application/json' ) ;
165168 res . send ( json ) ;
166169 } ) ;
167170 app . get ( '/json/4' , ( req , res ) => {
168- var json = fs . readFileSync ( './tasks/test-data/slow-response-export.json' , 'utf8' ) ;
171+ const json = fs . readFileSync ( './tasks/test-data/slow-response-export.json' , 'utf8' ) ;
169172 // res.status(200).send('OK');
170173 res . set ( 'Content-Type' , 'application/json' ) ;
171174 res . send ( json ) ;
172175 } ) ;
173176 app . get ( '/json/error' , ( req , res ) => {
174- var json = fs . readFileSync ( './tasks/test-data/json1.json' , 'utf8' ) ;
177+ let json = fs . readFileSync ( './tasks/test-data/json1.json' , 'utf8' ) ;
175178 res . set ( 'Content-Type' , 'application/json' ) ;
176179 json = '[Eroor]: An error occured' + json ;
177180 res . send ( json ) ;
178181 } ) ;
179182 app . get ( '/json/html' , ( req , res ) => {
180- var json = fs . readFileSync ( './tasks/test-data/json1.json' , 'utf8' ) ;
183+ const json = fs . readFileSync ( './tasks/test-data/json1.json' , 'utf8' ) ;
181184 res . set ( 'Content-Type' , 'text/html' ) ;
182185 res . send ( json ) ;
183186 } ) ;
184187 }
185188
186189 _setXML ( ) {
187190 app . get ( '/xml' , ( req , res ) => {
188- var json = fs . readFileSync ( './tasks/test-data/xml1.xml' , 'utf8' ) ;
191+ const json = fs . readFileSync ( './tasks/test-data/xml1.xml' , 'utf8' ) ;
189192 res . set ( 'Content-Type' , 'application/xml' ) ;
190193 res . send ( json ) ;
191194 } ) ;
192195 app . get ( '/xml2' , ( req , res ) => {
193- var json = fs . readFileSync ( './tasks/test-data/xml2.xml' , 'utf8' ) ;
196+ const json = fs . readFileSync ( './tasks/test-data/xml2.xml' , 'utf8' ) ;
194197 res . set ( 'Content-Type' , 'application/xml' ) ;
195198 res . send ( json ) ;
196199 } ) ;
197200 app . get ( '/xml3' , ( req , res ) => {
198- var json = fs . readFileSync ( './tasks/test-data/xml3.xml' , 'utf8' ) ;
201+ const json = fs . readFileSync ( './tasks/test-data/xml3.xml' , 'utf8' ) ;
199202 res . set ( 'Content-Type' , 'application/xml' ) ;
200203 res . send ( json ) ;
201204 } ) ;
202205 app . get ( '/xml4' , ( req , res ) => {
203- var json = fs . readFileSync ( './tasks/test-data/xml4.xml' , 'utf8' ) ;
206+ const json = fs . readFileSync ( './tasks/test-data/xml4.xml' , 'utf8' ) ;
204207 res . set ( 'Content-Type' , 'application/xml' ) ;
205208 res . send ( json ) ;
206209 } ) ;
@@ -209,15 +212,15 @@ class TestServer {
209212 uuid ( ) {
210213 // jscs:disable
211214 /* jshint ignore:start */
212- var lut = [ ] ;
213- for ( var i = 0 ; i < 256 ; i ++ ) {
215+ const lut = [ ] ;
216+ for ( let i = 0 ; i < 256 ; i ++ ) {
214217 lut [ i ] = ( i < 16 ? '0' : '' ) + ( i ) . toString ( 16 ) ;
215218 }
216- var fn = function ( ) {
217- var d0 = Math . random ( ) * 0xffffffff | 0 ;
218- var d1 = Math . random ( ) * 0xffffffff | 0 ;
219- var d2 = Math . random ( ) * 0xffffffff | 0 ;
220- var d3 = Math . random ( ) * 0xffffffff | 0 ;
219+ const fn = function ( ) {
220+ const d0 = Math . random ( ) * 0xffffffff | 0 ;
221+ const d1 = Math . random ( ) * 0xffffffff | 0 ;
222+ const d2 = Math . random ( ) * 0xffffffff | 0 ;
223+ const d3 = Math . random ( ) * 0xffffffff | 0 ;
221224 return lut [ d0 & 0xff ] + lut [ d0 >> 8 & 0xff ] + lut [ d0 >> 16 & 0xff ] +
222225 lut [ d0 >> 24 & 0xff ] + '-' + lut [ d1 & 0xff ] + lut [ d1 >> 8 & 0xff ] + '-' +
223226 lut [ d1 >> 16 & 0x0f | 0x40 ] + lut [ d1 >> 24 & 0xff ] + '-' + lut [ d2 & 0x3f | 0x80 ] +
@@ -230,18 +233,18 @@ class TestServer {
230233 }
231234
232235 _setCookie ( ) {
233- //set random cookies
236+ // set random cookies
234237 app . get ( '/cookies/random' , ( req , res ) => {
235- var Chance = require ( 'chance' ) ;
236- var chance = new Chance ( ) ;
237- for ( var i = 0 ; i < 10 ; i ++ ) {
238- var value = chance . string ( {
238+ const Chance = require ( 'chance' ) ;
239+ const chance = new Chance ( ) ;
240+ for ( let i = 0 ; i < 10 ; i ++ ) {
241+ const value = chance . string ( {
239242 length : chance . integer ( {
240243 min : 10 ,
241244 max : 100
242245 } )
243246 } ) ;
244- var opts = { } ;
247+ const opts = { } ;
245248 if ( chance . bool ( ) ) {
246249 opts . expires = 0 ;
247250 }
@@ -263,30 +266,30 @@ class TestServer {
263266 res . set ( 'Content-Type' , 'text/html' ) ;
264267 res . send ( '<h1>Cookies are set</h1>' ) ;
265268 } ) ;
266- //set cookies getting param keys as cookie name and param value as cookie value.
269+ // set cookies getting param keys as cookie name and param value as cookie value.
267270 app . get ( '/cookies/set' , ( req , res ) => {
268271 let params = req . query ;
269272 console . log ( 'Dumping params' ) ;
270273 console . log ( params ) ;
271- for ( let key in params ) {
274+ Object . keys ( params ) . forEach ( ( key ) => {
272275 res . cookie ( key , params [ key ] , {
273276 path : '/'
274277 } ) ;
275- }
278+ } ) ;
276279 res . redirect ( '/cookies' ) ;
277280 } ) ;
278- //delete cookies getting param keys as cookie name and param value as cookie value.
281+ // delete cookies getting param keys as cookie name and param value as cookie value.
279282 app . get ( '/cookies/delete' , ( req , res ) => {
280283 let params = req . query ;
281- for ( let key in params ) {
284+ Object . keys ( params ) . forEach ( ( key ) => {
282285 res . cookie ( key , params [ key ] , {
283286 path : '/' ,
284287 maxAge : - 86400000
285288 } ) ;
286- }
289+ } ) ;
287290 res . redirect ( '/cookies' ) ;
288291 } ) ;
289- //list cookies
292+ // list cookies
290293 app . get ( '/cookies' , function ( req , res ) {
291294 let resp = {
292295 cookies : req . cookies
@@ -298,7 +301,7 @@ class TestServer {
298301
299302 _setPost ( ) {
300303 app . post ( '/' , upload . array ( ) , ( req , res ) => {
301- var response = Object . assign ( { } , {
304+ const response = Object . assign ( { } , {
302305 'body' : req . body ,
303306 'query' : req . query
304307 } ) ;
@@ -386,7 +389,6 @@ class TestServer {
386389 res . redirect ( url ) ;
387390 }
388391 } ) ;
389-
390392 }
391393
392394 _setErrors ( ) {
@@ -400,8 +402,8 @@ class TestServer {
400402
401403 _setEmptyResponses ( ) {
402404 app . all ( '/empty' , ( req , res ) => {
403- var defaultStatus = 200 ;
404- var status = req . params . status ;
405+ const defaultStatus = 200 ;
406+ let status = req . params . status ;
405407 if ( status ) {
406408 status = Number ( status ) ;
407409 if ( status !== status ) {
@@ -436,9 +438,9 @@ class TestServer {
436438 } ) ;
437439 app . post ( '/ntlm' , ( req , res ) => {
438440 res . status ( 200 ) ;
439- var response = Object . assign ( { } , {
440- ' body' : req . body ,
441- ' query' : req . query ,
441+ const response = Object . assign ( { } , {
442+ body : req . body ,
443+ query : req . query ,
442444 headers : req . headers
443445 } ) ;
444446 console . log ( req . body , req . query ) ;
@@ -452,9 +454,9 @@ class TestServer {
452454
453455 _seStatusCodes ( ) {
454456 app . get ( '/status' , ( req , res ) => {
455- let params = req . query ;
457+ const params = req . query ;
456458 let status = params . status ? parseInt ( params . status ) : 200 ;
457- let statusText = params . text || 200 ;
459+ const statusText = params . text || 200 ;
458460 if ( status !== status ) {
459461 status = 200 ;
460462 }
0 commit comments