@@ -8,7 +8,7 @@ const formidable = require('../../src/index');
8
8
let ok = 0 ;
9
9
let errors = 0 ;
10
10
11
- const PORT = 13532 ;
11
+ const PORT = 0 ;
12
12
const server = http . createServer ( ( req , res ) => {
13
13
const form = formidable ( ) ;
14
14
form . on ( 'error' , ( ) => {
@@ -24,45 +24,50 @@ const server = http.createServer((req, res) => {
24
24
form . parse ( req ) ;
25
25
} ) ;
26
26
27
- server . listen ( PORT , 'localhost' , ( ) => {
27
+ server . listen ( PORT , ( ) => {
28
28
const choosenPort = server . address ( ) . port ;
29
29
const url = `http://localhost:${ choosenPort } ` ;
30
30
console . log ( 'Server up and running at:' , url ) ;
31
31
32
32
const client = net . createConnection ( choosenPort ) ;
33
33
34
- // first send malformed post upload
34
+ // first send malformed (boundary / hyphens) post upload
35
35
client . write (
36
36
'POST /upload-test HTTP/1.1\r\n' +
37
37
'Host: localhost\r\n' +
38
38
'Connection: keep-alive\r\n' +
39
39
'Content-Type: multipart/form-data; boundary=----aaa\r\n' +
40
40
'Content-Length: 10011\r\n\r\n' +
41
41
'------aaa\n\r' ,
42
- ) ; // expected \r\n
42
+ ) ;
43
43
44
44
setTimeout ( ( ) => {
45
45
const buf = Buffer . alloc ( 10000 ) ;
46
46
buf . fill ( 'a' ) ;
47
47
client . write ( buf ) ;
48
-
49
- // correct post upload
50
- client . write (
51
- 'POST /upload-test HTTP/1.1\r\n' +
52
- 'Host: localhost\r\n' +
53
- 'Connection: keep-alive\r\n' +
54
- 'Content-Type: multipart/form-data; boundary=----aaa\r\n' +
55
- 'Content-Length: 13\r\n\r\n' +
56
- '------aaa--\r\n' ,
57
- ) ;
48
+ client . end ( ) ;
58
49
59
50
setTimeout ( ( ) => {
60
- assert . strictEqual ( ok , 1 , `should ok count === 1, has: ${ ok } ` ) ;
61
- // TODO: fix it!
62
- // assert.strictEqual(errors, 1, 'should errors count === 1, has: ' + errors);
63
- console . log ( 'should errors === 1' , errors ) ;
64
- client . end ( ) ;
65
- server . close ( ) ;
66
- } , 100 ) ;
67
- } , 100 ) ;
51
+ assert . strictEqual ( errors , 1 , `should "errors" === 1, has: ${ errors } ` ) ;
52
+
53
+ const clientTwo = net . createConnection ( choosenPort ) ;
54
+
55
+ // correct post upload (with hyphens)
56
+ clientTwo . write (
57
+ 'POST /upload-test HTTP/1.1\r\n' +
58
+ 'Host: localhost\r\n' +
59
+ 'Connection: keep-alive\r\n' +
60
+ 'Content-Type: multipart/form-data; boundary=----aaa\r\n' +
61
+ 'Content-Length: 13\r\n\r\n' +
62
+ '------aaa--\r\n' ,
63
+ ) ;
64
+ clientTwo . end ( ) ;
65
+
66
+ setTimeout ( ( ) => {
67
+ assert . strictEqual ( ok , 1 , `should "ok" count === 1, has: ${ ok } ` ) ;
68
+
69
+ server . close ( ) ;
70
+ } , 300 ) ;
71
+ } , 200 ) ;
72
+ } , 150 ) ;
68
73
} ) ;
0 commit comments