33
44const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
55const parallel = require ( 'async/parallel' )
6- const EchoHttpServer = require ( '../utils/echo-http-server' )
7- const { isNode } = require ( 'ipfs-utils/src/env' )
8-
9- const httpServer = EchoHttpServer . createServer ( )
10- const httpsServer = EchoHttpServer . createServer ( { secure : true } )
6+ const { echoUrl, redirectUrl } = require ( '../utils/echo-http-server' )
117
128module . exports = ( createCommon , options ) => {
139 const describe = getDescribe ( options )
@@ -23,54 +19,21 @@ module.exports = (createCommon, options) => {
2319 // CI takes longer to instantiate the daemon, so we need to increase the
2420 // timeout for the before step
2521 this . timeout ( 60 * 1000 )
26- // Instructs node to not reject our snake oil SSL certificate when it
27- // can't verify the certificate authority
28- process . env . NODE_TLS_REJECT_UNAUTHORIZED = 0
29- parallel ( [
30- cb => common . setup ( ( err , factory ) => {
22+ common . setup ( ( err , factory ) => {
23+ expect ( err ) . to . not . exist ( )
24+ factory . spawnNode ( ( err , node ) => {
3125 expect ( err ) . to . not . exist ( )
32- factory . spawnNode ( ( err , node ) => {
33- expect ( err ) . to . not . exist ( )
34- ipfs = node
35- cb ( )
36- } )
37- } ) ,
38- cb => httpServer . start ( cb ) ,
39- cb => httpsServer . start ( cb )
40- ] , done )
26+ ipfs = node
27+ done ( )
28+ } )
29+ } )
4130 } )
4231
43- after ( ( done ) => {
44- // Reinstate unauthorised SSL cert rejection
45- process . env . NODE_TLS_REJECT_UNAUTHORIZED = 1
46- parallel ( [
47- cb => httpServer . stop ( cb ) ,
48- cb => httpsServer . stop ( cb ) ,
49- cb => common . teardown ( cb )
50- ] , done )
51- } )
32+ after ( ( done ) => common . teardown ( done ) )
5233
5334 it ( 'should add from a HTTP URL' , ( done ) => {
5435 const text = `TEST${ Date . now ( ) } `
55- const url = httpServer . echoUrl ( text )
56- parallel ( {
57- result : ( cb ) => ipfs . addFromURL ( url , cb ) ,
58- expectedResult : ( cb ) => ipfs . add ( Buffer . from ( text ) , cb )
59- } , ( err , { result, expectedResult } ) => {
60- expect ( err ) . to . not . exist ( )
61- expect ( result . err ) . to . not . exist ( )
62- expect ( expectedResult . err ) . to . not . exist ( )
63- expect ( result [ 0 ] . hash ) . to . equal ( expectedResult [ 0 ] . hash )
64- expect ( result [ 0 ] . size ) . to . equal ( expectedResult [ 0 ] . size )
65- expect ( result [ 0 ] . path ) . to . equal ( text )
66- done ( )
67- } )
68- } )
69-
70- it ( 'should add from a HTTPS URL' , function ( done ) {
71- if ( ! isNode ) return this . skip ( ) // unable to do self-signed HTTPS in browser
72- const text = `TEST${ Date . now ( ) } `
73- const url = httpsServer . echoUrl ( text )
36+ const url = echoUrl ( text )
7437 parallel ( {
7538 result : ( cb ) => ipfs . addFromURL ( url , cb ) ,
7639 expectedResult : ( cb ) => ipfs . add ( Buffer . from ( text ) , cb )
@@ -87,31 +50,10 @@ module.exports = (createCommon, options) => {
8750
8851 it ( 'should add from a HTTP URL with redirection' , ( done ) => {
8952 const text = `TEST${ Date . now ( ) } `
90- const url = httpServer . echoUrl ( text ) + '?foo=bar#buzz'
91- const redirectUrl = httpServer . redirectUrl ( url )
92-
93- parallel ( {
94- result : ( cb ) => ipfs . addFromURL ( redirectUrl , cb ) ,
95- expectedResult : ( cb ) => ipfs . add ( Buffer . from ( text ) , cb )
96- } , ( err , { result, expectedResult } ) => {
97- expect ( err ) . to . not . exist ( )
98- expect ( result . err ) . to . not . exist ( )
99- expect ( expectedResult . err ) . to . not . exist ( )
100- expect ( result [ 0 ] . hash ) . to . equal ( expectedResult [ 0 ] . hash )
101- expect ( result [ 0 ] . size ) . to . equal ( expectedResult [ 0 ] . size )
102- expect ( result [ 0 ] . path ) . to . equal ( text )
103- done ( )
104- } )
105- } )
106-
107- it ( 'should add from a HTTPS URL with redirection' , function ( done ) {
108- if ( ! isNode ) return this . skip ( ) // unable to do self-signed HTTPS in browser
109- const text = `TEST${ Date . now ( ) } `
110- const url = httpsServer . echoUrl ( text ) + '?foo=bar#buzz'
111- const redirectUrl = httpsServer . redirectUrl ( url )
53+ const url = echoUrl ( text ) + '?foo=bar#buzz'
11254
11355 parallel ( {
114- result : ( cb ) => ipfs . addFromURL ( redirectUrl , cb ) ,
56+ result : ( cb ) => ipfs . addFromURL ( redirectUrl ( url ) , cb ) ,
11557 expectedResult : ( cb ) => ipfs . add ( Buffer . from ( text ) , cb )
11658 } , ( err , { result, expectedResult } ) => {
11759 expect ( err ) . to . not . exist ( )
@@ -126,7 +68,7 @@ module.exports = (createCommon, options) => {
12668
12769 it ( 'should add from a URL with only-hash=true' , ( done ) => {
12870 const text = `TEST${ Date . now ( ) } `
129- const url = httpServer . echoUrl ( text )
71+ const url = echoUrl ( text )
13072 ipfs . addFromURL ( url , { onlyHash : true } , ( err , res ) => {
13173 expect ( err ) . to . not . exist ( )
13274
@@ -147,7 +89,7 @@ module.exports = (createCommon, options) => {
14789
14890 it ( 'should add from a URL with wrap-with-directory=true' , ( done ) => {
14991 const filename = `TEST${ Date . now ( ) } .txt` // also acts as data
150- const url = httpServer . echoUrl ( filename ) + '?foo=bar#buzz'
92+ const url = echoUrl ( filename ) + '?foo=bar#buzz'
15193 const addOpts = { wrapWithDirectory : true }
15294 parallel ( {
15395 result : ( cb ) => ipfs . addFromURL ( url , addOpts , cb ) ,
@@ -163,7 +105,7 @@ module.exports = (createCommon, options) => {
163105
164106 it ( 'should add from a URL with wrap-with-directory=true and URL-escaped file name' , ( done ) => {
165107 const filename = `320px-Domažlice,_Jiráskova_43_(${ Date . now ( ) } ).jpg` // also acts as data
166- const url = httpServer . echoUrl ( filename ) + '?foo=bar#buzz'
108+ const url = echoUrl ( filename ) + '?foo=bar#buzz'
167109 const addOpts = { wrapWithDirectory : true }
168110 parallel ( {
169111 result : ( cb ) => ipfs . addFromURL ( url , addOpts , cb ) ,
0 commit comments