3
3
4
4
const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
5
5
const 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' )
11
7
12
8
module . exports = ( createCommon , options ) => {
13
9
const describe = getDescribe ( options )
@@ -23,54 +19,21 @@ module.exports = (createCommon, options) => {
23
19
// CI takes longer to instantiate the daemon, so we need to increase the
24
20
// timeout for the before step
25
21
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 ) => {
31
25
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
+ } )
41
30
} )
42
31
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 ) )
52
33
53
34
it ( 'should add from a HTTP URL' , ( done ) => {
54
35
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 )
74
37
parallel ( {
75
38
result : ( cb ) => ipfs . addFromURL ( url , cb ) ,
76
39
expectedResult : ( cb ) => ipfs . add ( Buffer . from ( text ) , cb )
@@ -87,31 +50,10 @@ module.exports = (createCommon, options) => {
87
50
88
51
it ( 'should add from a HTTP URL with redirection' , ( done ) => {
89
52
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'
112
54
113
55
parallel ( {
114
- result : ( cb ) => ipfs . addFromURL ( redirectUrl , cb ) ,
56
+ result : ( cb ) => ipfs . addFromURL ( redirectUrl ( url ) , cb ) ,
115
57
expectedResult : ( cb ) => ipfs . add ( Buffer . from ( text ) , cb )
116
58
} , ( err , { result, expectedResult } ) => {
117
59
expect ( err ) . to . not . exist ( )
@@ -126,7 +68,7 @@ module.exports = (createCommon, options) => {
126
68
127
69
it ( 'should add from a URL with only-hash=true' , ( done ) => {
128
70
const text = `TEST${ Date . now ( ) } `
129
- const url = httpServer . echoUrl ( text )
71
+ const url = echoUrl ( text )
130
72
ipfs . addFromURL ( url , { onlyHash : true } , ( err , res ) => {
131
73
expect ( err ) . to . not . exist ( )
132
74
@@ -147,7 +89,7 @@ module.exports = (createCommon, options) => {
147
89
148
90
it ( 'should add from a URL with wrap-with-directory=true' , ( done ) => {
149
91
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'
151
93
const addOpts = { wrapWithDirectory : true }
152
94
parallel ( {
153
95
result : ( cb ) => ipfs . addFromURL ( url , addOpts , cb ) ,
@@ -163,7 +105,7 @@ module.exports = (createCommon, options) => {
163
105
164
106
it ( 'should add from a URL with wrap-with-directory=true and URL-escaped file name' , ( done ) => {
165
107
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'
167
109
const addOpts = { wrapWithDirectory : true }
168
110
parallel ( {
169
111
result : ( cb ) => ipfs . addFromURL ( url , addOpts , cb ) ,
0 commit comments