From 4bedf1e20d27537e522f8dc0e4680c763018e877 Mon Sep 17 00:00:00 2001 From: Alexis Campailla Date: Fri, 14 Aug 2015 13:57:50 +0200 Subject: [PATCH 1/2] test pr --- test/simple/test-arraybuffer-slice.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/simple/test-arraybuffer-slice.js b/test/simple/test-arraybuffer-slice.js index 7703cf73f9dd..1c19e12d5014 100644 --- a/test/simple/test-arraybuffer-slice.js +++ b/test/simple/test-arraybuffer-slice.js @@ -35,6 +35,8 @@ for (var i = 0; i < 8; i++) { buffer[i] = i; } +return 1; + // slice a copy of buffer sub = buffer.slice(2, 6); From 5ff28184ad86afd09e18c5802db5fdb4fab9eef0 Mon Sep 17 00:00:00 2001 From: Alexis Campailla Date: Fri, 14 Aug 2015 13:58:48 +0200 Subject: [PATCH 2/2] delete tests to make jenkins testing faster --- test/simple/test-assert.js | 313 ---- test/simple/test-bad-unicode.js | 31 - test/simple/test-buffer-ascii.js | 45 - test/simple/test-buffer-concat.js | 41 - test/simple/test-buffer-regress-GH-2659.js | 30 - test/simple/test-buffer.js | 1035 ------------ test/simple/test-c-ares.js | 58 - test/simple/test-chdir.js | 40 - test/simple/test-child-process-buffering.js | 65 - .../test-child-process-customfd-bounded.js | 29 - test/simple/test-child-process-cwd.js | 94 -- test/simple/test-child-process-detached.js | 45 - test/simple/test-child-process-disconnect.js | 108 -- test/simple/test-child-process-double-pipe.js | 117 -- test/simple/test-child-process-env.js | 55 - test/simple/test-child-process-exec-cwd.js | 56 - test/simple/test-child-process-exec-env.js | 62 - test/simple/test-child-process-exec-error.js | 45 - test/simple/test-child-process-exit-code.js | 53 - .../test-child-process-fork-and-spawn.js | 53 - test/simple/test-child-process-fork-close.js | 57 - test/simple/test-child-process-fork-dgram.js | 122 -- .../test-child-process-fork-exec-argv.js | 47 - .../test-child-process-fork-exec-path.js | 61 - .../test-child-process-fork-getconnections.js | 119 -- test/simple/test-child-process-fork-net.js | 205 --- test/simple/test-child-process-fork-net2.js | 174 -- test/simple/test-child-process-fork-ref.js | 57 - test/simple/test-child-process-fork-ref2.js | 45 - test/simple/test-child-process-fork.js | 52 - test/simple/test-child-process-fork3.js | 25 - test/simple/test-child-process-internal.js | 58 - test/simple/test-child-process-ipc.js | 66 - test/simple/test-child-process-kill-throw.js | 50 - test/simple/test-child-process-kill.js | 66 - test/simple/test-child-process-recv-handle.js | 85 - test/simple/test-child-process-send-utf8.js | 34 - .../simple/test-child-process-set-blocking.js | 40 - test/simple/test-child-process-silent.js | 106 -- .../test-child-process-spawn-typeerror.js | 103 -- test/simple/test-child-process-stdin.js | 89 - .../test-child-process-stdio-big-write-end.js | 79 - .../test-child-process-stdio-inherit.js | 55 - test/simple/test-child-process-stdio.js | 36 - .../simple/test-child-process-stdout-flush.js | 52 - test/simple/test-cli-eval.js | 92 - test/simple/test-cluster-basic.js | 183 -- test/simple/test-cluster-bind-twice-v1.js | 77 - test/simple/test-cluster-bind-twice-v2.js | 126 -- test/simple/test-cluster-dgram-1.js | 115 -- test/simple/test-cluster-dgram-2.js | 81 - ...test-cluster-disconnect-with-no-workers.js | 36 - test/simple/test-cluster-disconnect.js | 122 -- test/simple/test-cluster-eaccess.js | 62 - test/simple/test-cluster-eaddrinuse.js | 63 - test/simple/test-cluster-fork-env.js | 63 - test/simple/test-cluster-http-pipe.js | 63 - test/simple/test-cluster-listening-port.js | 44 - test/simple/test-cluster-master-error.js | 140 -- test/simple/test-cluster-master-kill.js | 98 -- test/simple/test-cluster-message.js | 141 -- test/simple/test-cluster-net-listen.js | 41 - test/simple/test-cluster-net-send.js | 67 - test/simple/test-cluster-send-deadlock.js | 65 - test/simple/test-cluster-send-handle-twice.js | 56 - test/simple/test-cluster-setup-master.js | 90 - .../simple/test-cluster-uncaught-exception.js | 59 - test/simple/test-cluster-worker-death.js | 46 - test/simple/test-cluster-worker-disconnect.js | 110 -- test/simple/test-cluster-worker-exit.js | 152 -- test/simple/test-cluster-worker-kill.js | 149 -- test/simple/test-console-instance.js | 80 - test/simple/test-console-not-call-toString.js | 36 - test/simple/test-console.js | 78 - test/simple/test-crypto-binary-default.js | 690 -------- test/simple/test-crypto-dh-odd-key.js | 31 - test/simple/test-crypto-domains.js | 50 - test/simple/test-crypto-ecb.js | 53 - test/simple/test-crypto-hash-stream-pipe.js | 42 - test/simple/test-crypto-padding-aes256.js | 69 - test/simple/test-crypto-padding.js | 132 -- test/simple/test-crypto-random.js | 78 - test/simple/test-crypto-stream.js | 76 - test/simple/test-crypto-verify-failure.js | 81 - test/simple/test-crypto.js | 954 ----------- test/simple/test-debug-brk-no-arg.js | 35 - test/simple/test-debugger-client.js | 232 --- .../test-debugger-repl-break-in-module.js | 80 - test/simple/test-debugger-repl-restart.js | 40 - test/simple/test-debugger-repl-utf8.js | 27 - test/simple/test-debugger-repl.js | 77 - test/simple/test-delayed-require.js | 34 - test/simple/test-deprecation-flags.js | 57 - test/simple/test-dgram-address.js | 64 - .../simple/test-dgram-bind-default-address.js | 39 - test/simple/test-dgram-bind.js | 32 - .../test-dgram-broadcast-multi-process.js | 240 --- test/simple/test-dgram-close.js | 43 - test/simple/test-dgram-implicit-bind.js | 49 - test/simple/test-dgram-listen-after-bind.js | 43 - test/simple/test-dgram-multicast-setTTL.js | 43 - test/simple/test-dgram-oob-buffer.js | 52 - test/simple/test-dgram-pingpong.js | 114 -- test/simple/test-dgram-ref.js | 27 - test/simple/test-dgram-regress-4496.js | 32 - test/simple/test-dgram-send-bad-arguments.js | 40 - test/simple/test-dgram-udp4.js | 81 - test/simple/test-dgram-unref.js | 39 - test/simple/test-dh-padding.js | 46 - test/simple/test-domain-crypto.js | 37 - test/simple/test-domain-exit-dispose-again.js | 76 - test/simple/test-domain-exit-dispose.js | 67 - test/simple/test-domain-from-timer.js | 39 - test/simple/test-domain-http-server.js | 117 -- test/simple/test-domain-implicit-fs.js | 72 - test/simple/test-domain-multi.js | 99 -- test/simple/test-domain-nested-throw.js | 113 -- test/simple/test-domain-nested.js | 42 - test/simple/test-domain-safe-exit.js | 36 - test/simple/test-domain-stack.js | 50 - test/simple/test-domain-timers.js | 60 - ...in-top-level-error-handler-clears-stack.js | 41 - ...st-domain-top-level-error-handler-throw.js | 74 - ...domain-with-abort-on-uncaught-exception.js | 215 --- test/simple/test-domain.js | 263 --- test/simple/test-error-reporting.js | 76 - test/simple/test-eval-require.js | 38 - test/simple/test-eval.js | 50 - .../test-event-emitter-add-listeners.js | 68 - ...test-event-emitter-check-listener-leaks.js | 58 - ...st-event-emitter-listeners-side-effects.js | 61 - test/simple/test-event-emitter-listeners.js | 52 - .../test-event-emitter-max-listeners.js | 53 - test/simple/test-event-emitter-memory-leak.js | 44 - .../simple/test-event-emitter-method-names.js | 32 - .../test-event-emitter-modify-in-emit.js | 77 - ...mitter-no-error-provided-to-error-event.js | 42 - test/simple/test-event-emitter-num-args.js | 48 - test/simple/test-event-emitter-once.js | 65 - ...test-event-emitter-remove-all-listeners.js | 80 - .../test-event-emitter-remove-listeners.js | 84 - ...-emitter-set-max-listeners-side-effects.js | 30 - test/simple/test-event-emitter-subclass.js | 55 - test/simple/test-exception-handler.js | 47 - test/simple/test-exception-handler2.js | 42 - test/simple/test-exec-max-buffer.js | 34 - test/simple/test-executable-path.js | 52 - test/simple/test-file-read-noexist.js | 42 - test/simple/test-file-write-stream.js | 85 - test/simple/test-file-write-stream2.js | 111 -- test/simple/test-file-write-stream3.js | 206 --- test/simple/test-force-repl.js | 44 - test/simple/test-fs-append-file-sync.js | 102 -- test/simple/test-fs-append-file.js | 134 -- test/simple/test-fs-chmod.js | 161 -- test/simple/test-fs-empty-readStream.js | 68 - test/simple/test-fs-error-messages.js | 216 --- test/simple/test-fs-exists.js | 43 - test/simple/test-fs-fsync.js | 59 - test/simple/test-fs-long-path.js | 59 - test/simple/test-fs-mkdir.js | 83 - .../test-fs-non-number-arguments-throw.js | 24 - test/simple/test-fs-null-bytes.js | 75 - test/simple/test-fs-open-flags.js | 60 - test/simple/test-fs-open.js | 59 - test/simple/test-fs-read-buffer.js | 50 - .../simple/test-fs-read-file-sync-hostname.js | 30 - test/simple/test-fs-read-file-sync.js | 33 - test/simple/test-fs-read-stream-err.js | 63 - test/simple/test-fs-read-stream-fd.js | 44 - test/simple/test-fs-read-stream-resume.js | 51 - test/simple/test-fs-read-stream.js | 197 --- test/simple/test-fs-read.js | 48 - test/simple/test-fs-readfile-empty.js | 38 - test/simple/test-fs-readfile-error.js | 64 - test/simple/test-fs-readfile-pipe.js | 55 - test/simple/test-fs-readfile-unlink.js | 48 - .../simple/test-fs-readfile-zero-byte-liar.js | 58 - test/simple/test-fs-realpath.js | 594 ------- test/simple/test-fs-sir-writes-alot.js | 71 - test/simple/test-fs-stat.js | 123 -- test/simple/test-fs-stream-double-close.js | 61 - test/simple/test-fs-symlink-dir-junction.js | 68 - test/simple/test-fs-symlink.js | 92 - test/simple/test-fs-sync-fd-leak.js | 69 - test/simple/test-fs-truncate-GH-6233.js | 44 - test/simple/test-fs-truncate.js | 135 -- test/simple/test-fs-utimes.js | 160 -- test/simple/test-fs-watch.js | 141 -- test/simple/test-fs-write-buffer.js | 54 - test/simple/test-fs-write-file-buffer.js | 51 - test/simple/test-fs-write-file-sync.js | 98 -- test/simple/test-fs-write-file.js | 108 -- .../test-fs-write-stream-change-open.js | 52 - test/simple/test-fs-write-stream-end.js | 42 - test/simple/test-fs-write-stream-err.js | 71 - test/simple/test-fs-write-stream.js | 50 - test/simple/test-fs-write-sync.js | 42 - test/simple/test-fs-write.js | 76 - test/simple/test-global.js | 39 - test/simple/test-http-1.0-keep-alive.js | 152 -- test/simple/test-http-1.0.js | 181 -- test/simple/test-http-304.js | 46 - test/simple/test-http-abort-before-end.js | 43 - test/simple/test-http-abort-client.js | 75 - test/simple/test-http-abort-stream-end.js | 61 - test/simple/test-http-after-connect.js | 89 - .../test-http-agent-destroyed-socket.js | 106 -- test/simple/test-http-agent-null.js | 47 - test/simple/test-http-agent.js | 61 - .../test-http-allow-req-after-204-res.js | 66 - test/simple/test-http-bind-twice.js | 47 - test/simple/test-http-blank-header.js | 68 - test/simple/test-http-buffer-sanity.js | 91 - test/simple/test-http-byteswritten.js | 56 - test/simple/test-http-chunked-304.js | 63 - test/simple/test-http-chunked.js | 63 - test/simple/test-http-client-abort.js | 80 - test/simple/test-http-client-abort2.js | 41 - test/simple/test-http-client-agent.js | 70 - test/simple/test-http-client-get-url.js | 44 - test/simple/test-http-client-parse-error.js | 59 - test/simple/test-http-client-pipe-end.js | 59 - test/simple/test-http-client-race-2.js | 118 -- test/simple/test-http-client-race.js | 66 - test/simple/test-http-client-readable.js | 96 -- .../test-http-client-response-domain.js | 66 - test/simple/test-http-client-timeout-agent.js | 96 -- test/simple/test-http-client-timeout-event.js | 58 - .../test-http-client-timeout-with-data.js | 67 - test/simple/test-http-client-timeout.js | 50 - test/simple/test-http-client-upload-buf.js | 74 - test/simple/test-http-client-upload.js | 77 - test/simple/test-http-conn-reset.js | 56 - test/simple/test-http-connect.js | 109 -- test/simple/test-http-contentLength0.js | 43 - test/simple/test-http-createConnection.js | 47 - test/simple/test-http-curl-chunk-problem.js | 85 - test/simple/test-http-date-header.js | 55 - test/simple/test-http-default-encoding.js | 62 - .../test-http-destroyed-socket-write.js | 122 -- test/simple/test-http-dns-error.js | 68 - .../test-http-end-throw-socket-handling.js | 67 - test/simple/test-http-eof-on-connect.js | 40 - test/simple/test-http-exceptions.js | 47 - test/simple/test-http-exit-delay.js | 60 - test/simple/test-http-expect-continue.js | 88 - test/simple/test-http-extra-response.js | 86 - test/simple/test-http-full-response.js | 96 -- test/simple/test-http-get-pipeline-problem.js | 111 -- test/simple/test-http-head-request.js | 69 - ...test-http-head-response-has-no-body-end.js | 62 - .../test-http-head-response-has-no-body.js | 59 - test/simple/test-http-header-read.js | 55 - .../test-http-header-response-splitting.js | 66 - test/simple/test-http-hex-write.js | 53 - test/simple/test-http-host-headers.js | 195 --- ...-http-incoming-pipelined-socket-destroy.js | 89 - .../test-http-keep-alive-close-on-header.js | 97 -- test/simple/test-http-keep-alive.js | 71 - test/simple/test-http-legacy.js | 105 -- .../test-http-localaddress-bind-error.js | 57 - test/simple/test-http-localaddress.js | 57 - test/simple/test-http-malformed-request.js | 57 - test/simple/test-http-many-ended-pipelines.js | 56 - .../test-http-many-keep-alive-connections.js | 69 - test/simple/test-http-max-headers-count.js | 88 - test/simple/test-http-multi-line-headers.js | 58 - test/simple/test-http-mutable-headers.js | 153 -- test/simple/test-http-no-content-length.js | 46 - test/simple/test-http-parser-bad-ref.js | 81 - test/simple/test-http-parser-free.js | 55 - test/simple/test-http-parser.js | 549 ------ test/simple/test-http-pause-resume-one-end.js | 58 - test/simple/test-http-pause.js | 75 - test/simple/test-http-pipe-fs.js | 69 - test/simple/test-http-pipeline-flood.js | 114 -- test/simple/test-http-proxy.js | 109 -- test/simple/test-http-request-end-twice.js | 42 - test/simple/test-http-request-end.js | 59 - test/simple/test-http-request-methods.js | 72 - ...test-http-res-write-end-dont-take-array.js | 66 - test/simple/test-http-response-close.js | 61 - test/simple/test-http-response-no-headers.js | 78 - test/simple/test-http-response-readable.js | 41 - test/simple/test-http-server-multiheaders.js | 74 - test/simple/test-http-server-stale-close.js | 52 - test/simple/test-http-server.js | 128 -- test/simple/test-http-set-cookies.js | 84 - test/simple/test-http-set-timeout-server.js | 179 -- test/simple/test-http-set-timeout.js | 51 - test/simple/test-http-set-trailers.js | 112 -- test/simple/test-http-should-keep-alive.js | 72 - test/simple/test-http-status-code.js | 70 - test/simple/test-http-timeout-overflow.js | 64 - test/simple/test-http-timeout.js | 66 - test/simple/test-http-unix-socket.js | 87 - test/simple/test-http-upgrade-agent.js | 93 -- test/simple/test-http-upgrade-client.js | 76 - test/simple/test-http-upgrade-client2.js | 86 - test/simple/test-http-upgrade-server.js | 185 -- test/simple/test-http-upgrade-server2.js | 72 - ...p-url.parse-auth-with-header-in-request.js | 50 - test/simple/test-http-url.parse-auth.js | 46 - test/simple/test-http-url.parse-basic.js | 55 - .../test-http-url.parse-https.request.js | 58 - ....parse-only-support-http-https-protocol.js | 82 - test/simple/test-http-url.parse-path.js | 45 - test/simple/test-http-url.parse-post.js | 52 - test/simple/test-http-url.parse-search.js | 46 - test/simple/test-http-wget.js | 87 - test/simple/test-http-write-empty-string.js | 57 - test/simple/test-http-zero-length-write.js | 93 -- test/simple/test-http.js | 109 -- test/simple/test-https-agent.js | 72 - test/simple/test-https-byteswritten.js | 56 - test/simple/test-https-client-get-url.js | 58 - test/simple/test-https-client-reject.js | 97 -- test/simple/test-https-client-resume.js | 92 - test/simple/test-https-connecting-to-http.js | 64 - test/simple/test-https-drain.js | 94 -- test/simple/test-https-eof-for-eom.js | 101 -- test/simple/test-https-foafssl.js | 100 -- test/simple/test-https-invalid-key.js | 62 - .../test-https-localaddress-bind-error.js | 63 - test/simple/test-https-localaddress.js | 66 - test/simple/test-https-no-reader.js | 68 - test/simple/test-https-pfx.js | 57 - test/simple/test-https-req-split.js | 75 - test/simple/test-https-simple.js | 75 - test/simple/test-https-socket-options.js | 88 - test/simple/test-https-strict.js | 222 --- test/simple/test-https-timeout-server-2.js | 51 - test/simple/test-https-timeout-server.js | 58 - test/simple/test-https-timeout.js | 74 - test/simple/test-init.js | 72 - test/simple/test-listen-fd-cluster.js | 136 -- .../simple/test-listen-fd-detached-inherit.js | 119 -- test/simple/test-listen-fd-detached.js | 117 -- test/simple/test-listen-fd-ebadf.js | 38 - test/simple/test-listen-fd-server.js | 122 -- test/simple/test-memory-usage-emfile.js | 37 - test/simple/test-memory-usage.js | 30 - test/simple/test-mkdir-rmdir.js | 61 - test/simple/test-module-loading-error.js | 44 - test/simple/test-module-loading.js | 308 ---- test/simple/test-net-GH-5504.js | 123 -- test/simple/test-net-after-close.js | 54 - test/simple/test-net-binary.js | 112 -- test/simple/test-net-bind-twice.js | 46 - test/simple/test-net-buffersize.js | 51 - test/simple/test-net-bytes-stats.js | 81 - test/simple/test-net-can-reset-timeout.js | 64 - test/simple/test-net-connect-buffer.js | 117 -- .../test-net-connect-handle-econnrefused.js | 48 - .../test-net-connect-immediate-finish.js | 41 - test/simple/test-net-connect-options.js | 62 - test/simple/test-net-create-connection.js | 50 - test/simple/test-net-dns-error.js | 49 - test/simple/test-net-during-close.js | 47 - test/simple/test-net-eaddrinuse.js | 35 - test/simple/test-net-end-without-connect.js | 26 - test/simple/test-net-error-twice.js | 53 - test/simple/test-net-isip.js | 61 - test/simple/test-net-keepalive.js | 51 - test/simple/test-net-large-string.js | 55 - test/simple/test-net-listen-error.js | 39 - test/simple/test-net-listen-fd0.js | 40 - test/simple/test-net-local-address-port.js | 47 - .../test-net-pause-resume-connecting.js | 101 -- test/simple/test-net-pingpong.js | 143 -- test/simple/test-net-pipe-connect-errors.js | 86 - test/simple/test-net-reconnect.js | 89 - test/simple/test-net-remote-address-port.js | 57 - test/simple/test-net-server-address.js | 58 - test/simple/test-net-server-bind.js | 95 -- test/simple/test-net-server-close.js | 58 - .../test-net-server-listen-remove-callback.js | 43 - .../simple/test-net-server-max-connections.js | 107 -- test/simple/test-net-server-try-ports.js | 76 - test/simple/test-net-server-unref.js | 39 - test/simple/test-net-settimeout.js | 56 - test/simple/test-net-socket-destroy-twice.js | 43 - test/simple/test-net-socket-timeout-unref.js | 47 - test/simple/test-net-socket-timeout.js | 44 - test/simple/test-net-stream.js | 72 - test/simple/test-net-write-after-close.js | 55 - test/simple/test-net-write-connect-write.js | 48 - test/simple/test-net-write-slow.js | 67 - test/simple/test-next-tick-doesnt-hang.js | 30 - test/simple/test-next-tick-domain.js | 29 - test/simple/test-next-tick-error-spin.js | 69 - test/simple/test-next-tick-errors.js | 57 - .../test-next-tick-intentional-starvation.js | 64 - test/simple/test-next-tick-ordering.js | 55 - test/simple/test-next-tick-ordering2.js | 38 - test/simple/test-next-tick-starvation.js | 52 - test/simple/test-next-tick.js | 52 - test/simple/test-os.js | 100 -- test/simple/test-path-makelong.js | 44 - test/simple/test-path.js | 407 ----- test/simple/test-pipe-address.js | 39 - test/simple/test-pipe-file-to-http.js | 109 -- test/simple/test-pipe-head.js | 48 - test/simple/test-pipe-return-val.js | 37 - test/simple/test-pipe-stream.js | 86 - test/simple/test-pipe-unref.js | 39 - test/simple/test-pipe.js | 135 -- test/simple/test-process-active-wraps.js | 61 - test/simple/test-process-argv-0.js | 55 - test/simple/test-process-config.js | 44 - test/simple/test-process-env.js | 79 - test/simple/test-process-exec-argv.js | 40 - test/simple/test-process-exit-recursive.js | 35 - test/simple/test-process-exit.js | 34 - test/simple/test-process-getgroups.js | 46 - test/simple/test-process-hrtime.js | 46 - test/simple/test-process-kill-null.js | 48 - test/simple/test-process-next-tick.js | 45 - test/simple/test-process-wrap.js | 73 - test/simple/test-pump-file2tcp-noexist.js | 72 - test/simple/test-pump-file2tcp.js | 65 - test/simple/test-punycode.js | 195 --- test/simple/test-querystring.js | 239 --- test/simple/test-readdir.js | 91 - test/simple/test-readdouble.js | 131 -- test/simple/test-readfloat.js | 93 -- test/simple/test-readint.js | 122 -- test/simple/test-readline-interface.js | 190 --- test/simple/test-readline-set-raw-mode.js | 91 - test/simple/test-readuint.js | 113 -- test/simple/test-regress-GH-1531.js | 63 - test/simple/test-regress-GH-1697.js | 70 - test/simple/test-regress-GH-1726.js | 64 - test/simple/test-regress-GH-1899.js | 40 - test/simple/test-regress-GH-3542.js | 54 - test/simple/test-regress-GH-3739.js | 66 - test/simple/test-regress-GH-4015.js | 33 - test/simple/test-regress-GH-4027.js | 41 - test/simple/test-regress-GH-4256.js | 25 - test/simple/test-regress-GH-4948.js | 62 - test/simple/test-regress-GH-5927.js | 42 - test/simple/test-regress-GH-746.js | 50 - test/simple/test-regress-GH-784.js | 157 -- test/simple/test-regress-GH-819.js | 28 - test/simple/test-regress-GH-877.js | 72 - test/simple/test-regress-GH-897.js | 35 - .../test-regression-object-prototype.js | 27 - test/simple/test-repl-.save.load.js | 98 -- test/simple/test-repl-autolibs.js | 80 - test/simple/test-repl-console.js | 43 - test/simple/test-repl-domain.js | 58 - test/simple/test-repl-end-emits-exit.js | 77 - test/simple/test-repl-options.js | 71 - test/simple/test-repl-require-cache.js | 33 - test/simple/test-repl-tab-complete.js | 213 --- test/simple/test-repl.js | 338 ---- .../simple/test-require-cache-without-stat.js | 72 - test/simple/test-require-cache.js | 43 - test/simple/test-require-exceptions.js | 42 - test/simple/test-require-json.js | 30 - test/simple/test-require-resolve.js | 35 - test/simple/test-script-context.js | 77 - test/simple/test-script-new.js | 93 -- test/simple/test-script-static-context.js | 40 - test/simple/test-script-static-new.js | 62 - test/simple/test-script-static-this.js | 56 - test/simple/test-script-this.js | 61 - test/simple/test-setproctitle.js | 52 - test/simple/test-sigint-infinite-loop.js | 61 - test/simple/test-signal-handler.js | 71 - test/simple/test-signal-unregister.js | 56 - .../test-socket-write-after-fin-error.js | 80 - test/simple/test-socket-write-after-fin.js | 64 - test/simple/test-stdin-child-proc.js | 28 - test/simple/test-stdin-from-file.js | 65 - test/simple/test-stdin-hang.js | 31 - test/simple/test-stdin-pause-resume-sync.js | 31 - test/simple/test-stdin-pause-resume.js | 37 - test/simple/test-stdin-pipe-resume.js | 48 - test/simple/test-stdin-resume-pause.js | 23 - test/simple/test-stdio-readable-writable.js | 32 - ...out-cannot-be-closed-child-process-pipe.js | 52 - test/simple/test-stdout-close-catch.js | 56 - test/simple/test-stdout-close-unref.js | 24 - test/simple/test-stdout-stderr-reading.js | 94 -- test/simple/test-stdout-to-file.js | 77 - test/simple/test-stream-big-packet.js | 73 - test/simple/test-stream-big-push.js | 84 - test/simple/test-stream-pipe-after-end.js | 86 - test/simple/test-stream-pipe-cleanup.js | 122 -- .../simple/test-stream-pipe-error-handling.js | 131 -- test/simple/test-stream-pipe-event.js | 49 - test/simple/test-stream-pipe-multi.js | 121 -- test/simple/test-stream-push-order.js | 52 - test/simple/test-stream-push-strings.js | 66 - test/simple/test-stream-readable-event.js | 126 -- .../test-stream-readable-flow-recursion.js | 76 - ...tream-transform-objectmode-falsey-value.js | 53 - .../simple/test-stream-unshift-empty-chunk.js | 81 - test/simple/test-stream-unshift-read-race.js | 133 -- .../test-stream-writable-decoded-encoding.js | 60 - ...est-stream2-base64-single-char-read-end.js | 58 - test/simple/test-stream2-basic.js | 475 ------ test/simple/test-stream2-compatibility.js | 50 - test/simple/test-stream2-finish-pipe.js | 41 - test/simple/test-stream2-fs.js | 72 - .../test-stream2-httpclient-response-end.js | 52 - test/simple/test-stream2-large-read-stall.js | 82 - test/simple/test-stream2-objects.js | 348 ---- .../test-stream2-pipe-error-handling.js | 105 -- .../test-stream2-pipe-error-once-listener.js | 64 - test/simple/test-stream2-push.js | 138 -- test/simple/test-stream2-read-sync-stack.js | 54 - ...st-stream2-readable-empty-buffer-no-eof.js | 118 -- .../simple/test-stream2-readable-from-list.js | 120 -- .../test-stream2-readable-legacy-drain.js | 75 - .../test-stream2-readable-non-empty-end.js | 78 - .../test-stream2-readable-wrap-empty.js | 43 - test/simple/test-stream2-readable-wrap.js | 111 -- test/simple/test-stream2-set-encoding.js | 361 ---- test/simple/test-stream2-stderr-sync.js | 130 -- test/simple/test-stream2-transform.js | 471 ------ test/simple/test-stream2-unpipe-drain.js | 76 - test/simple/test-stream2-unpipe-leak.js | 74 - test/simple/test-stream2-writable.js | 377 ----- test/simple/test-string-decoder-end.js | 75 - test/simple/test-string-decoder.js | 122 -- test/simple/test-sync-fileread.js | 32 - test/simple/test-sys.js | 129 -- test/simple/test-tcp-wrap-connect.js | 72 - test/simple/test-tcp-wrap-listen.js | 116 -- test/simple/test-tcp-wrap.js | 39 - test/simple/test-timers-blocking-callback.js | 99 -- test/simple/test-timers-first-fire.js | 33 - test/simple/test-timers-immediate.js | 53 - test/simple/test-timers-linked-list.js | 120 -- test/simple/test-timers-non-integer-delay.js | 50 - test/simple/test-timers-ordering.js | 48 - ...imeout-removes-other-socket-unref-timer.js | 69 - test/simple/test-timers-this.js | 64 - test/simple/test-timers-uncaught-exception.js | 60 - test/simple/test-timers-unref-active.js | 71 - ...emove-other-unref-timers-only-one-fires.js | 59 - ...-timers-unref-remove-other-unref-timers.js | 49 - test/simple/test-timers-unref.js | 69 - ...test-timers-unrefd-interval-still-fires.js | 39 - test/simple/test-timers-zero-timeout.js | 59 - test/simple/test-timers.js | 72 - test/simple/test-tls-check-server-identity.js | 209 --- test/simple/test-tls-client-abort.js | 44 - test/simple/test-tls-client-abort2.js | 45 - test/simple/test-tls-client-abort3.js | 68 - test/simple/test-tls-client-destroy-soon.js | 75 - test/simple/test-tls-client-reject.js | 92 - test/simple/test-tls-client-resume.js | 85 - test/simple/test-tls-client-verify.js | 155 -- test/simple/test-tls-close-notify.js | 58 - test/simple/test-tls-connect-given-socket.js | 65 - test/simple/test-tls-connect-pipe.js | 50 - test/simple/test-tls-connect-simple.js | 63 - test/simple/test-tls-connect.js | 77 - test/simple/test-tls-fast-writing.js | 80 - test/simple/test-tls-getcipher.js | 57 - test/simple/test-tls-handshake-nohang.js | 28 - test/simple/test-tls-hello-parser-failure.js | 61 - ...test-tls-honorcipherorder-secureOptions.js | 131 -- test/simple/test-tls-honorcipherorder.js | 89 - test/simple/test-tls-interleave.js | 69 - test/simple/test-tls-invalid-key.js | 62 - test/simple/test-tls-junk-closes-server.js | 54 - test/simple/test-tls-npn-server-client.js | 123 -- test/simple/test-tls-ondata.js | 54 - test/simple/test-tls-over-http-tunnel.js | 177 -- test/simple/test-tls-passphrase.js | 75 - test/simple/test-tls-pause-close.js | 103 -- test/simple/test-tls-pause.js | 92 - .../test-tls-peer-certificate-multi-keys.js | 61 - test/simple/test-tls-peer-certificate.js | 61 - test/simple/test-tls-remote.js | 65 - test/simple/test-tls-request-timeout.js | 53 - test/simple/test-tls-securepair-client.js | 201 --- test/simple/test-tls-securepair-server.js | 154 -- test/simple/test-tls-server-large-request.js | 74 - .../simple/test-tls-server-missing-options.js | 38 - test/simple/test-tls-server-slab.js | 66 - test/simple/test-tls-server-verify.js | 290 ---- test/simple/test-tls-session-cache.js | 118 -- test/simple/test-tls-set-ciphers.js | 62 - test/simple/test-tls-set-encoding.js | 74 - test/simple/test-tls-sni-server-client.js | 122 -- test/simple/test-tls-timeout-server-2.js | 47 - test/simple/test-tls-timeout-server.js | 52 - test/simple/test-tls-zero-clear-in.js | 71 - test/simple/test-tty-stdout-end.js | 36 - test/simple/test-tty-wrap.js | 48 - test/simple/test-typed-arrays.js | 249 --- test/simple/test-umask.js | 41 - test/simple/test-url.js | 1485 ----------------- test/simple/test-utf8-scripts.js | 30 - test/simple/test-util-format.js | 72 - test/simple/test-util-inspect.js | 157 -- test/simple/test-util.js | 80 - .../test-vm-create-context-accessors.js | 47 - test/simple/test-vm-create-context-arg.js | 33 - ...st-vm-create-context-circular-reference.js | 34 - test/simple/test-writedouble.js | 197 --- test/simple/test-writefloat.js | 135 -- test/simple/test-writeint.js | 192 --- test/simple/test-writeuint.js | 151 -- test/simple/test-zerolengthbufferbug.js | 57 - test/simple/test-zlib-close-after-write.js | 38 - test/simple/test-zlib-dictionary-fail.js | 48 - test/simple/test-zlib-dictionary.js | 95 -- test/simple/test-zlib-from-gzip.js | 48 - test/simple/test-zlib-from-string.js | 78 - test/simple/test-zlib-invalid-input.js | 65 - test/simple/test-zlib-random-byte-pipes.js | 181 -- test/simple/test-zlib-write-after-close.js | 40 - test/simple/test-zlib-write-after-flush.js | 54 - test/simple/test-zlib-zero-byte.js | 48 - test/simple/test-zlib.js | 229 --- 622 files changed, 53902 deletions(-) delete mode 100644 test/simple/test-assert.js delete mode 100644 test/simple/test-bad-unicode.js delete mode 100644 test/simple/test-buffer-ascii.js delete mode 100644 test/simple/test-buffer-concat.js delete mode 100644 test/simple/test-buffer-regress-GH-2659.js delete mode 100644 test/simple/test-buffer.js delete mode 100644 test/simple/test-c-ares.js delete mode 100644 test/simple/test-chdir.js delete mode 100644 test/simple/test-child-process-buffering.js delete mode 100644 test/simple/test-child-process-customfd-bounded.js delete mode 100644 test/simple/test-child-process-cwd.js delete mode 100644 test/simple/test-child-process-detached.js delete mode 100644 test/simple/test-child-process-disconnect.js delete mode 100644 test/simple/test-child-process-double-pipe.js delete mode 100644 test/simple/test-child-process-env.js delete mode 100644 test/simple/test-child-process-exec-cwd.js delete mode 100644 test/simple/test-child-process-exec-env.js delete mode 100644 test/simple/test-child-process-exec-error.js delete mode 100644 test/simple/test-child-process-exit-code.js delete mode 100644 test/simple/test-child-process-fork-and-spawn.js delete mode 100644 test/simple/test-child-process-fork-close.js delete mode 100644 test/simple/test-child-process-fork-dgram.js delete mode 100644 test/simple/test-child-process-fork-exec-argv.js delete mode 100755 test/simple/test-child-process-fork-exec-path.js delete mode 100644 test/simple/test-child-process-fork-getconnections.js delete mode 100644 test/simple/test-child-process-fork-net.js delete mode 100644 test/simple/test-child-process-fork-net2.js delete mode 100644 test/simple/test-child-process-fork-ref.js delete mode 100644 test/simple/test-child-process-fork-ref2.js delete mode 100644 test/simple/test-child-process-fork.js delete mode 100644 test/simple/test-child-process-fork3.js delete mode 100644 test/simple/test-child-process-internal.js delete mode 100644 test/simple/test-child-process-ipc.js delete mode 100644 test/simple/test-child-process-kill-throw.js delete mode 100644 test/simple/test-child-process-kill.js delete mode 100644 test/simple/test-child-process-recv-handle.js delete mode 100644 test/simple/test-child-process-send-utf8.js delete mode 100644 test/simple/test-child-process-set-blocking.js delete mode 100644 test/simple/test-child-process-silent.js delete mode 100644 test/simple/test-child-process-spawn-typeerror.js delete mode 100644 test/simple/test-child-process-stdin.js delete mode 100644 test/simple/test-child-process-stdio-big-write-end.js delete mode 100644 test/simple/test-child-process-stdio-inherit.js delete mode 100644 test/simple/test-child-process-stdio.js delete mode 100644 test/simple/test-child-process-stdout-flush.js delete mode 100644 test/simple/test-cli-eval.js delete mode 100644 test/simple/test-cluster-basic.js delete mode 100644 test/simple/test-cluster-bind-twice-v1.js delete mode 100644 test/simple/test-cluster-bind-twice-v2.js delete mode 100644 test/simple/test-cluster-dgram-1.js delete mode 100644 test/simple/test-cluster-dgram-2.js delete mode 100644 test/simple/test-cluster-disconnect-with-no-workers.js delete mode 100644 test/simple/test-cluster-disconnect.js delete mode 100644 test/simple/test-cluster-eaccess.js delete mode 100644 test/simple/test-cluster-eaddrinuse.js delete mode 100644 test/simple/test-cluster-fork-env.js delete mode 100644 test/simple/test-cluster-http-pipe.js delete mode 100644 test/simple/test-cluster-listening-port.js delete mode 100644 test/simple/test-cluster-master-error.js delete mode 100644 test/simple/test-cluster-master-kill.js delete mode 100644 test/simple/test-cluster-message.js delete mode 100644 test/simple/test-cluster-net-listen.js delete mode 100644 test/simple/test-cluster-net-send.js delete mode 100644 test/simple/test-cluster-send-deadlock.js delete mode 100644 test/simple/test-cluster-send-handle-twice.js delete mode 100644 test/simple/test-cluster-setup-master.js delete mode 100644 test/simple/test-cluster-uncaught-exception.js delete mode 100644 test/simple/test-cluster-worker-death.js delete mode 100644 test/simple/test-cluster-worker-disconnect.js delete mode 100644 test/simple/test-cluster-worker-exit.js delete mode 100644 test/simple/test-cluster-worker-kill.js delete mode 100644 test/simple/test-console-instance.js delete mode 100644 test/simple/test-console-not-call-toString.js delete mode 100644 test/simple/test-console.js delete mode 100644 test/simple/test-crypto-binary-default.js delete mode 100644 test/simple/test-crypto-dh-odd-key.js delete mode 100644 test/simple/test-crypto-domains.js delete mode 100644 test/simple/test-crypto-ecb.js delete mode 100644 test/simple/test-crypto-hash-stream-pipe.js delete mode 100644 test/simple/test-crypto-padding-aes256.js delete mode 100644 test/simple/test-crypto-padding.js delete mode 100644 test/simple/test-crypto-random.js delete mode 100644 test/simple/test-crypto-stream.js delete mode 100644 test/simple/test-crypto-verify-failure.js delete mode 100644 test/simple/test-crypto.js delete mode 100644 test/simple/test-debug-brk-no-arg.js delete mode 100644 test/simple/test-debugger-client.js delete mode 100644 test/simple/test-debugger-repl-break-in-module.js delete mode 100644 test/simple/test-debugger-repl-restart.js delete mode 100644 test/simple/test-debugger-repl-utf8.js delete mode 100644 test/simple/test-debugger-repl.js delete mode 100644 test/simple/test-delayed-require.js delete mode 100644 test/simple/test-deprecation-flags.js delete mode 100644 test/simple/test-dgram-address.js delete mode 100644 test/simple/test-dgram-bind-default-address.js delete mode 100644 test/simple/test-dgram-bind.js delete mode 100644 test/simple/test-dgram-broadcast-multi-process.js delete mode 100644 test/simple/test-dgram-close.js delete mode 100644 test/simple/test-dgram-implicit-bind.js delete mode 100644 test/simple/test-dgram-listen-after-bind.js delete mode 100644 test/simple/test-dgram-multicast-setTTL.js delete mode 100644 test/simple/test-dgram-oob-buffer.js delete mode 100644 test/simple/test-dgram-pingpong.js delete mode 100644 test/simple/test-dgram-ref.js delete mode 100644 test/simple/test-dgram-regress-4496.js delete mode 100644 test/simple/test-dgram-send-bad-arguments.js delete mode 100644 test/simple/test-dgram-udp4.js delete mode 100644 test/simple/test-dgram-unref.js delete mode 100644 test/simple/test-dh-padding.js delete mode 100644 test/simple/test-domain-crypto.js delete mode 100644 test/simple/test-domain-exit-dispose-again.js delete mode 100644 test/simple/test-domain-exit-dispose.js delete mode 100644 test/simple/test-domain-from-timer.js delete mode 100644 test/simple/test-domain-http-server.js delete mode 100644 test/simple/test-domain-implicit-fs.js delete mode 100644 test/simple/test-domain-multi.js delete mode 100644 test/simple/test-domain-nested-throw.js delete mode 100644 test/simple/test-domain-nested.js delete mode 100644 test/simple/test-domain-safe-exit.js delete mode 100644 test/simple/test-domain-stack.js delete mode 100644 test/simple/test-domain-timers.js delete mode 100644 test/simple/test-domain-top-level-error-handler-clears-stack.js delete mode 100644 test/simple/test-domain-top-level-error-handler-throw.js delete mode 100644 test/simple/test-domain-with-abort-on-uncaught-exception.js delete mode 100644 test/simple/test-domain.js delete mode 100644 test/simple/test-error-reporting.js delete mode 100644 test/simple/test-eval-require.js delete mode 100644 test/simple/test-eval.js delete mode 100644 test/simple/test-event-emitter-add-listeners.js delete mode 100644 test/simple/test-event-emitter-check-listener-leaks.js delete mode 100644 test/simple/test-event-emitter-listeners-side-effects.js delete mode 100644 test/simple/test-event-emitter-listeners.js delete mode 100644 test/simple/test-event-emitter-max-listeners.js delete mode 100644 test/simple/test-event-emitter-memory-leak.js delete mode 100644 test/simple/test-event-emitter-method-names.js delete mode 100644 test/simple/test-event-emitter-modify-in-emit.js delete mode 100644 test/simple/test-event-emitter-no-error-provided-to-error-event.js delete mode 100644 test/simple/test-event-emitter-num-args.js delete mode 100644 test/simple/test-event-emitter-once.js delete mode 100644 test/simple/test-event-emitter-remove-all-listeners.js delete mode 100644 test/simple/test-event-emitter-remove-listeners.js delete mode 100644 test/simple/test-event-emitter-set-max-listeners-side-effects.js delete mode 100644 test/simple/test-event-emitter-subclass.js delete mode 100644 test/simple/test-exception-handler.js delete mode 100644 test/simple/test-exception-handler2.js delete mode 100644 test/simple/test-exec-max-buffer.js delete mode 100644 test/simple/test-executable-path.js delete mode 100644 test/simple/test-file-read-noexist.js delete mode 100644 test/simple/test-file-write-stream.js delete mode 100644 test/simple/test-file-write-stream2.js delete mode 100644 test/simple/test-file-write-stream3.js delete mode 100644 test/simple/test-force-repl.js delete mode 100644 test/simple/test-fs-append-file-sync.js delete mode 100644 test/simple/test-fs-append-file.js delete mode 100644 test/simple/test-fs-chmod.js delete mode 100644 test/simple/test-fs-empty-readStream.js delete mode 100644 test/simple/test-fs-error-messages.js delete mode 100644 test/simple/test-fs-exists.js delete mode 100644 test/simple/test-fs-fsync.js delete mode 100644 test/simple/test-fs-long-path.js delete mode 100644 test/simple/test-fs-mkdir.js delete mode 100644 test/simple/test-fs-non-number-arguments-throw.js delete mode 100644 test/simple/test-fs-null-bytes.js delete mode 100644 test/simple/test-fs-open-flags.js delete mode 100644 test/simple/test-fs-open.js delete mode 100644 test/simple/test-fs-read-buffer.js delete mode 100644 test/simple/test-fs-read-file-sync-hostname.js delete mode 100644 test/simple/test-fs-read-file-sync.js delete mode 100644 test/simple/test-fs-read-stream-err.js delete mode 100644 test/simple/test-fs-read-stream-fd.js delete mode 100644 test/simple/test-fs-read-stream-resume.js delete mode 100644 test/simple/test-fs-read-stream.js delete mode 100644 test/simple/test-fs-read.js delete mode 100644 test/simple/test-fs-readfile-empty.js delete mode 100644 test/simple/test-fs-readfile-error.js delete mode 100644 test/simple/test-fs-readfile-pipe.js delete mode 100644 test/simple/test-fs-readfile-unlink.js delete mode 100644 test/simple/test-fs-readfile-zero-byte-liar.js delete mode 100644 test/simple/test-fs-realpath.js delete mode 100644 test/simple/test-fs-sir-writes-alot.js delete mode 100644 test/simple/test-fs-stat.js delete mode 100644 test/simple/test-fs-stream-double-close.js delete mode 100644 test/simple/test-fs-symlink-dir-junction.js delete mode 100644 test/simple/test-fs-symlink.js delete mode 100644 test/simple/test-fs-sync-fd-leak.js delete mode 100644 test/simple/test-fs-truncate-GH-6233.js delete mode 100644 test/simple/test-fs-truncate.js delete mode 100644 test/simple/test-fs-utimes.js delete mode 100644 test/simple/test-fs-watch.js delete mode 100644 test/simple/test-fs-write-buffer.js delete mode 100644 test/simple/test-fs-write-file-buffer.js delete mode 100644 test/simple/test-fs-write-file-sync.js delete mode 100644 test/simple/test-fs-write-file.js delete mode 100644 test/simple/test-fs-write-stream-change-open.js delete mode 100644 test/simple/test-fs-write-stream-end.js delete mode 100644 test/simple/test-fs-write-stream-err.js delete mode 100644 test/simple/test-fs-write-stream.js delete mode 100644 test/simple/test-fs-write-sync.js delete mode 100644 test/simple/test-fs-write.js delete mode 100644 test/simple/test-global.js delete mode 100644 test/simple/test-http-1.0-keep-alive.js delete mode 100644 test/simple/test-http-1.0.js delete mode 100644 test/simple/test-http-304.js delete mode 100644 test/simple/test-http-abort-before-end.js delete mode 100644 test/simple/test-http-abort-client.js delete mode 100644 test/simple/test-http-abort-stream-end.js delete mode 100644 test/simple/test-http-after-connect.js delete mode 100644 test/simple/test-http-agent-destroyed-socket.js delete mode 100644 test/simple/test-http-agent-null.js delete mode 100644 test/simple/test-http-agent.js delete mode 100644 test/simple/test-http-allow-req-after-204-res.js delete mode 100644 test/simple/test-http-bind-twice.js delete mode 100644 test/simple/test-http-blank-header.js delete mode 100644 test/simple/test-http-buffer-sanity.js delete mode 100644 test/simple/test-http-byteswritten.js delete mode 100644 test/simple/test-http-chunked-304.js delete mode 100644 test/simple/test-http-chunked.js delete mode 100644 test/simple/test-http-client-abort.js delete mode 100644 test/simple/test-http-client-abort2.js delete mode 100644 test/simple/test-http-client-agent.js delete mode 100644 test/simple/test-http-client-get-url.js delete mode 100644 test/simple/test-http-client-parse-error.js delete mode 100644 test/simple/test-http-client-pipe-end.js delete mode 100644 test/simple/test-http-client-race-2.js delete mode 100644 test/simple/test-http-client-race.js delete mode 100644 test/simple/test-http-client-readable.js delete mode 100644 test/simple/test-http-client-response-domain.js delete mode 100644 test/simple/test-http-client-timeout-agent.js delete mode 100644 test/simple/test-http-client-timeout-event.js delete mode 100644 test/simple/test-http-client-timeout-with-data.js delete mode 100644 test/simple/test-http-client-timeout.js delete mode 100644 test/simple/test-http-client-upload-buf.js delete mode 100644 test/simple/test-http-client-upload.js delete mode 100644 test/simple/test-http-conn-reset.js delete mode 100644 test/simple/test-http-connect.js delete mode 100644 test/simple/test-http-contentLength0.js delete mode 100644 test/simple/test-http-createConnection.js delete mode 100644 test/simple/test-http-curl-chunk-problem.js delete mode 100644 test/simple/test-http-date-header.js delete mode 100644 test/simple/test-http-default-encoding.js delete mode 100644 test/simple/test-http-destroyed-socket-write.js delete mode 100644 test/simple/test-http-dns-error.js delete mode 100644 test/simple/test-http-end-throw-socket-handling.js delete mode 100644 test/simple/test-http-eof-on-connect.js delete mode 100644 test/simple/test-http-exceptions.js delete mode 100644 test/simple/test-http-exit-delay.js delete mode 100644 test/simple/test-http-expect-continue.js delete mode 100644 test/simple/test-http-extra-response.js delete mode 100644 test/simple/test-http-full-response.js delete mode 100644 test/simple/test-http-get-pipeline-problem.js delete mode 100644 test/simple/test-http-head-request.js delete mode 100644 test/simple/test-http-head-response-has-no-body-end.js delete mode 100644 test/simple/test-http-head-response-has-no-body.js delete mode 100644 test/simple/test-http-header-read.js delete mode 100644 test/simple/test-http-header-response-splitting.js delete mode 100644 test/simple/test-http-hex-write.js delete mode 100644 test/simple/test-http-host-headers.js delete mode 100644 test/simple/test-http-incoming-pipelined-socket-destroy.js delete mode 100644 test/simple/test-http-keep-alive-close-on-header.js delete mode 100644 test/simple/test-http-keep-alive.js delete mode 100644 test/simple/test-http-legacy.js delete mode 100644 test/simple/test-http-localaddress-bind-error.js delete mode 100644 test/simple/test-http-localaddress.js delete mode 100644 test/simple/test-http-malformed-request.js delete mode 100644 test/simple/test-http-many-ended-pipelines.js delete mode 100644 test/simple/test-http-many-keep-alive-connections.js delete mode 100644 test/simple/test-http-max-headers-count.js delete mode 100644 test/simple/test-http-multi-line-headers.js delete mode 100644 test/simple/test-http-mutable-headers.js delete mode 100644 test/simple/test-http-no-content-length.js delete mode 100644 test/simple/test-http-parser-bad-ref.js delete mode 100644 test/simple/test-http-parser-free.js delete mode 100644 test/simple/test-http-parser.js delete mode 100644 test/simple/test-http-pause-resume-one-end.js delete mode 100644 test/simple/test-http-pause.js delete mode 100644 test/simple/test-http-pipe-fs.js delete mode 100644 test/simple/test-http-pipeline-flood.js delete mode 100644 test/simple/test-http-proxy.js delete mode 100644 test/simple/test-http-request-end-twice.js delete mode 100644 test/simple/test-http-request-end.js delete mode 100644 test/simple/test-http-request-methods.js delete mode 100644 test/simple/test-http-res-write-end-dont-take-array.js delete mode 100644 test/simple/test-http-response-close.js delete mode 100644 test/simple/test-http-response-no-headers.js delete mode 100644 test/simple/test-http-response-readable.js delete mode 100644 test/simple/test-http-server-multiheaders.js delete mode 100644 test/simple/test-http-server-stale-close.js delete mode 100644 test/simple/test-http-server.js delete mode 100644 test/simple/test-http-set-cookies.js delete mode 100644 test/simple/test-http-set-timeout-server.js delete mode 100644 test/simple/test-http-set-timeout.js delete mode 100644 test/simple/test-http-set-trailers.js delete mode 100644 test/simple/test-http-should-keep-alive.js delete mode 100644 test/simple/test-http-status-code.js delete mode 100644 test/simple/test-http-timeout-overflow.js delete mode 100644 test/simple/test-http-timeout.js delete mode 100644 test/simple/test-http-unix-socket.js delete mode 100644 test/simple/test-http-upgrade-agent.js delete mode 100644 test/simple/test-http-upgrade-client.js delete mode 100644 test/simple/test-http-upgrade-client2.js delete mode 100644 test/simple/test-http-upgrade-server.js delete mode 100644 test/simple/test-http-upgrade-server2.js delete mode 100644 test/simple/test-http-url.parse-auth-with-header-in-request.js delete mode 100644 test/simple/test-http-url.parse-auth.js delete mode 100644 test/simple/test-http-url.parse-basic.js delete mode 100644 test/simple/test-http-url.parse-https.request.js delete mode 100644 test/simple/test-http-url.parse-only-support-http-https-protocol.js delete mode 100644 test/simple/test-http-url.parse-path.js delete mode 100644 test/simple/test-http-url.parse-post.js delete mode 100644 test/simple/test-http-url.parse-search.js delete mode 100644 test/simple/test-http-wget.js delete mode 100644 test/simple/test-http-write-empty-string.js delete mode 100644 test/simple/test-http-zero-length-write.js delete mode 100644 test/simple/test-http.js delete mode 100644 test/simple/test-https-agent.js delete mode 100644 test/simple/test-https-byteswritten.js delete mode 100644 test/simple/test-https-client-get-url.js delete mode 100644 test/simple/test-https-client-reject.js delete mode 100644 test/simple/test-https-client-resume.js delete mode 100644 test/simple/test-https-connecting-to-http.js delete mode 100644 test/simple/test-https-drain.js delete mode 100644 test/simple/test-https-eof-for-eom.js delete mode 100644 test/simple/test-https-foafssl.js delete mode 100644 test/simple/test-https-invalid-key.js delete mode 100644 test/simple/test-https-localaddress-bind-error.js delete mode 100644 test/simple/test-https-localaddress.js delete mode 100644 test/simple/test-https-no-reader.js delete mode 100644 test/simple/test-https-pfx.js delete mode 100644 test/simple/test-https-req-split.js delete mode 100644 test/simple/test-https-simple.js delete mode 100644 test/simple/test-https-socket-options.js delete mode 100644 test/simple/test-https-strict.js delete mode 100644 test/simple/test-https-timeout-server-2.js delete mode 100644 test/simple/test-https-timeout-server.js delete mode 100644 test/simple/test-https-timeout.js delete mode 100644 test/simple/test-init.js delete mode 100644 test/simple/test-listen-fd-cluster.js delete mode 100644 test/simple/test-listen-fd-detached-inherit.js delete mode 100644 test/simple/test-listen-fd-detached.js delete mode 100644 test/simple/test-listen-fd-ebadf.js delete mode 100644 test/simple/test-listen-fd-server.js delete mode 100644 test/simple/test-memory-usage-emfile.js delete mode 100644 test/simple/test-memory-usage.js delete mode 100644 test/simple/test-mkdir-rmdir.js delete mode 100644 test/simple/test-module-loading-error.js delete mode 100644 test/simple/test-module-loading.js delete mode 100644 test/simple/test-net-GH-5504.js delete mode 100644 test/simple/test-net-after-close.js delete mode 100644 test/simple/test-net-binary.js delete mode 100644 test/simple/test-net-bind-twice.js delete mode 100644 test/simple/test-net-buffersize.js delete mode 100644 test/simple/test-net-bytes-stats.js delete mode 100644 test/simple/test-net-can-reset-timeout.js delete mode 100644 test/simple/test-net-connect-buffer.js delete mode 100644 test/simple/test-net-connect-handle-econnrefused.js delete mode 100644 test/simple/test-net-connect-immediate-finish.js delete mode 100644 test/simple/test-net-connect-options.js delete mode 100644 test/simple/test-net-create-connection.js delete mode 100644 test/simple/test-net-dns-error.js delete mode 100644 test/simple/test-net-during-close.js delete mode 100644 test/simple/test-net-eaddrinuse.js delete mode 100644 test/simple/test-net-end-without-connect.js delete mode 100644 test/simple/test-net-error-twice.js delete mode 100644 test/simple/test-net-isip.js delete mode 100644 test/simple/test-net-keepalive.js delete mode 100644 test/simple/test-net-large-string.js delete mode 100644 test/simple/test-net-listen-error.js delete mode 100644 test/simple/test-net-listen-fd0.js delete mode 100644 test/simple/test-net-local-address-port.js delete mode 100644 test/simple/test-net-pause-resume-connecting.js delete mode 100644 test/simple/test-net-pingpong.js delete mode 100644 test/simple/test-net-pipe-connect-errors.js delete mode 100644 test/simple/test-net-reconnect.js delete mode 100644 test/simple/test-net-remote-address-port.js delete mode 100644 test/simple/test-net-server-address.js delete mode 100644 test/simple/test-net-server-bind.js delete mode 100644 test/simple/test-net-server-close.js delete mode 100644 test/simple/test-net-server-listen-remove-callback.js delete mode 100644 test/simple/test-net-server-max-connections.js delete mode 100644 test/simple/test-net-server-try-ports.js delete mode 100644 test/simple/test-net-server-unref.js delete mode 100644 test/simple/test-net-settimeout.js delete mode 100644 test/simple/test-net-socket-destroy-twice.js delete mode 100644 test/simple/test-net-socket-timeout-unref.js delete mode 100644 test/simple/test-net-socket-timeout.js delete mode 100644 test/simple/test-net-stream.js delete mode 100644 test/simple/test-net-write-after-close.js delete mode 100644 test/simple/test-net-write-connect-write.js delete mode 100644 test/simple/test-net-write-slow.js delete mode 100644 test/simple/test-next-tick-doesnt-hang.js delete mode 100644 test/simple/test-next-tick-domain.js delete mode 100644 test/simple/test-next-tick-error-spin.js delete mode 100644 test/simple/test-next-tick-errors.js delete mode 100644 test/simple/test-next-tick-intentional-starvation.js delete mode 100644 test/simple/test-next-tick-ordering.js delete mode 100644 test/simple/test-next-tick-ordering2.js delete mode 100644 test/simple/test-next-tick-starvation.js delete mode 100644 test/simple/test-next-tick.js delete mode 100644 test/simple/test-os.js delete mode 100644 test/simple/test-path-makelong.js delete mode 100644 test/simple/test-path.js delete mode 100644 test/simple/test-pipe-address.js delete mode 100644 test/simple/test-pipe-file-to-http.js delete mode 100644 test/simple/test-pipe-head.js delete mode 100644 test/simple/test-pipe-return-val.js delete mode 100644 test/simple/test-pipe-stream.js delete mode 100644 test/simple/test-pipe-unref.js delete mode 100644 test/simple/test-pipe.js delete mode 100644 test/simple/test-process-active-wraps.js delete mode 100644 test/simple/test-process-argv-0.js delete mode 100644 test/simple/test-process-config.js delete mode 100644 test/simple/test-process-env.js delete mode 100644 test/simple/test-process-exec-argv.js delete mode 100644 test/simple/test-process-exit-recursive.js delete mode 100644 test/simple/test-process-exit.js delete mode 100644 test/simple/test-process-getgroups.js delete mode 100644 test/simple/test-process-hrtime.js delete mode 100644 test/simple/test-process-kill-null.js delete mode 100644 test/simple/test-process-next-tick.js delete mode 100644 test/simple/test-process-wrap.js delete mode 100644 test/simple/test-pump-file2tcp-noexist.js delete mode 100644 test/simple/test-pump-file2tcp.js delete mode 100644 test/simple/test-punycode.js delete mode 100644 test/simple/test-querystring.js delete mode 100644 test/simple/test-readdir.js delete mode 100644 test/simple/test-readdouble.js delete mode 100644 test/simple/test-readfloat.js delete mode 100644 test/simple/test-readint.js delete mode 100644 test/simple/test-readline-interface.js delete mode 100644 test/simple/test-readline-set-raw-mode.js delete mode 100644 test/simple/test-readuint.js delete mode 100644 test/simple/test-regress-GH-1531.js delete mode 100644 test/simple/test-regress-GH-1697.js delete mode 100644 test/simple/test-regress-GH-1726.js delete mode 100644 test/simple/test-regress-GH-1899.js delete mode 100644 test/simple/test-regress-GH-3542.js delete mode 100644 test/simple/test-regress-GH-3739.js delete mode 100644 test/simple/test-regress-GH-4015.js delete mode 100644 test/simple/test-regress-GH-4027.js delete mode 100644 test/simple/test-regress-GH-4256.js delete mode 100644 test/simple/test-regress-GH-4948.js delete mode 100644 test/simple/test-regress-GH-5927.js delete mode 100644 test/simple/test-regress-GH-746.js delete mode 100644 test/simple/test-regress-GH-784.js delete mode 100644 test/simple/test-regress-GH-819.js delete mode 100644 test/simple/test-regress-GH-877.js delete mode 100644 test/simple/test-regress-GH-897.js delete mode 100644 test/simple/test-regression-object-prototype.js delete mode 100644 test/simple/test-repl-.save.load.js delete mode 100644 test/simple/test-repl-autolibs.js delete mode 100644 test/simple/test-repl-console.js delete mode 100644 test/simple/test-repl-domain.js delete mode 100644 test/simple/test-repl-end-emits-exit.js delete mode 100644 test/simple/test-repl-options.js delete mode 100644 test/simple/test-repl-require-cache.js delete mode 100644 test/simple/test-repl-tab-complete.js delete mode 100644 test/simple/test-repl.js delete mode 100644 test/simple/test-require-cache-without-stat.js delete mode 100644 test/simple/test-require-cache.js delete mode 100644 test/simple/test-require-exceptions.js delete mode 100644 test/simple/test-require-json.js delete mode 100644 test/simple/test-require-resolve.js delete mode 100644 test/simple/test-script-context.js delete mode 100644 test/simple/test-script-new.js delete mode 100644 test/simple/test-script-static-context.js delete mode 100644 test/simple/test-script-static-new.js delete mode 100644 test/simple/test-script-static-this.js delete mode 100644 test/simple/test-script-this.js delete mode 100644 test/simple/test-setproctitle.js delete mode 100644 test/simple/test-sigint-infinite-loop.js delete mode 100644 test/simple/test-signal-handler.js delete mode 100644 test/simple/test-signal-unregister.js delete mode 100644 test/simple/test-socket-write-after-fin-error.js delete mode 100644 test/simple/test-socket-write-after-fin.js delete mode 100644 test/simple/test-stdin-child-proc.js delete mode 100644 test/simple/test-stdin-from-file.js delete mode 100644 test/simple/test-stdin-hang.js delete mode 100644 test/simple/test-stdin-pause-resume-sync.js delete mode 100644 test/simple/test-stdin-pause-resume.js delete mode 100644 test/simple/test-stdin-pipe-resume.js delete mode 100644 test/simple/test-stdin-resume-pause.js delete mode 100644 test/simple/test-stdio-readable-writable.js delete mode 100644 test/simple/test-stdout-cannot-be-closed-child-process-pipe.js delete mode 100644 test/simple/test-stdout-close-catch.js delete mode 100644 test/simple/test-stdout-close-unref.js delete mode 100644 test/simple/test-stdout-stderr-reading.js delete mode 100644 test/simple/test-stdout-to-file.js delete mode 100644 test/simple/test-stream-big-packet.js delete mode 100644 test/simple/test-stream-big-push.js delete mode 100644 test/simple/test-stream-pipe-after-end.js delete mode 100644 test/simple/test-stream-pipe-cleanup.js delete mode 100644 test/simple/test-stream-pipe-error-handling.js delete mode 100644 test/simple/test-stream-pipe-event.js delete mode 100644 test/simple/test-stream-pipe-multi.js delete mode 100644 test/simple/test-stream-push-order.js delete mode 100644 test/simple/test-stream-push-strings.js delete mode 100644 test/simple/test-stream-readable-event.js delete mode 100644 test/simple/test-stream-readable-flow-recursion.js delete mode 100644 test/simple/test-stream-transform-objectmode-falsey-value.js delete mode 100644 test/simple/test-stream-unshift-empty-chunk.js delete mode 100644 test/simple/test-stream-unshift-read-race.js delete mode 100644 test/simple/test-stream-writable-decoded-encoding.js delete mode 100644 test/simple/test-stream2-base64-single-char-read-end.js delete mode 100644 test/simple/test-stream2-basic.js delete mode 100644 test/simple/test-stream2-compatibility.js delete mode 100644 test/simple/test-stream2-finish-pipe.js delete mode 100644 test/simple/test-stream2-fs.js delete mode 100644 test/simple/test-stream2-httpclient-response-end.js delete mode 100644 test/simple/test-stream2-large-read-stall.js delete mode 100644 test/simple/test-stream2-objects.js delete mode 100644 test/simple/test-stream2-pipe-error-handling.js delete mode 100755 test/simple/test-stream2-pipe-error-once-listener.js delete mode 100644 test/simple/test-stream2-push.js delete mode 100644 test/simple/test-stream2-read-sync-stack.js delete mode 100644 test/simple/test-stream2-readable-empty-buffer-no-eof.js delete mode 100644 test/simple/test-stream2-readable-from-list.js delete mode 100644 test/simple/test-stream2-readable-legacy-drain.js delete mode 100644 test/simple/test-stream2-readable-non-empty-end.js delete mode 100644 test/simple/test-stream2-readable-wrap-empty.js delete mode 100644 test/simple/test-stream2-readable-wrap.js delete mode 100644 test/simple/test-stream2-set-encoding.js delete mode 100644 test/simple/test-stream2-stderr-sync.js delete mode 100644 test/simple/test-stream2-transform.js delete mode 100644 test/simple/test-stream2-unpipe-drain.js delete mode 100644 test/simple/test-stream2-unpipe-leak.js delete mode 100644 test/simple/test-stream2-writable.js delete mode 100644 test/simple/test-string-decoder-end.js delete mode 100644 test/simple/test-string-decoder.js delete mode 100644 test/simple/test-sync-fileread.js delete mode 100644 test/simple/test-sys.js delete mode 100644 test/simple/test-tcp-wrap-connect.js delete mode 100644 test/simple/test-tcp-wrap-listen.js delete mode 100644 test/simple/test-tcp-wrap.js delete mode 100644 test/simple/test-timers-blocking-callback.js delete mode 100644 test/simple/test-timers-first-fire.js delete mode 100644 test/simple/test-timers-immediate.js delete mode 100644 test/simple/test-timers-linked-list.js delete mode 100644 test/simple/test-timers-non-integer-delay.js delete mode 100644 test/simple/test-timers-ordering.js delete mode 100644 test/simple/test-timers-socket-timeout-removes-other-socket-unref-timer.js delete mode 100644 test/simple/test-timers-this.js delete mode 100644 test/simple/test-timers-uncaught-exception.js delete mode 100644 test/simple/test-timers-unref-active.js delete mode 100644 test/simple/test-timers-unref-remove-other-unref-timers-only-one-fires.js delete mode 100644 test/simple/test-timers-unref-remove-other-unref-timers.js delete mode 100644 test/simple/test-timers-unref.js delete mode 100644 test/simple/test-timers-unrefd-interval-still-fires.js delete mode 100644 test/simple/test-timers-zero-timeout.js delete mode 100644 test/simple/test-timers.js delete mode 100644 test/simple/test-tls-check-server-identity.js delete mode 100644 test/simple/test-tls-client-abort.js delete mode 100644 test/simple/test-tls-client-abort2.js delete mode 100644 test/simple/test-tls-client-abort3.js delete mode 100644 test/simple/test-tls-client-destroy-soon.js delete mode 100644 test/simple/test-tls-client-reject.js delete mode 100644 test/simple/test-tls-client-resume.js delete mode 100644 test/simple/test-tls-client-verify.js delete mode 100644 test/simple/test-tls-close-notify.js delete mode 100644 test/simple/test-tls-connect-given-socket.js delete mode 100644 test/simple/test-tls-connect-pipe.js delete mode 100644 test/simple/test-tls-connect-simple.js delete mode 100644 test/simple/test-tls-connect.js delete mode 100644 test/simple/test-tls-fast-writing.js delete mode 100644 test/simple/test-tls-getcipher.js delete mode 100644 test/simple/test-tls-handshake-nohang.js delete mode 100644 test/simple/test-tls-hello-parser-failure.js delete mode 100644 test/simple/test-tls-honorcipherorder-secureOptions.js delete mode 100644 test/simple/test-tls-honorcipherorder.js delete mode 100644 test/simple/test-tls-interleave.js delete mode 100644 test/simple/test-tls-invalid-key.js delete mode 100644 test/simple/test-tls-junk-closes-server.js delete mode 100644 test/simple/test-tls-npn-server-client.js delete mode 100644 test/simple/test-tls-ondata.js delete mode 100644 test/simple/test-tls-over-http-tunnel.js delete mode 100644 test/simple/test-tls-passphrase.js delete mode 100644 test/simple/test-tls-pause-close.js delete mode 100644 test/simple/test-tls-pause.js delete mode 100644 test/simple/test-tls-peer-certificate-multi-keys.js delete mode 100644 test/simple/test-tls-peer-certificate.js delete mode 100644 test/simple/test-tls-remote.js delete mode 100644 test/simple/test-tls-request-timeout.js delete mode 100644 test/simple/test-tls-securepair-client.js delete mode 100644 test/simple/test-tls-securepair-server.js delete mode 100644 test/simple/test-tls-server-large-request.js delete mode 100644 test/simple/test-tls-server-missing-options.js delete mode 100644 test/simple/test-tls-server-slab.js delete mode 100644 test/simple/test-tls-server-verify.js delete mode 100644 test/simple/test-tls-session-cache.js delete mode 100644 test/simple/test-tls-set-ciphers.js delete mode 100644 test/simple/test-tls-set-encoding.js delete mode 100644 test/simple/test-tls-sni-server-client.js delete mode 100644 test/simple/test-tls-timeout-server-2.js delete mode 100644 test/simple/test-tls-timeout-server.js delete mode 100644 test/simple/test-tls-zero-clear-in.js delete mode 100644 test/simple/test-tty-stdout-end.js delete mode 100644 test/simple/test-tty-wrap.js delete mode 100644 test/simple/test-typed-arrays.js delete mode 100644 test/simple/test-umask.js delete mode 100644 test/simple/test-url.js delete mode 100644 test/simple/test-utf8-scripts.js delete mode 100644 test/simple/test-util-format.js delete mode 100644 test/simple/test-util-inspect.js delete mode 100644 test/simple/test-util.js delete mode 100644 test/simple/test-vm-create-context-accessors.js delete mode 100644 test/simple/test-vm-create-context-arg.js delete mode 100644 test/simple/test-vm-create-context-circular-reference.js delete mode 100644 test/simple/test-writedouble.js delete mode 100644 test/simple/test-writefloat.js delete mode 100644 test/simple/test-writeint.js delete mode 100644 test/simple/test-writeuint.js delete mode 100644 test/simple/test-zerolengthbufferbug.js delete mode 100644 test/simple/test-zlib-close-after-write.js delete mode 100644 test/simple/test-zlib-dictionary-fail.js delete mode 100644 test/simple/test-zlib-dictionary.js delete mode 100644 test/simple/test-zlib-from-gzip.js delete mode 100644 test/simple/test-zlib-from-string.js delete mode 100644 test/simple/test-zlib-invalid-input.js delete mode 100644 test/simple/test-zlib-random-byte-pipes.js delete mode 100644 test/simple/test-zlib-write-after-close.js delete mode 100644 test/simple/test-zlib-write-after-flush.js delete mode 100644 test/simple/test-zlib-zero-byte.js delete mode 100644 test/simple/test-zlib.js diff --git a/test/simple/test-assert.js b/test/simple/test-assert.js deleted file mode 100644 index 6b8350095dbb..000000000000 --- a/test/simple/test-assert.js +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var a = require('assert'); - -function makeBlock(f) { - var args = Array.prototype.slice.call(arguments, 1); - return function() { - return f.apply(this, args); - }; -} - -assert.ok(common.indirectInstanceOf(a.AssertionError.prototype, Error), - 'a.AssertionError instanceof Error'); - -assert.throws(makeBlock(a, false), a.AssertionError, 'ok(false)'); - -assert.doesNotThrow(makeBlock(a, true), a.AssertionError, 'ok(true)'); - -assert.doesNotThrow(makeBlock(a, 'test', 'ok(\'test\')')); - -assert.throws(makeBlock(a.ok, false), - a.AssertionError, 'ok(false)'); - -assert.doesNotThrow(makeBlock(a.ok, true), - a.AssertionError, 'ok(true)'); - -assert.doesNotThrow(makeBlock(a.ok, 'test'), 'ok(\'test\')'); - -assert.throws(makeBlock(a.equal, true, false), a.AssertionError, 'equal'); - -assert.doesNotThrow(makeBlock(a.equal, null, null), 'equal'); - -assert.doesNotThrow(makeBlock(a.equal, undefined, undefined), 'equal'); - -assert.doesNotThrow(makeBlock(a.equal, null, undefined), 'equal'); - -assert.doesNotThrow(makeBlock(a.equal, true, true), 'equal'); - -assert.doesNotThrow(makeBlock(a.equal, 2, '2'), 'equal'); - -assert.doesNotThrow(makeBlock(a.notEqual, true, false), 'notEqual'); - -assert.throws(makeBlock(a.notEqual, true, true), - a.AssertionError, 'notEqual'); - -assert.throws(makeBlock(a.strictEqual, 2, '2'), - a.AssertionError, 'strictEqual'); - -assert.throws(makeBlock(a.strictEqual, null, undefined), - a.AssertionError, 'strictEqual'); - -assert.doesNotThrow(makeBlock(a.notStrictEqual, 2, '2'), 'notStrictEqual'); - -// deepEquals joy! -// 7.2 -assert.doesNotThrow(makeBlock(a.deepEqual, new Date(2000, 3, 14), - new Date(2000, 3, 14)), 'deepEqual date'); - -assert.throws(makeBlock(a.deepEqual, new Date(), new Date(2000, 3, 14)), - a.AssertionError, - 'deepEqual date'); - -// 7.3 -assert.doesNotThrow(makeBlock(a.deepEqual, /a/, /a/)); -assert.doesNotThrow(makeBlock(a.deepEqual, /a/g, /a/g)); -assert.doesNotThrow(makeBlock(a.deepEqual, /a/i, /a/i)); -assert.doesNotThrow(makeBlock(a.deepEqual, /a/m, /a/m)); -assert.doesNotThrow(makeBlock(a.deepEqual, /a/igm, /a/igm)); -assert.throws(makeBlock(a.deepEqual, /ab/, /a/)); -assert.throws(makeBlock(a.deepEqual, /a/g, /a/)); -assert.throws(makeBlock(a.deepEqual, /a/i, /a/)); -assert.throws(makeBlock(a.deepEqual, /a/m, /a/)); -assert.throws(makeBlock(a.deepEqual, /a/igm, /a/im)); - -var re1 = /a/; -re1.lastIndex = 3; -assert.throws(makeBlock(a.deepEqual, re1, /a/)); - - -// 7.4 -assert.doesNotThrow(makeBlock(a.deepEqual, 4, '4'), 'deepEqual == check'); -assert.doesNotThrow(makeBlock(a.deepEqual, true, 1), 'deepEqual == check'); -assert.throws(makeBlock(a.deepEqual, 4, '5'), - a.AssertionError, - 'deepEqual == check'); - -// 7.5 -// having the same number of owned properties && the same set of keys -assert.doesNotThrow(makeBlock(a.deepEqual, {a: 4}, {a: 4})); -assert.doesNotThrow(makeBlock(a.deepEqual, {a: 4, b: '2'}, {a: 4, b: '2'})); -assert.doesNotThrow(makeBlock(a.deepEqual, [4], ['4'])); -assert.throws(makeBlock(a.deepEqual, {a: 4}, {a: 4, b: true}), - a.AssertionError); -assert.doesNotThrow(makeBlock(a.deepEqual, ['a'], {0: 'a'})); -//(although not necessarily the same order), -assert.doesNotThrow(makeBlock(a.deepEqual, {a: 4, b: '1'}, {b: '1', a: 4})); -var a1 = [1, 2, 3]; -var a2 = [1, 2, 3]; -a1.a = 'test'; -a1.b = true; -a2.b = true; -a2.a = 'test'; -assert.throws(makeBlock(a.deepEqual, Object.keys(a1), Object.keys(a2)), - a.AssertionError); -assert.doesNotThrow(makeBlock(a.deepEqual, a1, a2)); - -// having an identical prototype property -var nbRoot = { - toString: function() { return this.first + ' ' + this.last; } -}; - -function nameBuilder(first, last) { - this.first = first; - this.last = last; - return this; -} -nameBuilder.prototype = nbRoot; - -function nameBuilder2(first, last) { - this.first = first; - this.last = last; - return this; -} -nameBuilder2.prototype = nbRoot; - -var nb1 = new nameBuilder('Ryan', 'Dahl'); -var nb2 = new nameBuilder2('Ryan', 'Dahl'); - -assert.doesNotThrow(makeBlock(a.deepEqual, nb1, nb2)); - -nameBuilder2.prototype = Object; -nb2 = new nameBuilder2('Ryan', 'Dahl'); -assert.throws(makeBlock(a.deepEqual, nb1, nb2), a.AssertionError); - -// String literal + object blew up my implementation... -assert.throws(makeBlock(a.deepEqual, 'a', {}), a.AssertionError); - -// Testing the throwing -function thrower(errorConstructor) { - throw new errorConstructor('test'); -} -var aethrow = makeBlock(thrower, a.AssertionError); -aethrow = makeBlock(thrower, a.AssertionError); - -// the basic calls work -assert.throws(makeBlock(thrower, a.AssertionError), - a.AssertionError, 'message'); -assert.throws(makeBlock(thrower, a.AssertionError), a.AssertionError); -assert.throws(makeBlock(thrower, a.AssertionError)); - -// if not passing an error, catch all. -assert.throws(makeBlock(thrower, TypeError)); - -// when passing a type, only catch errors of the appropriate type -var threw = false; -try { - a.throws(makeBlock(thrower, TypeError), a.AssertionError); -} catch (e) { - threw = true; - assert.ok(e instanceof TypeError, 'type'); -} -assert.equal(true, threw, - 'a.throws with an explicit error is eating extra errors', - a.AssertionError); -threw = false; - -// doesNotThrow should pass through all errors -try { - a.doesNotThrow(makeBlock(thrower, TypeError), a.AssertionError); -} catch (e) { - threw = true; - assert.ok(e instanceof TypeError); -} -assert.equal(true, threw, - 'a.doesNotThrow with an explicit error is eating extra errors'); - -// key difference is that throwing our correct error makes an assertion error -try { - a.doesNotThrow(makeBlock(thrower, TypeError), TypeError); -} catch (e) { - threw = true; - assert.ok(e instanceof a.AssertionError); -} -assert.equal(true, threw, - 'a.doesNotThrow is not catching type matching errors'); - -assert.throws(function() {assert.ifError(new Error('test error'))}); -assert.doesNotThrow(function() {assert.ifError(null)}); -assert.doesNotThrow(function() {assert.ifError()}); - -// make sure that validating using constructor really works -threw = false; -try { - assert.throws( - function() { - throw ({}); - }, - Array - ); -} catch (e) { - threw = true; -} -assert.ok(threw, 'wrong constructor validation'); - -// use a RegExp to validate error message -a.throws(makeBlock(thrower, TypeError), /test/); - -// use a fn to validate error object -a.throws(makeBlock(thrower, TypeError), function(err) { - if ((err instanceof TypeError) && /test/.test(err)) { - return true; - } -}); - - -// GH-207. Make sure deepEqual doesn't loop forever on circular refs - -var b = {}; -b.b = b; - -var c = {}; -c.b = c; - -var gotError = false; -try { - assert.deepEqual(b, c); -} catch (e) { - gotError = true; -} - -// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects. -var args = (function() { return arguments; })(); -a.throws(makeBlock(a.deepEqual, [], args)); -a.throws(makeBlock(a.deepEqual, args, [])); - -console.log('All OK'); -assert.ok(gotError); - - -// #217 -function testAssertionMessage(actual, expected) { - try { - assert.equal(actual, ''); - } catch (e) { - assert.equal(e.toString(), - ['AssertionError:', expected, '==', '""'].join(' ')); - } -} -testAssertionMessage(undefined, '"undefined"'); -testAssertionMessage(null, 'null'); -testAssertionMessage(true, 'true'); -testAssertionMessage(false, 'false'); -testAssertionMessage(0, '0'); -testAssertionMessage(100, '100'); -testAssertionMessage(NaN, '"NaN"'); -testAssertionMessage(Infinity, '"Infinity"'); -testAssertionMessage(-Infinity, '"-Infinity"'); -testAssertionMessage('', '""'); -testAssertionMessage('foo', '"foo"'); -testAssertionMessage([], '[]'); -testAssertionMessage([1, 2, 3], '[1,2,3]'); -testAssertionMessage(/a/, '"/a/"'); -testAssertionMessage(/abc/gim, '"/abc/gim"'); -testAssertionMessage(function f() {}, '"function f() {}"'); -testAssertionMessage({}, '{}'); -testAssertionMessage({a: undefined, b: null}, '{"a":"undefined","b":null}'); -testAssertionMessage({a: NaN, b: Infinity, c: -Infinity}, - '{"a":"NaN","b":"Infinity","c":"-Infinity"}'); - -// #2893 -try { - assert.throws(function () { - assert.ifError(null); - }); -} catch (e) { - threw = true; - assert.equal(e.message, 'Missing expected exception..'); -} -assert.ok(threw); - -// #5292 -try { - assert.equal(1, 2); -} catch (e) { - assert.equal(e.toString().split('\n')[0], 'AssertionError: 1 == 2') -} - -try { - assert.equal(1, 2, 'oh no'); -} catch (e) { - assert.equal(e.toString().split('\n')[0], 'AssertionError: oh no') -} diff --git a/test/simple/test-bad-unicode.js b/test/simple/test-bad-unicode.js deleted file mode 100644 index 0e57909a60f6..000000000000 --- a/test/simple/test-bad-unicode.js +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'), - exception = null; - -try { - eval('"\\uc/ef"'); -} catch (e) { - exception = e; -} - -assert(exception instanceof SyntaxError); diff --git a/test/simple/test-buffer-ascii.js b/test/simple/test-buffer-ascii.js deleted file mode 100644 index 784597a48e40..000000000000 --- a/test/simple/test-buffer-ascii.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// ASCII conversion in node.js simply masks off the high bits, -// it doesn't do transliteration. -assert.equal(Buffer('hérité').toString('ascii'), 'hC)ritC)'); - -// 71 characters, 78 bytes. The ’ character is a triple-byte sequence. -var input = 'C’est, graphiquement, la réunion d’un accent aigu ' + - 'et d’un accent grave.'; - -var expected = 'Cb\u0000\u0019est, graphiquement, la rC)union ' + - 'db\u0000\u0019un accent aigu et db\u0000\u0019un ' + - 'accent grave.'; - -var buf = Buffer(input); - -for (var i = 0; i < expected.length; ++i) { - assert.equal(buf.slice(i).toString('ascii'), expected.slice(i)); - - // Skip remainder of multi-byte sequence. - if (input.charCodeAt(i) > 65535) ++i; - if (input.charCodeAt(i) > 127) ++i; -} diff --git a/test/simple/test-buffer-concat.js b/test/simple/test-buffer-concat.js deleted file mode 100644 index 858d6924f95f..000000000000 --- a/test/simple/test-buffer-concat.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var zero = []; -var one = [ new Buffer('asdf') ]; -var long = []; -for (var i = 0; i < 10; i++) long.push(new Buffer('asdf')); - -var flatZero = Buffer.concat(zero); -var flatOne = Buffer.concat(one); -var flatLong = Buffer.concat(long); -var flatLongLen = Buffer.concat(long, 40); - -assert(flatZero.length === 0); -assert(flatOne.toString() === 'asdf'); -assert(flatOne === one[0]); -assert(flatLong.toString() === (new Array(10+1).join('asdf'))); -assert(flatLongLen.toString() === (new Array(10+1).join('asdf'))); - -console.log("ok"); diff --git a/test/simple/test-buffer-regress-GH-2659.js b/test/simple/test-buffer-regress-GH-2659.js deleted file mode 100644 index 19a1362fd77a..000000000000 --- a/test/simple/test-buffer-regress-GH-2659.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// This is not a great test. It depends on a Node internal, namely the slab -// size. Maybe we should expose that in some way. Then again, maybe not... -for (var n = 1; n <= 8192; ++n) { - Buffer(n); - Buffer(0).write('', 'base64'); -} diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js deleted file mode 100644 index 8ba024157aee..000000000000 --- a/test/simple/test-buffer.js +++ /dev/null @@ -1,1035 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var SlowBuffer = require('buffer').SlowBuffer; -var Buffer = require('buffer').Buffer; - -// counter to ensure unique value is always copied -var cntr = 0; - -// Regression test for segfault introduced in commit e501ce4. -['base64','binary','ucs2','utf8','ascii'].forEach(function(encoding) { - var buf = new SlowBuffer(0); - buf.write('', encoding); -}); - -var b = Buffer(1024); // safe constructor - -console.log('b.length == %d', b.length); -assert.strictEqual(1024, b.length); - -b[0] = -1; -assert.strictEqual(b[0], 255); - -for (var i = 0; i < 1024; i++) { - b[i] = i % 256; -} - -for (var i = 0; i < 1024; i++) { - assert.strictEqual(i % 256, b[i]); -} - -var c = new Buffer(512); -console.log('c.length == %d', c.length); -assert.strictEqual(512, c.length); - -// copy 512 bytes, from 0 to 512. -b.fill(++cntr); -c.fill(++cntr); -var copied = b.copy(c, 0, 0, 512); -console.log('copied %d bytes from b into c', copied); -assert.strictEqual(512, copied); -for (var i = 0; i < c.length; i++) { - assert.strictEqual(b[i], c[i]); -} - -// copy c into b, without specifying sourceEnd -b.fill(++cntr); -c.fill(++cntr); -var copied = c.copy(b, 0, 0); -console.log('copied %d bytes from c into b w/o sourceEnd', copied); -assert.strictEqual(c.length, copied); -for (var i = 0; i < c.length; i++) { - assert.strictEqual(c[i], b[i]); -} - -// copy c into b, without specifying sourceStart -b.fill(++cntr); -c.fill(++cntr); -var copied = c.copy(b, 0); -console.log('copied %d bytes from c into b w/o sourceStart', copied); -assert.strictEqual(c.length, copied); -for (var i = 0; i < c.length; i++) { - assert.strictEqual(c[i], b[i]); -} - -// copy longer buffer b to shorter c without targetStart -b.fill(++cntr); -c.fill(++cntr); -var copied = b.copy(c); -console.log('copied %d bytes from b into c w/o targetStart', copied); -assert.strictEqual(c.length, copied); -for (var i = 0; i < c.length; i++) { - assert.strictEqual(b[i], c[i]); -} - -// copy starting near end of b to c -b.fill(++cntr); -c.fill(++cntr); -var copied = b.copy(c, 0, b.length - Math.floor(c.length / 2)); -console.log('copied %d bytes from end of b into beginning of c', copied); -assert.strictEqual(Math.floor(c.length / 2), copied); -for (var i = 0; i < Math.floor(c.length / 2); i++) { - assert.strictEqual(b[b.length - Math.floor(c.length / 2) + i], c[i]); -} -for (var i = Math.floor(c.length /2) + 1; i < c.length; i++) { - assert.strictEqual(c[c.length-1], c[i]); -} - -// try to copy 513 bytes, and check we don't overrun c -b.fill(++cntr); -c.fill(++cntr); -var copied = b.copy(c, 0, 0, 513); -console.log('copied %d bytes from b trying to overrun c', copied); -assert.strictEqual(c.length, copied); -for (var i = 0; i < c.length; i++) { - assert.strictEqual(b[i], c[i]); -} - -// copy 768 bytes from b into b -b.fill(++cntr); -b.fill(++cntr, 256); -var copied = b.copy(b, 0, 256, 1024); -console.log('copied %d bytes from b into b', copied); -assert.strictEqual(768, copied); -for (var i = 0; i < b.length; i++) { - assert.strictEqual(cntr, b[i]); -} - - -// copy from fast to slow buffer -var sb = new SlowBuffer(b.length); -var copied = b.copy(sb); -console.log('copied %d bytes from b into sb'); -for (var i = 0; i < sb.length; i++) { - assert.strictEqual(sb[i], b[i]); -} - -var caught_error = null; - -// try to copy from before the beginning of b -caught_error = null; -try { - var copied = b.copy(c, 0, 100, 10); -} catch (err) { - caught_error = err; -} - -// copy from b to c with negative sourceStart -b.fill(++cntr); -c.fill(++cntr); -var copied = b.copy(c, 0, -1); -assert.strictEqual(c.length, copied); -console.log('copied %d bytes from b into c w/ negative sourceStart', copied); -for (var i = 0; i < c.length; i++) { - assert.strictEqual(b[i], c[i]); -} - -// check sourceEnd resets to targetEnd if former is greater than the latter -b.fill(++cntr); -c.fill(++cntr); -var copied = b.copy(c, 0, 0, 1025); -console.log('copied %d bytes from b into c', copied); -for (var i = 0; i < c.length; i++) { - assert.strictEqual(b[i], c[i]); -} - -// copy from fast buffer to slow buffer without parameters -var sb = new SlowBuffer(b.length); -sb.fill(++cntr, 0, sb.length); -b.fill(++cntr); -var copied = b.copy(sb); -console.log('copied %d bytes from fast buffer to slow buffer', copied); -for (var i = 0 ; i < b.length; i++) { - assert.strictEqual(b[i], sb[i]); -} - -// throw with negative sourceEnd -console.log('test copy at negative sourceEnd'); -assert.throws(function() { - b.copy(c, 0, 0, -1); -}, RangeError); - -// throw when sourceStart is greater than sourceEnd -assert.throws(function() { - b.copy(c, 0, 100, 10); -}, RangeError); - -// throw attempting to copy after end of c -assert.throws(function() { - b.copy(c, 512, 0, 10); -}, RangeError); - -var caught_error; - -// invalid encoding for Buffer.toString -caught_error = null; -try { - var copied = b.toString('invalid'); -} catch (err) { - caught_error = err; -} -assert.strictEqual('Unknown encoding: invalid', caught_error.message); - -// invalid encoding for Buffer.write -caught_error = null; -try { - var copied = b.write('test string', 0, 5, 'invalid'); -} catch (err) { - caught_error = err; -} -assert.strictEqual('Unknown encoding: invalid', caught_error.message); - -// try to create 0-length buffers -new Buffer(''); -new Buffer('', 'ascii'); -new Buffer('', 'binary'); -new Buffer(0); - -// try to write a 0-length string beyond the end of b -b.write('', 1024); -b.write('', 2048); - -// throw when writing past bounds from the pool -assert.throws(function() { - b.write('a', 2048); -}, RangeError); - -// throw when writing to negative offset -assert.throws(function() { - b.write('a', -1); -}, RangeError); - -// try to copy 0 bytes worth of data into an empty buffer -b.copy(new Buffer(0), 0, 0, 0); - -// try to copy 0 bytes past the end of the target buffer -b.copy(new Buffer(0), 1, 1, 1); -b.copy(new Buffer(1), 1, 1, 1); - -// try to copy 0 bytes from past the end of the source buffer -b.copy(new Buffer(1), 0, 2048, 2048); - -// try to toString() a 0-length slice of a buffer, both within and without the -// valid buffer range -assert.equal(new Buffer('abc').toString('ascii', 0, 0), ''); -assert.equal(new Buffer('abc').toString('ascii', -100, -100), ''); -assert.equal(new Buffer('abc').toString('ascii', 100, 100), ''); - -// try toString() with a object as a encoding -assert.equal(new Buffer('abc').toString({toString: function() { - return 'ascii'; -}}), 'abc'); - -// testing for smart defaults and ability to pass string values as offset -var writeTest = new Buffer('abcdes'); -writeTest.write('n', 'ascii'); -writeTest.write('o', 'ascii', '1'); -writeTest.write('d', '2', 'ascii'); -writeTest.write('e', 3, 'ascii'); -writeTest.write('j', 'ascii', 4); -assert.equal(writeTest.toString(), 'nodejs'); - -var asciiString = 'hello world'; -var offset = 100; -for (var j = 0; j < 500; j++) { - - for (var i = 0; i < asciiString.length; i++) { - b[i] = asciiString.charCodeAt(i); - } - var asciiSlice = b.toString('ascii', 0, asciiString.length); - assert.equal(asciiString, asciiSlice); - - var written = b.write(asciiString, offset, 'ascii'); - assert.equal(asciiString.length, written); - var asciiSlice = b.toString('ascii', offset, offset + asciiString.length); - assert.equal(asciiString, asciiSlice); - - var sliceA = b.slice(offset, offset + asciiString.length); - var sliceB = b.slice(offset, offset + asciiString.length); - for (var i = 0; i < asciiString.length; i++) { - assert.equal(sliceA[i], sliceB[i]); - } - - // TODO utf8 slice tests -} - - -for (var j = 0; j < 100; j++) { - var slice = b.slice(100, 150); - assert.equal(50, slice.length); - for (var i = 0; i < 50; i++) { - assert.equal(b[100 + i], slice[i]); - } -} - - - -// Bug regression test -var testValue = '\u00F6\u65E5\u672C\u8A9E'; // ö日本語 -var buffer = new Buffer(32); -var size = buffer.write(testValue, 0, 'utf8'); -console.log('bytes written to buffer: ' + size); -var slice = buffer.toString('utf8', 0, size); -assert.equal(slice, testValue); - - -// Test triple slice -var a = new Buffer(8); -for (var i = 0; i < 8; i++) a[i] = i; -var b = a.slice(4, 8); -assert.equal(4, b[0]); -assert.equal(5, b[1]); -assert.equal(6, b[2]); -assert.equal(7, b[3]); -var c = b.slice(2, 4); -assert.equal(6, c[0]); -assert.equal(7, c[1]); - - -var d = new Buffer([23, 42, 255]); -assert.equal(d.length, 3); -assert.equal(d[0], 23); -assert.equal(d[1], 42); -assert.equal(d[2], 255); -assert.deepEqual(d, new Buffer(d)); - -var e = new Buffer('über'); -console.error('uber: \'%s\'', e.toString()); -assert.deepEqual(e, new Buffer([195, 188, 98, 101, 114])); - -var f = new Buffer('über', 'ascii'); -console.error('f.length: %d (should be 4)', f.length); -assert.deepEqual(f, new Buffer([252, 98, 101, 114])); - -['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) { - var f = new Buffer('über', encoding); - console.error('f.length: %d (should be 8)', f.length); - assert.deepEqual(f, new Buffer([252, 0, 98, 0, 101, 0, 114, 0])); - - var f = new Buffer('привет', encoding); - console.error('f.length: %d (should be 12)', f.length); - assert.deepEqual(f, new Buffer([63, 4, 64, 4, 56, 4, 50, 4, 53, 4, 66, 4])); - assert.equal(f.toString(encoding), 'привет'); - - var f = new Buffer([0, 0, 0, 0, 0]); - assert.equal(f.length, 5); - var size = f.write('あいうえお', encoding); - var charsWritten = Buffer._charsWritten; // Copy value out. - console.error('bytes written to buffer: %d (should be 4)', size); - console.error('chars written to buffer: %d (should be 2)', charsWritten); - assert.equal(size, 4); - assert.equal(charsWritten, 2); - assert.deepEqual(f, new Buffer([0x42, 0x30, 0x44, 0x30, 0x00])); -}); - -var f = new Buffer('\uD83D\uDC4D', 'utf-16le'); // THUMBS UP SIGN (U+1F44D) -assert.equal(f.length, 4); -assert.deepEqual(f, new Buffer('3DD84DDC', 'hex')); - - -var arrayIsh = {0: 0, 1: 1, 2: 2, 3: 3, length: 4}; -var g = new Buffer(arrayIsh); -assert.deepEqual(g, new Buffer([0, 1, 2, 3])); -var strArrayIsh = {0: '0', 1: '1', 2: '2', 3: '3', length: 4}; -g = new Buffer(strArrayIsh); -assert.deepEqual(g, new Buffer([0, 1, 2, 3])); - - -// -// Test toString('base64') -// -assert.equal('TWFu', (new Buffer('Man')).toString('base64')); - -// test that regular and URL-safe base64 both work -var expected = [0xff, 0xff, 0xbe, 0xff, 0xef, 0xbf, 0xfb, 0xef, 0xff]; -assert.deepEqual(Buffer('//++/++/++//', 'base64'), Buffer(expected)); -assert.deepEqual(Buffer('__--_--_--__', 'base64'), Buffer(expected)); - -// big example -var quote = 'Man is distinguished, not only by his reason, but by this ' + - 'singular passion from other animals, which is a lust ' + - 'of the mind, that by a perseverance of delight in the continued ' + - 'and indefatigable generation of knowledge, exceeds the short ' + - 'vehemence of any carnal pleasure.'; -var expected = 'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24s' + - 'IGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltY' + - 'WxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZX' + - 'JzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmR' + - 'lZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo' + - 'ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4='; -assert.equal(expected, (new Buffer(quote)).toString('base64')); - - -b = new Buffer(1024); -var bytesWritten = b.write(expected, 0, 'base64'); -assert.equal(quote.length, bytesWritten); -assert.equal(quote, b.toString('ascii', 0, quote.length)); - -// check that the base64 decoder ignores whitespace -var expectedWhite = expected.slice(0, 60) + ' \n' + - expected.slice(60, 120) + ' \n' + - expected.slice(120, 180) + ' \n' + - expected.slice(180, 240) + ' \n' + - expected.slice(240, 300) + '\n' + - expected.slice(300, 360) + '\n'; -b = new Buffer(1024); -bytesWritten = b.write(expectedWhite, 0, 'base64'); -assert.equal(quote.length, bytesWritten); -assert.equal(quote, b.toString('ascii', 0, quote.length)); - -// check that the base64 decoder on the constructor works -// even in the presence of whitespace. -b = new Buffer(expectedWhite, 'base64'); -assert.equal(quote.length, b.length); -assert.equal(quote, b.toString('ascii', 0, quote.length)); - -// check that the base64 decoder ignores illegal chars -var expectedIllegal = expected.slice(0, 60) + ' \x80' + - expected.slice(60, 120) + ' \xff' + - expected.slice(120, 180) + ' \x00' + - expected.slice(180, 240) + ' \x98' + - expected.slice(240, 300) + '\x03' + - expected.slice(300, 360); -b = new Buffer(expectedIllegal, 'base64'); -assert.equal(quote.length, b.length); -assert.equal(quote, b.toString('ascii', 0, quote.length)); - - -assert.equal(new Buffer('', 'base64').toString(), ''); -assert.equal(new Buffer('K', 'base64').toString(), ''); - -// multiple-of-4 with padding -assert.equal(new Buffer('Kg==', 'base64').toString(), '*'); -assert.equal(new Buffer('Kio=', 'base64').toString(), '**'); -assert.equal(new Buffer('Kioq', 'base64').toString(), '***'); -assert.equal(new Buffer('KioqKg==', 'base64').toString(), '****'); -assert.equal(new Buffer('KioqKio=', 'base64').toString(), '*****'); -assert.equal(new Buffer('KioqKioq', 'base64').toString(), '******'); -assert.equal(new Buffer('KioqKioqKg==', 'base64').toString(), '*******'); -assert.equal(new Buffer('KioqKioqKio=', 'base64').toString(), '********'); -assert.equal(new Buffer('KioqKioqKioq', 'base64').toString(), '*********'); -assert.equal(new Buffer('KioqKioqKioqKg==', 'base64').toString(), - '**********'); -assert.equal(new Buffer('KioqKioqKioqKio=', 'base64').toString(), - '***********'); -assert.equal(new Buffer('KioqKioqKioqKioq', 'base64').toString(), - '************'); -assert.equal(new Buffer('KioqKioqKioqKioqKg==', 'base64').toString(), - '*************'); -assert.equal(new Buffer('KioqKioqKioqKioqKio=', 'base64').toString(), - '**************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioq', 'base64').toString(), - '***************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKg==', 'base64').toString(), - '****************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKio=', 'base64').toString(), - '*****************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKioq', 'base64').toString(), - '******************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKg==', 'base64').toString(), - '*******************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKio=', 'base64').toString(), - '********************'); - -// no padding, not a multiple of 4 -assert.equal(new Buffer('Kg', 'base64').toString(), '*'); -assert.equal(new Buffer('Kio', 'base64').toString(), '**'); -assert.equal(new Buffer('KioqKg', 'base64').toString(), '****'); -assert.equal(new Buffer('KioqKio', 'base64').toString(), '*****'); -assert.equal(new Buffer('KioqKioqKg', 'base64').toString(), '*******'); -assert.equal(new Buffer('KioqKioqKio', 'base64').toString(), '********'); -assert.equal(new Buffer('KioqKioqKioqKg', 'base64').toString(), '**********'); -assert.equal(new Buffer('KioqKioqKioqKio', 'base64').toString(), '***********'); -assert.equal(new Buffer('KioqKioqKioqKioqKg', 'base64').toString(), - '*************'); -assert.equal(new Buffer('KioqKioqKioqKioqKio', 'base64').toString(), - '**************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKg', 'base64').toString(), - '****************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKio', 'base64').toString(), - '*****************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKg', 'base64').toString(), - '*******************'); -assert.equal(new Buffer('KioqKioqKioqKioqKioqKioqKio', 'base64').toString(), - '********************'); - -// handle padding graciously, multiple-of-4 or not -assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw==', - 'base64').length, 32); -assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw=', - 'base64').length, 32); -assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw', - 'base64').length, 32); -assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg==', - 'base64').length, 31); -assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg=', - 'base64').length, 31); -assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg', - 'base64').length, 31); - -// This string encodes single '.' character in UTF-16 -var dot = new Buffer('//4uAA==', 'base64'); -assert.equal(dot[0], 0xff); -assert.equal(dot[1], 0xfe); -assert.equal(dot[2], 0x2e); -assert.equal(dot[3], 0x00); -assert.equal(dot.toString('base64'), '//4uAA=='); - -// Writing base64 at a position > 0 should not mangle the result. -// -// https://github.com/joyent/node/issues/402 -var segments = ['TWFkbmVzcz8h', 'IFRoaXM=', 'IGlz', 'IG5vZGUuanMh']; -var buf = new Buffer(64); -var pos = 0; - -for (var i = 0; i < segments.length; ++i) { - pos += b.write(segments[i], pos, 'base64'); -} -assert.equal(b.toString('binary', 0, pos), 'Madness?! This is node.js!'); - -// Creating buffers larger than pool size. -var l = Buffer.poolSize + 5; -var s = ''; -for (i = 0; i < l; i++) { - s += 'h'; -} - -var b = new Buffer(s); - -for (i = 0; i < l; i++) { - assert.equal('h'.charCodeAt(0), b[i]); -} - -var sb = b.toString(); -assert.equal(sb.length, s.length); -assert.equal(sb, s); - - -// Single argument slice -b = new Buffer('abcde'); -assert.equal('bcde', b.slice(1).toString()); - -// byte length -assert.equal(14, Buffer.byteLength('Il était tué')); -assert.equal(14, Buffer.byteLength('Il était tué', 'utf8')); -['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) { - assert.equal(24, Buffer.byteLength('Il était tué', encoding)); -}); -assert.equal(12, Buffer.byteLength('Il était tué', 'ascii')); -assert.equal(12, Buffer.byteLength('Il était tué', 'binary')); - -// slice(0,0).length === 0 -assert.equal(0, Buffer('hello').slice(0, 0).length); - -// test hex toString -console.log('Create hex string from buffer'); -var hexb = new Buffer(256); -for (var i = 0; i < 256; i++) { - hexb[i] = i; -} -var hexStr = hexb.toString('hex'); -assert.equal(hexStr, - '000102030405060708090a0b0c0d0e0f' + - '101112131415161718191a1b1c1d1e1f' + - '202122232425262728292a2b2c2d2e2f' + - '303132333435363738393a3b3c3d3e3f' + - '404142434445464748494a4b4c4d4e4f' + - '505152535455565758595a5b5c5d5e5f' + - '606162636465666768696a6b6c6d6e6f' + - '707172737475767778797a7b7c7d7e7f' + - '808182838485868788898a8b8c8d8e8f' + - '909192939495969798999a9b9c9d9e9f' + - 'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf' + - 'b0b1b2b3b4b5b6b7b8b9babbbcbdbebf' + - 'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf' + - 'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf' + - 'e0e1e2e3e4e5e6e7e8e9eaebecedeeef' + - 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'); - -console.log('Create buffer from hex string'); -var hexb2 = new Buffer(hexStr, 'hex'); -for (var i = 0; i < 256; i++) { - assert.equal(hexb2[i], hexb[i]); -} - -// test an invalid slice end. -console.log('Try to slice off the end of the buffer'); -var b = new Buffer([1, 2, 3, 4, 5]); -var b2 = b.toString('hex', 1, 10000); -var b3 = b.toString('hex', 1, 5); -var b4 = b.toString('hex', 1); -assert.equal(b2, b3); -assert.equal(b2, b4); - - -// Test slice on SlowBuffer GH-843 -var SlowBuffer = process.binding('buffer').SlowBuffer; - -function buildSlowBuffer(data) { - if (Array.isArray(data)) { - var buffer = new SlowBuffer(data.length); - data.forEach(function(v, k) { - buffer[k] = v; - }); - return buffer; - } - return null; -} - -var x = buildSlowBuffer([0x81, 0xa3, 0x66, 0x6f, 0x6f, 0xa3, 0x62, 0x61, 0x72]); - -console.log(x.inspect()); -assert.equal('', x.inspect()); - -var z = x.slice(4); -console.log(z.inspect()); -console.log(z.length); -assert.equal(5, z.length); -assert.equal(0x6f, z[0]); -assert.equal(0xa3, z[1]); -assert.equal(0x62, z[2]); -assert.equal(0x61, z[3]); -assert.equal(0x72, z[4]); - -var z = x.slice(0); -console.log(z.inspect()); -console.log(z.length); -assert.equal(z.length, x.length); - -var z = x.slice(0, 4); -console.log(z.inspect()); -console.log(z.length); -assert.equal(4, z.length); -assert.equal(0x81, z[0]); -assert.equal(0xa3, z[1]); - -var z = x.slice(0, 9); -console.log(z.inspect()); -console.log(z.length); -assert.equal(9, z.length); - -var z = x.slice(1, 4); -console.log(z.inspect()); -console.log(z.length); -assert.equal(3, z.length); -assert.equal(0xa3, z[0]); - -var z = x.slice(2, 4); -console.log(z.inspect()); -console.log(z.length); -assert.equal(2, z.length); -assert.equal(0x66, z[0]); -assert.equal(0x6f, z[1]); - -assert.equal(0, Buffer('hello').slice(0, 0).length); - -b = new Buffer(50); -b.fill('h'); -for (var i = 0; i < b.length; i++) { - assert.equal('h'.charCodeAt(0), b[i]); -} - -b.fill(0); -for (var i = 0; i < b.length; i++) { - assert.equal(0, b[i]); -} - -b.fill(1, 16, 32); -for (var i = 0; i < 16; i++) assert.equal(0, b[i]); -for (; i < 32; i++) assert.equal(1, b[i]); -for (; i < b.length; i++) assert.equal(0, b[i]); - -['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) { - var b = new SlowBuffer(10); - b.write('あいうえお', encoding); - assert.equal(b.toString(encoding), 'あいうえお'); -}); - -// Binary encoding should write only one byte per character. -var b = Buffer([0xde, 0xad, 0xbe, 0xef]); -var s = String.fromCharCode(0xffff); -b.write(s, 0, 'binary'); -assert.equal(0xff, b[0]); -assert.equal(0xad, b[1]); -assert.equal(0xbe, b[2]); -assert.equal(0xef, b[3]); -s = String.fromCharCode(0xaaee); -b.write(s, 0, 'binary'); -assert.equal(0xee, b[0]); -assert.equal(0xad, b[1]); -assert.equal(0xbe, b[2]); -assert.equal(0xef, b[3]); - -// testing invalid encoding on SlowBuffer.toString -caught_error = null; -try { - var copied = b.toString('invalid'); -} catch (err) { - caught_error = err; -} -assert.strictEqual('Unknown encoding: invalid', caught_error.message); - -// testing invalid encoding on SlowBuffer.write -caught_error = null; -try { - var copied = b.write('some string', 0, 5, 'invalid'); -} catch (err) { - caught_error = err; -} -assert.strictEqual('Unknown encoding: invalid', caught_error.message); - - -// This should not segfault the program. -assert.throws(function() { - new Buffer('"pong"', 0, 6, 8031, '127.0.0.1'); -}); - -// #1210 Test UTF-8 string includes null character -var buf = new Buffer('\0'); -assert.equal(buf.length, 1); -buf = new Buffer('\0\0'); -assert.equal(buf.length, 2); - -buf = new Buffer(2); -var written = buf.write(''); // 0byte -assert.equal(written, 0); -written = buf.write('\0'); // 1byte (v8 adds null terminator) -assert.equal(written, 1); -written = buf.write('a\0'); // 1byte * 2 -assert.equal(written, 2); -written = buf.write('あ'); // 3bytes -assert.equal(written, 0); -written = buf.write('\0あ'); // 1byte + 3bytes -assert.equal(written, 1); -written = buf.write('\0\0あ'); // 1byte * 2 + 3bytes -assert.equal(written, 2); - -buf = new Buffer(10); -written = buf.write('あいう'); // 3bytes * 3 (v8 adds null terminator) -assert.equal(written, 9); -written = buf.write('あいう\0'); // 3bytes * 3 + 1byte -assert.equal(written, 10); - -// #243 Test write() with maxLength -var buf = new Buffer(4); -buf.fill(0xFF); -var written = buf.write('abcd', 1, 2, 'utf8'); -console.log(buf); -assert.equal(written, 2); -assert.equal(buf[0], 0xFF); -assert.equal(buf[1], 0x61); -assert.equal(buf[2], 0x62); -assert.equal(buf[3], 0xFF); - -buf.fill(0xFF); -written = buf.write('abcd', 1, 4); -console.log(buf); -assert.equal(written, 3); -assert.equal(buf[0], 0xFF); -assert.equal(buf[1], 0x61); -assert.equal(buf[2], 0x62); -assert.equal(buf[3], 0x63); - -buf.fill(0xFF); -written = buf.write('abcd', 'utf8', 1, 2); // legacy style -console.log(buf); -assert.equal(written, 2); -assert.equal(buf[0], 0xFF); -assert.equal(buf[1], 0x61); -assert.equal(buf[2], 0x62); -assert.equal(buf[3], 0xFF); - -buf.fill(0xFF); -written = buf.write('abcdef', 1, 2, 'hex'); -console.log(buf); -assert.equal(written, 2); -assert.equal(buf[0], 0xFF); -assert.equal(buf[1], 0xAB); -assert.equal(buf[2], 0xCD); -assert.equal(buf[3], 0xFF); - -['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) { - buf.fill(0xFF); - written = buf.write('abcd', 0, 2, encoding); - console.log(buf); - assert.equal(written, 2); - assert.equal(buf[0], 0x61); - assert.equal(buf[1], 0x00); - assert.equal(buf[2], 0xFF); - assert.equal(buf[3], 0xFF); -}); - -// test unmatched surrogates not producing invalid utf8 output -// ef bf bd = utf-8 representation of unicode replacement character -// see https://codereview.chromium.org/121173009/ -buf = new Buffer('ab\ud800cd', 'utf8'); -assert.equal(buf[0], 0x61); -assert.equal(buf[1], 0x62); -assert.equal(buf[2], 0xef); -assert.equal(buf[3], 0xbf); -assert.equal(buf[4], 0xbd); -assert.equal(buf[5], 0x63); -assert.equal(buf[6], 0x64); - -// test for buffer overrun -buf = new Buffer([0, 0, 0, 0, 0]); // length: 5 -var sub = buf.slice(0, 4); // length: 4 -written = sub.write('12345', 'binary'); -assert.equal(written, 4); -assert.equal(buf[4], 0); - -// test for _charsWritten -buf = new Buffer(9); -buf.write('あいうえ', 'utf8'); // 3bytes * 4 -assert.equal(Buffer._charsWritten, 3); -['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) { - buf.write('あいうえお', encoding); // 2bytes * 5 - assert.equal(Buffer._charsWritten, 4); -}); -buf.write('0123456789', 'ascii'); -assert.equal(Buffer._charsWritten, 9); -buf.write('0123456789', 'binary'); -assert.equal(Buffer._charsWritten, 9); -buf.write('123456', 'base64'); -assert.equal(Buffer._charsWritten, 4); -buf.write('00010203040506070809', 'hex'); -assert.equal(Buffer._charsWritten, 18); - -// Check for fractional length args, junk length args, etc. -// https://github.com/joyent/node/issues/1758 -Buffer(3.3).toString(); // throws bad argument error in commit 43cb4ec -assert.equal(Buffer(-1).length, 0); -assert.equal(Buffer(NaN).length, 0); -assert.equal(Buffer(3.3).length, 4); -assert.equal(Buffer({length: 3.3}).length, 4); -assert.equal(Buffer({length: 'BAM'}).length, 0); - -// Make sure that strings are not coerced to numbers. -assert.equal(Buffer('99').length, 2); -assert.equal(Buffer('13.37').length, 5); - -// Ensure that the length argument is respected. -'ascii utf8 hex base64 binary'.split(' ').forEach(function(enc) { - assert.equal(Buffer(1).write('aaaaaa', 0, 1, enc), 1); -}); - -// Regression test, guard against buffer overrun in the base64 decoder. -var a = Buffer(3); -var b = Buffer('xxx'); -a.write('aaaaaaaa', 'base64'); -assert.equal(b.toString(), 'xxx'); - -// issue GH-3416 -Buffer(Buffer(0), 0, 0); - -[ 'hex', - 'utf8', - 'utf-8', - 'ascii', - 'binary', - 'base64', - 'ucs2', - 'ucs-2', - 'utf16le', - 'utf-16le' ].forEach(function(enc) { - assert.equal(Buffer.isEncoding(enc), true); - }); - -[ 'utf9', - 'utf-7', - 'Unicode-FTW', - 'new gnu gun' ].forEach(function(enc) { - assert.equal(Buffer.isEncoding(enc), false); - }); - - -// GH-3905 -assert.equal(JSON.stringify(Buffer('test')), '[116,101,115,116]'); - -// issue GH-4331 -assert.throws(function() { - new Buffer(0xFFFFFFFF); -}, RangeError); -assert.throws(function() { - new Buffer(0xFFFFFFFFF); -}, TypeError); - - -// attempt to overflow buffers, similar to previous bug in array buffers -assert.throws(function() { - var buf = new Buffer(8); - buf.readFloatLE(0xffffffff); -}, /Trying to access beyond buffer length/); - -assert.throws(function() { - var buf = new Buffer(8); - buf.writeFloatLE(0.0, 0xffffffff); -}, /Trying to access beyond buffer length/); - -assert.throws(function() { - var buf = new SlowBuffer(8); - buf.readFloatLE(0xffffffff); -}, /Trying to read beyond buffer length/); - -assert.throws(function() { - var buf = new SlowBuffer(8); - buf.writeFloatLE(0.0, 0xffffffff); -}, /Trying to write beyond buffer length/); - - -// ensure negative values can't get past offset -assert.throws(function() { - var buf = new Buffer(8); - buf.readFloatLE(-1); -}, /offset is not uint/); - -assert.throws(function() { - var buf = new Buffer(8); - buf.writeFloatLE(0.0, -1); -}, /offset is not uint/); - -assert.throws(function() { - var buf = new SlowBuffer(8); - buf.readFloatLE(-1); -}, /offset is not uint/); - -assert.throws(function() { - var buf = new SlowBuffer(8); - buf.writeFloatLE(0.0, -1); -}, /offset is not uint/); - -// offset checks -var buf = new Buffer(0); - -assert.throws(function() { buf.readUInt8(0); }, /beyond buffer length/); -assert.throws(function() { buf.readInt8(0); }, /beyond buffer length/); - -[16, 32].forEach(function(bits) { - var buf = new Buffer(bits / 8 - 1); - - assert.throws( - function() { buf['readUInt' + bits + 'BE'](0); }, - /beyond buffer length/, - 'readUInt' + bits + 'BE' - ); - - assert.throws( - function() { buf['readUInt' + bits + 'LE'](0); }, - /beyond buffer length/, - 'readUInt' + bits + 'LE' - ); - - assert.throws( - function() { buf['readInt' + bits + 'BE'](0); }, - /beyond buffer length/, - 'readInt' + bits + 'BE()' - ); - - assert.throws( - function() { buf['readInt' + bits + 'LE'](0); }, - /beyond buffer length/, - 'readInt' + bits + 'LE()' - ); -}); - -[16, 32].forEach(function(bits) { - var buf = new Buffer([0xFF, 0xFF, 0xFF, 0xFF]); - - assert.equal(buf['readUInt' + bits + 'BE'](0), - (0xFFFFFFFF >>> (32 - bits))); - - assert.equal(buf['readUInt' + bits + 'LE'](0), - (0xFFFFFFFF >>> (32 - bits))); - - assert.equal(buf['readInt' + bits + 'BE'](0), - (0xFFFFFFFF >> (32 - bits))); - - assert.equal(buf['readInt' + bits + 'LE'](0), - (0xFFFFFFFF >> (32 - bits))); -}); - -// SlowBuffer sanity checks. -assert.throws(function() { - var len = 0xfffff; - var sbuf = new SlowBuffer(len); - var buf = new Buffer(sbuf, len, 0); - SlowBuffer.makeFastBuffer(sbuf, buf, -len, len); // Should throw. - for (var i = 0; i < len; ++i) buf[i] = 0x42; // Try to force segfault. -}, RangeError); - -assert.throws(function() { - var len = 0xfffff; - var sbuf = new SlowBuffer(len); - var buf = new Buffer(sbuf, len, -len); // Should throw. - for (var i = 0; i < len; ++i) buf[i] = 0x42; // Try to force segfault. -}, RangeError); - -assert.throws(function() { - var sbuf = new SlowBuffer(1); - var buf = new Buffer(sbuf, 1, 0); - buf.length = 0xffffffff; - buf.slice(0xffffff0, 0xffffffe); // Should throw. -}, Error); - -(function() { - var buf = new Buffer('0123456789'); - assert.equal(buf.slice(-10, 10), '0123456789'); - assert.equal(buf.slice(-20, 10), '0123456789'); - assert.equal(buf.slice(-20, -10), ''); - assert.equal(buf.slice(0, -1), '012345678'); - assert.equal(buf.slice(2, -2), '234567'); - assert.equal(buf.slice(0, 65536), '0123456789'); - assert.equal(buf.slice(65536, 0), ''); - for (var i = 0, s = buf.toString(); i < buf.length; ++i) { - assert.equal(buf.slice(-i), s.slice(-i)); - assert.equal(buf.slice(0, -i), s.slice(0, -i)); - } -})(); - -// Make sure byteLength properly checks for base64 padding -assert.equal(Buffer.byteLength('aaa=', 'base64'), 2); -assert.equal(Buffer.byteLength('aaaa==', 'base64'), 3); - -// Regression test for #5482: should throw but not assert in C++ land. -assert.throws(function() { - Buffer('', 'buffer'); -}, TypeError); - -assert.doesNotThrow(function () { - var slow = new SlowBuffer(1); - assert(slow.write('', Buffer.poolSize * 10) === 0); - var fast = new Buffer(1); - assert(fast.write('', Buffer.poolSize * 10) === 0); -}); diff --git a/test/simple/test-c-ares.js b/test/simple/test-c-ares.js deleted file mode 100644 index 3a3a9223d88f..000000000000 --- a/test/simple/test-c-ares.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var dns = require('dns'); - - -// Try resolution without callback - -dns.lookup(null, function(error, result, addressType) { - assert.equal(null, result); - assert.equal(4, addressType); -}); - -dns.lookup('127.0.0.1', function(error, result, addressType) { - assert.equal('127.0.0.1', result); - assert.equal(4, addressType); -}); - -dns.lookup('::1', function(error, result, addressType) { - assert.equal('::1', result); - assert.equal(6, addressType); -}); - -// Try calling resolve with an unsupported type. -assert.throws(function() { - dns.resolve('www.google.com', 'HI'); -}, /Unknown type/); - -// Windows doesn't usually have an entry for localhost 127.0.0.1 in -// C:\Windows\System32\drivers\etc\hosts -// so we disable this test on Windows. -if (process.platform != 'win32') { - dns.resolve('127.0.0.1', 'PTR', function(error, domains) { - if (error) throw error; - assert.ok(Array.isArray(domains)); - }); -} diff --git a/test/simple/test-chdir.js b/test/simple/test-chdir.js deleted file mode 100644 index 7454bee2d338..000000000000 --- a/test/simple/test-chdir.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); - -assert.equal(true, process.cwd() !== __dirname); - -process.chdir(__dirname); -assert.equal(true, process.cwd() === __dirname); - -var dir = path.resolve(common.fixturesDir, - 'weird \uc3a4\uc3ab\uc3af characters \u00e1\u00e2\u00e3'); -fs.mkdirSync(dir); -process.chdir(dir); -assert(process.cwd() == dir); - -process.chdir('..'); -assert(process.cwd() == path.resolve(common.fixturesDir)); -fs.rmdirSync(dir); diff --git a/test/simple/test-child-process-buffering.js b/test/simple/test-child-process-buffering.js deleted file mode 100644 index 3fb13b6208f4..000000000000 --- a/test/simple/test-child-process-buffering.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var spawn = require('child_process').spawn; - -var pwd_called = false; -var childClosed = false; -var childExited = false; - -function pwd(callback) { - var output = ''; - var child = common.spawnPwd(); - - child.stdout.setEncoding('utf8'); - child.stdout.on('data', function(s) { - console.log('stdout: ' + JSON.stringify(s)); - output += s; - }); - - child.on('exit', function(c) { - console.log('exit: ' + c); - assert.equal(0, c); - childExited = true; - }); - - child.on('close', function () { - callback(output); - pwd_called = true; - childClosed = true; - }); -} - - -pwd(function(result) { - console.dir(result); - assert.equal(true, result.length > 1); - assert.equal('\n', result[result.length - 1]); -}); - -process.on('exit', function() { - assert.equal(true, pwd_called); - assert.equal(true, childExited); - assert.equal(true, childClosed); -}); diff --git a/test/simple/test-child-process-customfd-bounded.js b/test/simple/test-child-process-customfd-bounded.js deleted file mode 100644 index c1efd8378df5..000000000000 --- a/test/simple/test-child-process-customfd-bounded.js +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); - -var bigish = Array(200); - -for (var i = 0, il = bigish.length; i < il; ++i) - bigish[i] = -1; - -common.spawnPwd({ customFds: bigish }); diff --git a/test/simple/test-child-process-cwd.js b/test/simple/test-child-process-cwd.js deleted file mode 100644 index b06e8e479385..000000000000 --- a/test/simple/test-child-process-cwd.js +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; -var path = require('path'); - -var returns = 0; - -/* - Spawns 'pwd' with given options, then test - - whether the exit code equals forCode, - - optionally whether the stdout result matches forData - (after removing traling whitespace) -*/ -function testCwd(options, forCode, forData) { - var data = ''; - - var child = common.spawnPwd(options); - - child.stdout.setEncoding('utf8'); - - child.stdout.on('data', function(chunk) { - data += chunk; - }); - - child.on('exit', function(code, signal) { - assert.strictEqual(forCode, code); - }); - - child.on('close', function () { - forData && assert.strictEqual(forData, data.replace(/[\s\r\n]+$/, '')); - returns--; - }); - - returns++; - - return child; -} - -// Assume these exist, and 'pwd' gives us the right directory back -if (process.platform == 'win32') { - testCwd({cwd: process.env.windir}, 0, process.env.windir); - testCwd({cwd: 'c:\\'}, 0, 'c:\\'); -} else { - testCwd({cwd: '/dev'}, 0, '/dev'); - testCwd({cwd: '/'}, 0, '/'); -} - -// Assume does-not-exist doesn't exist, expect exitCode=-1 and errno=ENOENT -(function() { - var errors = 0; - - testCwd({cwd: 'does-not-exist'}, -1).on('error', function(e) { - assert.equal(e.code, 'ENOENT'); - errors++; - }); - - process.on('exit', function() { - assert.equal(errors, 1); - }); -})(); - -// Spawn() shouldn't try to chdir() so this should just work -testCwd(undefined, 0); -testCwd({}, 0); -testCwd({cwd: ''}, 0); -testCwd({cwd: undefined}, 0); -testCwd({cwd: null}, 0); - -// Check whether all tests actually returned -assert.notEqual(0, returns); -process.on('exit', function() { - assert.equal(0, returns); -}); diff --git a/test/simple/test-child-process-detached.js b/test/simple/test-child-process-detached.js deleted file mode 100644 index 10ce5d15274c..000000000000 --- a/test/simple/test-child-process-detached.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); - -var spawn = require('child_process').spawn; -var childPath = path.join(__dirname, '..', 'fixtures', 'parent-process-nonpersistent.js'); -var persistentPid = -1; - -var child = spawn(process.execPath, [ childPath ]); - -child.stdout.on('data', function (data) { - persistentPid = parseInt(data, 10); -}); - -process.on('exit', function () { - assert(persistentPid !== -1); - assert.throws(function () { - process.kill(child.pid); - }); - assert.doesNotThrow(function () { - process.kill(persistentPid); - }); -}); - diff --git a/test/simple/test-child-process-disconnect.js b/test/simple/test-child-process-disconnect.js deleted file mode 100644 index 162e7dde8be1..000000000000 --- a/test/simple/test-child-process-disconnect.js +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var common = require('../common'); -var fork = require('child_process').fork; -var net = require('net'); - -// child -if (process.argv[2] === 'child') { - - var server = net.createServer(); - - server.on('connection', function(socket) { - - socket.resume(); - - process.on('disconnect', function() { - socket.end((process.connected).toString()); - }); - - // when the socket is closed, we will close the server - // allowing the process to self terminate - socket.on('end', function() { - server.close(); - }); - - socket.write('ready'); - }); - - // when the server is ready tell parent - server.on('listening', function() { - process.send('ready'); - }); - - server.listen(common.PORT); - -} else { - // testcase - var child = fork(process.argv[1], ['child']); - - var childFlag = false; - var childSelfTerminate = false; - var parentEmit = false; - var parentFlag = false; - - // when calling .disconnect the event should emit - // and the disconnected flag should be true. - child.on('disconnect', function() { - parentEmit = true; - parentFlag = child.connected; - }); - - // the process should also self terminate without using signals - child.on('exit', function() { - childSelfTerminate = true; - }); - - // when child is listning - child.on('message', function(msg) { - if (msg === 'ready') { - - // connect to child using TCP to know if disconnect was emitted - var socket = net.connect(common.PORT); - - socket.on('data', function(data) { - data = data.toString(); - - // ready to be disconnected - if (data === 'ready') { - child.disconnect(); - assert.throws(child.disconnect.bind(child), Error); - return; - } - - // disconnect is emitted - childFlag = (data === 'true'); - }); - - } - }); - - process.on('exit', function() { - assert.equal(childFlag, false); - assert.equal(parentFlag, false); - - assert.ok(childSelfTerminate); - assert.ok(parentEmit); - }); -} diff --git a/test/simple/test-child-process-double-pipe.js b/test/simple/test-child-process-double-pipe.js deleted file mode 100644 index 84fbf4fb205c..000000000000 --- a/test/simple/test-child-process-double-pipe.js +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var is_windows = process.platform === 'win32'; - -var common = require('../common'); -var assert = require('assert'), - util = require('util'), - spawn = require('child_process').spawn; - -// We're trying to reproduce: -// $ echo "hello\nnode\nand\nworld" | grep o | sed s/o/a/ - -var grep = spawn('grep', ['o']), - sed = spawn('sed', ['s/o/O/']), - echo; - -if (is_windows) { - echo = spawn('cmd.exe', - ['/c', 'echo', 'hello&&', 'echo', - 'node&&', 'echo', 'and&&', 'echo', 'world']); -} else { - echo = spawn('echo', ['hello\nnode\nand\nworld\n']); -} - -/* - * grep and sed hang if the spawn function leaks file descriptors to child - * processes. - * This happens when calling pipe(2) and then forgetting to set the - * FD_CLOEXEC flag on the resulting file descriptors. - * - * This test checks child processes exit, meaning they don't hang like - * explained above. - */ - - - -// pipe echo | grep -echo.stdout.on('data', function(data) { - console.error('grep stdin write ' + data.length); - if (!grep.stdin.write(data)) { - echo.stdout.pause(); - } -}); - -grep.stdin.on('drain', function(data) { - echo.stdout.resume(); -}); - -// propagate end from echo to grep -echo.stdout.on('end', function(code) { - grep.stdin.end(); -}); - -echo.on('exit', function() { - console.error('echo exit'); -}); - -grep.on('exit', function() { - console.error('grep exit'); -}); - -sed.on('exit', function() { - console.error('sed exit'); -}); - - - -// pipe grep | sed -grep.stdout.on('data', function(data) { - console.error('grep stdout ' + data.length); - if (!sed.stdin.write(data)) { - grep.stdout.pause(); - } -}); - -sed.stdin.on('drain', function(data) { - grep.stdout.resume(); -}); - -// propagate end from grep to sed -grep.stdout.on('end', function(code) { - console.error('grep stdout end'); - sed.stdin.end(); -}); - - - -var result = ''; - -// print sed's output -sed.stdout.on('data', function(data) { - result += data.toString('utf8', 0, data.length); - util.print(data); -}); - -sed.stdout.on('end', function(code) { - assert.equal(result, 'hellO\nnOde\nwOrld\n'); -}); diff --git a/test/simple/test-child-process-env.js b/test/simple/test-child-process-env.js deleted file mode 100644 index caeb1936c2c3..000000000000 --- a/test/simple/test-child-process-env.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var spawn = require('child_process').spawn; - -var isWindows = process.platform === 'win32'; - -var env = { - 'HELLO': 'WORLD' -}; -env.__proto__ = { - 'FOO': 'BAR' -}; - -if (isWindows) { - var child = spawn('cmd.exe', ['/c', 'set'], {env: env}); -} else { - var child = spawn('/usr/bin/env', [], {env: env}); -} - - -var response = ''; - -child.stdout.setEncoding('utf8'); - -child.stdout.on('data', function(chunk) { - console.log('stdout: ' + chunk); - response += chunk; -}); - -process.on('exit', function() { - assert.ok(response.indexOf('HELLO=WORLD') >= 0); - assert.ok(response.indexOf('FOO=BAR') >= 0); -}); diff --git a/test/simple/test-child-process-exec-cwd.js b/test/simple/test-child-process-exec-cwd.js deleted file mode 100644 index 282faec8ba9a..000000000000 --- a/test/simple/test-child-process-exec-cwd.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; - -var success_count = 0; -var error_count = 0; - -var pwdcommand, dir; - -if (process.platform == 'win32') { - pwdcommand = 'echo %cd%'; - dir = 'c:\\windows'; -} else { - pwdcommand = 'pwd'; - dir = '/dev'; -} - -var child = exec(pwdcommand, {cwd: dir}, function(err, stdout, stderr) { - if (err) { - error_count++; - console.log('error!: ' + err.code); - console.log('stdout: ' + JSON.stringify(stdout)); - console.log('stderr: ' + JSON.stringify(stderr)); - assert.equal(false, err.killed); - } else { - success_count++; - console.log(stdout); - assert.ok(stdout.indexOf(dir) == 0); - } -}); - -process.on('exit', function() { - assert.equal(1, success_count); - assert.equal(0, error_count); -}); diff --git a/test/simple/test-child-process-exec-env.js b/test/simple/test-child-process-exec-env.js deleted file mode 100644 index b14ce741fef7..000000000000 --- a/test/simple/test-child-process-exec-env.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; -var success_count = 0; -var error_count = 0; -var response = ''; -var child; - -function after(err, stdout, stderr) { - if (err) { - error_count++; - console.log('error!: ' + err.code); - console.log('stdout: ' + JSON.stringify(stdout)); - console.log('stderr: ' + JSON.stringify(stderr)); - assert.equal(false, err.killed); - } else { - success_count++; - assert.equal(true, stdout != ''); - } -} - -if (process.platform !== 'win32') { - child = exec('/usr/bin/env', { env: { 'HELLO': 'WORLD' } }, after); -} else { - child = exec('set', { env: { 'HELLO': 'WORLD' } }, after); -} - -child.stdout.setEncoding('utf8'); -child.stdout.on('data', function(chunk) { - response += chunk; -}); - -process.on('exit', function() { - console.log('response: ', response); - assert.equal(1, success_count); - assert.equal(0, error_count); - assert.ok(response.indexOf('HELLO=WORLD') >= 0); -}); diff --git a/test/simple/test-child-process-exec-error.js b/test/simple/test-child-process-exec-error.js deleted file mode 100644 index 2afe1144341f..000000000000 --- a/test/simple/test-child-process-exec-error.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var child_process = require('child_process'); - -function test(fun, code) { - var errors = 0; - - fun('does-not-exist', function(err) { - assert.equal(err.code, code); - errors++; - }); - - process.on('exit', function() { - assert.equal(errors, 1); - }); -} - -if (process.platform === 'win32') { - test(child_process.exec, 1); // exit code of cmd.exe -} else { - test(child_process.exec, 127); // exit code of /bin/sh -} - -test(child_process.execFile, 'ENOENT'); diff --git a/test/simple/test-child-process-exit-code.js b/test/simple/test-child-process-exit-code.js deleted file mode 100644 index c0c25858bb13..000000000000 --- a/test/simple/test-child-process-exit-code.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; -var path = require('path'); - -var exits = 0; - -var exitScript = path.join(common.fixturesDir, 'exit.js'); -var exitChild = spawn(process.argv[0], [exitScript, 23]); -exitChild.on('exit', function(code, signal) { - assert.strictEqual(code, 23); - assert.strictEqual(signal, null); - - exits++; -}); - - - -var errorScript = path.join(common.fixturesDir, - 'child_process_should_emit_error.js'); -var errorChild = spawn(process.argv[0], [errorScript]); -errorChild.on('exit', function(code, signal) { - assert.ok(code !== 0); - assert.strictEqual(signal, null); - - exits++; -}); - - -process.on('exit', function() { - assert.equal(2, exits); -}); diff --git a/test/simple/test-child-process-fork-and-spawn.js b/test/simple/test-child-process-fork-and-spawn.js deleted file mode 100644 index 989bf7ee3a1a..000000000000 --- a/test/simple/test-child-process-fork-and-spawn.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; -var fork = require('child_process').fork; - -// Fork, then spawn. The spawned process should not hang. -switch (process.argv[2] || '') { -case '': - fork(__filename, ['fork']).on('exit', checkExit); - process.on('exit', haveExit); - break; -case 'fork': - spawn(process.execPath, [__filename, 'spawn']).on('exit', checkExit); - process.on('exit', haveExit); - break; -case 'spawn': - break; -default: - assert(0); -} - -var seenExit = false; - -function checkExit(statusCode) { - seenExit = true; - assert.equal(statusCode, 0); - process.nextTick(process.exit); -} - -function haveExit() { - assert.equal(seenExit, true); -} diff --git a/test/simple/test-child-process-fork-close.js b/test/simple/test-child-process-fork-close.js deleted file mode 100644 index 342cffec3c3a..000000000000 --- a/test/simple/test-child-process-fork-close.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'), - common = require('../common'), - fork = require('child_process').fork, - fork = require('child_process').fork; - -var cp = fork(common.fixturesDir + '/child-process-message-and-exit.js'); - -var gotMessage = false, - gotExit = false, - gotClose = false; - -cp.on('message', function(message) { - assert(!gotMessage); - assert(!gotClose); - assert.strictEqual(message, 'hello'); - gotMessage = true; -}); - -cp.on('exit', function() { - assert(!gotExit); - assert(!gotClose); - gotExit = true; -}); - -cp.on('close', function() { - assert(gotMessage); - assert(gotExit); - assert(!gotClose); - gotClose = true; -}); - -process.on('exit', function() { - assert(gotMessage); - assert(gotExit); - assert(gotClose); -}); diff --git a/test/simple/test-child-process-fork-dgram.js b/test/simple/test-child-process-fork-dgram.js deleted file mode 100644 index 1c4e9acc3b75..000000000000 --- a/test/simple/test-child-process-fork-dgram.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * The purpose of this test is to make sure that when forking a process, - * sending a fd representing a UDP socket to the child and sending messages - * to this endpoint, these messages are distributed to the parent and the - * child process. - * - * Because it's not really possible to predict how the messages will be - * distributed among the parent and the child processes, we keep sending - * messages until both the parent and the child received at least one - * message. The worst case scenario is when either one never receives - * a message. In this case the test runner will timeout after 60 secs - * and the test will fail. - */ - -var dgram = require('dgram'); -var fork = require('child_process').fork; -var assert = require('assert'); -var common = require('../common'); - -if (process.platform === 'win32') { - console.error('Sending dgram sockets to child processes not supported'); - process.exit(0); -} - -if (process.argv[2] === 'child') { - var childCollected = 0; - var server; - - process.on('message', function removeMe(msg, clusterServer) { - if (msg === 'server') { - server = clusterServer; - - server.on('message', function () { - process.send('gotMessage'); - }); - - } else if (msg === 'stop') { - server.close(); - process.removeListener('message', removeMe); - } - }); - -} else { - var server = dgram.createSocket('udp4'); - var client = dgram.createSocket('udp4'); - var child = fork(__filename, ['child']); - - var msg = new Buffer('Some bytes'); - - var childGotMessage = false; - var parentGotMessage = false; - - server.on('message', function (msg, rinfo) { - parentGotMessage = true; - }); - - server.on('listening', function () { - child.send('server', server); - - child.once('message', function (msg) { - if (msg === 'gotMessage') { - childGotMessage = true; - } - }); - - sendMessages(); - }); - - var sendMessages = function () { - var timer = setInterval(function () { - client.send(msg, 0, msg.length, common.PORT, '127.0.0.1', function(err) { - if (err) throw err; - } - ); - - /* - * Both the parent and the child got at least one message, - * test passed, clean up everyting. - */ - if (parentGotMessage && childGotMessage) { - clearInterval(timer); - shutdown(); - } - - }, 1); - }; - - var shutdown = function () { - child.send('stop'); - - server.close(); - client.close(); - }; - - server.bind(common.PORT, '127.0.0.1'); - - process.once('exit', function () { - assert(parentGotMessage); - assert(childGotMessage); - }); -} diff --git a/test/simple/test-child-process-fork-exec-argv.js b/test/simple/test-child-process-fork-exec-argv.js deleted file mode 100644 index 2fbc3799690f..000000000000 --- a/test/simple/test-child-process-fork-exec-argv.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var child_process = require('child_process'); -var spawn = child_process.spawn; -var fork = child_process.fork; - -if (process.argv[2] === 'fork') { - process.stdout.write(JSON.stringify(process.execArgv), function() { - process.exit(); - }); -} else if (process.argv[2] === 'child') { - fork(__filename, ['fork']); -} else { - var execArgv = ['--harmony_proxies', '--max-stack-size=0']; - var args = [__filename, 'child', 'arg0']; - - var child = spawn(process.execPath, execArgv.concat(args)); - var out = ''; - - child.stdout.on('data', function (chunk) { - out += chunk; - }); - - child.on('exit', function () { - assert.deepEqual(JSON.parse(out), execArgv); - }); -} diff --git a/test/simple/test-child-process-fork-exec-path.js b/test/simple/test-child-process-fork-exec-path.js deleted file mode 100755 index e0cf77c28eb9..000000000000 --- a/test/simple/test-child-process-fork-exec-path.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var cp = require('child_process'); -var fs = require('fs'); -var path = require('path'); -var common = require('../common'); -var msg = {test: 'this'}; -var nodePath = process.execPath; -var copyPath = path.join(common.tmpDir, 'node-copy.exe'); - -if (process.env.FORK) { - assert(process.send); - assert.equal(process.argv[0], copyPath); - process.send(msg); - process.exit(); -} -else { - try { - fs.unlinkSync(copyPath); - } - catch (e) { - if (e.code !== 'ENOENT') throw e; - } - fs.writeFileSync(copyPath, fs.readFileSync(nodePath)); - fs.chmodSync(copyPath, '0755'); - - // slow but simple - var envCopy = JSON.parse(JSON.stringify(process.env)); - envCopy.FORK = 'true'; - var child = require('child_process').fork(__filename, { - execPath: copyPath, - env: envCopy - }); - child.on('message', common.mustCall(function(recv) { - assert.deepEqual(msg, recv); - })); - child.on('exit', common.mustCall(function(code) { - fs.unlinkSync(copyPath); - assert.equal(code, 0); - })); -} diff --git a/test/simple/test-child-process-fork-getconnections.js b/test/simple/test-child-process-fork-getconnections.js deleted file mode 100644 index 597c23fd2b7c..000000000000 --- a/test/simple/test-child-process-fork-getconnections.js +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var common = require('../common'); -var fork = require('child_process').fork; -var net = require('net'); -var count = 12; - -if (process.argv[2] === 'child') { - var sockets = []; - var id = process.argv[3]; - - process.on('message', function(m, socket) { - if (m.cmd === 'new') { - assert(socket); - assert(socket instanceof net.Socket, 'should be a net.Socket'); - sockets.push(socket); - socket.on('end', function() { - if (!this.closingOnPurpose) - throw new Error('[c] closing by accident! ' + process._errno); - }); - } - - if (m.cmd === 'close') { - assert.equal(socket, undefined); - sockets[m.id].once('close', function() { - process.send({ id: m.id, status: 'closed' }); - }); - sockets[m.id].destroy(); - } - }); - -} else { - var child = fork(process.argv[1], ['child']); - - child.on('exit', function(code, signal) { - if (!childKilled) - throw new Error('child died unexpectedly!'); - }); - - var server = net.createServer(); - var sockets = []; - var sent = 0; - - server.on('connection', function(socket) { - child.send({ cmd: 'new' }, socket, { track: false }); - sockets.push(socket); - - if (sockets.length === count) { - closeSockets(0); - } - }); - - var disconnected = 0; - var clients = []; - server.on('listening', function() { - var j = count, client; - while (j--) { - client = net.connect(common.PORT, '127.0.0.1'); - client.id = j; - client.on('close', function() { - disconnected += 1; - }); - clients.push(client); - } - }); - - var childKilled = false; - function closeSockets(i) { - if (i === count) { - childKilled = true; - server.close(); - child.kill(); - return; - } - - sent++; - child.send({ id: i, cmd: 'close' }); - child.once('message', function(m) { - assert(m.status === 'closed'); - server.getConnections(function(err, num) { - closeSockets(i + 1); - }); - }); - }; - - var closeEmitted = false; - server.on('close', function() { - closeEmitted = true; - }); - - server.listen(common.PORT, '127.0.0.1'); - - process.on('exit', function() { - assert.equal(sent, count); - assert.equal(disconnected, count); - assert.ok(closeEmitted); - console.log('ok'); - }); -} diff --git a/test/simple/test-child-process-fork-net.js b/test/simple/test-child-process-fork-net.js deleted file mode 100644 index feb2588fe25e..000000000000 --- a/test/simple/test-child-process-fork-net.js +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var common = require('../common'); -var fork = require('child_process').fork; -var net = require('net'); - -// progress tracker -function ProgressTracker(missing, callback) { - this.missing = missing; - this.callback = callback; -} -ProgressTracker.prototype.done = function() { - this.missing -= 1; - this.check(); -}; -ProgressTracker.prototype.check = function() { - if (this.missing === 0) this.callback(); -}; - -if (process.argv[2] === 'child') { - - var serverScope; - - process.on('message', function onServer(msg, server) { - if (msg.what !== 'server') return; - process.removeListener('message', onServer); - - serverScope = server; - - server.on('connection', function(socket) { - console.log('CHILD: got connection'); - process.send({what: 'connection'}); - socket.destroy(); - }); - - // start making connection from parent - console.log('CHILD: server listening'); - process.send({what: 'listening'}); - }); - - process.on('message', function onClose(msg) { - if (msg.what !== 'close') return; - process.removeListener('message', onClose); - - serverScope.on('close', function() { - process.send({what: 'close'}); - }); - serverScope.close(); - }); - - process.on('message', function onSocket(msg, socket) { - if (msg.what !== 'socket') return; - process.removeListener('message', onSocket); - socket.end('echo'); - console.log('CHILD: got socket'); - }); - - process.send({what: 'ready'}); -} else { - - var child = fork(process.argv[1], ['child']); - - child.on('exit', function() { - console.log('CHILD: died'); - }); - - // send net.Server to child and test by connecting - var testServer = function(callback) { - - // destroy server execute callback when done - var progress = new ProgressTracker(2, function() { - server.on('close', function() { - console.log('PARENT: server closed'); - child.send({what: 'close'}); - }); - server.close(); - }); - - // we expect 10 connections and close events - var connections = new ProgressTracker(10, progress.done.bind(progress)); - var closed = new ProgressTracker(10, progress.done.bind(progress)); - - // create server and send it to child - var server = net.createServer(); - server.on('connection', function(socket) { - console.log('PARENT: got connection'); - socket.destroy(); - connections.done(); - }); - server.on('listening', function() { - console.log('PARENT: server listening'); - child.send({what: 'server'}, server); - }); - server.listen(common.PORT); - - // handle client messages - var messageHandlers = function(msg) { - - if (msg.what === 'listening') { - // make connections - var socket; - for (var i = 0; i < 10; i++) { - socket = net.connect(common.PORT, function() { - console.log('CLIENT: connected'); - }); - socket.on('close', function() { - closed.done(); - console.log('CLIENT: closed'); - }); - } - - } else if (msg.what === 'connection') { - // child got connection - connections.done(); - } else if (msg.what === 'close') { - child.removeListener('message', messageHandlers); - callback(); - } - }; - - child.on('message', messageHandlers); - }; - - // send net.Socket to child - var testSocket = function(callback) { - - // create a new server and connect to it, - // but the socket will be handled by the child - var server = net.createServer(); - server.on('connection', function(socket) { - socket.on('close', function() { - console.log('CLIENT: socket closed'); - }); - child.send({what: 'socket'}, socket); - }); - server.on('close', function() { - console.log('PARENT: server closed'); - callback(); - }); - // don't listen on the same port, because SmartOS sometimes says - // that the server's fd is closed, but it still cannot listen - // on the same port again. - // - // An isolated test for this would be lovely, but for now, this - // will have to do. - server.listen(common.PORT + 1, function() { - console.error('testSocket, listening'); - var connect = net.connect(common.PORT + 1); - var store = ''; - connect.on('data', function(chunk) { - store += chunk; - console.log('CLIENT: got data'); - }); - connect.on('close', function() { - console.log('CLIENT: closed'); - assert.equal(store, 'echo'); - server.close(); - }); - }); - }; - - // create server and send it to child - var serverSuccess = false; - var socketSuccess = false; - child.on('message', function onReady(msg) { - if (msg.what !== 'ready') return; - child.removeListener('message', onReady); - - testServer(function() { - serverSuccess = true; - - testSocket(function() { - socketSuccess = true; - child.kill(); - }); - }); - - }); - - process.on('exit', function() { - assert.ok(serverSuccess); - assert.ok(socketSuccess); - }); - -} diff --git a/test/simple/test-child-process-fork-net2.js b/test/simple/test-child-process-fork-net2.js deleted file mode 100644 index a8e8039b2741..000000000000 --- a/test/simple/test-child-process-fork-net2.js +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var common = require('../common'); -var fork = require('child_process').fork; -var net = require('net'); -var count = 12; - -if (process.argv[2] === 'child') { - var needEnd = []; - var id = process.argv[3]; - - process.on('message', function(m, socket) { - if (!socket) return; - - console.error('[%d] got socket', id, m); - - // will call .end('end') or .write('write'); - socket[m](m); - - socket.resume(); - - socket.on('data', function() { - console.error('[%d] socket.data', id, m); - }); - - socket.on('end', function() { - console.error('[%d] socket.end', id, m); - }); - - // store the unfinished socket - if (m === 'write') { - needEnd.push(socket); - } - - socket.on('close', function() { - console.error('[%d] socket.close', id, m); - }); - - socket.on('finish', function() { - console.error('[%d] socket finished', id, m); - }); - }); - - process.on('message', function(m) { - if (m !== 'close') return; - console.error('[%d] got close message', id); - needEnd.forEach(function(endMe, i) { - console.error('[%d] ending %d', id, i); - endMe.end('end'); - }); - }); - - process.on('disconnect', function() { - console.error('[%d] process disconnect, ending', id); - needEnd.forEach(function(endMe, i) { - console.error('[%d] ending %d', id, i); - endMe.end('end'); - }); - }); - -} else { - - var child1 = fork(process.argv[1], ['child', '1']); - var child2 = fork(process.argv[1], ['child', '2']); - var child3 = fork(process.argv[1], ['child', '3']); - - var server = net.createServer(); - - var connected = 0, - closed = 0; - server.on('connection', function(socket) { - switch (connected % 6) { - case 0: - child1.send('end', socket, { track: false }); break; - case 1: - child1.send('write', socket, { track: true }); break; - case 2: - child2.send('end', socket, { track: true }); break; - case 3: - child2.send('write', socket, { track: false }); break; - case 4: - child3.send('end', socket, { track: false }); break; - case 5: - child3.send('write', socket, { track: false }); break; - } - connected += 1; - - socket.once('close', function() { - console.log('[m] socket closed, total %d', ++closed); - }); - - if (connected === count) { - closeServer(); - } - }); - - var disconnected = 0; - server.on('listening', function() { - - var j = count, client; - while (j--) { - client = net.connect(common.PORT, '127.0.0.1'); - client.on('close', function() { - console.error('[m] CLIENT: close event'); - disconnected += 1; - }); - // XXX This resume() should be unnecessary. - // a stream high water mark should be enough to keep - // consuming the input. - client.resume(); - } - }); - - var closeEmitted = false; - server.on('close', function() { - console.error('[m] server close'); - closeEmitted = true; - - child1.kill(); - child2.kill(); - child3.kill(); - }); - - server.listen(common.PORT, '127.0.0.1'); - - var timeElasped = 0; - var closeServer = function() { - console.error('[m] closeServer'); - var startTime = Date.now(); - server.on('close', function() { - console.error('[m] emit(close)'); - timeElasped = Date.now() - startTime; - }); - - console.error('[m] calling server.close'); - server.close(); - - setTimeout(function() { - assert(!closeEmitted); - console.error('[m] sending close to children'); - child1.send('close'); - child2.send('close'); - child3.disconnect(); - }, 200); - }; - - process.on('exit', function() { - assert.equal(disconnected, count); - assert.equal(connected, count); - assert.ok(closeEmitted); - assert.ok(timeElasped >= 190 && timeElasped <= 1000, - 'timeElasped was not between 190 and 1000 ms'); - }); -} diff --git a/test/simple/test-child-process-fork-ref.js b/test/simple/test-child-process-fork-ref.js deleted file mode 100644 index 21954ec733b4..000000000000 --- a/test/simple/test-child-process-fork-ref.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fork = require('child_process').fork; - -if (process.argv[2] === 'child') { - process.send('1'); - - // check that child don't instantly die - setTimeout(function() { - process.send('2'); - }, 200); - - process.on('disconnect', function () { - process.stdout.write('3'); - }); - -} else { - var child = fork(__filename, ['child'], {silent: true}); - - var ipc = [], stdout = ''; - - child.on('message', function (msg) { - ipc.push(msg); - - if (msg === '2') child.disconnect(); - }); - - child.stdout.on('data', function (chunk) { - stdout += chunk; - }); - - child.once('exit', function () { - assert.deepEqual(ipc, ['1', '2']); - assert.equal(stdout, '3'); - }); -} diff --git a/test/simple/test-child-process-fork-ref2.js b/test/simple/test-child-process-fork-ref2.js deleted file mode 100644 index 3d604142bbac..000000000000 --- a/test/simple/test-child-process-fork-ref2.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fork = require('child_process').fork; - -if (process.argv[2] === 'child') { - console.log('child -> call disconnect'); - process.disconnect(); - - setTimeout(function() { - console.log('child -> will this keep it alive?'); - process.on('message', function () { }); - }, 400); - -} else { - var child = fork(__filename, ['child']); - - child.on('disconnect', function () { - console.log('parent -> disconnect'); - }); - - child.once('exit', function () { - console.log('parent -> exit'); - }); -} diff --git a/test/simple/test-child-process-fork.js b/test/simple/test-child-process-fork.js deleted file mode 100644 index 41cc28c72e40..000000000000 --- a/test/simple/test-child-process-fork.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var common = require('../common'); -var fork = require('child_process').fork; -var args = ['foo', 'bar']; - -var n = fork(common.fixturesDir + '/child-process-spawn-node.js', args); -assert.deepEqual(args, ['foo', 'bar']); - -var messageCount = 0; - -n.on('message', function(m) { - console.log('PARENT got message:', m); - assert.ok(m.foo); - messageCount++; -}); - -// https://github.com/joyent/node/issues/2355 - JSON.stringify(undefined) -// returns "undefined" but JSON.parse() cannot parse that... -assert.throws(function() { n.send(undefined); }, TypeError); -assert.throws(function() { n.send(); }, TypeError); - -n.send({ hello: 'world' }); - -var childExitCode = -1; -n.on('exit', function(c) { - childExitCode = c; -}); - -process.on('exit', function() { - assert.ok(childExitCode == 0); -}); diff --git a/test/simple/test-child-process-fork3.js b/test/simple/test-child-process-fork3.js deleted file mode 100644 index 0f75b029e339..000000000000 --- a/test/simple/test-child-process-fork3.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var child_process = require('child_process'); - -child_process.fork(common.fixturesDir + '/empty.js'); // should not hang diff --git a/test/simple/test-child-process-internal.js b/test/simple/test-child-process-internal.js deleted file mode 100644 index dd7ce556b52b..000000000000 --- a/test/simple/test-child-process-internal.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -//messages -var PREFIX = 'NODE_'; -var normal = {cmd: 'foo' + PREFIX}; -var internal = {cmd: PREFIX + 'bar'}; - -if (process.argv[2] === 'child') { - //send non-internal message containing PREFIX at a non prefix position - process.send(normal); - - //send inernal message - process.send(internal); - - process.exit(0); - -} else { - - var fork = require('child_process').fork; - var child = fork(process.argv[1], ['child']); - - var gotNormal; - child.once('message', function(data) { - gotNormal = data; - }); - - var gotInternal; - child.once('internalMessage', function(data) { - gotInternal = data; - }); - - process.on('exit', function() { - assert.deepEqual(gotNormal, normal); - assert.deepEqual(gotInternal, internal); - }); -} diff --git a/test/simple/test-child-process-ipc.js b/test/simple/test-child-process-ipc.js deleted file mode 100644 index e8144e439dd3..000000000000 --- a/test/simple/test-child-process-ipc.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var spawn = require('child_process').spawn; - -var path = require('path'); - -var sub = path.join(common.fixturesDir, 'echo.js'); - -var gotHelloWorld = false; -var gotEcho = false; - -var child = spawn(process.argv[0], [sub]); - -child.stderr.on('data', function(data) { - console.log('parent stderr: ' + data); -}); - -child.stdout.setEncoding('utf8'); - -child.stdout.on('data', function(data) { - console.log('child said: ' + JSON.stringify(data)); - if (!gotHelloWorld) { - console.error('testing for hello world'); - assert.equal('hello world\r\n', data); - gotHelloWorld = true; - console.error('writing echo me'); - child.stdin.write('echo me\r\n'); - } else { - console.error('testing for echo me'); - assert.equal('echo me\r\n', data); - gotEcho = true; - child.stdin.end(); - } -}); - -child.stdout.on('end', function(data) { - console.log('child end'); -}); - - -process.on('exit', function() { - assert.ok(gotHelloWorld); - assert.ok(gotEcho); -}); diff --git a/test/simple/test-child-process-kill-throw.js b/test/simple/test-child-process-kill-throw.js deleted file mode 100644 index 4beba7e7a21d..000000000000 --- a/test/simple/test-child-process-kill-throw.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -if (process.argv[2] === 'child') { - process.exit(0); -} else { - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [process.argv[1], 'child']); - - var error = {}; - child.on('exit', function() { - child._handle = { - kill: function() { - process._errno = 42; - return -1; - } - }; - child.once('error', function(err) { - error = err; - }); - child.kill(); - }); - - process.on('exit', function() { - // we shouldn't reset errno since it accturlly isn't set - // because of the fake .kill method - assert.equal(error.syscall, 'kill'); - }); -} diff --git a/test/simple/test-child-process-kill.js b/test/simple/test-child-process-kill.js deleted file mode 100644 index 08a0185d33ae..000000000000 --- a/test/simple/test-child-process-kill.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -var spawn = require('child_process').spawn; - -var is_windows = process.platform === 'win32'; - -var exitCode; -var termSignal; -var gotStdoutEOF = false; -var gotStderrEOF = false; - -var cat = spawn(is_windows ? 'cmd' : 'cat'); - - -cat.stdout.on('end', function() { - gotStdoutEOF = true; -}); - -cat.stderr.on('data', function(chunk) { - assert.ok(false); -}); - -cat.stderr.on('end', function() { - gotStderrEOF = true; -}); - -cat.on('exit', function(code, signal) { - exitCode = code; - termSignal = signal; -}); - -assert.equal(cat.killed, false); -cat.kill(); -assert.equal(cat.killed, true); - -process.on('exit', function() { - assert.strictEqual(exitCode, null); - assert.strictEqual(termSignal, 'SIGTERM'); - assert.ok(gotStdoutEOF); - assert.ok(gotStderrEOF); -}); diff --git a/test/simple/test-child-process-recv-handle.js b/test/simple/test-child-process-recv-handle.js deleted file mode 100644 index dce5bdcbaf74..000000000000 --- a/test/simple/test-child-process-recv-handle.js +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Test that a Linux specific quirk in the handle passing protocol is handled -// correctly. See https://github.com/joyent/node/issues/5330 for details. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var spawn = require('child_process').spawn; - -if (process.argv[2] === 'worker') - worker(); -else - master(); - -function master() { - // spawn() can only create one IPC channel so we use stdin/stdout as an - // ad-hoc command channel. - var proc = spawn(process.execPath, [__filename, 'worker'], { - stdio: ['pipe', 'pipe', 'pipe', 'ipc'] - }); - var handle = null; - proc.on('exit', function() { - handle.close(); - }); - proc.stdout.on('data', function(data) { - assert.equal(data, 'ok\r\n'); - net.createServer(assert.fail).listen(common.PORT, function() { - handle = this._handle; - proc.send('one'); - proc.send('two', handle); - proc.send('three'); - proc.stdin.write('ok\r\n'); - }); - }); - proc.stderr.pipe(process.stderr); -} - -function worker() { - process._channel.readStop(); // Make messages batch up. - process.stdout.ref(); - process.stdout.write('ok\r\n'); - process.stdin.once('data', function(data) { - assert.equal(data, 'ok\r\n'); - process._channel.readStart(); - }); - var n = 0; - process.on('message', function(msg, handle) { - n += 1; - if (n === 1) { - assert.equal(msg, 'one'); - assert.equal(handle, undefined); - } - else if (n === 2) { - assert.equal(msg, 'two'); - assert.equal(typeof handle, 'object'); // Also matches null, therefore... - assert.ok(handle); // also check that it's truthy. - handle.close(); - } - else if (n === 3) { - assert.equal(msg, 'three'); - assert.equal(handle, undefined); - process.exit(); - } - }); -} diff --git a/test/simple/test-child-process-send-utf8.js b/test/simple/test-child-process-send-utf8.js deleted file mode 100644 index b3ce24390ed7..000000000000 --- a/test/simple/test-child-process-send-utf8.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fork = require('child_process').fork; - -var expected = Array(1e5).join('ßßßß'); -if (process.argv[2] === 'child') { - process.send(expected); -} else { - var child = fork(process.argv[1], ['child']); - child.on('message', common.mustCall(function(actual) { - assert.equal(actual, expected); - })); -} diff --git a/test/simple/test-child-process-set-blocking.js b/test/simple/test-child-process-set-blocking.js deleted file mode 100644 index 030b6829c63b..000000000000 --- a/test/simple/test-child-process-set-blocking.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var ch = require('child_process'); - -var SIZE = 100000; -var childGone = false; - -var cp = ch.spawn('python', ['-c', 'print ' + SIZE + ' * "C"'], { - customFds: [0, 1, 2] -}); - -cp.on('exit', function(code) { - childGone = true; - assert.equal(0, code); -}); - -process.on('exit', function() { - assert.ok(childGone); -}); diff --git a/test/simple/test-child-process-silent.js b/test/simple/test-child-process-silent.js deleted file mode 100644 index e34daa3a833e..000000000000 --- a/test/simple/test-child-process-silent.js +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var childProcess = require('child_process'); - -// Child pipe test -if (process.argv[2] === 'pipetest') { - process.stdout.write('stdout message'); - process.stderr.write('stderr message'); - -} else if (process.argv[2] === 'ipctest') { - // Child IPC test - process.send('message from child'); - process.on('message', function() { - process.send('got message from master'); - }); - -} else if (process.argv[2] === 'parent') { - // Parent | start child pipe test - - var child = childProcess.fork(process.argv[1], ['pipetest'], {silent: true}); - - // Allow child process to self terminate - child._channel.close(); - child._channel = null; - - child.on('exit', function() { - process.exit(0); - }); - -} else { - // testcase | start parent && child IPC test - - // testing: is stderr and stdout piped to parent - var args = [process.argv[1], 'parent']; - var parent = childProcess.spawn(process.execPath, args); - - //got any stderr or std data - var stdoutData = false; - parent.stdout.on('data', function() { - stdoutData = true; - }); - var stderrData = false; - parent.stdout.on('data', function() { - stderrData = true; - }); - - // testing: do message system work when using silent - var child = childProcess.fork(process.argv[1], ['ipctest'], {silent: true}); - - // Manual pipe so we will get errors - child.stderr.pipe(process.stderr, {end: false}); - child.stdout.pipe(process.stdout, {end: false}); - - var childSending = false; - var childReciveing = false; - child.on('message', function(message) { - if (childSending === false) { - childSending = (message === 'message from child'); - } - - if (childReciveing === false) { - childReciveing = (message === 'got message from master'); - } - - if (childReciveing === true) { - child.kill(); - } - }); - child.send('message to child'); - - // Check all values - process.on('exit', function() { - // clean up - child.kill(); - parent.kill(); - - // Check std(out|err) pipes - assert.ok(!stdoutData, 'The stdout socket was piped to parent'); - assert.ok(!stderrData, 'The stderr socket was piped to parent'); - - // Check message system - assert.ok(childSending, 'The child was able to send a message'); - assert.ok(childReciveing, 'The child was able to receive a message'); - }); -} diff --git a/test/simple/test-child-process-spawn-typeerror.js b/test/simple/test-child-process-spawn-typeerror.js deleted file mode 100644 index d0adacc7f339..000000000000 --- a/test/simple/test-child-process-spawn-typeerror.js +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var child_process = require('child_process'); -var spawn = child_process.spawn; -var fork = child_process.fork; -var execFile = child_process.execFile; -var cmd = (process.platform === 'win32') ? 'rundll32' : 'ls'; -var empty = require('../common').fixturesDir + '/empty.js'; - -// Argument types for combinatorics -var a=[], o={}, c=(function callback(){}), s='string', u=undefined, n=null; - -// function spawn(file=f [,args=a] [, options=o]) has valid combinations: -// (f) -// (f, a) -// (f, a, o) -// (f, o) -assert.doesNotThrow(function() { spawn(cmd); }); -assert.doesNotThrow(function() { spawn(cmd, a); }); -assert.doesNotThrow(function() { spawn(cmd, a, o); }); -assert.doesNotThrow(function() { spawn(cmd, o); }); - -// Variants of undefined as explicit 'no argument' at a position -assert.doesNotThrow(function() { spawn(cmd, u, o); }); -assert.doesNotThrow(function() { spawn(cmd, a, u); }); -assert.doesNotThrow(function() { spawn(cmd, n, o); }); -assert.doesNotThrow(function() { spawn(cmd, a, n); }); - -assert.throws(function() { spawn(cmd, s); }, TypeError); -assert.doesNotThrow(function() { spawn(cmd, a, s); }, TypeError); - - -// verify that execFile has same argument parsing behaviour as spawn -// -// function execFile(file=f [,args=a] [, options=o] [, callback=c]) has valid -// combinations: -// (f) -// (f, a) -// (f, a, o) -// (f, a, o, c) -// (f, a, c) -// (f, o) -// (f, o, c) -// (f, c) -assert.doesNotThrow(function() { execFile(cmd); }); -assert.doesNotThrow(function() { execFile(cmd, a); }); -assert.doesNotThrow(function() { execFile(cmd, a, o); }); -assert.doesNotThrow(function() { execFile(cmd, a, o, c); }); -assert.doesNotThrow(function() { execFile(cmd, a, c); }); -assert.doesNotThrow(function() { execFile(cmd, o); }); -assert.doesNotThrow(function() { execFile(cmd, o, c); }); -assert.doesNotThrow(function() { execFile(cmd, c); }); - -// Variants of undefined as explicit 'no argument' at a position -assert.doesNotThrow(function() { execFile(cmd, u, o, c); }); -assert.doesNotThrow(function() { execFile(cmd, a, u, c); }); -assert.doesNotThrow(function() { execFile(cmd, a, o, u); }); -assert.doesNotThrow(function() { execFile(cmd, n, o, c); }); -assert.doesNotThrow(function() { execFile(cmd, a, n, c); }); -assert.doesNotThrow(function() { execFile(cmd, a, o, n); }); - -// string is invalid in arg position (this may seem strange, but is -// consistent across node API, cf. `net.createServer('not options', 'not -// callback')` -assert.throws(function() { execFile(cmd, s, o, c); }, TypeError); -assert.doesNotThrow(function() { execFile(cmd, a, s, c); }); -assert.doesNotThrow(function() { execFile(cmd, a, o, s); }); - - -// verify that fork has same argument parsing behaviour as spawn -// -// function fork(file=f [,args=a] [, options=o]) has valid combinations: -// (f) -// (f, a) -// (f, a, o) -// (f, o) -assert.doesNotThrow(function() { fork(empty); }); -assert.doesNotThrow(function() { fork(empty, a); }); -assert.doesNotThrow(function() { fork(empty, a, o); }); -assert.doesNotThrow(function() { fork(empty, o); }); - -assert.throws(function() { fork(empty, s); }, TypeError); -assert.doesNotThrow(function() { fork(empty, a, s); }, TypeError); diff --git a/test/simple/test-child-process-stdin.js b/test/simple/test-child-process-stdin.js deleted file mode 100644 index fdb40cc82c47..000000000000 --- a/test/simple/test-child-process-stdin.js +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var spawn = require('child_process').spawn; -var is_windows = process.platform === 'win32'; - -var cat = spawn(is_windows ? 'more' : 'cat'); -cat.stdin.write('hello'); -cat.stdin.write(' '); -cat.stdin.write('world'); - -assert.ok(cat.stdin.writable); -assert.ok(!cat.stdin.readable); - -cat.stdin.end(); - -var response = ''; -var exitStatus = -1; -var closed = false; - -var gotStdoutEOF = false; - -cat.stdout.setEncoding('utf8'); -cat.stdout.on('data', function(chunk) { - console.log('stdout: ' + chunk); - response += chunk; -}); - -cat.stdout.on('end', function() { - gotStdoutEOF = true; -}); - - -var gotStderrEOF = false; - -cat.stderr.on('data', function(chunk) { - // shouldn't get any stderr output - assert.ok(false); -}); - -cat.stderr.on('end', function(chunk) { - gotStderrEOF = true; -}); - - -cat.on('exit', function(status) { - console.log('exit event'); - exitStatus = status; -}); - -cat.on('close', function () { - closed = true; - if (is_windows) { - assert.equal('hello world\r\n', response); - } else { - assert.equal('hello world', response); - } -}); - -process.on('exit', function() { - assert.equal(0, exitStatus); - assert(closed); - if (is_windows) { - assert.equal('hello world\r\n', response); - } else { - assert.equal('hello world', response); - } -}); diff --git a/test/simple/test-child-process-stdio-big-write-end.js b/test/simple/test-child-process-stdio-big-write-end.js deleted file mode 100644 index 845a23e661a0..000000000000 --- a/test/simple/test-child-process-stdio-big-write-end.js +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var BUFSIZE = 1024; - -switch (process.argv[2]) { - case undefined: - return parent(); - case 'child': - return child(); - default: - throw new Error('wtf?'); -} - -function parent() { - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child']); - var sent = 0; - - var n = ''; - child.stdout.setEncoding('ascii'); - child.stdout.on('data', function(c) { - n += c; - }); - child.stdout.on('end', function() { - assert.equal(+n, sent); - console.log('ok'); - }); - - // Write until the buffer fills up. - do { - var buf = new Buffer(BUFSIZE); - buf.fill('.'); - sent += BUFSIZE; - } while (child.stdin.write(buf)); - - // then write a bunch more times. - for (var i = 0; i < 100; i++) { - var buf = new Buffer(BUFSIZE); - buf.fill('.'); - sent += BUFSIZE; - child.stdin.write(buf); - } - - // now end, before it's all flushed. - child.stdin.end(); - - // now we wait... -} - -function child() { - var received = 0; - process.stdin.on('data', function(c) { - received += c.length; - }); - process.stdin.on('end', function() { - console.log(received); - }); -} diff --git a/test/simple/test-child-process-stdio-inherit.js b/test/simple/test-child-process-stdio-inherit.js deleted file mode 100644 index f7776fecb9a4..000000000000 --- a/test/simple/test-child-process-stdio-inherit.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; - -if (process.argv[2] === 'parent') - parent(); -else - grandparent(); - -function grandparent() { - var child = spawn(process.execPath, [__filename, 'parent']); - child.stderr.pipe(process.stderr); - var output = ''; - var input = 'asdfasdf'; - - child.stdout.on('data', function(chunk) { - output += chunk; - }); - child.stdout.setEncoding('utf8'); - - child.stdin.end(input); - - child.on('close', function(code, signal) { - assert.equal(code, 0); - assert.equal(signal, null); - // cat on windows adds a \r\n at the end. - assert.equal(output.trim(), input.trim()); - }); -} - -function parent() { - // should not immediately exit. - var child = common.spawnCat({ stdio: 'inherit' }); -} diff --git a/test/simple/test-child-process-stdio.js b/test/simple/test-child-process-stdio.js deleted file mode 100644 index 32da15f5f5c8..000000000000 --- a/test/simple/test-child-process-stdio.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; - -var options = {stdio: ['pipe']}; -var child = common.spawnPwd(options); - -assert.notEqual(child.stdout, null); -assert.notEqual(child.stderr, null); - -options = {stdio: 'ignore'}; -child = common.spawnPwd(options); - -assert.equal(child.stdout, null); -assert.equal(child.stderr, null); diff --git a/test/simple/test-child-process-stdout-flush.js b/test/simple/test-child-process-stdout-flush.js deleted file mode 100644 index adb33f5c0354..000000000000 --- a/test/simple/test-child-process-stdout-flush.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var spawn = require('child_process').spawn; -var sub = path.join(common.fixturesDir, 'print-chars.js'); - -var n = 500000; - -var child = spawn(process.argv[0], [sub, n]); - -var count = 0; - -child.stderr.setEncoding('utf8'); -child.stderr.on('data', function(data) { - console.log('parent stderr: ' + data); - assert.ok(false); -}); - -child.stdout.setEncoding('utf8'); -child.stdout.on('data', function(data) { - count += data.length; - console.log(count); -}); - -child.on('close', function(data) { - assert.equal(n, count); - console.log('okay'); -}); diff --git a/test/simple/test-cli-eval.js b/test/simple/test-cli-eval.js deleted file mode 100644 index acb85d4caa16..000000000000 --- a/test/simple/test-cli-eval.js +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (module.parent) { - // signal we've been loaded as a module - console.log('Loaded as a module, exiting with status code 42.'); - process.exit(42); -} - -var common = require('../common.js'), - assert = require('assert'), - child = require('child_process'), - nodejs = '"' + process.execPath + '"'; - - -// replace \ by / because windows uses backslashes in paths, but they're still -// interpreted as the escape character when put between quotes. -var filename = __filename.replace(/\\/g, '/'); - -// assert that nothing is written to stdout -child.exec(nodejs + ' --eval 42', - function(err, stdout, stderr) { - assert.equal(stdout, ''); - assert.equal(stderr, ''); - }); - -// assert that "42\n" is written to stderr -child.exec(nodejs + ' --eval "console.error(42)"', - function(err, stdout, stderr) { - assert.equal(stdout, ''); - assert.equal(stderr, '42\n'); - }); - -// assert that the expected output is written to stdout -['--print', '-p -e', '-pe', '-p'].forEach(function(s) { - var cmd = nodejs + ' ' + s + ' '; - - child.exec(cmd + '42', - function(err, stdout, stderr) { - assert.equal(stdout, '42\n'); - assert.equal(stderr, ''); - }); - - child.exec(cmd + "'[]'", - function(err, stdout, stderr) { - assert.equal(stdout, '[]\n'); - assert.equal(stderr, ''); - }); -}); - -// assert that module loading works -child.exec(nodejs + ' --eval "require(\'' + filename + '\')"', - function(status, stdout, stderr) { - assert.equal(status.code, 42); - }); - -// module path resolve bug, regression test -child.exec(nodejs + ' --eval "require(\'./test/simple/test-cli-eval.js\')"', - function(status, stdout, stderr) { - assert.equal(status.code, 42); - }); - -// empty program should do nothing -child.exec(nodejs + ' -e ""', function(status, stdout, stderr) { - assert.equal(stdout, ''); - assert.equal(stderr, ''); -}); - -// "\\-42" should be interpreted as an escaped expression, not a switch -child.exec(nodejs + ' -p "\\-42"', - function(err, stdout, stderr) { - assert.equal(stdout, '-42\n'); - assert.equal(stderr, ''); - }); diff --git a/test/simple/test-cluster-basic.js b/test/simple/test-cluster-basic.js deleted file mode 100644 index e6adfb5bad23..000000000000 --- a/test/simple/test-cluster-basic.js +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); - -assert.equal('NODE_UNIQUE_ID' in process.env, false, - 'NODE_UNIQUE_ID should be removed on startup'); - -function forEach(obj, fn) { - Object.keys(obj).forEach(function(name, index) { - fn(obj[name], name, index); - }); -} - - -if (cluster.isWorker) { - var http = require('http'); - http.Server(function() { - - }).listen(common.PORT, '127.0.0.1'); -} - -else if (cluster.isMaster) { - - var checks = { - cluster: { - events: { - fork: false, - online: false, - listening: false, - exit: false - }, - equal: { - fork: false, - online: false, - listening: false, - exit: false - } - }, - - worker: { - events: { - online: false, - listening: false, - exit: false - }, - equal: { - online: false, - listening: false, - exit: false - }, - states: { - none: false, - online: false, - listening: false, - dead: false - } - } - }; - - var worker; - var stateNames = Object.keys(checks.worker.states); - - //Check events, states, and emit arguments - forEach(checks.cluster.events, function(bool, name, index) { - - //Listen on event - cluster.on(name, function(/* worker */) { - - //Set event - checks.cluster.events[name] = true; - - //Check argument - checks.cluster.equal[name] = worker === arguments[0]; - - //Check state - var state = stateNames[index]; - checks.worker.states[state] = (state === worker.state); - }); - }); - - //Kill worker when listening - cluster.on('listening', function() { - worker.kill(); - }); - - //Kill process when worker is killed - cluster.on('exit', function() { - process.exit(0); - }); - - //Create worker - worker = cluster.fork(); - assert.equal(worker.id, 1); - assert.ok(worker instanceof cluster.Worker, - 'the worker is not a instance of the Worker constructor'); - - //Check event - forEach(checks.worker.events, function(bool, name, index) { - worker.on(name, function() { - //Set event - checks.worker.events[name] = true; - - //Check argument - checks.worker.equal[name] = (worker === this); - - switch (name) { - case 'exit': - assert.equal(arguments[0], worker.process.exitCode); - assert.equal(arguments[1], worker.process.signalCode); - assert.equal(arguments.length, 2); - break; - - case 'listening': - assert.equal(arguments.length, 1); - var expect = { address: '127.0.0.1', - port: common.PORT, - addressType: 4, - fd: undefined }; - assert.deepEqual(arguments[0], expect); - break; - - default: - assert.equal(arguments.length, 0); - break; - } - }); - }); - - //Check all values - process.once('exit', function() { - //Check cluster events - forEach(checks.cluster.events, function(check, name) { - assert.ok(check, 'The cluster event "' + name + '" on the cluster ' + - 'object did not fire'); - }); - - //Check cluster event arguments - forEach(checks.cluster.equal, function(check, name) { - assert.ok(check, 'The cluster event "' + name + '" did not emit ' + - 'with correct argument'); - }); - - //Check worker states - forEach(checks.worker.states, function(check, name) { - assert.ok(check, 'The worker state "' + name + '" was not set to true'); - }); - - //Check worker events - forEach(checks.worker.events, function(check, name) { - assert.ok(check, 'The worker event "' + name + '" on the worker object ' + - 'did not fire'); - }); - - //Check worker event arguments - forEach(checks.worker.equal, function(check, name) { - assert.ok(check, 'The worker event "' + name + '" did not emit with ' + - 'corrent argument'); - }); - }); - -} diff --git a/test/simple/test-cluster-bind-twice-v1.js b/test/simple/test-cluster-bind-twice-v1.js deleted file mode 100644 index 068842fa535f..000000000000 --- a/test/simple/test-cluster-bind-twice-v1.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// This test starts two clustered HTTP servers on the same port. It expects the -// first cluster to succeed and the second cluster to fail with EADDRINUSE. - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var fork = require('child_process').fork; -var http = require('http'); - -var id = process.argv[2]; - -if (!id) { - var a = fork(__filename, ['one']); - var b = fork(__filename, ['two']); - - a.on('message', function(m) { - assert.equal(m, 'READY'); - b.send('START'); - }); - - var ok = false; - - b.on('message', function(m) { - assert.equal(m, 'EADDRINUSE'); - a.kill(); - b.kill(); - ok = true; - }); - - process.on('exit', function() { - a.kill(); - b.kill(); - assert(ok); - }); -} -else if (id === 'one') { - if (cluster.isMaster) cluster.fork(); - http.createServer(assert.fail).listen(common.PORT, function() { - process.send('READY'); - }); -} -else if (id === 'two') { - if (cluster.isMaster) cluster.fork(); - process.on('message', function(m) { - assert.equal(m, 'START'); - var server = http.createServer(assert.fail); - server.listen(common.PORT, assert.fail); - server.on('error', function(e) { - assert.equal(e.code, 'EADDRINUSE'); - process.send(e.code); - }); - }); -} -else { - assert(0); // bad command line argument -} diff --git a/test/simple/test-cluster-bind-twice-v2.js b/test/simple/test-cluster-bind-twice-v2.js deleted file mode 100644 index dc059edc7c52..000000000000 --- a/test/simple/test-cluster-bind-twice-v2.js +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// This test starts two clustered HTTP servers on the same port. It expects the -// first cluster to succeed and the second cluster to fail with EADDRINUSE. -// -// The test may seem complex but most of it is plumbing that routes messages -// from the child processes back to the supervisor. As a tree it looks something -// like this: -// -// -// / \ -// -// / \ -// -// -// The first worker starts a server on a fixed port and fires a ready message -// that is routed to the second worker. When it tries to bind, it expects to -// see an EADDRINUSE error. -// -// See https://github.com/joyent/node/issues/2721 for more details. - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var fork = require('child_process').fork; -var http = require('http'); - -var id = process.argv[2]; - -if (!id) { - var a = fork(__filename, ['one']); - var b = fork(__filename, ['two']); - - a.on('exit', function(c) { - if (c) - throw new Error('A exited with ' + c); - }); - - b.on('exit', function(c) { - if (c) - throw new Error('B exited with ' + c); - }); - - - a.on('message', function(m) { - if (typeof m === 'object') return; - assert.equal(m, 'READY'); - b.send('START'); - }); - - var ok = false; - - b.on('message', function(m) { - if (typeof m === 'object') return; // ignore system messages - assert.equal(m, 'EADDRINUSE'); - a.kill(); - b.kill(); - ok = true; - }); - - process.on('exit', function() { - a.kill(); - b.kill(); - assert(ok); - }); -} -else if (id === 'one') { - if (cluster.isMaster) return startWorker(); - - http.createServer(assert.fail).listen(common.PORT, function() { - process.send('READY'); - }); -} -else if (id === 'two') { - if (cluster.isMaster) return startWorker(); - - var ok = false; - process.on('SIGTERM', process.exit); - process.on('exit', function() { - assert(ok); - }); - - process.on('message', function(m) { - if (typeof m === 'object') return; // ignore system messages - assert.equal(m, 'START'); - var server = http.createServer(assert.fail); - server.listen(common.PORT, assert.fail); - server.on('error', function(e) { - assert.equal(e.code, 'EADDRINUSE'); - process.send(e.code); - ok = true; - }); - }); -} -else { - assert(0); // bad command line argument -} - -function startWorker() { - var worker = cluster.fork(); - worker.on('message', process.send.bind(process)); - process.on('message', worker.send.bind(worker)); - process.on('SIGTERM', function() { - worker.destroy(); - process.exit(); - }); -} diff --git a/test/simple/test-cluster-dgram-1.js b/test/simple/test-cluster-dgram-1.js deleted file mode 100644 index c6dc095d0832..000000000000 --- a/test/simple/test-cluster-dgram-1.js +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var NUM_WORKERS = 4; -var PACKETS_PER_WORKER = 10; - -var assert = require('assert'); -var cluster = require('cluster'); -var common = require('../common'); -var dgram = require('dgram'); - - -if (process.platform === 'win32') { - console.warn("dgram clustering is currently not supported on windows."); - process.exit(0); -} - -if (cluster.isMaster) - master(); -else - worker(); - - -function master() { - var listening = 0; - - // Fork 4 workers. - for (var i = 0; i < NUM_WORKERS; i++) - cluster.fork(); - - // Wait until all workers are listening. - cluster.on('listening', function() { - if (++listening < NUM_WORKERS) - return; - - // Start sending messages. - var buf = new Buffer('hello world'); - var socket = dgram.createSocket('udp4'); - var sent = 0; - doSend(); - - function doSend() { - socket.send(buf, 0, buf.length, common.PORT, '127.0.0.1', afterSend); - } - - function afterSend() { - sent++; - if (sent < NUM_WORKERS * PACKETS_PER_WORKER) { - doSend(); - } else { - console.log('master sent %d packets', sent); - socket.close(); - } - } - }); - - // Set up event handlers for every worker. Each worker sends a message when - // it has received the expected number of packets. After that it disconnects. - for (var key in cluster.workers) { - if (cluster.workers.hasOwnProperty(key)) - setupWorker(cluster.workers[key]); - } - - function setupWorker(worker) { - var received = 0; - - worker.on('message', function(msg) { - received = msg.received; - console.log('worker %d received %d packets', worker.id, received); - }); - - worker.on('disconnect', function() { - assert(received === PACKETS_PER_WORKER); - console.log('worker %d disconnected', worker.id); - }); - } -} - - -function worker() { - var received = 0; - - // Create udp socket and start listening. - var socket = dgram.createSocket('udp4'); - - socket.on('message', function(data, info) { - received++; - - // Every 10 messages, notify the master. - if (received == PACKETS_PER_WORKER) { - process.send({received: received}); - process.disconnect(); - } - }); - - socket.bind(common.PORT); -} diff --git a/test/simple/test-cluster-dgram-2.js b/test/simple/test-cluster-dgram-2.js deleted file mode 100644 index d06ad7935a7f..000000000000 --- a/test/simple/test-cluster-dgram-2.js +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following condonitions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var NUM_WORKERS = 4; -var PACKETS_PER_WORKER = 10; - -var assert = require('assert'); -var cluster = require('cluster'); -var common = require('../common'); -var dgram = require('dgram'); - - -if (process.platform === 'win32') { - console.warn("dgram clustering is currently not supported on windows."); - process.exit(0); -} - -if (cluster.isMaster) - master(); -else - worker(); - - -function master() { - var i; - var received = 0; - - // Start listening on a socket. - var socket = dgram.createSocket('udp4'); - socket.bind(common.PORT); - - // Disconnect workers when the expected number of messages have been - // received. - socket.on('message', function(data, info) { - received++; - - if (received == PACKETS_PER_WORKER * NUM_WORKERS) { - console.log('master received %d packets', received); - - // Close the socket. - socket.close(); - - // Disconnect all workers. - cluster.disconnect(); - } - }); - - // Fork workers. - for (var i = 0; i < NUM_WORKERS; i++) - cluster.fork(); -} - - -function worker() { - // Create udp socket and send packets to master. - var socket = dgram.createSocket('udp4'); - var buf = new Buffer('hello world'); - - for (var i = 0; i < PACKETS_PER_WORKER; i++) - socket.send(buf, 0, buf.length, common.PORT, '127.0.0.1'); - - console.log('worker %d sent %d packets', cluster.worker.id, PACKETS_PER_WORKER); -} diff --git a/test/simple/test-cluster-disconnect-with-no-workers.js b/test/simple/test-cluster-disconnect-with-no-workers.js deleted file mode 100644 index 48e3b0925995..000000000000 --- a/test/simple/test-cluster-disconnect-with-no-workers.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var cluster = require('cluster'); - -var disconnected; - -process.on('exit', function() { - assert(disconnected); -}); - -cluster.disconnect(function() { - disconnected = true; -}); - -// Assert that callback is not sometimes synchronous -assert(!disconnected); diff --git a/test/simple/test-cluster-disconnect.js b/test/simple/test-cluster-disconnect.js deleted file mode 100644 index 8fbdb9338514..000000000000 --- a/test/simple/test-cluster-disconnect.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); - -if (cluster.isWorker) { - net.createServer(function(socket) { - socket.end('echo'); - }).listen(common.PORT, '127.0.0.1'); - - net.createServer(function(socket) { - socket.end('echo'); - }).listen(common.PORT + 1, '127.0.0.1'); - -} else if (cluster.isMaster) { - - // test a single TCP server - var testConnection = function(port, cb) { - var socket = net.connect(port, '127.0.0.1', function() { - // buffer result - var result = ''; - socket.on('data', function(chunk) { result += chunk; }); - - // check result - socket.on('end', function() { - cb(result === 'echo'); - }); - }); - }; - - // test both servers created in the cluster - var testCluster = function(cb) { - var servers = 2; - var done = 0; - - for (var i = 0, l = servers; i < l; i++) { - testConnection(common.PORT + i, function(success) { - assert.ok(success); - done += 1; - if (done === servers) { - cb(); - } - }); - } - }; - - // start two workers and execute callback when both is listening - var startCluster = function(cb) { - var workers = 8; - var online = 0; - - for (var i = 0, l = workers; i < l; i++) { - - var worker = cluster.fork(); - worker.on('listening', function() { - online += 1; - if (online === workers) { - cb(); - } - }); - } - }; - - - var results = { - start: 0, - test: 0, - disconnect: 0 - }; - - var test = function(again) { - //1. start cluster - startCluster(function() { - results.start += 1; - - //2. test cluster - testCluster(function() { - results.test += 1; - - //3. disconnect cluster - cluster.disconnect(function() { - results.disconnect += 1; - - // run test again to confirm cleanup - if (again) { - test(); - } - }); - }); - }); - }; - - test(true); - - process.once('exit', function() { - assert.equal(results.start, 2); - assert.equal(results.test, 2); - assert.equal(results.disconnect, 2); - }); -} diff --git a/test/simple/test-cluster-eaccess.js b/test/simple/test-cluster-eaccess.js deleted file mode 100644 index c87dfe83b3bd..000000000000 --- a/test/simple/test-cluster-eaccess.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var path = require('path'); -var fs = require('fs'); -var net = require('net'); - -var socketPath = path.join(common.fixturesDir, 'socket-path'); - -if (cluster.isMaster) { - var worker = cluster.fork(); - var gotError = 0; - worker.on('message', function(err) { - gotError++; - console.log(err); - if (process.platform === 'win32') - assert.strictEqual('EACCES', err.code); - else - assert.strictEqual('EADDRINUSE', err.code); - worker.disconnect(); - }); - process.on('exit', function() { - console.log('master exited'); - try { - fs.unlinkSync(socketPath); - } catch (e) { - } - assert.equal(gotError, 1); - }); -} else { - fs.writeFileSync(socketPath, 'some contents'); - - var server = net.createServer().listen(socketPath, function() { - console.log('here'); - }); - - server.on('error', function(err) { - process.send(err); - }); -} diff --git a/test/simple/test-cluster-eaddrinuse.js b/test/simple/test-cluster-eaddrinuse.js deleted file mode 100644 index 73b1df0a5476..000000000000 --- a/test/simple/test-cluster-eaddrinuse.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Check that having a worker bind to a port that's already taken doesn't -// leave the master process in a confused state. Releasing the port and -// trying again should Just Work[TM]. - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var fork = require('child_process').fork; -var net = require('net'); - -var id = '' + process.argv[2]; - -if (id === 'undefined') { - var server = net.createServer(assert.fail); - server.listen(common.PORT, function() { - var worker = fork(__filename, ['worker']); - worker.on('message', function(msg) { - if (msg !== 'stop-listening') return; - server.close(function() { - worker.send('stopped-listening'); - }); - }); - }); -} -else if (id === 'worker') { - var server = net.createServer(assert.fail); - server.listen(common.PORT, assert.fail); - server.on('error', common.mustCall(function(e) { - assert(e.code, 'EADDRINUSE'); - process.send('stop-listening'); - process.once('message', function(msg) { - if (msg !== 'stopped-listening') return; - server = net.createServer(assert.fail); - server.listen(common.PORT, common.mustCall(function() { - server.close(); - })); - }); - })); -} -else { - assert(0); // Bad argument. -} diff --git a/test/simple/test-cluster-fork-env.js b/test/simple/test-cluster-fork-env.js deleted file mode 100644 index a0b50aebdc33..000000000000 --- a/test/simple/test-cluster-fork-env.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); - -if (cluster.isWorker) { - cluster.worker.send({ - prop: process.env['cluster_test_prop'], - overwrite: process.env['cluster_test_overwrite'] - }); - -} else if (cluster.isMaster) { - - var checks = { - using: false, - overwrite: false - }; - - // To check that the cluster extend on the process.env we will overwrite a - // property - process.env['cluster_test_overwrite'] = 'old'; - - // Fork worker - var worker = cluster.fork({ - 'cluster_test_prop': 'custom', - 'cluster_test_overwrite': 'new' - }); - - // Checks worker env - worker.on('message', function(data) { - checks.using = (data.prop === 'custom'); - checks.overwrite = (data.overwrite === 'new'); - process.exit(0); - }); - - process.once('exit', function() { - assert.ok(checks.using, 'The worker did not receive the correct env.'); - assert.ok(checks.overwrite, 'The custom environment did not overwrite ' + - 'the existing environment.'); - }); - -} diff --git a/test/simple/test-cluster-http-pipe.js b/test/simple/test-cluster-http-pipe.js deleted file mode 100644 index 7123bf62756f..000000000000 --- a/test/simple/test-cluster-http-pipe.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// It is not possible to send pipe handles over the IPC pipe on Windows. -if (process.platform === 'win32') { - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var http = require('http'); - -if (cluster.isMaster) { - var ok = false; - var worker = cluster.fork(); - worker.on('message', function(msg) { - assert.equal(msg, 'DONE'); - ok = true; - }); - worker.on('exit', function() { - process.exit(); - }); - process.on('exit', function() { - assert(ok); - }); - return; -} - -http.createServer(function(req, res) { - assert.equal(req.connection.remoteAddress, undefined); - assert.equal(req.connection.localAddress, undefined); // TODO common.PIPE? - res.writeHead(200); - res.end('OK'); -}).listen(common.PIPE, function() { - var self = this; - http.get({ socketPath: common.PIPE, path: '/' }, function(res) { - res.resume(); - res.on('end', function(err) { - if (err) throw err; - process.send('DONE'); - process.exit(); - }); - }); -}); diff --git a/test/simple/test-cluster-listening-port.js b/test/simple/test-cluster-listening-port.js deleted file mode 100644 index 352c4d757eba..000000000000 --- a/test/simple/test-cluster-listening-port.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); - -if (cluster.isMaster) { - var port = null; - cluster.fork(); - cluster.on('listening', function(worker, address) { - port = address.port; - // ensure that the port is not 0 or null - assert(port); - // ensure that the port is numerical - assert.strictEqual(typeof(port), 'number'); - worker.kill(); - }); - process.on('exit', function() { - // ensure that the 'listening' handler has been called - assert(port); - }); -} -else { - net.createServer(assert.fail).listen(0); -} diff --git a/test/simple/test-cluster-master-error.js b/test/simple/test-cluster-master-error.js deleted file mode 100644 index ee2ed9eb4ee5..000000000000 --- a/test/simple/test-cluster-master-error.js +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); - -// Cluster setup -if (cluster.isWorker) { - var http = require('http'); - http.Server(function() { - - }).listen(common.PORT, '127.0.0.1'); - -} else if (process.argv[2] === 'cluster') { - - var totalWorkers = 2; - - // Send PID to testcase process - var forkNum = 0; - cluster.on('fork', function forkEvent(worker) { - - // Send PID - process.send({ - cmd: 'worker', - workerPID: worker.process.pid - }); - - // Stop listening when done - if (++forkNum === totalWorkers) { - cluster.removeListener('fork', forkEvent); - } - }); - - // Throw accidently error when all workers are listening - var listeningNum = 0; - cluster.on('listening', function listeningEvent() { - - // When all workers are listening - if (++listeningNum === totalWorkers) { - // Stop listening - cluster.removeListener('listening', listeningEvent); - - // throw accidently error - process.nextTick(function() { - console.error('about to throw'); - throw new Error('accidently error'); - }); - } - - }); - - // Startup a basic cluster - cluster.fork(); - cluster.fork(); - -} else { - // This is the testcase - - var fork = require('child_process').fork; - - var isAlive = function(pid) { - try { - //this will throw an error if the process is dead - process.kill(pid, 0); - - return true; - } catch (e) { - return false; - } - }; - - var existMaster = false; - var existWorker = false; - - // List all workers - var workers = []; - - // Spawn a cluster process - var master = fork(process.argv[1], ['cluster'], {silent: true}); - - // Handle messages from the cluster - master.on('message', function(data) { - - // Add worker pid to list and progress tracker - if (data.cmd === 'worker') { - workers.push(data.workerPID); - } - }); - - // When cluster is dead - master.on('exit', function(code) { - - // Check that the cluster died accidently - existMaster = !!code; - - // Give the workers time to shut down - setTimeout(checkWorkers, 200); - - function checkWorkers() { - // When master is dead all workers should be dead to - var alive = false; - workers.forEach(function(pid) { - if (isAlive(pid)) { - alive = true; - } - }); - - // If a worker was alive this did not act as expected - existWorker = !alive; - } - }); - - process.once('exit', function() { - var m = 'The master did not die after an error was throwed'; - assert.ok(existMaster, m); - m = 'The workers did not die after an error in the master'; - assert.ok(existWorker, m); - }); - -} diff --git a/test/simple/test-cluster-master-kill.js b/test/simple/test-cluster-master-kill.js deleted file mode 100644 index 362540390396..000000000000 --- a/test/simple/test-cluster-master-kill.js +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); - -if (cluster.isWorker) { - - // keep the worker alive - var http = require('http'); - http.Server().listen(common.PORT, '127.0.0.1'); - -} else if (process.argv[2] === 'cluster') { - - var worker = cluster.fork(); - - // send PID info to testcase process - process.send({ - pid: worker.process.pid - }); - - // terminate the cluster process - worker.once('listening', function() { - setTimeout(function() { - process.exit(0); - }, 1000); - }); - -} else { - - // This is the testcase - var fork = require('child_process').fork; - - // is process alive helper - var isAlive = function(pid) { - try { - //this will throw an error if the process is dead - process.kill(pid, 0); - - return true; - } catch (e) { - return false; - } - }; - - // Spawn a cluster process - var master = fork(process.argv[1], ['cluster']); - - // get pid info - var pid = null; - master.once('message', function(data) { - pid = data.pid; - }); - - // When master is dead - var alive = true; - master.on('exit', function(code) { - - // make sure that the master died by purpose - assert.equal(code, 0); - - // check worker process status - setTimeout(function() { - alive = isAlive(pid); - }, 200); - }); - - process.once('exit', function() { - // cleanup: kill the worker if alive - if (alive) { - process.kill(pid); - } - - assert.equal(typeof pid, 'number', 'did not get worker pid info'); - assert.equal(alive, false, 'worker was alive after master died'); - }); - -} diff --git a/test/simple/test-cluster-message.js b/test/simple/test-cluster-message.js deleted file mode 100644 index 005cf2833943..000000000000 --- a/test/simple/test-cluster-message.js +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); - -function forEach(obj, fn) { - Object.keys(obj).forEach(function(name, index) { - fn(obj[name], name, index); - }); -} - -if (cluster.isWorker) { - // Create a tcp server. This will be used as cluster-shared-server and as an - // alternative IPC channel. - var server = net.Server(); - var socket, message; - - function maybeReply() { - if (!socket || !message) return; - - // Tell master using TCP socket that a message is received. - socket.write(JSON.stringify({ - code: 'received message', - echo: message - })); - } - - server.on('connection', function(socket_) { - socket = socket_; - maybeReply(); - - // Send a message back over the IPC channel. - process.send('message from worker'); - }); - - process.on('message', function(message_) { - message = message_; - maybeReply(); - }); - - server.listen(common.PORT, '127.0.0.1'); -} - -else if (cluster.isMaster) { - - var checks = { - master: { - 'receive': false, - 'correct': false - }, - worker: { - 'receive': false, - 'correct': false - } - }; - - - var client; - var check = function(type, result) { - checks[type].receive = true; - checks[type].correct = result; - console.error('check', checks); - - var missing = false; - forEach(checks, function(type) { - if (type.receive === false) missing = true; - }); - - if (missing === false) { - console.error('end client'); - client.end(); - } - }; - - // Spawn worker - var worker = cluster.fork(); - - // When a IPC message is resicved form the worker - worker.on('message', function(message) { - check('master', message === 'message from worker'); - }); - - // When a TCP connection is made with the worker connect to it - worker.on('listening', function() { - - client = net.connect(common.PORT, function() { - // Send message to worker. - worker.send('message from master'); - }); - - client.on('data', function(data) { - // All data is JSON - data = JSON.parse(data.toString()); - - if (data.code === 'received message') { - check('worker', data.echo === 'message from master'); - } else { - throw new Error('wrong TCP message recived: ' + data); - } - }); - - // When the connection ends kill worker and shutdown process - client.on('end', function() { - worker.kill(); - }); - - worker.on('exit', function() { - process.exit(0); - }); - }); - - process.once('exit', function() { - forEach(checks, function(check, type) { - assert.ok(check.receive, 'The ' + type + ' did not receive any message'); - assert.ok(check.correct, - 'The ' + type + ' did not get the correct message'); - }); - }); -} diff --git a/test/simple/test-cluster-net-listen.js b/test/simple/test-cluster-net-listen.js deleted file mode 100644 index 927169c7296d..000000000000 --- a/test/simple/test-cluster-net-listen.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); - -if (cluster.isMaster) { - // ensure that the worker exits peacefully - var worker = cluster.fork(); - worker.on('exit', function(statusCode) { - assert.equal(statusCode, 0); - worker = null; - }); - process.on('exit', function() { - assert.equal(worker, null); - }); -} -else { - // listen() without port should not trigger a libuv assert - net.createServer(assert.fail).listen(process.exit); -} diff --git a/test/simple/test-cluster-net-send.js b/test/simple/test-cluster-net-send.js deleted file mode 100644 index 846ae5d7a691..000000000000 --- a/test/simple/test-cluster-net-send.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fork = require('child_process').fork; -var net = require('net'); - -if (process.argv[2] !== 'child') { - console.error('[%d] master', process.pid); - - var worker = fork(__filename, ['child']); - var called = false; - - worker.once('message', function(msg, handle) { - assert.equal(msg, 'handle'); - assert.ok(handle); - worker.send('got'); - - handle.on('data', function(data) { - called = true; - assert.equal(data.toString(), 'hello'); - worker.kill(); - }); - }); - - process.once('exit', function() { - assert.ok(called); - }); -} else { - console.error('[%d] worker', process.pid); - - var server = net.createServer(function(c) { - process.once('message', function(msg) { - assert.equal(msg, 'got'); - c.end('hello'); - }); - }); - server.listen(common.PORT, function() { - var socket = net.connect(common.PORT, '127.0.0.1', function() { - process.send('handle', socket); - }); - }); - - process.on('disconnect', function() { - process.exit(); - server.close(); - }); -} diff --git a/test/simple/test-cluster-send-deadlock.js b/test/simple/test-cluster-send-deadlock.js deleted file mode 100644 index 1b4a90dee00e..000000000000 --- a/test/simple/test-cluster-send-deadlock.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Testing mutual send of handles: from master to worker, and from worker to -// master. - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); - -if (cluster.isMaster) { - var worker = cluster.fork(); - worker.on('exit', function(code, signal) { - assert.equal(code, 0, 'Worker exited with an error code'); - assert(!signal, 'Worker exited by a signal'); - server.close(); - }); - - var server = net.createServer(function(socket) { - worker.send('handle', socket); - }); - - server.listen(common.PORT, function() { - worker.send('listen'); - }); -} else { - process.on('message', function(msg, handle) { - if (msg === 'listen') { - var client1 = net.connect({ host: 'localhost', port: common.PORT }); - var client2 = net.connect({ host: 'localhost', port: common.PORT }); - var waiting = 2; - client1.on('close', onclose); - client2.on('close', onclose); - function onclose() { - if (--waiting === 0) - cluster.worker.disconnect(); - } - setTimeout(function() { - client1.end(); - client2.end(); - }, 50); - } else { - process.send('reply', handle); - } - }); -} diff --git a/test/simple/test-cluster-send-handle-twice.js b/test/simple/test-cluster-send-handle-twice.js deleted file mode 100644 index 3215eae79ed0..000000000000 --- a/test/simple/test-cluster-send-handle-twice.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Testing to send an handle twice to the parent process. - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); - -var workers = { - toStart: 1 -}; - -if (cluster.isMaster) { - for (var i = 0; i < workers.toStart; ++i) { - var worker = cluster.fork(); - worker.on('exit', function(code, signal) { - assert.equal(code, 0, 'Worker exited with an error code'); - assert(!signal, 'Worker exited by a signal'); - }); - } -} else { - var server = net.createServer(function(socket) { - process.send('send-handle-1', socket); - process.send('send-handle-2', socket); - }); - - server.listen(common.PORT, function() { - var client = net.connect({ host: 'localhost', port: common.PORT }); - client.on('close', function() { cluster.worker.disconnect(); }); - setTimeout(function() { client.end(); }, 50); - }).on('error', function(e) { - console.error(e); - assert(false, 'server.listen failed'); - cluster.worker.disconnect(); - }); -} diff --git a/test/simple/test-cluster-setup-master.js b/test/simple/test-cluster-setup-master.js deleted file mode 100644 index b842228fc961..000000000000 --- a/test/simple/test-cluster-setup-master.js +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); - -if (cluster.isWorker) { - - // Just keep the worker alive - process.send(process.argv[2]); - -} else if (cluster.isMaster) { - - var checks = { - args: false, - setupEvent: false, - settingsObject: false - }; - - var totalWorkers = 2; - - cluster.once('setup', function() { - checks.setupEvent = true; - - var settings = cluster.settings; - if (settings && - settings.args && settings.args[0] === 'custom argument' && - settings.silent === true && - settings.exec === process.argv[1]) { - checks.settingsObject = true; - } - }); - - // Setup master - cluster.setupMaster({ - args: ['custom argument'], - silent: true - }); - - var correctIn = 0; - - cluster.on('online', function lisenter(worker) { - - worker.once('message', function(data) { - correctIn += (data === 'custom argument' ? 1 : 0); - if (correctIn === totalWorkers) { - checks.args = true; - } - worker.kill(); - }); - - // All workers are online - if (cluster.onlineWorkers === totalWorkers) { - checks.workers = true; - } - }); - - // Start all workers - cluster.fork(); - cluster.fork(); - - // Check all values - process.once('exit', function() { - assert.ok(checks.args, 'The arguments was noy send to the worker'); - assert.ok(checks.setupEvent, 'The setup event was never emitted'); - var m = 'The settingsObject do not have correct properties'; - assert.ok(checks.settingsObject, m); - }); - -} diff --git a/test/simple/test-cluster-uncaught-exception.js b/test/simple/test-cluster-uncaught-exception.js deleted file mode 100644 index 48a82512704b..000000000000 --- a/test/simple/test-cluster-uncaught-exception.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Installing a custom uncaughtException handler should override the default -// one that the cluster module installs. -// https://github.com/joyent/node/issues/2556 - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var fork = require('child_process').fork; - -var MAGIC_EXIT_CODE = 42; - -var isTestRunner = process.argv[2] != 'child'; - -if (isTestRunner) { - var exitCode = -1; - - process.on('exit', function() { - assert.equal(exitCode, MAGIC_EXIT_CODE); - }); - - var master = fork(__filename, ['child']); - master.on('exit', function(code) { - exitCode = code; - }); -} -else if (cluster.isMaster) { - process.on('uncaughtException', function() { - process.nextTick(function() { - process.exit(MAGIC_EXIT_CODE); - }); - }); - - cluster.fork(); - throw new Error('kill master'); -} -else { // worker - process.exit(); -} diff --git a/test/simple/test-cluster-worker-death.js b/test/simple/test-cluster-worker-death.js deleted file mode 100644 index ccd48552ab95..000000000000 --- a/test/simple/test-cluster-worker-death.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); - -if (!cluster.isMaster) { - process.exit(42); -} -else { - var seenExit = 0; - var seenDeath = 0; - var worker = cluster.fork(); - worker.on('exit', function(exitCode, signalCode) { - assert.equal(exitCode, 42); - assert.equal(signalCode, null); - seenExit++; - }); - cluster.on('exit', function(worker_) { - assert.equal(worker_, worker); - seenDeath++; - }); - process.on('exit', function() { - assert.equal(seenExit, 1); - assert.equal(seenDeath, 1); - }); -} diff --git a/test/simple/test-cluster-worker-disconnect.js b/test/simple/test-cluster-worker-disconnect.js deleted file mode 100644 index 15329c998dde..000000000000 --- a/test/simple/test-cluster-worker-disconnect.js +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); - -if (cluster.isWorker) { - var http = require('http'); - http.Server(function() { - - }).listen(common.PORT, '127.0.0.1'); - -} else if (cluster.isMaster) { - - var checks = { - cluster: { - emitDisconnect: false, - emitExit: false, - callback: false - }, - worker: { - emitDisconnect: false, - emitExit: false, - state: false, - suicideMode: false, - died: false - } - }; - - // helper function to check if a process is alive - var alive = function(pid) { - try { - process.kill(pid, 0); - return true; - } catch (e) { - return false; - } - }; - - // start worker - var worker = cluster.fork(); - - // Disconnect worker when it is ready - worker.once('listening', function() { - worker.disconnect(); - }); - - // Check cluster events - cluster.once('disconnect', function() { - checks.cluster.emitDisconnect = true; - }); - cluster.once('exit', function() { - checks.cluster.emitExit = true; - }); - - // Check worker eventes and properties - worker.once('disconnect', function() { - checks.worker.emitDisconnect = true; - checks.worker.suicideMode = worker.suicide; - checks.worker.state = worker.state; - }); - - // Check that the worker died - worker.once('exit', function() { - checks.worker.emitExit = true; - checks.worker.died = !alive(worker.process.pid); - process.nextTick(function() { - process.exit(0); - }); - }); - - process.once('exit', function() { - - var w = checks.worker; - var c = checks.cluster; - - // events - assert.ok(w.emitDisconnect, 'Disconnect event did not emit'); - assert.ok(c.emitDisconnect, 'Disconnect event did not emit'); - assert.ok(w.emitExit, 'Exit event did not emit'); - assert.ok(c.emitExit, 'Exit event did not emit'); - - // flags - assert.equal(w.state, 'disconnected', 'The state property was not set'); - assert.equal(w.suicideMode, true, 'Suicide mode was not set'); - - // is process alive - assert.ok(w.died, 'The worker did not die'); - }); -} diff --git a/test/simple/test-cluster-worker-exit.js b/test/simple/test-cluster-worker-exit.js deleted file mode 100644 index 38b44c199c10..000000000000 --- a/test/simple/test-cluster-worker-exit.js +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -// test-cluster-worker-exit.js -// verifies that, when a child process exits (by calling `process.exit(code)`) -// - the parent receives the proper events in the proper order, no duplicates -// - the exitCode and signalCode are correct in the 'exit' event -// - the worker.suicide flag, and worker.state are correct -// - the worker process actually goes away - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); - -var EXIT_CODE = 42; - -if (cluster.isWorker) { - var http = require('http'); - var server = http.Server(function() { }); - - server.once('listening', function() { - process.exit(EXIT_CODE); - }); - server.listen(common.PORT, '127.0.0.1'); - -} else if (cluster.isMaster) { - - var expected_results = { - cluster_emitDisconnect: [1, "the cluster did not emit 'disconnect'"], - cluster_emitExit: [1, "the cluster did not emit 'exit'"], - cluster_exitCode: [EXIT_CODE, 'the cluster exited w/ incorrect exitCode'], - cluster_signalCode: [null, 'the cluster exited w/ incorrect signalCode'], - worker_emitDisconnect: [1, "the worker did not emit 'disconnect'"], - worker_emitExit: [1, "the worker did not emit 'exit'"], - worker_state: ['disconnected', 'the worker state is incorrect'], - worker_suicideMode: [false, 'the worker.suicide flag is incorrect'], - worker_died: [true, 'the worker is still running'], - worker_exitCode: [EXIT_CODE, 'the worker exited w/ incorrect exitCode'], - worker_signalCode: [null, 'the worker exited w/ incorrect signalCode'] - }; - var results = { - cluster_emitDisconnect: 0, - cluster_emitExit: 0, - worker_emitDisconnect: 0, - worker_emitExit: 0 - }; - - - // start worker - var worker = cluster.fork(); - - worker.once('listening', function() { - // the worker is up and running... - }); - - - // Check cluster events - cluster.on('disconnect', function() { - results.cluster_emitDisconnect += 1; - }); - cluster.on('exit', function(worker) { - results.cluster_exitCode = worker.process.exitCode; - results.cluster_signalCode = worker.process.signalCode; - results.cluster_emitExit += 1; - assert.ok(results.cluster_emitDisconnect, - "cluster: 'exit' event before 'disconnect' event"); - }); - - // Check worker eventes and properties - worker.on('disconnect', function() { - results.worker_emitDisconnect += 1; - results.worker_suicideMode = worker.suicide; - results.worker_state = worker.state; - }); - - // Check that the worker died - worker.once('exit', function(exitCode, signalCode) { - results.worker_exitCode = exitCode; - results.worker_signalCode = signalCode; - results.worker_emitExit += 1; - results.worker_died = !alive(worker.process.pid); - assert.ok(results.worker_emitDisconnect, - "worker: 'exit' event before 'disconnect' event"); - - process.nextTick(function() { finish_test(); }); - }); - - var finish_test = function() { - try { - checkResults(expected_results, results); - } catch (exc) { - console.error('FAIL: ' + exc.message); - if (exc.name != 'AssertionError') { - console.trace(exc); - } - - process.exit(1); - return; - } - process.exit(0); - }; -} - -// some helper functions ... - - function checkResults(expected_results, results) { - for (var k in expected_results) { - var actual = results[k], - expected = expected_results[k]; - - if (typeof expected === 'function') { - expected(r[k]); - } else { - var msg = (expected[1] || '') + - (' [expected: ' + expected[0] + ' / actual: ' + actual + ']'); - - if (expected && expected.length) { - assert.equal(actual, expected[0], msg); - } else { - assert.equal(actual, expected, msg); - } - } - } - } - - function alive(pid) { - try { - process.kill(pid, 'SIGCONT'); - return true; - } catch (e) { - return false; - } - } diff --git a/test/simple/test-cluster-worker-kill.js b/test/simple/test-cluster-worker-kill.js deleted file mode 100644 index 284b83e7fe2a..000000000000 --- a/test/simple/test-cluster-worker-kill.js +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -// test-cluster-worker-kill.js -// verifies that, when a child process is killed (we use SIGKILL) -// - the parent receives the proper events in the proper order, no duplicates -// - the exitCode and signalCode are correct in the 'exit' event -// - the worker.suicide flag, and worker.state are correct -// - the worker process actually goes away - -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); - -if (cluster.isWorker) { - var http = require('http'); - var server = http.Server(function() { }); - - server.once('listening', function() { }); - server.listen(common.PORT, '127.0.0.1'); - -} else if (cluster.isMaster) { - - var KILL_SIGNAL = 'SIGKILL', - expected_results = { - cluster_emitDisconnect: [1, "the cluster did not emit 'disconnect'"], - cluster_emitExit: [1, "the cluster did not emit 'exit'"], - cluster_exitCode: [null, 'the cluster exited w/ incorrect exitCode'], - cluster_signalCode: [KILL_SIGNAL, 'the cluster exited w/ incorrect signalCode'], - worker_emitDisconnect: [1, "the worker did not emit 'disconnect'"], - worker_emitExit: [1, "the worker did not emit 'exit'"], - worker_state: ['disconnected', 'the worker state is incorrect'], - worker_suicideMode: [false, 'the worker.suicide flag is incorrect'], - worker_died: [true, 'the worker is still running'], - worker_exitCode: [null, 'the worker exited w/ incorrect exitCode'], - worker_signalCode: [KILL_SIGNAL, 'the worker exited w/ incorrect signalCode'] - }, - results = { - cluster_emitDisconnect: 0, - cluster_emitExit: 0, - worker_emitDisconnect: 0, - worker_emitExit: 0 - }; - - - // start worker - var worker = cluster.fork(); - - // when the worker is up and running, kill it - worker.once('listening', function() { - worker.process.kill(KILL_SIGNAL); - }); - - - // Check cluster events - cluster.on('disconnect', function() { - results.cluster_emitDisconnect += 1; - }); - cluster.on('exit', function(worker) { - results.cluster_exitCode = worker.process.exitCode; - results.cluster_signalCode = worker.process.signalCode; - results.cluster_emitExit += 1; - assert.ok(results.cluster_emitDisconnect, - "cluster: 'exit' event before 'disconnect' event"); - }); - - // Check worker eventes and properties - worker.on('disconnect', function() { - results.worker_emitDisconnect += 1; - results.worker_suicideMode = worker.suicide; - results.worker_state = worker.state; - }); - - // Check that the worker died - worker.once('exit', function(exitCode, signalCode) { - results.worker_exitCode = exitCode; - results.worker_signalCode = signalCode; - results.worker_emitExit += 1; - results.worker_died = !alive(worker.process.pid); - assert.ok(results.worker_emitDisconnect, - "worker: 'exit' event before 'disconnect' event"); - - process.nextTick(function() { finish_test(); }); - }); - - var finish_test = function() { - try { - checkResults(expected_results, results); - } catch (exc) { - console.error('FAIL: ' + exc.message); - if (exc.name != 'AssertionError') { - console.trace(exc); - } - - process.exit(1); - return; - } - process.exit(0); - }; -} - -// some helper functions ... - - function checkResults(expected_results, results) { - for (var k in expected_results) { - var actual = results[k], - expected = expected_results[k]; - - if (typeof expected === 'function') { - expected(r[k]); - } else { - var msg = (expected[1] || '') + - (' [expected: ' + expected[0] + ' / actual: ' + actual + ']'); - if (expected && expected.length) { - assert.equal(actual, expected[0], msg); - } else { - assert.equal(actual, expected, msg); - } - } - } - } - - function alive(pid) { - try { - process.kill(pid, 'SIGCONT'); - return true; - } catch (e) { - return false; - } - } diff --git a/test/simple/test-console-instance.js b/test/simple/test-console-instance.js deleted file mode 100644 index e0166ebd3148..000000000000 --- a/test/simple/test-console-instance.js +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var Stream = require('stream'); -var Console = require('console').Console; -var called = false; - -// ensure the Console instance doesn't write to the -// process' "stdout" or "stderr" streams -process.stdout.write = process.stderr.write = function() { - throw new Error('write() should not be called!'); -}; - -// make sure that the "Console" function exists -assert.equal('function', typeof Console); - -// make sure that the Console constructor throws -// when not given a writable stream instance -assert.throws(function () { - new Console(); -}, /Console expects a writable stream/); - -var out = new Stream(); -var err = new Stream(); -out.writable = err.writable = true; -out.write = err.write = function(d) {}; - -var c = new Console(out, err); - -out.write = err.write = function(d) { - assert.equal(d, 'test\n'); - called = true; -}; - -assert(!called); -c.log('test'); -assert(called); - -called = false; -c.error('test'); -assert(called); - -out.write = function(d) { - assert.equal('{ foo: 1 }\n', d); - called = true; -}; - -called = false; -c.dir({ foo: 1 }); -assert(called); - -// ensure that the console functions are bound to the console instance -called = 0; -out.write = function(d) { - called++; - assert.equal(d, called + ' ' + (called - 1) + ' [ 1, 2, 3 ]\n'); -}; -[1, 2, 3].forEach(c.log); -assert.equal(3, called); diff --git a/test/simple/test-console-not-call-toString.js b/test/simple/test-console-not-call-toString.js deleted file mode 100644 index a62004f70af5..000000000000 --- a/test/simple/test-console-not-call-toString.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -var func = function() {}; -var toStringCalled = false; -func.toString = function() { - toStringCalled = true; -}; - -require('util').inspect(func); - -assert.ok(!toStringCalled); diff --git a/test/simple/test-console.js b/test/simple/test-console.js deleted file mode 100644 index 2c45a06bb9bb..000000000000 --- a/test/simple/test-console.js +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -assert.ok(process.stdout.writable); -assert.ok(process.stderr.writable); -// Support legacy API -assert.equal('number', typeof process.stdout.fd); -assert.equal('number', typeof process.stderr.fd); - - -var stdout_write = global.process.stdout.write; -var strings = []; -global.process.stdout.write = function(string) { - strings.push(string); -}; - -console.log('foo'); -console.log('foo', 'bar'); -console.log('%s %s', 'foo', 'bar', 'hop'); -console.log({slashes: '\\\\'}); - -console._stderr = process.stdout; -console.trace('This is a %j %d', { formatted: 'trace' }, 10, 'foo'); - -assert.throws(function () { - console.timeEnd('no such label'); -}); - -assert.doesNotThrow(function () { - console.time('label'); - console.timeEnd('label'); -}); - -console.time('__proto__'); -console.timeEnd('__proto__'); -console.time('constructor'); -console.timeEnd('constructor'); -console.time('hasOwnProperty'); -console.timeEnd('hasOwnProperty'); - -global.process.stdout.write = stdout_write; - -assert.equal('foo\n', strings.shift()); -assert.equal('foo bar\n', strings.shift()); -assert.equal('foo bar hop\n', strings.shift()); -assert.equal("{ slashes: '\\\\\\\\' }\n", strings.shift()); -assert.equal('Trace: This is a {"formatted":"trace"} 10 foo', - strings.shift().split('\n').shift()); - -assert.ok(/^label: \d+ms$/.test(strings.shift().trim())); -assert.ok(/^__proto__: \d+ms$/.test(strings.shift().trim())); -assert.ok(/^constructor: \d+ms$/.test(strings.shift().trim())); -assert.ok(/^hasOwnProperty: \d+ms$/.test(strings.shift().trim())); -assert.equal(strings.length, 0); diff --git a/test/simple/test-crypto-binary-default.js b/test/simple/test-crypto-binary-default.js deleted file mode 100644 index 85c5447a2b18..000000000000 --- a/test/simple/test-crypto-binary-default.js +++ /dev/null @@ -1,690 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// This is the same as test/simple/test-crypto, but from before the shift -// to use buffers by default. - - -var common = require('../common'); -var assert = require('assert'); - -try { - var crypto = require('crypto'); -} catch (e) { - console.log('Not compiled with OPENSSL support.'); - process.exit(); -} - -crypto.DEFAULT_ENCODING = 'binary'; - -var fs = require('fs'); -var path = require('path'); - -// Test Certificates -var caPem = fs.readFileSync(common.fixturesDir + '/test_ca.pem', 'ascii'); -var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); -var certPfx = fs.readFileSync(common.fixturesDir + '/test_cert.pfx'); -var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); -var rsaPubPem = fs.readFileSync(common.fixturesDir + '/test_rsa_pubkey.pem', - 'ascii'); -var rsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_rsa_privkey.pem', - 'ascii'); - -try { - var credentials = crypto.createCredentials( - {key: keyPem, - cert: certPem, - ca: caPem}); -} catch (e) { - console.log('Not compiled with OPENSSL support.'); - process.exit(); -} - -// PFX tests -assert.doesNotThrow(function() { - crypto.createCredentials({pfx:certPfx, passphrase:'sample'}); -}); - -assert.throws(function() { - crypto.createCredentials({pfx:certPfx}); -}, 'mac verify failure'); - -assert.throws(function() { - crypto.createCredentials({pfx:certPfx, passphrase:'test'}); -}, 'mac verify failure'); - -assert.throws(function() { - crypto.createCredentials({pfx:'sample', passphrase:'test'}); -}, 'not enough data'); - -// Test HMAC -var h1 = crypto.createHmac('sha1', 'Node') - .update('some data') - .update('to hmac') - .digest('hex'); -assert.equal(h1, '19fd6e1ba73d9ed2224dd5094a71babe85d9a892', 'test HMAC'); - -// Test HMAC-SHA-* (rfc 4231 Test Cases) -var rfc4231 = [ - { - key: new Buffer('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), - data: new Buffer('4869205468657265', 'hex'), // 'Hi There' - hmac: { - sha224: '896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22', - sha256: - 'b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c' + - '2e32cff7', - sha384: - 'afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c' + - '7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6', - sha512: - '87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b305' + - '45e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f170' + - '2e696c203a126854' - } - }, - { - key: new Buffer('4a656665', 'hex'), // 'Jefe' - data: new Buffer('7768617420646f2079612077616e7420666f72206e6f74686' + - '96e673f', 'hex'), // 'what do ya want for nothing?' - hmac: { - sha224: 'a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44', - sha256: - '5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b9' + - '64ec3843', - sha384: - 'af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec373' + - '6322445e8e2240ca5e69e2c78b3239ecfab21649', - sha512: - '164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7' + - 'ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b' + - '636e070a38bce737' - } - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: new Buffer('ddddddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddddddddd', - 'hex'), - hmac: { - sha224: '7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea', - sha256: - '773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514' + - 'ced565fe', - sha384: - '88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e5' + - '5966144b2a5ab39dc13814b94e3ab6e101a34f27', - sha512: - 'fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33' + - 'b2279d39bf3e848279a722c806b485a47e67c807b946a337bee89426' + - '74278859e13292fb' - } - }, - { - key: new Buffer('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), - data: new Buffer('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', - 'hex'), - hmac: { - sha224: '6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a', - sha256: - '82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff4' + - '6729665b', - sha384: - '3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e' + - '1f573b4e6801dd23c4a7d679ccf8a386c674cffb', - sha512: - 'b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050' + - '361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2d' + - 'e2adebeb10a298dd' - } - }, - - { - key: new Buffer('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'), - // 'Test With Truncation' - data: new Buffer('546573742057697468205472756e636174696f6e', 'hex'), - hmac: { - sha224: '0e2aea68a90c8d37c988bcdb9fca6fa8', - sha256: 'a3b6167473100ee06e0c796c2955552b', - sha384: '3abf34c3503b2a23a46efc619baef897', - sha512: '415fad6271580a531d4179bc891d87a6' - }, - truncate: true - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaa', 'hex'), - // 'Test Using Larger Than Block-Size Key - Hash Key First' - data: new Buffer('54657374205573696e67204c6172676572205468616e20426' + - 'c6f636b2d53697a65204b6579202d2048617368204b657920' + - '4669727374', 'hex'), - hmac: { - sha224: '95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e', - sha256: - '60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f' + - '0ee37f54', - sha384: - '4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05' + - '033ac4c60c2ef6ab4030fe8296248df163f44952', - sha512: - '80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b0137' + - '83f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec' + - '8b915a985d786598' - } - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaa', 'hex'), - // 'This is a test using a larger than block-size key and a larger ' + - // 'than block-size data. The key needs to be hashed before being ' + - // 'used by the HMAC algorithm.' - data: new Buffer('5468697320697320612074657374207573696e672061206c6' + - '172676572207468616e20626c6f636b2d73697a65206b6579' + - '20616e642061206c6172676572207468616e20626c6f636b2' + - 'd73697a6520646174612e20546865206b6579206e65656473' + - '20746f20626520686173686564206265666f7265206265696' + - 'e6720757365642062792074686520484d414320616c676f72' + - '6974686d2e', 'hex'), - hmac: { - sha224: '3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1', - sha256: - '9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f5153' + - '5c3a35e2', - sha384: - '6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82' + - '461e99c5a678cc31e799176d3860e6110c46523e', - sha512: - 'e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d' + - '20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de04460' + - '65c97440fa8c6a58' - } - } -]; - -for (var i = 0, l = rfc4231.length; i < l; i++) { - for (var hash in rfc4231[i]['hmac']) { - var result = crypto.createHmac(hash, rfc4231[i]['key']) - .update(rfc4231[i]['data']) - .digest('hex'); - if (rfc4231[i]['truncate']) { - result = result.substr(0, 32); // first 128 bits == 32 hex chars - } - assert.equal(rfc4231[i]['hmac'][hash], - result, - 'Test HMAC-' + hash + ': Test case ' + (i + 1) + ' rfc 4231'); - } -} - -// Test HMAC-MD5/SHA1 (rfc 2202 Test Cases) -var rfc2202_md5 = [ - { - key: new Buffer('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), - data: 'Hi There', - hmac: '9294727a3638bb1c13f48ef8158bfc9d' - }, - { - key: 'Jefe', - data: 'what do ya want for nothing?', - hmac: '750c783e6ab0b503eaa86e310a5db738' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: new Buffer('ddddddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddddddddd', - 'hex'), - hmac: '56be34521d144c88dbb8c733f0e8b3f6' - }, - { - key: new Buffer('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), - data: new Buffer('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + - 'cdcdcdcdcd', - 'hex'), - hmac: '697eaf0aca3a3aea3a75164746ffaa79' - }, - { - key: new Buffer('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'), - data: 'Test With Truncation', - hmac: '56461ef2342edc00f9bab995690efd4c' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: 'Test Using Larger Than Block-Size Key - Hash Key First', - hmac: '6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: - 'Test Using Larger Than Block-Size Key and Larger Than One ' + - 'Block-Size Data', - hmac: '6f630fad67cda0ee1fb1f562db3aa53e' - } -]; -var rfc2202_sha1 = [ - { - key: new Buffer('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), - data: 'Hi There', - hmac: 'b617318655057264e28bc0b6fb378c8ef146be00' - }, - { - key: 'Jefe', - data: 'what do ya want for nothing?', - hmac: 'effcdf6ae5eb2fa2d27416d5f184df9c259a7c79' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: new Buffer('ddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddd' + - 'dddddddddd', - 'hex'), - hmac: '125d7342b9ac11cd91a39af48aa17b4f63f175d3' - }, - { - key: new Buffer('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), - data: new Buffer('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + - 'cdcdcdcdcd', - 'hex'), - hmac: '4c9007f4026250c6bc8414f9bf50c86c2d7235da' - }, - { - key: new Buffer('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'), - data: 'Test With Truncation', - hmac: '4c1a03424b55e07fe7f27be1d58bb9324a9a5a04' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: 'Test Using Larger Than Block-Size Key - Hash Key First', - hmac: 'aa4ae5e15272d00e95705637ce8a3b55ed402112' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: - 'Test Using Larger Than Block-Size Key and Larger Than One ' + - 'Block-Size Data', - hmac: 'e8e99d0f45237d786d6bbaa7965c7808bbff1a91' - } -]; - -for (var i = 0, l = rfc2202_md5.length; i < l; i++) { - assert.equal(rfc2202_md5[i]['hmac'], - crypto.createHmac('md5', rfc2202_md5[i]['key']) - .update(rfc2202_md5[i]['data']) - .digest('hex'), - 'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202'); -} -for (var i = 0, l = rfc2202_sha1.length; i < l; i++) { - assert.equal(rfc2202_sha1[i]['hmac'], - crypto.createHmac('sha1', rfc2202_sha1[i]['key']) - .update(rfc2202_sha1[i]['data']) - .digest('hex'), - 'Test HMAC-SHA1 : Test case ' + (i + 1) + ' rfc 2202'); -} - -// Test hashing -var a0 = crypto.createHash('sha1').update('Test123').digest('hex'); -var a1 = crypto.createHash('md5').update('Test123').digest('binary'); -var a2 = crypto.createHash('sha256').update('Test123').digest('base64'); -var a3 = crypto.createHash('sha512').update('Test123').digest(); // binary -var a4 = crypto.createHash('sha1').update('Test123').digest('buffer'); - -assert.equal(a0, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1'); -assert.equal(a1, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca' + - '\u00bd\u008c', 'Test MD5 as binary'); -assert.equal(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=', - 'Test SHA256 as base64'); - -assert.equal(a3, '\u00c1(4\u00f1\u0003\u001fd\u0097!O\'\u00d4C/&Qz\u00d4' + - '\u0094\u0015l\u00b8\u008dQ+\u00db\u001d\u00c4\u00b5}\u00b2' + - '\u00d6\u0092\u00a3\u00df\u00a2i\u00a1\u009b\n\n*\u000f' + - '\u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093' + - '\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'', - 'Test SHA512 as assumed binary'); - -assert.deepEqual(a4, - new Buffer('8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'hex'), - 'Test SHA1'); - -// Test multiple updates to same hash -var h1 = crypto.createHash('sha1').update('Test123').digest('hex'); -var h2 = crypto.createHash('sha1').update('Test').update('123').digest('hex'); -assert.equal(h1, h2, 'multipled updates'); - -// Test hashing for binary files -var fn = path.join(common.fixturesDir, 'sample.png'); -var sha1Hash = crypto.createHash('sha1'); -var fileStream = fs.createReadStream(fn); -fileStream.on('data', function(data) { - sha1Hash.update(data); -}); -fileStream.on('close', function() { - assert.equal(sha1Hash.digest('hex'), - '22723e553129a336ad96e10f6aecdf0f45e4149e', - 'Test SHA1 of sample.png'); -}); - -// Issue #2227: unknown digest method should throw an error. -assert.throws(function() { - crypto.createHash('xyzzy'); -}); - -// Test signing and verifying -var s1 = crypto.createSign('RSA-SHA1') - .update('Test123') - .sign(keyPem, 'base64'); -var verified = crypto.createVerify('RSA-SHA1') - .update('Test') - .update('123') - .verify(certPem, s1, 'base64'); -assert.strictEqual(verified, true, 'sign and verify (base 64)'); - -var s2 = crypto.createSign('RSA-SHA256') - .update('Test123') - .sign(keyPem); // binary -var verified = crypto.createVerify('RSA-SHA256') - .update('Test') - .update('123') - .verify(certPem, s2); // binary -assert.strictEqual(verified, true, 'sign and verify (binary)'); - -var s3 = crypto.createSign('RSA-SHA1') - .update('Test123') - .sign(keyPem, 'buffer'); -var verified = crypto.createVerify('RSA-SHA1') - .update('Test') - .update('123') - .verify(certPem, s3); -assert.strictEqual(verified, true, 'sign and verify (buffer)'); - - -function testCipher1(key) { - // Test encryption and decryption - var plaintext = 'Keep this a secret? No! Tell everyone about node.js!'; - var cipher = crypto.createCipher('aes192', key); - - // encrypt plaintext which is in utf8 format - // to a ciphertext which will be in hex - var ciph = cipher.update(plaintext, 'utf8', 'hex'); - // Only use binary or hex, not base64. - ciph += cipher.final('hex'); - - var decipher = crypto.createDecipher('aes192', key); - var txt = decipher.update(ciph, 'hex', 'utf8'); - txt += decipher.final('utf8'); - - assert.equal(txt, plaintext, 'encryption and decryption'); -} - - -function testCipher2(key) { - // encryption and decryption with Base64 - // reported in https://github.com/joyent/node/issues/738 - var plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; - var cipher = crypto.createCipher('aes256', key); - - // encrypt plaintext which is in utf8 format - // to a ciphertext which will be in Base64 - var ciph = cipher.update(plaintext, 'utf8', 'base64'); - ciph += cipher.final('base64'); - - var decipher = crypto.createDecipher('aes256', key); - var txt = decipher.update(ciph, 'base64', 'utf8'); - txt += decipher.final('utf8'); - - assert.equal(txt, plaintext, 'encryption and decryption with Base64'); -} - - -function testCipher3(key, iv) { - // Test encyrption and decryption with explicit key and iv - var plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; - var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); - var ciph = cipher.update(plaintext, 'utf8', 'hex'); - ciph += cipher.final('hex'); - - var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv); - var txt = decipher.update(ciph, 'hex', 'utf8'); - txt += decipher.final('utf8'); - - assert.equal(txt, plaintext, 'encryption and decryption with key and iv'); -} - - -function testCipher4(key, iv) { - // Test encyrption and decryption with explicit key and iv - var plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; - var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); - var ciph = cipher.update(plaintext, 'utf8', 'buffer'); - ciph = Buffer.concat([ciph, cipher.final('buffer')]); - - var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv); - var txt = decipher.update(ciph, 'buffer', 'utf8'); - txt += decipher.final('utf8'); - - assert.equal(txt, plaintext, 'encryption and decryption with key and iv'); -} - - -testCipher1('MySecretKey123'); -testCipher1(new Buffer('MySecretKey123')); - -testCipher2('0123456789abcdef'); -testCipher2(new Buffer('0123456789abcdef')); - -testCipher3('0123456789abcd0123456789', '12345678'); -testCipher3('0123456789abcd0123456789', new Buffer('12345678')); -testCipher3(new Buffer('0123456789abcd0123456789'), '12345678'); -testCipher3(new Buffer('0123456789abcd0123456789'), new Buffer('12345678')); - -testCipher4(new Buffer('0123456789abcd0123456789'), new Buffer('12345678')); - - -// update() should only take buffers / strings -assert.throws(function() { - crypto.createHash('sha1').update({foo: 'bar'}); -}, /buffer/); - - -// Test Diffie-Hellman with two parties sharing a secret, -// using various encodings as we go along -var dh1 = crypto.createDiffieHellman(256); -var p1 = dh1.getPrime('buffer'); -var dh2 = crypto.createDiffieHellman(p1, 'base64'); -var key1 = dh1.generateKeys(); -var key2 = dh2.generateKeys('hex'); -var secret1 = dh1.computeSecret(key2, 'hex', 'base64'); -var secret2 = dh2.computeSecret(key1, 'binary', 'buffer'); - -assert.equal(secret1, secret2.toString('base64')); - -// Create "another dh1" using generated keys from dh1, -// and compute secret again -var dh3 = crypto.createDiffieHellman(p1, 'buffer'); -var privkey1 = dh1.getPrivateKey(); -dh3.setPublicKey(key1); -dh3.setPrivateKey(privkey1); - -assert.equal(dh1.getPrime(), dh3.getPrime()); -assert.equal(dh1.getGenerator(), dh3.getGenerator()); -assert.equal(dh1.getPublicKey(), dh3.getPublicKey()); -assert.equal(dh1.getPrivateKey(), dh3.getPrivateKey()); - -var secret3 = dh3.computeSecret(key2, 'hex', 'base64'); - -assert.equal(secret1, secret3); - -// https://github.com/joyent/node/issues/2338 -assert.throws(function() { - var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + - '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' + - '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' + - 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'; - crypto.createDiffieHellman(p, 'hex'); -}); - -// Test RSA key signing/verification -var rsaSign = crypto.createSign('RSA-SHA1'); -var rsaVerify = crypto.createVerify('RSA-SHA1'); -assert.ok(rsaSign); -assert.ok(rsaVerify); - -rsaSign.update(rsaPubPem); -var rsaSignature = rsaSign.sign(rsaKeyPem, 'hex'); -assert.equal(rsaSignature, - '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c' + - '8f020d7e2688b122bfb54c724ac9ee169f83f66d2fe90abeb95e8' + - 'e1290e7e177152a4de3d944cf7d4883114a20ed0f78e70e25ef0f' + - '60f06b858e6af42a2f276ede95bbc6bc9a9bbdda15bd663186a6f' + - '40819a7af19e577bb2efa5e579a1f5ce8a0d4ca8b8f6'); - -rsaVerify.update(rsaPubPem); -assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); - - -// -// Test RSA signing and verification -// -(function() { - var privateKey = fs.readFileSync( - common.fixturesDir + '/test_rsa_privkey_2.pem'); - - var publicKey = fs.readFileSync( - common.fixturesDir + '/test_rsa_pubkey_2.pem'); - - var input = 'I AM THE WALRUS'; - - var signature = - '79d59d34f56d0e94aa6a3e306882b52ed4191f07521f25f505a078dc2f89' + - '396e0c8ac89e996fde5717f4cb89199d8fec249961fcb07b74cd3d2a4ffa' + - '235417b69618e4bcd76b97e29975b7ce862299410e1b522a328e44ac9bb2' + - '8195e0268da7eda23d9825ac43c724e86ceeee0d0d4465678652ccaf6501' + - '0ddfb299bedeb1ad'; - - var sign = crypto.createSign('RSA-SHA256'); - sign.update(input); - - var output = sign.sign(privateKey, 'hex'); - assert.equal(output, signature); - - var verify = crypto.createVerify('RSA-SHA256'); - verify.update(input); - - assert.strictEqual(verify.verify(publicKey, signature, 'hex'), true); -})(); - - -// -// Test DSA signing and verification -// -(function() { - var privateKey = fs.readFileSync( - common.fixturesDir + '/test_dsa_privkey.pem'); - - var publicKey = fs.readFileSync( - common.fixturesDir + '/test_dsa_pubkey.pem'); - - var input = 'I AM THE WALRUS'; - - // DSA signatures vary across runs so there is no static string to verify - // against - var sign = crypto.createSign('DSS1'); - sign.update(input); - var signature = sign.sign(privateKey, 'hex'); - - var verify = crypto.createVerify('DSS1'); - verify.update(input); - - assert.strictEqual(verify.verify(publicKey, signature, 'hex'), true); -})(); - - -// -// Test PBKDF2 with RFC 6070 test vectors (except #4) -// -function testPBKDF2(password, salt, iterations, keylen, expected) { - var actual = crypto.pbkdf2Sync(password, salt, iterations, keylen); - assert.equal(actual, expected); - - crypto.pbkdf2(password, salt, iterations, keylen, function(err, actual) { - assert.equal(actual, expected); - }); -} - - -testPBKDF2('password', 'salt', 1, 20, - '\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9\xb5\x24' + - '\xaf\x60\x12\x06\x2f\xe0\x37\xa6'); - -testPBKDF2('password', 'salt', 2, 20, - '\xea\x6c\x01\x4d\xc7\x2d\x6f\x8c\xcd\x1e\xd9\x2a' + - '\xce\x1d\x41\xf0\xd8\xde\x89\x57'); - -testPBKDF2('password', 'salt', 4096, 20, - '\x4b\x00\x79\x01\xb7\x65\x48\x9a\xbe\xad\x49\xd9\x26' + - '\xf7\x21\xd0\x65\xa4\x29\xc1'); - -testPBKDF2('passwordPASSWORDpassword', - 'saltSALTsaltSALTsaltSALTsaltSALTsalt', - 4096, - 25, - '\x3d\x2e\xec\x4f\xe4\x1c\x84\x9b\x80\xc8\xd8\x36\x62' + - '\xc0\xe4\x4a\x8b\x29\x1a\x96\x4c\xf2\xf0\x70\x38'); - -testPBKDF2('pass\0word', 'sa\0lt', 4096, 16, - '\x56\xfa\x6a\xa7\x55\x48\x09\x9d\xcc\x37\xd7\xf0\x34' + - '\x25\xe0\xc3'); diff --git a/test/simple/test-crypto-dh-odd-key.js b/test/simple/test-crypto-dh-odd-key.js deleted file mode 100644 index a3d99e9b55d1..000000000000 --- a/test/simple/test-crypto-dh-odd-key.js +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var crypto = require('crypto'); -var odd = new Buffer(39); -odd.fill('A'); - -var c = crypto.createDiffieHellman(32); -c.setPrivateKey(odd); -c.generateKeys(); diff --git a/test/simple/test-crypto-domains.js b/test/simple/test-crypto-domains.js deleted file mode 100644 index 5c383860d14a..000000000000 --- a/test/simple/test-crypto-domains.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. - -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: - -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var crypto = require('crypto'); -var domain = require('domain'); -var assert = require('assert'); -var d = domain.create(); -var expect = ['pbkdf2', 'randomBytes', 'pseudoRandomBytes'] - -d.on('error', function (e) { - var idx = expect.indexOf(e.message); - assert.notEqual(idx, -1, 'we should have error: ' + e.message); - expect.splice(idx, 1); -}); - -d.run(function () { - crypto.pbkdf2('a', 'b', 1, 8, function () { - throw new Error('pbkdf2'); - }); - - crypto.randomBytes(4, function () { - throw new Error('randomBytes'); - }); - - crypto.pseudoRandomBytes(4, function () { - throw new Error('pseudoRandomBytes'); - }); -}); - -process.on('exit', function () { - assert.strictEqual(expect.length, 0, 'we should have seen all error messages'); -}); diff --git a/test/simple/test-crypto-ecb.js b/test/simple/test-crypto-ecb.js deleted file mode 100644 index e5b893cfcbe2..000000000000 --- a/test/simple/test-crypto-ecb.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -try { - var crypto = require('crypto'); -} catch (e) { - console.log('Not compiled with OPENSSL support.'); - process.exit(); -} - -crypto.DEFAULT_ENCODING = 'buffer'; - -// Testing whether EVP_CipherInit_ex is functioning correctly. -// Reference: bug#1997 - -(function() { - var encrypt = crypto.createCipheriv('BF-ECB', 'SomeRandomBlahz0c5GZVnR', ''); - var hex = encrypt.update('Hello World!', 'ascii', 'hex'); - hex += encrypt.final('hex'); - assert.equal(hex.toUpperCase(), '6D385F424AAB0CFBF0BB86E07FFB7D71'); -}()); - -(function() { - var decrypt = crypto.createDecipheriv('BF-ECB', 'SomeRandomBlahz0c5GZVnR', - ''); - var msg = decrypt.update('6D385F424AAB0CFBF0BB86E07FFB7D71', 'hex', 'ascii'); - msg += decrypt.final('ascii'); - assert.equal(msg, 'Hello World!'); -}()); diff --git a/test/simple/test-crypto-hash-stream-pipe.js b/test/simple/test-crypto-hash-stream-pipe.js deleted file mode 100644 index 1394903fab00..000000000000 --- a/test/simple/test-crypto-hash-stream-pipe.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var crypto = require('crypto'); -var stream = require('stream') -var s = new stream.PassThrough(); -var h = crypto.createHash('sha1'); -var expect = '15987e60950cf22655b9323bc1e281f9c4aff47e'; -var gotData = false; - -process.on('exit', function() { - assert(gotData); - console.log('ok'); -}); - -s.pipe(h).on('data', function(c) { - assert.equal(c, expect); - gotData = true; -}).setEncoding('hex'); - -s.end('aoeu'); diff --git a/test/simple/test-crypto-padding-aes256.js b/test/simple/test-crypto-padding-aes256.js deleted file mode 100644 index dd293feb1048..000000000000 --- a/test/simple/test-crypto-padding-aes256.js +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -try { - var crypto = require('crypto'); -} catch (e) { - console.log('Not compiled with OpenSSL support.'); - process.exit(); -} - -crypto.DEFAULT_ENCODING = 'buffer'; - -function aes256(decipherFinal) { - var iv = new Buffer('00000000000000000000000000000000', 'hex'); - var key = new Buffer('0123456789abcdef0123456789abcdef' + - '0123456789abcdef0123456789abcdef', 'hex'); - - function encrypt(val, pad) { - var c = crypto.createCipheriv('aes256', key, iv); - c.setAutoPadding(pad); - return c.update(val, 'utf8', 'binary') + c.final('binary'); - } - - function decrypt(val, pad) { - var c = crypto.createDecipheriv('aes256', key, iv); - c.setAutoPadding(pad); - return c.update(val, 'binary', 'utf8') + c[decipherFinal]('utf8'); - } - - // echo 0123456789abcdef0123456789abcdef \ - // | openssl enc -e -aes256 -nopad -K -iv \ - // | openssl enc -d -aes256 -nopad -K -iv - var plaintext = '0123456789abcdef0123456789abcdef'; // multiple of block size - var encrypted = encrypt(plaintext, false); - var decrypted = decrypt(encrypted, false); - assert.equal(decrypted, plaintext); - - // echo 0123456789abcdef0123456789abcde \ - // | openssl enc -e -aes256 -K -iv \ - // | openssl enc -d -aes256 -K -iv - plaintext = '0123456789abcdef0123456789abcde'; // not a multiple - encrypted = encrypt(plaintext, true); - decrypted = decrypt(encrypted, true); - assert.equal(decrypted, plaintext); -} - -aes256('final'); -aes256('finaltol'); diff --git a/test/simple/test-crypto-padding.js b/test/simple/test-crypto-padding.js deleted file mode 100644 index 22edbf481443..000000000000 --- a/test/simple/test-crypto-padding.js +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -try { - var crypto = require('crypto'); -} catch (e) { - console.log('Not compiled with OPENSSL support.'); - process.exit(); -} - -crypto.DEFAULT_ENCODING = 'buffer'; - - -/* - * Input data - */ - -var ODD_LENGTH_PLAIN = 'Hello node world!', - EVEN_LENGTH_PLAIN = 'Hello node world!AbC09876dDeFgHi'; - -var KEY_PLAIN = 'S3c.r.e.t.K.e.Y!', - IV_PLAIN = 'blahFizz2011Buzz'; - -var CIPHER_NAME = 'aes-128-cbc'; - - -/* - * Expected result data - */ - -// echo -n 'Hello node world!' | \ -// openssl enc -aes-128-cbc -e -K 5333632e722e652e742e4b2e652e5921 \ -// -iv 626c616846697a7a3230313142757a7a | xxd -p -c256 -var ODD_LENGTH_ENCRYPTED = - '7f57859550d4d2fdb9806da2a750461a9fe77253cd1cbd4b07beee4e070d561f'; - -// echo -n 'Hello node world!AbC09876dDeFgHi' | \ -// openssl enc -aes-128-cbc -e -K 5333632e722e652e742e4b2e652e5921 \ -// -iv 626c616846697a7a3230313142757a7a | xxd -p -c256 -var EVEN_LENGTH_ENCRYPTED = - '7f57859550d4d2fdb9806da2a750461ab46e71b3d78ebe2d9684dfc87f7575b988' + - '6119866912cb8c7bcaf76c5ebc2378'; - -// echo -n 'Hello node world!AbC09876dDeFgHi' | \ -// openssl enc -aes-128-cbc -e -K 5333632e722e652e742e4b2e652e5921 \ -// -iv 626c616846697a7a3230313142757a7a -nopad | xxd -p -c256 -var EVEN_LENGTH_ENCRYPTED_NOPAD = - '7f57859550d4d2fdb9806da2a750461ab46e' + - '71b3d78ebe2d9684dfc87f7575b9'; - - -/* - * Helper wrappers - */ - -function enc(plain, pad) { - var encrypt = crypto.createCipheriv(CIPHER_NAME, KEY_PLAIN, IV_PLAIN); - encrypt.setAutoPadding(pad); - var hex = encrypt.update(plain, 'ascii', 'hex'); - hex += encrypt.final('hex'); - return hex; -} - -function dec(encd, pad) { - var decrypt = crypto.createDecipheriv(CIPHER_NAME, KEY_PLAIN, IV_PLAIN); - decrypt.setAutoPadding(pad); - var plain = decrypt.update(encd, 'hex'); - plain += decrypt.final('binary'); - return plain; -} - - -/* - * Test encryption - */ - -assert.equal(enc(ODD_LENGTH_PLAIN, true), ODD_LENGTH_ENCRYPTED); -assert.equal(enc(EVEN_LENGTH_PLAIN, true), EVEN_LENGTH_ENCRYPTED); - -assert.throws(function() { - // input must have block length % - enc(ODD_LENGTH_PLAIN, false); -}); - -assert.doesNotThrow(function() { - assert.equal(enc(EVEN_LENGTH_PLAIN, false), EVEN_LENGTH_ENCRYPTED_NOPAD); -}); - - -/* - * Test decryption - */ - -assert.equal(dec(ODD_LENGTH_ENCRYPTED, true), ODD_LENGTH_PLAIN); -assert.equal(dec(EVEN_LENGTH_ENCRYPTED, true), EVEN_LENGTH_PLAIN); - -assert.doesNotThrow(function() { - // returns including original padding - assert.equal(dec(ODD_LENGTH_ENCRYPTED, false).length, 32); - assert.equal(dec(EVEN_LENGTH_ENCRYPTED, false).length, 48); -}); - -assert.throws(function() { - // must have at least 1 byte of padding (PKCS): - assert.equal(dec(EVEN_LENGTH_ENCRYPTED_NOPAD, true), EVEN_LENGTH_PLAIN); -}); - -assert.doesNotThrow(function() { - // no-pad encrypted string should return the same: - assert.equal(dec(EVEN_LENGTH_ENCRYPTED_NOPAD, false), EVEN_LENGTH_PLAIN); -}); diff --git a/test/simple/test-crypto-random.js b/test/simple/test-crypto-random.js deleted file mode 100644 index 24a76f4f1aca..000000000000 --- a/test/simple/test-crypto-random.js +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -try { - var crypto = require('crypto'); -} catch (e) { - console.log('Not compiled with OPENSSL support.'); - process.exit(); -} - -crypto.DEFAULT_ENCODING = 'buffer'; - -// bump, we register a lot of exit listeners -process.setMaxListeners(256); - -[crypto.randomBytes, - crypto.pseudoRandomBytes -].forEach(function(f) { - [-1, - undefined, - null, - false, - true, - {}, - [] - ].forEach(function(value) { - assert.throws(function() { f(value); }); - assert.throws(function() { f(value, function() {}); }); - }); - - [0, 1, 2, 4, 16, 256, 1024].forEach(function(len) { - f(len, checkCall(function(ex, buf) { - assert.equal(null, ex); - assert.equal(len, buf.length); - assert.ok(Buffer.isBuffer(buf)); - })); - }); -}); - -// assert that the callback is indeed called -function checkCall(cb, desc) { - var called_ = false; - - process.on('exit', function() { - assert.equal(true, called_, desc || ('callback not called: ' + cb)); - }); - - return function() { - return called_ = true, cb.apply(cb, Array.prototype.slice.call(arguments)); - }; -} - -// #5126, "FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() -// length exceeds max acceptable value" -assert.throws(function() { - crypto.randomBytes(0x3fffffff + 1); -}, TypeError); diff --git a/test/simple/test-crypto-stream.js b/test/simple/test-crypto-stream.js deleted file mode 100644 index 34eb3c18d8df..000000000000 --- a/test/simple/test-crypto-stream.js +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var stream = require('stream'); -var util = require('util'); - -try { - var crypto = require('crypto'); -} catch (e) { - console.log('Not compiled with OPENSSL support.'); - process.exit(); -} - -// Small stream to buffer converter -function Stream2buffer(callback) { - stream.Writable.call(this); - - this._buffers = []; - this.once('finish', function () { - callback(null, Buffer.concat(this._buffers)); - }); -} -util.inherits(Stream2buffer, stream.Writable); - -Stream2buffer.prototype._write = function (data, encodeing, done) { - this._buffers.push(data); - return done(null); -}; - -// Create an md5 hash of "Hallo world" -var hasher1 = crypto.createHash('md5'); - hasher1.pipe(new Stream2buffer(common.mustCall(function end(err, hash) { - assert.equal(err, null); - assert.equal(hash.toString('hex'), '06460dadb35d3d503047ce750ceb2d07'); - }))); - hasher1.end('Hallo world'); - -// Simpler check for unpipe, setEncoding, pause and resume -crypto.createHash('md5').unpipe({}); -crypto.createHash('md5').setEncoding('utf8'); -crypto.createHash('md5').pause(); -crypto.createHash('md5').resume(); - -// Decipher._flush() should emit an error event, not an exception. -var key = new Buffer('48fb56eb10ffeb13fc0ef551bbca3b1b', 'hex'), - badkey = new Buffer('12341234123412341234123412341234', 'hex'), - iv = new Buffer('6d358219d1f488f5f4eb12820a66d146', 'hex'), - cipher = crypto.createCipheriv('aes-128-cbc', key, iv), - decipher = crypto.createDecipheriv('aes-128-cbc', badkey, iv); - -cipher.pipe(decipher) - .on('error', common.mustCall(function end(err) { - assert(/bad decrypt/.test(err)); - })); - -cipher.end('Papaya!'); // Should not cause an unhandled exception. diff --git a/test/simple/test-crypto-verify-failure.js b/test/simple/test-crypto-verify-failure.js deleted file mode 100644 index 6162d16519d3..000000000000 --- a/test/simple/test-crypto-verify-failure.js +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -try { - var crypto = require('crypto'); - var tls = require('tls'); -} catch (e) { - console.log('Not compiled with OPENSSL support.'); - process.exit(); -} - -crypto.DEFAULT_ENCODING = 'buffer'; - -var fs = require('fs'); - -var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var canSend = true; - -var server = tls.Server(options, function(socket) { - process.nextTick(function() { - console.log('sending'); - socket.destroy(); - verify(); - }); -}); - -var client; - -function verify() { - console.log('verify'); - var verified = crypto.createVerify('RSA-SHA1') - .update('Test') - .verify(certPem, 'asdfasdfas', 'base64'); -} - -server.listen(common.PORT, function() { - client = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - verify(); - }).on('data', function(data) { - console.log(data); - }).on('error', function(err) { - throw err; - }).on('close', function() { - server.close(); - }).resume(); -}); - -server.unref(); diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js deleted file mode 100644 index 25bb359190e3..000000000000 --- a/test/simple/test-crypto.js +++ /dev/null @@ -1,954 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -try { - var crypto = require('crypto'); -} catch (e) { - console.log('Not compiled with OPENSSL support.'); - process.exit(); -} - -crypto.DEFAULT_ENCODING = 'buffer'; - -var fs = require('fs'); -var path = require('path'); - -// Test Certificates -var caPem = fs.readFileSync(common.fixturesDir + '/test_ca.pem', 'ascii'); -var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii'); -var certPfx = fs.readFileSync(common.fixturesDir + '/test_cert.pfx'); -var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); -var rsaPubPem = fs.readFileSync(common.fixturesDir + '/test_rsa_pubkey.pem', - 'ascii'); -var rsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_rsa_privkey.pem', - 'ascii'); - -try { - var credentials = crypto.createCredentials( - {key: keyPem, - cert: certPem, - ca: caPem}); -} catch (e) { - console.log('Not compiled with OPENSSL support.'); - process.exit(); -} - -// PFX tests -assert.doesNotThrow(function() { - crypto.createCredentials({pfx:certPfx, passphrase:'sample'}); -}); - -assert.throws(function() { - crypto.createCredentials({pfx:certPfx}); -}, 'mac verify failure'); - -assert.throws(function() { - crypto.createCredentials({pfx:certPfx, passphrase:'test'}); -}, 'mac verify failure'); - -assert.throws(function() { - crypto.createCredentials({pfx:'sample', passphrase:'test'}); -}, 'not enough data'); - -// Test HMAC -var h1 = crypto.createHmac('sha1', 'Node') - .update('some data') - .update('to hmac') - .digest('hex'); -assert.equal(h1, '19fd6e1ba73d9ed2224dd5094a71babe85d9a892', 'test HMAC'); - -// Test HMAC (Wikipedia Test Cases) -var wikipedia = [ - { - key: 'key', data: 'The quick brown fox jumps over the lazy dog', - hmac: { // HMACs lifted from Wikipedia. - md5: '80070713463e7749b90c2dc24911e275', - sha1: 'de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9', - sha256: - 'f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc' + - '2d1a3cd8' - } - }, - { - key: 'key', data: '', - hmac: { // Intermediate test to help debugging. - md5: '63530468a04e386459855da0063b6596', - sha1: 'f42bb0eeb018ebbd4597ae7213711ec60760843f', - sha256: - '5d5d139563c95b5967b9bd9a8c9b233a9dedb45072794cd232dc1b74' + - '832607d0' - } - }, - { - key: '', data: 'The quick brown fox jumps over the lazy dog', - hmac: { // Intermediate test to help debugging. - md5: 'ad262969c53bc16032f160081c4a07a0', - sha1: '2ba7f707ad5f187c412de3106583c3111d668de8', - sha256: - 'fb011e6154a19b9a4c767373c305275a5a69e8b68b0b4c9200c383dc' + - 'ed19a416' - } - }, - { - key: '', data: '', - hmac: { // HMACs lifted from Wikipedia. - md5: '74e6f7298a9c2d168935f58c001bad88', - sha1: 'fbdb1d1b18aa6c08324b7d64b71fb76370690e1d', - sha256: - 'b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c71214' + - '4292c5ad' - } - }, -] - -for (var i = 0, l = wikipedia.length; i < l; i++) { - for (var hash in wikipedia[i]['hmac']) { - var result = crypto.createHmac(hash, wikipedia[i]['key']) - .update(wikipedia[i]['data']) - .digest('hex'); - assert.equal(wikipedia[i]['hmac'][hash], - result, - 'Test HMAC-' + hash + ': Test case ' + (i + 1) + ' wikipedia'); - } -} - - -// Test HMAC-SHA-* (rfc 4231 Test Cases) -var rfc4231 = [ - { - key: new Buffer('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), - data: new Buffer('4869205468657265', 'hex'), // 'Hi There' - hmac: { - sha224: '896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22', - sha256: - 'b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c' + - '2e32cff7', - sha384: - 'afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c' + - '7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6', - sha512: - '87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b305' + - '45e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f170' + - '2e696c203a126854' - } - }, - { - key: new Buffer('4a656665', 'hex'), // 'Jefe' - data: new Buffer('7768617420646f2079612077616e7420666f72206e6f74686' + - '96e673f', 'hex'), // 'what do ya want for nothing?' - hmac: { - sha224: 'a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44', - sha256: - '5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b9' + - '64ec3843', - sha384: - 'af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec373' + - '6322445e8e2240ca5e69e2c78b3239ecfab21649', - sha512: - '164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7' + - 'ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b' + - '636e070a38bce737' - } - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: new Buffer('ddddddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddddddddd', - 'hex'), - hmac: { - sha224: '7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea', - sha256: - '773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514' + - 'ced565fe', - sha384: - '88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e5' + - '5966144b2a5ab39dc13814b94e3ab6e101a34f27', - sha512: - 'fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33' + - 'b2279d39bf3e848279a722c806b485a47e67c807b946a337bee89426' + - '74278859e13292fb' - } - }, - { - key: new Buffer('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), - data: new Buffer('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', - 'hex'), - hmac: { - sha224: '6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a', - sha256: - '82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff4' + - '6729665b', - sha384: - '3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e' + - '1f573b4e6801dd23c4a7d679ccf8a386c674cffb', - sha512: - 'b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050' + - '361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2d' + - 'e2adebeb10a298dd' - } - }, - - { - key: new Buffer('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'), - // 'Test With Truncation' - data: new Buffer('546573742057697468205472756e636174696f6e', 'hex'), - hmac: { - sha224: '0e2aea68a90c8d37c988bcdb9fca6fa8', - sha256: 'a3b6167473100ee06e0c796c2955552b', - sha384: '3abf34c3503b2a23a46efc619baef897', - sha512: '415fad6271580a531d4179bc891d87a6' - }, - truncate: true - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaa', 'hex'), - // 'Test Using Larger Than Block-Size Key - Hash Key First' - data: new Buffer('54657374205573696e67204c6172676572205468616e20426' + - 'c6f636b2d53697a65204b6579202d2048617368204b657920' + - '4669727374', 'hex'), - hmac: { - sha224: '95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e', - sha256: - '60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f' + - '0ee37f54', - sha384: - '4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05' + - '033ac4c60c2ef6ab4030fe8296248df163f44952', - sha512: - '80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b0137' + - '83f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec' + - '8b915a985d786598' - } - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaa', 'hex'), - // 'This is a test using a larger than block-size key and a larger ' + - // 'than block-size data. The key needs to be hashed before being ' + - // 'used by the HMAC algorithm.' - data: new Buffer('5468697320697320612074657374207573696e672061206c6' + - '172676572207468616e20626c6f636b2d73697a65206b6579' + - '20616e642061206c6172676572207468616e20626c6f636b2' + - 'd73697a6520646174612e20546865206b6579206e65656473' + - '20746f20626520686173686564206265666f7265206265696' + - 'e6720757365642062792074686520484d414320616c676f72' + - '6974686d2e', 'hex'), - hmac: { - sha224: '3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1', - sha256: - '9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f5153' + - '5c3a35e2', - sha384: - '6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82' + - '461e99c5a678cc31e799176d3860e6110c46523e', - sha512: - 'e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d' + - '20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de04460' + - '65c97440fa8c6a58' - } - } -]; - -for (var i = 0, l = rfc4231.length; i < l; i++) { - for (var hash in rfc4231[i]['hmac']) { - var str = crypto.createHmac(hash, rfc4231[i].key); - str.end(rfc4231[i].data); - var strRes = str.read().toString('hex'); - var result = crypto.createHmac(hash, rfc4231[i]['key']) - .update(rfc4231[i]['data']) - .digest('hex'); - if (rfc4231[i]['truncate']) { - result = result.substr(0, 32); // first 128 bits == 32 hex chars - strRes = strRes.substr(0, 32); - } - assert.equal(rfc4231[i]['hmac'][hash], - result, - 'Test HMAC-' + hash + ': Test case ' + (i + 1) + ' rfc 4231'); - assert.equal(strRes, result, 'Should get same result from stream'); - } -} - -// Test HMAC-MD5/SHA1 (rfc 2202 Test Cases) -var rfc2202_md5 = [ - { - key: new Buffer('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), - data: 'Hi There', - hmac: '9294727a3638bb1c13f48ef8158bfc9d' - }, - { - key: 'Jefe', - data: 'what do ya want for nothing?', - hmac: '750c783e6ab0b503eaa86e310a5db738' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: new Buffer('ddddddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddddddddd', - 'hex'), - hmac: '56be34521d144c88dbb8c733f0e8b3f6' - }, - { - key: new Buffer('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), - data: new Buffer('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + - 'cdcdcdcdcd', - 'hex'), - hmac: '697eaf0aca3a3aea3a75164746ffaa79' - }, - { - key: new Buffer('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'), - data: 'Test With Truncation', - hmac: '56461ef2342edc00f9bab995690efd4c' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: 'Test Using Larger Than Block-Size Key - Hash Key First', - hmac: '6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: - 'Test Using Larger Than Block-Size Key and Larger Than One ' + - 'Block-Size Data', - hmac: '6f630fad67cda0ee1fb1f562db3aa53e' - } -]; -var rfc2202_sha1 = [ - { - key: new Buffer('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b', 'hex'), - data: 'Hi There', - hmac: 'b617318655057264e28bc0b6fb378c8ef146be00' - }, - { - key: 'Jefe', - data: 'what do ya want for nothing?', - hmac: 'effcdf6ae5eb2fa2d27416d5f184df9c259a7c79' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: new Buffer('ddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddd' + - 'dddddddddd', - 'hex'), - hmac: '125d7342b9ac11cd91a39af48aa17b4f63f175d3' - }, - { - key: new Buffer('0102030405060708090a0b0c0d0e0f10111213141516171819', - 'hex'), - data: new Buffer('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + - 'cdcdcdcdcd', - 'hex'), - hmac: '4c9007f4026250c6bc8414f9bf50c86c2d7235da' - }, - { - key: new Buffer('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c', 'hex'), - data: 'Test With Truncation', - hmac: '4c1a03424b55e07fe7f27be1d58bb9324a9a5a04' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: 'Test Using Larger Than Block-Size Key - Hash Key First', - hmac: 'aa4ae5e15272d00e95705637ce8a3b55ed402112' - }, - { - key: new Buffer('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: - 'Test Using Larger Than Block-Size Key and Larger Than One ' + - 'Block-Size Data', - hmac: 'e8e99d0f45237d786d6bbaa7965c7808bbff1a91' - } -]; - -for (var i = 0, l = rfc2202_md5.length; i < l; i++) { - assert.equal(rfc2202_md5[i]['hmac'], - crypto.createHmac('md5', rfc2202_md5[i]['key']) - .update(rfc2202_md5[i]['data']) - .digest('hex'), - 'Test HMAC-MD5 : Test case ' + (i + 1) + ' rfc 2202'); -} -for (var i = 0, l = rfc2202_sha1.length; i < l; i++) { - assert.equal(rfc2202_sha1[i]['hmac'], - crypto.createHmac('sha1', rfc2202_sha1[i]['key']) - .update(rfc2202_sha1[i]['data']) - .digest('hex'), - 'Test HMAC-SHA1 : Test case ' + (i + 1) + ' rfc 2202'); -} - -// Test hashing -var a0 = crypto.createHash('sha1').update('Test123').digest('hex'); -var a1 = crypto.createHash('md5').update('Test123').digest('binary'); -var a2 = crypto.createHash('sha256').update('Test123').digest('base64'); -var a3 = crypto.createHash('sha512').update('Test123').digest(); // binary -var a4 = crypto.createHash('sha1').update('Test123').digest('buffer'); - -// stream interface -var a5 = crypto.createHash('sha512'); -a5.end('Test123'); -a5 = a5.read(); - -var a6 = crypto.createHash('sha512'); -a6.write('Te'); -a6.write('st'); -a6.write('123'); -a6.end(); -a6 = a6.read(); - -assert.equal(a0, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1'); -assert.equal(a1, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca' + - '\u00bd\u008c', 'Test MD5 as binary'); -assert.equal(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=', - 'Test SHA256 as base64'); -assert.deepEqual( - a3, - new Buffer( - '\u00c1(4\u00f1\u0003\u001fd\u0097!O\'\u00d4C/&Qz\u00d4' + - '\u0094\u0015l\u00b8\u008dQ+\u00db\u001d\u00c4\u00b5}\u00b2' + - '\u00d6\u0092\u00a3\u00df\u00a2i\u00a1\u009b\n\n*\u000f' + - '\u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093' + - '\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'', - 'binary'), - 'Test SHA512 as assumed buffer'); -assert.deepEqual(a4, - new Buffer('8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'hex'), - 'Test SHA1'); - -// stream interface should produce the same result. -assert.deepEqual(a5, a3, 'stream interface is consistent'); -assert.deepEqual(a6, a3, 'stream interface is consistent'); - -// Test multiple updates to same hash -var h1 = crypto.createHash('sha1').update('Test123').digest('hex'); -var h2 = crypto.createHash('sha1').update('Test').update('123').digest('hex'); -assert.equal(h1, h2, 'multipled updates'); - -// Test hashing for binary files -var fn = path.join(common.fixturesDir, 'sample.png'); -var sha1Hash = crypto.createHash('sha1'); -var fileStream = fs.createReadStream(fn); -fileStream.on('data', function(data) { - sha1Hash.update(data); -}); -fileStream.on('close', function() { - assert.equal(sha1Hash.digest('hex'), - '22723e553129a336ad96e10f6aecdf0f45e4149e', - 'Test SHA1 of sample.png'); -}); - -// Issue #2227: unknown digest method should throw an error. -assert.throws(function() { - crypto.createHash('xyzzy'); -}); - -// Test signing and verifying -var s1 = crypto.createSign('RSA-SHA1') - .update('Test123') - .sign(keyPem, 'base64'); -var s1stream = crypto.createSign('RSA-SHA1'); -s1stream.end('Test123'); -s1stream = s1stream.sign(keyPem, 'base64'); -assert.equal(s1, s1stream, 'Stream produces same output'); - -var verified = crypto.createVerify('RSA-SHA1') - .update('Test') - .update('123') - .verify(certPem, s1, 'base64'); -assert.strictEqual(verified, true, 'sign and verify (base 64)'); - -var s2 = crypto.createSign('RSA-SHA256') - .update('Test123') - .sign(keyPem, 'binary'); -var s2stream = crypto.createSign('RSA-SHA256'); -s2stream.end('Test123'); -s2stream = s2stream.sign(keyPem, 'binary'); -assert.equal(s2, s2stream, 'Stream produces same output'); - -var verified = crypto.createVerify('RSA-SHA256') - .update('Test') - .update('123') - .verify(certPem, s2, 'binary'); -assert.strictEqual(verified, true, 'sign and verify (binary)'); - -var verStream = crypto.createVerify('RSA-SHA256'); -verStream.write('Tes'); -verStream.write('t12'); -verStream.end('3'); -verified = verStream.verify(certPem, s2, 'binary'); -assert.strictEqual(verified, true, 'sign and verify (stream)'); - -var s3 = crypto.createSign('RSA-SHA1') - .update('Test123') - .sign(keyPem, 'buffer'); -var verified = crypto.createVerify('RSA-SHA1') - .update('Test') - .update('123') - .verify(certPem, s3); -assert.strictEqual(verified, true, 'sign and verify (buffer)'); - -var verStream = crypto.createVerify('RSA-SHA1'); -verStream.write('Tes'); -verStream.write('t12'); -verStream.end('3'); -verified = verStream.verify(certPem, s3); -assert.strictEqual(verified, true, 'sign and verify (stream)'); - - -function testCipher1(key) { - // Test encryption and decryption - var plaintext = 'Keep this a secret? No! Tell everyone about node.js!'; - var cipher = crypto.createCipher('aes192', key); - - // encrypt plaintext which is in utf8 format - // to a ciphertext which will be in hex - var ciph = cipher.update(plaintext, 'utf8', 'hex'); - // Only use binary or hex, not base64. - ciph += cipher.final('hex'); - - var decipher = crypto.createDecipher('aes192', key); - var txt = decipher.update(ciph, 'hex', 'utf8'); - txt += decipher.final('utf8'); - - assert.equal(txt, plaintext, 'encryption and decryption'); - - // streaming cipher interface - // NB: In real life, it's not guaranteed that you can get all of it - // in a single read() like this. But in this case, we know it's - // quite small, so there's no harm. - var cStream = crypto.createCipher('aes192', key); - cStream.end(plaintext); - ciph = cStream.read(); - - var dStream = crypto.createDecipher('aes192', key); - dStream.end(ciph); - txt = dStream.read().toString('utf8'); - - assert.equal(txt, plaintext, 'encryption and decryption with streams'); -} - - -function testCipher2(key) { - // encryption and decryption with Base64 - // reported in https://github.com/joyent/node/issues/738 - var plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; - var cipher = crypto.createCipher('aes256', key); - - // encrypt plaintext which is in utf8 format - // to a ciphertext which will be in Base64 - var ciph = cipher.update(plaintext, 'utf8', 'base64'); - ciph += cipher.final('base64'); - - var decipher = crypto.createDecipher('aes256', key); - var txt = decipher.update(ciph, 'base64', 'utf8'); - txt += decipher.final('utf8'); - - assert.equal(txt, plaintext, 'encryption and decryption with Base64'); -} - - -function testCipher3(key, iv) { - // Test encyrption and decryption with explicit key and iv - var plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; - var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); - var ciph = cipher.update(plaintext, 'utf8', 'hex'); - ciph += cipher.final('hex'); - - var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv); - var txt = decipher.update(ciph, 'hex', 'utf8'); - txt += decipher.final('utf8'); - - assert.equal(txt, plaintext, 'encryption and decryption with key and iv'); - - // streaming cipher interface - // NB: In real life, it's not guaranteed that you can get all of it - // in a single read() like this. But in this case, we know it's - // quite small, so there's no harm. - var cStream = crypto.createCipheriv('des-ede3-cbc', key, iv); - cStream.end(plaintext); - ciph = cStream.read(); - - var dStream = crypto.createDecipheriv('des-ede3-cbc', key, iv); - dStream.end(ciph); - txt = dStream.read().toString('utf8'); - - assert.equal(txt, plaintext, 'streaming cipher iv'); -} - - -function testCipher4(key, iv) { - // Test encyrption and decryption with explicit key and iv - var plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; - var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); - var ciph = cipher.update(plaintext, 'utf8', 'buffer'); - ciph = Buffer.concat([ciph, cipher.final('buffer')]); - - var decipher = crypto.createDecipheriv('des-ede3-cbc', key, iv); - var txt = decipher.update(ciph, 'buffer', 'utf8'); - txt += decipher.final('utf8'); - - assert.equal(txt, plaintext, 'encryption and decryption with key and iv'); -} - - -testCipher1('MySecretKey123'); -testCipher1(new Buffer('MySecretKey123')); - -testCipher2('0123456789abcdef'); -testCipher2(new Buffer('0123456789abcdef')); - -testCipher3('0123456789abcd0123456789', '12345678'); -testCipher3('0123456789abcd0123456789', new Buffer('12345678')); -testCipher3(new Buffer('0123456789abcd0123456789'), '12345678'); -testCipher3(new Buffer('0123456789abcd0123456789'), new Buffer('12345678')); - -testCipher4(new Buffer('0123456789abcd0123456789'), new Buffer('12345678')); - - -// update() should only take buffers / strings -assert.throws(function() { - crypto.createHash('sha1').update({foo: 'bar'}); -}, /buffer/); - - -// Test Diffie-Hellman with two parties sharing a secret, -// using various encodings as we go along -var dh1 = crypto.createDiffieHellman(256); -var p1 = dh1.getPrime('buffer'); -var dh2 = crypto.createDiffieHellman(p1, 'base64'); -var key1 = dh1.generateKeys(); -var key2 = dh2.generateKeys('hex'); -var secret1 = dh1.computeSecret(key2, 'hex', 'base64'); -var secret2 = dh2.computeSecret(key1, 'binary', 'buffer'); - -assert.equal(secret1, secret2.toString('base64')); - -// Create "another dh1" using generated keys from dh1, -// and compute secret again -var dh3 = crypto.createDiffieHellman(p1, 'buffer'); -var privkey1 = dh1.getPrivateKey(); -dh3.setPublicKey(key1); -dh3.setPrivateKey(privkey1); - -assert.deepEqual(dh1.getPrime(), dh3.getPrime()); -assert.deepEqual(dh1.getGenerator(), dh3.getGenerator()); -assert.deepEqual(dh1.getPublicKey(), dh3.getPublicKey()); -assert.deepEqual(dh1.getPrivateKey(), dh3.getPrivateKey()); - -var secret3 = dh3.computeSecret(key2, 'hex', 'base64'); - -assert.equal(secret1, secret3); - -// Run this one twice to make sure that the dh3 clears its error properly -(function() { - var c = crypto.createDecipher('aes-128-ecb', ''); - assert.throws(function() { c.final('utf8') }, /wrong final block length/); -})(); - -assert.throws(function() { - dh3.computeSecret(''); -}, /key is too small/i); - -(function() { - var c = crypto.createDecipher('aes-128-ecb', ''); - assert.throws(function() { c.final('utf8') }, /wrong final block length/); -})(); - -// Create a shared using a DH group. -var alice = crypto.createDiffieHellmanGroup('modp5'); -var bob = crypto.createDiffieHellmanGroup('modp5'); -alice.generateKeys(); -bob.generateKeys(); -var aSecret = alice.computeSecret(bob.getPublicKey()).toString('hex'); -var bSecret = bob.computeSecret(alice.getPublicKey()).toString('hex'); -assert.equal(aSecret, bSecret); - - -// https://github.com/joyent/node/issues/2338 -assert.throws(function() { - var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + - '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' + - '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' + - 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'; - crypto.createDiffieHellman(p, 'hex'); -}); - -// Test RSA key signing/verification -var rsaSign = crypto.createSign('RSA-SHA1'); -var rsaVerify = crypto.createVerify('RSA-SHA1'); -assert.ok(rsaSign); -assert.ok(rsaVerify); - -rsaSign.update(rsaPubPem); -var rsaSignature = rsaSign.sign(rsaKeyPem, 'hex'); -assert.equal(rsaSignature, - '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c' + - '8f020d7e2688b122bfb54c724ac9ee169f83f66d2fe90abeb95e8' + - 'e1290e7e177152a4de3d944cf7d4883114a20ed0f78e70e25ef0f' + - '60f06b858e6af42a2f276ede95bbc6bc9a9bbdda15bd663186a6f' + - '40819a7af19e577bb2efa5e579a1f5ce8a0d4ca8b8f6'); - -rsaVerify.update(rsaPubPem); -assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); - - -// -// Test RSA signing and verification -// -(function() { - var privateKey = fs.readFileSync( - common.fixturesDir + '/test_rsa_privkey_2.pem'); - - var publicKey = fs.readFileSync( - common.fixturesDir + '/test_rsa_pubkey_2.pem'); - - var input = 'I AM THE WALRUS'; - - var signature = - '79d59d34f56d0e94aa6a3e306882b52ed4191f07521f25f505a078dc2f89' + - '396e0c8ac89e996fde5717f4cb89199d8fec249961fcb07b74cd3d2a4ffa' + - '235417b69618e4bcd76b97e29975b7ce862299410e1b522a328e44ac9bb2' + - '8195e0268da7eda23d9825ac43c724e86ceeee0d0d4465678652ccaf6501' + - '0ddfb299bedeb1ad'; - - var sign = crypto.createSign('RSA-SHA256'); - sign.update(input); - - var output = sign.sign(privateKey, 'hex'); - assert.equal(output, signature); - - var verify = crypto.createVerify('RSA-SHA256'); - verify.update(input); - - assert.strictEqual(verify.verify(publicKey, signature, 'hex'), true); -})(); - - -// -// Test DSA signing and verification -// -(function() { - var privateKey = fs.readFileSync( - common.fixturesDir + '/test_dsa_privkey.pem'); - - var publicKey = fs.readFileSync( - common.fixturesDir + '/test_dsa_pubkey.pem'); - - var input = 'I AM THE WALRUS'; - - // DSA signatures vary across runs so there is no static string to verify - // against - var sign = crypto.createSign('DSS1'); - sign.update(input); - var signature = sign.sign(privateKey, 'hex'); - - var verify = crypto.createVerify('DSS1'); - verify.update(input); - - assert.strictEqual(verify.verify(publicKey, signature, 'hex'), true); -})(); - - -// -// Test PBKDF2 with RFC 6070 test vectors (except #4) -// -function testPBKDF2(password, salt, iterations, keylen, expected) { - var actual = crypto.pbkdf2Sync(password, salt, iterations, keylen); - assert.equal(actual.toString('binary'), expected); - - crypto.pbkdf2(password, salt, iterations, keylen, function(err, actual) { - assert.equal(actual.toString('binary'), expected); - }); -} - - -testPBKDF2('password', 'salt', 1, 20, - '\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9\xb5\x24' + - '\xaf\x60\x12\x06\x2f\xe0\x37\xa6'); - -testPBKDF2('password', 'salt', 2, 20, - '\xea\x6c\x01\x4d\xc7\x2d\x6f\x8c\xcd\x1e\xd9\x2a' + - '\xce\x1d\x41\xf0\xd8\xde\x89\x57'); - -testPBKDF2('password', 'salt', 4096, 20, - '\x4b\x00\x79\x01\xb7\x65\x48\x9a\xbe\xad\x49\xd9\x26' + - '\xf7\x21\xd0\x65\xa4\x29\xc1'); - -testPBKDF2('passwordPASSWORDpassword', - 'saltSALTsaltSALTsaltSALTsaltSALTsalt', - 4096, - 25, - '\x3d\x2e\xec\x4f\xe4\x1c\x84\x9b\x80\xc8\xd8\x36\x62' + - '\xc0\xe4\x4a\x8b\x29\x1a\x96\x4c\xf2\xf0\x70\x38'); - -testPBKDF2('pass\0word', 'sa\0lt', 4096, 16, - '\x56\xfa\x6a\xa7\x55\x48\x09\x9d\xcc\x37\xd7\xf0\x34' + - '\x25\xe0\xc3'); - -function assertSorted(list) { - assert.deepEqual(list, list.sort()); -} - -// Assume that we have at least AES-128-CBC. -assert.notEqual(0, crypto.getCiphers().length); -assert.notEqual(-1, crypto.getCiphers().indexOf('aes-128-cbc')); -assert.equal(-1, crypto.getCiphers().indexOf('AES-128-CBC')); -assertSorted(crypto.getCiphers()); - -// Assume that we have at least AES256-SHA. -var tls = require('tls'); -assert.notEqual(0, tls.getCiphers().length); -assert.notEqual(-1, tls.getCiphers().indexOf('aes256-sha')); -assert.equal(-1, tls.getCiphers().indexOf('AES256-SHA')); -assertSorted(tls.getCiphers()); - -// Assert that we have sha and sha1 but not SHA and SHA1. -assert.notEqual(0, crypto.getHashes().length); -assert.notEqual(-1, crypto.getHashes().indexOf('sha1')); -assert.notEqual(-1, crypto.getHashes().indexOf('sha')); -assert.equal(-1, crypto.getHashes().indexOf('SHA1')); -assert.equal(-1, crypto.getHashes().indexOf('SHA')); -assert.notEqual(-1, crypto.getHashes().indexOf('RSA-SHA1')); -assert.equal(-1, crypto.getHashes().indexOf('rsa-sha1')); -assertSorted(crypto.getHashes()); - -// Base64 padding regression test, see #4837. -(function() { - var c = crypto.createCipher('aes-256-cbc', 'secret'); - var s = c.update('test', 'utf8', 'base64') + c.final('base64'); - assert.equal(s, '375oxUQCIocvxmC5At+rvA=='); -})(); - -// Error path should not leak memory (check with valgrind). -assert.throws(function() { - crypto.pbkdf2('password', 'salt', 1, 20, null); -}); - -// Calling Cipher.final() or Decipher.final() twice should error but -// not assert. See #4886. -(function() { - var c = crypto.createCipher('aes-256-cbc', 'secret'); - try { c.final('xxx') } catch (e) { /* Ignore. */ } - try { c.final('xxx') } catch (e) { /* Ignore. */ } - try { c.final('xxx') } catch (e) { /* Ignore. */ } - var d = crypto.createDecipher('aes-256-cbc', 'secret'); - try { d.final('xxx') } catch (e) { /* Ignore. */ } - try { d.final('xxx') } catch (e) { /* Ignore. */ } - try { d.final('xxx') } catch (e) { /* Ignore. */ } -})(); - -// Regression test for #5482: string to Cipher#update() should not assert. -(function() { - var c = crypto.createCipher('aes192', '0123456789abcdef'); - c.update('update'); - c.final(); -})(); - -// #5655 regression tests, 'utf-8' and 'utf8' are identical. -(function() { - var c = crypto.createCipher('aes192', '0123456789abcdef'); - c.update('update', ''); // Defaults to "utf8". - c.final('utf-8'); // Should not throw. - - c = crypto.createCipher('aes192', '0123456789abcdef'); - c.update('update', 'utf8'); - c.final('utf-8'); // Should not throw. - - c = crypto.createCipher('aes192', '0123456789abcdef'); - c.update('update', 'utf-8'); - c.final('utf8'); // Should not throw. -})(); - -// Regression tests for #5725: hex input that's not a power of two should -// throw, not assert in C++ land. -assert.throws(function() { - crypto.createCipher('aes192', 'test').update('0', 'hex'); -}, /Bad input string/); - -assert.throws(function() { - crypto.createDecipher('aes192', 'test').update('0', 'hex'); -}, /Bad input string/); - -assert.throws(function() { - crypto.createHash('sha1').update('0', 'hex'); -}, /Bad input string/); - -assert.throws(function() { - crypto.createSign('RSA-SHA1').update('0', 'hex'); -}, /Bad input string/); - -assert.throws(function() { - crypto.createVerify('RSA-SHA1').update('0', 'hex'); -}, /Bad input string/); - -assert.throws(function() { - var private = [ - '-----BEGIN RSA PRIVATE KEY-----', - 'MIGrAgEAAiEA+3z+1QNF2/unumadiwEr+C5vfhezsb3hp4jAnCNRpPcCAwEAAQIgQNriSQK4', - 'EFwczDhMZp2dvbcz7OUUyt36z3S4usFPHSECEQD/41K7SujrstBfoCPzwC1xAhEA+5kt4BJy', - 'eKN7LggbF3Dk5wIQN6SL+fQ5H/+7NgARsVBp0QIRANxYRukavs4QvuyNhMx+vrkCEQCbf6j/', - 'Ig6/HueCK/0Jkmp+', - '-----END RSA PRIVATE KEY-----', - '' - ].join('\n'); - crypto.createSign('RSA-SHA256').update('test').sign(private); -}, /SignFinal/); diff --git a/test/simple/test-debug-brk-no-arg.js b/test/simple/test-debug-brk-no-arg.js deleted file mode 100644 index f02527cf66e8..000000000000 --- a/test/simple/test-debug-brk-no-arg.js +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; - -var child = spawn(process.execPath, ['--debug-brk=' + common.PORT]); -child.stderr.once('data', function(c) { - console.error('%j', c.toString()); - child.stdin.end(); -}); - -child.on('exit', function(c) { - assert(c === 0); - console.log('ok'); -}); diff --git a/test/simple/test-debugger-client.js b/test/simple/test-debugger-client.js deleted file mode 100644 index 6480e1c4d6ba..000000000000 --- a/test/simple/test-debugger-client.js +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -process.env.NODE_DEBUGGER_TIMEOUT = 2000; -var common = require('../common'); -var assert = require('assert'); -var debug = require('_debugger'); - -var debugPort = common.PORT + 1337; -debug.port = debugPort; -var spawn = require('child_process').spawn; - -setTimeout(function() { - if (nodeProcess) nodeProcess.kill('SIGTERM'); - throw new Error('timeout'); -}, 10000).unref(); - - -var resCount = 0; -var p = new debug.Protocol(); -p.onResponse = function(res) { - resCount++; -}; - -p.execute('Type: connect\r\n' + - 'V8-Version: 3.0.4.1\r\n' + - 'Protocol-Version: 1\r\n' + - 'Embedding-Host: node v0.3.3-pre\r\n' + - 'Content-Length: 0\r\n\r\n'); -assert.equal(1, resCount); - -// Make sure split messages go in. - -var parts = []; -parts.push('Content-Length: 336\r\n'); -assert.equal(21, parts[0].length); -parts.push('\r\n'); -assert.equal(2, parts[1].length); -var bodyLength = 0; - -parts.push('{"seq":12,"type":"event","event":"break","body":' + - '{"invocationText":"#'); -assert.equal(78, parts[2].length); -bodyLength += parts[2].length; - -parts.push('.[anonymous](req=#, ' + - 'res=#)","sourceLine"'); -assert.equal(78, parts[3].length); -bodyLength += parts[3].length; - -parts.push(':45,"sourceColumn":4,"sourceLineText":" debugger;",' + - '"script":{"id":24,"name":"/home/ryan/projects/node/' + - 'benchmark/http_simple.js","lineOffset":0,"columnOffset":0,' + - '"lineCount":98}}}'); -assert.equal(180, parts[4].length); -bodyLength += parts[4].length; - -assert.equal(336, bodyLength); - -for (var i = 0; i < parts.length; i++) { - p.execute(parts[i]); -} -assert.equal(2, resCount); - - -// Make sure that if we get backed up, we still manage to get all the -// messages -var d = 'Content-Length: 466\r\n\r\n' + - '{"seq":10,"type":"event","event":"afterCompile","success":true,' + - '"body":{"script":{"handle":1,"type":"script","name":"dns.js",' + - '"id":34,"lineOffset":0,"columnOffset":0,"lineCount":241,' + - '"sourceStart":"(function (module, exports, require) {' + - 'var dns = process.binding(\'cares\')' + - ';\\nvar ne","sourceLength":6137,"scriptType":2,"compilationType":0,' + - '"context":{"ref":0},"text":"dns.js (lines: 241)"}},"refs":' + - '[{"handle":0' + - ',"type":"context","text":"#"}],"running":true}' + - 'Content-Length: 119\r\n\r\n' + - '{"seq":11,"type":"event","event":"scriptCollected","success":true,' + - '"body":{"script":{"id":26}},"refs":[],"running":true}'; -p.execute(d); -assert.equal(4, resCount); - -var expectedConnections = 0; -var tests = []; -function addTest(cb) { - expectedConnections++; - tests.push(cb); -} - -addTest(function(client, done) { - console.error('requesting version'); - client.reqVersion(function(err, v) { - assert.ok(!err); - console.log('version: %s', v); - assert.equal(process.versions.v8, v); - done(); - }); -}); - -addTest(function(client, done) { - console.error('requesting scripts'); - client.reqScripts(function(err) { - assert.ok(!err); - console.error('got %d scripts', Object.keys(client.scripts).length); - - var foundMainScript = false; - for (var k in client.scripts) { - var script = client.scripts[k]; - if (script && script.name === 'node.js') { - foundMainScript = true; - break; - } - } - assert.ok(foundMainScript); - done(); - }); -}); - -addTest(function(client, done) { - console.error('eval 2+2'); - client.reqEval('2+2', function(err, res) { - console.error(res); - assert.ok(!err); - assert.equal('4', res.text); - assert.equal(4, res.value); - done(); - }); -}); - - -var connectCount = 0; -var script = 'setTimeout(function () { console.log("blah"); });' + - 'setInterval(function () {}, 1000000);'; - -var nodeProcess; - -function doTest(cb, done) { - var args = ['--debug=' + debugPort, '-e', script]; - nodeProcess = spawn(process.execPath, args); - - nodeProcess.stdout.once('data', function(c) { - console.log('>>> new node process: %d', nodeProcess.pid); - var failed = true; - try { - process._debugProcess(nodeProcess.pid); - failed = false; - } finally { - // At least TRY not to leave zombie procs if this fails. - if (failed) - nodeProcess.kill('SIGTERM'); - } - console.log('>>> starting debugger session'); - }); - - var didTryConnect = false; - nodeProcess.stderr.setEncoding('utf8'); - var b = ''; - nodeProcess.stderr.on('data', function(data) { - console.error('got stderr data %j', data); - nodeProcess.stderr.resume(); - b += data; - if (didTryConnect == false && - b.match(/debugger listening on port/)) { - didTryConnect = true; - - setTimeout(function() { - // Wait for some data before trying to connect - var c = new debug.Client(); - console.error('>>> connecting...'); - c.connect(debug.port); - c.on('break', function(brk) { - c.reqContinue(function() {}); - }); - c.on('ready', function() { - connectCount++; - console.log('ready!'); - cb(c, function() { - c.end(); - c.on('end', function() { - console.error( - '>>> killing node process %d\n\n', - nodeProcess.pid); - nodeProcess.kill(); - done(); - }); - }); - }); - }); - } - }); -} - - -function run() { - var t = tests[0]; - if (!t) return; - - doTest(t, function() { - tests.shift(); - run(); - }); -} - -run(); - -process.on('exit', function(code) { - if (!code) - assert.equal(expectedConnections, connectCount); -}); - diff --git a/test/simple/test-debugger-repl-break-in-module.js b/test/simple/test-debugger-repl-break-in-module.js deleted file mode 100644 index 1fe0aba841ea..000000000000 --- a/test/simple/test-debugger-repl-break-in-module.js +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var repl = require('./helper-debugger-repl.js'); - -repl.startDebugger('break-in-module/main.js'); - -// -- SET BREAKPOINT -- - -// Set breakpoint by file name + line number where the file is not loaded yet -repl.addTest('sb("mod.js", 23)', [ - /Warning: script 'mod\.js' was not loaded yet\./, - /1/, /2/, /3/, /4/, /5/, /6/ -]); - -// Check escaping of regex characters -repl.addTest('sb(")^$*+?}{|][(.js\\\\", 1)', [ - /Warning: script '[^']+' was not loaded yet\./, - /1/, /2/, /3/, /4/, /5/, /6/ -]); - -// continue - the breakpoint should be triggered -repl.addTest('c', [ - /break in .*[\\\/]mod\.js:23/, - /21/, /22/, /23/, /24/, /25/ -]); - -// -- RESTORE BREAKPOINT ON RESTART -- - -// Restart the application - breakpoint should be restored -repl.addTest('restart', [].concat( - [ - /terminated/ - ], - repl.handshakeLines, - [ - /Restoring breakpoint mod.js:23/, - /Warning: script 'mod\.js' was not loaded yet\./, - /Restoring breakpoint \).*:\d+/, - /Warning: script '\)[^']*' was not loaded yet\./ - ], - repl.initialBreakLines)); - -// continue - the breakpoint should be triggered -repl.addTest('c', [ - /break in .*[\\\/]mod\.js:23/, - /21/, /22/, /23/, /24/, /25/ -]); - -// -- CLEAR BREAKPOINT SET IN MODULE TO BE LOADED -- - -repl.addTest('cb("mod.js", 23)', [ - /18/, /./, /./, /./, /./, /./, /./, /./, /26/ -]); - -repl.addTest('c', [ - /break in .*[\\\/]main\.js:4/, - /2/, /3/, /4/, /5/, /6/ -]); - -// -- (END) -- -repl.addTest('quit', []); diff --git a/test/simple/test-debugger-repl-restart.js b/test/simple/test-debugger-repl-restart.js deleted file mode 100644 index 5bfc3bbed7e3..000000000000 --- a/test/simple/test-debugger-repl-restart.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var repl = require('./helper-debugger-repl.js'); - -repl.startDebugger('breakpoints.js'); -var linesWithBreakpoint = [ - /1/, /2/, /3/, /4/, /5/, /\* 6/ -]; -// We slice here, because addTest will change the given array. -repl.addTest('sb(6)', linesWithBreakpoint.slice()); - -var initialLines = repl.initialLines.slice() -initialLines.splice(2, 0, /Restoring/, /Warning/); - -// Restart the debugged script -repl.addTest('restart', [ - /terminated/, -].concat(initialLines)); - -repl.addTest('list(5)', linesWithBreakpoint); -repl.addTest('quit', []); diff --git a/test/simple/test-debugger-repl-utf8.js b/test/simple/test-debugger-repl-utf8.js deleted file mode 100644 index 73314b8a6a5b..000000000000 --- a/test/simple/test-debugger-repl-utf8.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var script = common.fixturesDir + '/breakpoints_utf8.js'; -process.env.NODE_DEBUGGER_TEST_SCRIPT = script; - -require('./test-debugger-repl.js'); - diff --git a/test/simple/test-debugger-repl.js b/test/simple/test-debugger-repl.js deleted file mode 100644 index 40639e0219fd..000000000000 --- a/test/simple/test-debugger-repl.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var repl = require('./helper-debugger-repl.js'); - -repl.startDebugger('breakpoints.js'); - -var addTest = repl.addTest; - -// Next -addTest('n', [ - /break in .*:11/, - /9/, /10/, /11/, /12/, /13/ -]); - -// Watch -addTest('watch("\'x\'")'); - -// Continue -addTest('c', [ - /break in .*:5/, - /Watchers/, - /0:\s+'x' = "x"/, - /()/, - /3/, /4/, /5/, /6/, /7/ -]); - -// Show watchers -addTest('watchers', [ - /0:\s+'x' = "x"/ -]); - -// Unwatch -addTest('unwatch("\'x\'")'); - -// Step out -addTest('o', [ - /break in .*:12/, - /10/, /11/, /12/, /13/, /14/ -]); - -// Continue -addTest('c', [ - /break in .*:5/, - /3/, /4/, /5/, /6/, /7/ -]); - -// Set breakpoint by function name -addTest('sb("setInterval()", "!(setInterval.flag++)")', [ - /1/, /2/, /3/, /4/, /5/, /6/, /7/, /8/, /9/, /10/ -]); - -// Continue -addTest('c', [ - /break in node.js:\d+/, - /\d/, /\d/, /\d/, /\d/, /\d/ -]); - -addTest('quit', []); diff --git a/test/simple/test-delayed-require.js b/test/simple/test-delayed-require.js deleted file mode 100644 index 31c324976f32..000000000000 --- a/test/simple/test-delayed-require.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var a; -setTimeout(function() { - a = require('../fixtures/a'); -}, 50); - -process.on('exit', function() { - assert.equal(true, 'A' in a); - assert.equal('A', a.A()); - assert.equal('D', a.D()); -}); diff --git a/test/simple/test-deprecation-flags.js b/test/simple/test-deprecation-flags.js deleted file mode 100644 index 81605da21f39..000000000000 --- a/test/simple/test-deprecation-flags.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var execFile = require('child_process').execFile; -var depmod = require.resolve('../fixtures/deprecated.js'); -var node = process.execPath; - -var normal = [depmod]; -var noDep = ['--no-deprecation', depmod]; -var traceDep = ['--trace-deprecation', depmod]; - -execFile(node, normal, function(er, stdout, stderr) { - console.error('normal: show deprecation warning'); - assert.equal(er, null); - assert.equal(stdout, ''); - assert.equal(stderr, 'util.p: Use console.error() instead.\n\'This is deprecated\'\n'); - console.log('normal ok'); -}); - -execFile(node, noDep, function(er, stdout, stderr) { - console.error('--no-deprecation: silence deprecations'); - assert.equal(er, null); - assert.equal(stdout, ''); - assert.equal(stderr, '\'This is deprecated\'\n'); - console.log('silent ok'); -}); - -execFile(node, traceDep, function(er, stdout, stderr) { - console.error('--trace-deprecation: show stack'); - assert.equal(er, null); - assert.equal(stdout, ''); - var stack = stderr.trim().split('\n'); - // just check the top and bottom. - assert.equal(stack[0], 'Trace: util.p: Use console.error() instead.'); - assert.equal(stack.pop(), '\'This is deprecated\''); - console.log('trace ok'); -}); diff --git a/test/simple/test-dgram-address.js b/test/simple/test-dgram-address.js deleted file mode 100644 index 30d8eb0e16cd..000000000000 --- a/test/simple/test-dgram-address.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); - -// IPv4 Test -var localhost_ipv4 = '127.0.0.1'; -var socket_ipv4 = dgram.createSocket('udp4'); -var family_ipv4 = 'IPv4'; - -socket_ipv4.on('listening', function() { - var address_ipv4 = socket_ipv4.address(); - assert.strictEqual(address_ipv4.address, localhost_ipv4); - assert.strictEqual(address_ipv4.port, common.PORT); - assert.strictEqual(address_ipv4.family, family_ipv4); - socket_ipv4.close(); -}); - -socket_ipv4.on('error', function(e) { - console.log('Error on udp4 socket. ' + e.toString()); - socket_ipv4.close(); -}); - -socket_ipv4.bind(common.PORT, localhost_ipv4); - -// IPv6 Test -var localhost_ipv6 = '::1'; -var socket_ipv6 = dgram.createSocket('udp6'); -var family_ipv6 = 'IPv6'; - -socket_ipv6.on('listening', function() { - var address_ipv6 = socket_ipv6.address(); - assert.strictEqual(address_ipv6.address, localhost_ipv6); - assert.strictEqual(address_ipv6.port, common.PORT); - assert.strictEqual(address_ipv6.family, family_ipv6); - socket_ipv6.close(); -}); - -socket_ipv6.on('error', function(e) { - console.log('Error on udp6 socket. ' + e.toString()); - socket_ipv6.close(); -}); - -socket_ipv6.bind(common.PORT, localhost_ipv6); diff --git a/test/simple/test-dgram-bind-default-address.js b/test/simple/test-dgram-bind-default-address.js deleted file mode 100644 index ae1b472a08e0..000000000000 --- a/test/simple/test-dgram-bind-default-address.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); - -dgram.createSocket('udp4').bind(common.PORT + 0, common.mustCall(function() { - assert.equal(this.address().port, common.PORT + 0); - assert.equal(this.address().address, '0.0.0.0'); - this.close(); -})); - -dgram.createSocket('udp6').bind(common.PORT + 1, common.mustCall(function() { - assert.equal(this.address().port, common.PORT + 1); - var address = this.address().address; - if (address === '::ffff:0.0.0.0') - address = '::'; - assert.equal(address, '::'); - this.close(); -})); diff --git a/test/simple/test-dgram-bind.js b/test/simple/test-dgram-bind.js deleted file mode 100644 index 8ee67637fcb6..000000000000 --- a/test/simple/test-dgram-bind.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); - -var socket = dgram.createSocket('udp4'); - -socket.on('listening', function () { - socket.close(); -}); - -socket.bind(); // should not throw diff --git a/test/simple/test-dgram-broadcast-multi-process.js b/test/simple/test-dgram-broadcast-multi-process.js deleted file mode 100644 index ad5b4eba82d4..000000000000 --- a/test/simple/test-dgram-broadcast-multi-process.js +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'), - assert = require('assert'), - dgram = require('dgram'), - util = require('util'), - networkInterfaces = require('os').networkInterfaces(), - Buffer = require('buffer').Buffer, - fork = require('child_process').fork, - LOCAL_BROADCAST_HOST = '255.255.255.255', - TIMEOUT = 5000, - messages = [ - new Buffer('First message to send'), - new Buffer('Second message to send'), - new Buffer('Third message to send'), - new Buffer('Fourth message to send') - ]; - -// take the first non-internal interface as the address for binding -get_bindAddress: for (var name in networkInterfaces) { - var interfaces = networkInterfaces[name]; - for(var i = 0; i < interfaces.length; i++) { - var localInterface = interfaces[i]; - if (!localInterface.internal && localInterface.family === 'IPv4') { - var bindAddress = localInterface.address; - break get_bindAddress; - } - } -} -assert.ok(bindAddress); - -if (process.argv[2] !== 'child') { - var workers = {}, - listeners = 3, - listening = 0, - dead = 0, - i = 0, - done = 0, - timer = null; - - //exit the test if it doesn't succeed within TIMEOUT - timer = setTimeout(function() { - console.error('[PARENT] Responses were not received within %d ms.', - TIMEOUT); - console.error('[PARENT] Fail'); - - killChildren(workers); - - process.exit(1); - }, TIMEOUT); - - //launch child processes - for (var x = 0; x < listeners; x++) { - (function() { - var worker = fork(process.argv[1], ['child']); - workers[worker.pid] = worker; - - worker.messagesReceived = []; - - //handle the death of workers - worker.on('exit', function(code, signal) { - // don't consider this the true death if the worker - // has finished successfully - // or if the exit code is 0 - if (worker.isDone || code == 0) { - return; - } - - dead += 1; - console.error('[PARENT] Worker %d died. %d dead of %d', - worker.pid, - dead, - listeners); - - if (dead === listeners) { - console.error('[PARENT] All workers have died.'); - console.error('[PARENT] Fail'); - - killChildren(workers); - - process.exit(1); - } - }); - - worker.on('message', function(msg) { - if (msg.listening) { - listening += 1; - - if (listening === listeners) { - //all child process are listening, so start sending - sendSocket.sendNext(); - } - } - else if (msg.message) { - worker.messagesReceived.push(msg.message); - - if (worker.messagesReceived.length === messages.length) { - done += 1; - worker.isDone = true; - console.error('[PARENT] %d received %d messages total.', - worker.pid, - worker.messagesReceived.length); - } - - if (done === listeners) { - console.error('[PARENT] All workers have received the ' + - 'required number of ' + - 'messages. Will now compare.'); - - Object.keys(workers).forEach(function(pid) { - var worker = workers[pid]; - - var count = 0; - - worker.messagesReceived.forEach(function(buf) { - for (var i = 0; i < messages.length; ++i) { - if (buf.toString() === messages[i].toString()) { - count++; - break; - } - } - }); - - console.error('[PARENT] %d received %d matching messges.', - worker.pid, - count); - - assert.equal(count, messages.length, - 'A worker received an invalid multicast message'); - }); - - clearTimeout(timer); - console.error('[PARENT] Success'); - killChildren(workers); - } - } - }); - })(x); - } - - var sendSocket = dgram.createSocket('udp4'); - - // bind the address explicitly for sending - // INADDR_BROADCAST to only one interface - sendSocket.bind(common.PORT, bindAddress); - sendSocket.on('listening', function () { - sendSocket.setBroadcast(true); - }); - - sendSocket.on('close', function() { - console.error('[PARENT] sendSocket closed'); - }); - - sendSocket.sendNext = function() { - var buf = messages[i++]; - - if (!buf) { - try { sendSocket.close(); } catch (e) {} - return; - } - - sendSocket.send(buf, 0, buf.length, - common.PORT, LOCAL_BROADCAST_HOST, function(err) { - - if (err) throw err; - - console.error('[PARENT] sent %s to %s:%s', - util.inspect(buf.toString()), - LOCAL_BROADCAST_HOST, common.PORT); - - process.nextTick(sendSocket.sendNext); - }); - }; - - function killChildren(children) { - Object.keys(children).forEach(function(key) { - var child = children[key]; - child.kill(); - }); - } -} - -if (process.argv[2] === 'child') { - var receivedMessages = []; - var listenSocket = dgram.createSocket('udp4'); - - listenSocket.on('message', function(buf, rinfo) { - // receive udp messages only sent from parent - if (rinfo.address !== bindAddress) return; - - console.error('[CHILD] %s received %s from %j', - process.pid, - util.inspect(buf.toString()), - rinfo); - - receivedMessages.push(buf); - - process.send({ message: buf.toString() }); - - if (receivedMessages.length == messages.length) { - process.nextTick(function() { - listenSocket.close(); - }); - } - }); - - listenSocket.on('close', function() { - //HACK: Wait to exit the process to ensure that the parent - //process has had time to receive all messages via process.send() - //This may be indicitave of some other issue. - setTimeout(function() { - process.exit(); - }, 1000); - }); - - listenSocket.on('listening', function() { - process.send({ listening: true }); - }); - - listenSocket.bind(common.PORT); -} diff --git a/test/simple/test-dgram-close.js b/test/simple/test-dgram-close.js deleted file mode 100644 index 77af6f13b801..000000000000 --- a/test/simple/test-dgram-close.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Ensure that if a dgram socket is closed before the DNS lookup completes, it -// won't crash. - -var assert = require('assert'), - common = require('../common'), - dgram = require('dgram'); - -var buf = new Buffer(1024); -buf.fill(42); - -var socket = dgram.createSocket('udp4'); -var handle = socket._handle; -socket.send(buf, 0, buf.length, common.PORT, 'localhost'); -socket.close(); -socket = null; - -// Verify that accessing handle after closure doesn't throw -setImmediate(function() { - setImmediate(function() { - console.log('Handle fd is: ', handle.fd); - }); -}); diff --git a/test/simple/test-dgram-implicit-bind.js b/test/simple/test-dgram-implicit-bind.js deleted file mode 100644 index 6039629c4183..000000000000 --- a/test/simple/test-dgram-implicit-bind.js +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); - -var source = dgram.createSocket('udp4'); -var target = dgram.createSocket('udp4'); -var messages = 0; - -process.on('exit', function() { - assert.equal(messages, 2); -}); - -target.on('message', function(buf) { - if (buf.toString() === 'abc') ++messages; - if (buf.toString() === 'def') ++messages; - if (messages === 2) { - source.close(); - target.close(); - } -}); - -target.on('listening', function() { - // Second .send() call should not throw a bind error. - source.send(Buffer('abc'), 0, 3, common.PORT, '127.0.0.1'); - source.send(Buffer('def'), 0, 3, common.PORT, '127.0.0.1'); -}); - -target.bind(common.PORT); diff --git a/test/simple/test-dgram-listen-after-bind.js b/test/simple/test-dgram-listen-after-bind.js deleted file mode 100644 index e5f1c4d653f0..000000000000 --- a/test/simple/test-dgram-listen-after-bind.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); - -var socket = dgram.createSocket('udp4'); - -socket.bind(); - -var fired = false; -var timer = setTimeout(function () { - socket.close(); -}, 100); - -socket.on('listening', function () { - clearTimeout(timer); - fired = true; - socket.close(); -}); - -socket.on('close', function () { - assert(fired, 'listening should fire after bind'); -}); diff --git a/test/simple/test-dgram-multicast-setTTL.js b/test/simple/test-dgram-multicast-setTTL.js deleted file mode 100644 index 2ef0c167a883..000000000000 --- a/test/simple/test-dgram-multicast-setTTL.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'), - assert = require('assert'), - dgram = require('dgram'), - thrown = false, - socket = dgram.createSocket('udp4'); - -socket.bind(common.PORT); -socket.on('listening', function () { - socket.setMulticastTTL(16); - - //Try to set an invalid TTL (valid ttl is > 0 and < 256) - try { - socket.setMulticastTTL(1000); - } catch (e) { - thrown = true; - } - - assert(thrown, 'Setting an invalid multicast TTL should throw some error'); - - //close the socket - socket.close(); -}); diff --git a/test/simple/test-dgram-oob-buffer.js b/test/simple/test-dgram-oob-buffer.js deleted file mode 100644 index a3967fb614a4..000000000000 --- a/test/simple/test-dgram-oob-buffer.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Some operating systems report errors when an UDP message is sent to an -// unreachable host. This error can be reported by sendto() and even by -// recvfrom(). Node should not propagate this error to the user. - -var common = require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); - -var socket = dgram.createSocket('udp4'); -var buf = Buffer([1,2,3,4]); - -function ok() {} -socket.send(buf, 0, 0, common.PORT, '127.0.0.1', ok); // useful? no -socket.send(buf, 0, 4, common.PORT, '127.0.0.1', ok); -socket.send(buf, 1, 3, common.PORT, '127.0.0.1', ok); -socket.send(buf, 3, 1, common.PORT, '127.0.0.1', ok); - -assert.throws(function() { - socket.send(buf, 0, 5, common.PORT, '127.0.0.1', assert.fail); -}); -assert.throws(function() { - socket.send(buf, 2, 3, common.PORT, '127.0.0.1', assert.fail); -}); -assert.throws(function() { - socket.send(buf, 4, 0, common.PORT, '127.0.0.1', assert.fail); -}); -assert.throws(function() { - socket.send(buf, 4, 4, common.PORT, '127.0.0.1', assert.fail); -}); - -socket.close(); // FIXME should not be necessary diff --git a/test/simple/test-dgram-pingpong.js b/test/simple/test-dgram-pingpong.js deleted file mode 100644 index 992153293bac..000000000000 --- a/test/simple/test-dgram-pingpong.js +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var Buffer = require('buffer').Buffer; -var dgram = require('dgram'); - -var debug = false; -var tests_run = 0; - -function pingPongTest(port, host) { - var callbacks = 0; - var N = 500; - var count = 0; - var sent_final_ping = false; - - var server = dgram.createSocket('udp4', function(msg, rinfo) { - if (debug) console.log('server got: ' + msg + - ' from ' + rinfo.address + ':' + rinfo.port); - - if (/PING/.exec(msg)) { - var buf = new Buffer(4); - buf.write('PONG'); - server.send(buf, 0, buf.length, - rinfo.port, rinfo.address, - function(err, sent) { - callbacks++; - }); - } - }); - - server.on('error', function(e) { - throw e; - }); - - server.on('listening', function() { - console.log('server listening on ' + port + ' ' + host); - - var buf = new Buffer('PING'), - client = dgram.createSocket('udp4'); - - client.on('message', function(msg, rinfo) { - if (debug) console.log('client got: ' + msg + - ' from ' + rinfo.address + ':' + rinfo.port); - assert.equal('PONG', msg.toString('ascii')); - - count += 1; - - if (count < N) { - client.send(buf, 0, buf.length, port, 'localhost'); - } else { - sent_final_ping = true; - client.send(buf, 0, buf.length, port, 'localhost', function() { - client.close(); - }); - } - }); - - client.on('close', function() { - console.log('client has closed, closing server'); - assert.equal(N, count); - tests_run += 1; - server.close(); - assert.equal(N - 1, callbacks); - }); - - client.on('error', function(e) { - throw e; - }); - - console.log('Client sending to ' + port + ', localhost ' + buf); - client.send(buf, 0, buf.length, port, 'localhost', function(err, bytes) { - if (err) { - throw err; - } - console.log('Client sent ' + bytes + ' bytes'); - }); - count += 1; - }); - server.bind(port, host); -} - -// All are run at once, so run on different ports -pingPongTest(common.PORT + 0, 'localhost'); -pingPongTest(common.PORT + 1, 'localhost'); -pingPongTest(common.PORT + 2); -//pingPongTest('/tmp/pingpong.sock'); - -process.on('exit', function() { - assert.equal(3, tests_run); - console.log('done'); -}); diff --git a/test/simple/test-dgram-ref.js b/test/simple/test-dgram-ref.js deleted file mode 100644 index ebbbac2fc641..000000000000 --- a/test/simple/test-dgram-ref.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var dgram = require('dgram'); - -// should not hang, see #1282 -dgram.createSocket('udp4'); -dgram.createSocket('udp6'); diff --git a/test/simple/test-dgram-regress-4496.js b/test/simple/test-dgram-regress-4496.js deleted file mode 100644 index 33b12847f434..000000000000 --- a/test/simple/test-dgram-regress-4496.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Remove this test once we support sending strings. - -var common = require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); - -// Should throw but not crash. -var socket = dgram.createSocket('udp4'); -assert.throws(function() { socket.send('BAM', 0, 1, 1, 'host') }, TypeError); -assert.throws(function() { socket.sendto('BAM', 0, 1, 1, 'host') }, TypeError); -socket.close(); diff --git a/test/simple/test-dgram-send-bad-arguments.js b/test/simple/test-dgram-send-bad-arguments.js deleted file mode 100644 index a9a12d458153..000000000000 --- a/test/simple/test-dgram-send-bad-arguments.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var dgram = require('dgram'); - -var buf = Buffer('test'); -var host = '127.0.0.1'; -var sock = dgram.createSocket('udp4'); - -assert.throws(function() { - sock.send(); -}, TypeError); // First argument should be a buffer. - -assert.throws(function() { sock.send(buf, -1, 1, 1, host); }, RangeError); -assert.throws(function() { sock.send(buf, 1, -1, 1, host); }, RangeError); -assert.throws(function() { sock.send(buf, 1, 1, -1, host); }, RangeError); -assert.throws(function() { sock.send(buf, 5, 1, 1, host); }, RangeError); -assert.throws(function() { sock.send(buf, 1, 5, 1, host); }, RangeError); -assert.throws(function() { sock.send(buf, 1, 1, 0, host); }, RangeError); -assert.throws(function() { sock.send(buf, 1, 1, 65536, host); }, RangeError); diff --git a/test/simple/test-dgram-udp4.js b/test/simple/test-dgram-udp4.js deleted file mode 100644 index 9a82de5c0d0c..000000000000 --- a/test/simple/test-dgram-udp4.js +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -var Buffer = require('buffer').Buffer, - fs = require('fs'), - dgram = require('dgram'), server, client, - server_port = 20989, - message_to_send = new Buffer('A message to send'), - timer; - -server = dgram.createSocket('udp4'); -server.on('message', function(msg, rinfo) { - console.log('server got: ' + msg + - ' from ' + rinfo.address + ':' + rinfo.port); - assert.strictEqual(rinfo.address, '127.0.0.1'); - assert.strictEqual(msg.toString(), message_to_send.toString()); - server.send(msg, 0, msg.length, rinfo.port, rinfo.address); -}); -server.on('listening', function() { - var address = server.address(); - console.log('server is listening on ' + address.address + ':' + address.port); - client = dgram.createSocket('udp4'); - client.on('message', function(msg, rinfo) { - console.log('client got: ' + msg + - ' from ' + rinfo.address + ':' + address.port); - assert.strictEqual(rinfo.address, '127.0.0.1'); - assert.strictEqual(rinfo.port, server_port); - assert.strictEqual(msg.toString(), message_to_send.toString()); - client.close(); - server.close(); - }); - client.send(message_to_send, 0, message_to_send.length, - server_port, 'localhost', function(err, bytes) { - if (err) { - console.log('Caught error in client send.'); - throw err; - } - console.log('client wrote ' + bytes + ' bytes.'); - assert.strictEqual(bytes, message_to_send.length); - }); - client.on('close', - function() { - if (server.fd === null) { - clearTimeout(timer); - } - }); -}); -server.on('close', function() { - if (client.fd === null) { - clearTimeout(timer); - } -}); -server.bind(server_port); - -timer = setTimeout(function() { - throw new Error('Timeout'); -}, 200); diff --git a/test/simple/test-dgram-unref.js b/test/simple/test-dgram-unref.js deleted file mode 100644 index 38abbac2741e..000000000000 --- a/test/simple/test-dgram-unref.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var dgram = require('dgram'); -var closed = false; - -var s = dgram.createSocket('udp4'); -s.bind(); -s.unref(); - -setTimeout(function() { - closed = true; - s.close(); -}, 1000).unref(); - -process.on('exit', function() { - assert.strictEqual(closed, false, 'Unrefd socket should not hold loop open'); -}); diff --git a/test/simple/test-dh-padding.js b/test/simple/test-dh-padding.js deleted file mode 100644 index 753c0eb81955..000000000000 --- a/test/simple/test-dh-padding.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -try { - var crypto = require('crypto'); -} catch (e) { - console.log('Not compiled with OPENSSL support.'); - process.exit(); -} - -var prime = 'c51f7bf8f0e1cf899243cdf408b1bc7c09c010e33ef7f3fbe5bd5feaf906113b'; -var apub = '6fe9f37037d8d017f908378c1ee04fe60e1cd3668bfc5075fac55c2f7153dd84'; -var bpub = '31d83e167fdf956c9dae6b980140577a9f8868acbfcbdc19113e58bfb9223abc'; -var apriv = '4fbfd4661f9181bbf574537b1a78adf473e8e771eef13c605e963c0f3094b697'; -var secret = '25616eed33f1af7975bbd0a8071d98a014f538b243bef90d76c08e81a0b3c500'; - -var p = crypto.createDiffieHellman(prime, 'hex'); - -p.setPublicKey(apub, 'hex'); -p.setPrivateKey(apriv, 'hex'); - -assert.equal( - p.computeSecret(bpub, 'hex', 'hex'), - '0025616eed33f1af7975bbd0a8071d98a014f538b243bef90d76c08e81a0b3c5' -); diff --git a/test/simple/test-domain-crypto.js b/test/simple/test-domain-crypto.js deleted file mode 100644 index 66e962880448..000000000000 --- a/test/simple/test-domain-crypto.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -try { - var crypto = require('crypto'); -} catch (e) { - console.log('Not compiled with OPENSSL support.'); - process.exit(); -} - -// the missing var keyword is intentional -domain = require('domain'); - -// should not throw a 'TypeError: undefined is not a function' exception -crypto.randomBytes(8); -crypto.randomBytes(8, function() {}); -crypto.pseudoRandomBytes(8); -crypto.pseudoRandomBytes(8, function() {}); -crypto.pbkdf2('password', 'salt', 8, 8, function() {}); diff --git a/test/simple/test-domain-exit-dispose-again.js b/test/simple/test-domain-exit-dispose-again.js deleted file mode 100644 index 22928f260451..000000000000 --- a/test/simple/test-domain-exit-dispose-again.js +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var assert = require('assert'); -var domain = require('domain'); -var disposalFailed = false; - -// no matter what happens, we should increment a 10 times. -var a = 0; -log(); -function log(){ - console.log(a++, process.domain); - if (a < 10) setTimeout(log, 20); -} - -var secondTimerRan = false; - -// in 50ms we'll throw an error. -setTimeout(err, 50); -setTimeout(secondTimer, 50); -function err(){ - var d = domain.create(); - d.on('error', handle); - d.run(err2); - - function err2() { - // this timeout should never be called, since the domain gets - // disposed when the error happens. - setTimeout(function() { - console.error('This should not happen.'); - disposalFailed = true; - process.exit(1); - }); - - // this function doesn't exist, and throws an error as a result. - err3(); - } - - function handle(e) { - // this should clean up everything properly. - d.dispose(); - console.error(e); - console.error('in handler', process.domain, process.domain === d); - } -} - -function secondTimer() { - console.log('In second timer'); - secondTimerRan = true; -} - -process.on('exit', function() { - assert.equal(a, 10); - assert.equal(disposalFailed, false); - assert(secondTimerRan); - console.log('ok'); -}); diff --git a/test/simple/test-domain-exit-dispose.js b/test/simple/test-domain-exit-dispose.js deleted file mode 100644 index fd990911c169..000000000000 --- a/test/simple/test-domain-exit-dispose.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var assert = require('assert'); -var domain = require('domain'); -var disposalFailed = false; - -// no matter what happens, we should increment a 10 times. -var a = 0; -log(); -function log(){ - console.log(a++, process.domain); - if (a < 10) setTimeout(log, 20); -} - -// in 50ms we'll throw an error. -setTimeout(err, 50); -function err(){ - var d = domain.create(); - d.on('error', handle); - d.run(err2); - - function err2() { - // this timeout should never be called, since the domain gets - // disposed when the error happens. - setTimeout(function() { - console.error('This should not happen.'); - disposalFailed = true; - process.exit(1); - }); - - // this function doesn't exist, and throws an error as a result. - err3(); - } - - function handle(e) { - // this should clean up everything properly. - d.dispose(); - console.error(e); - console.error('in handler', process.domain, process.domain === d); - } -} - -process.on('exit', function() { - assert.equal(a, 10); - assert.equal(disposalFailed, false); - console.log('ok'); -}); diff --git a/test/simple/test-domain-from-timer.js b/test/simple/test-domain-from-timer.js deleted file mode 100644 index 3e73a5c4b89e..000000000000 --- a/test/simple/test-domain-from-timer.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -// Simple tests of most basic domain functionality. - -var common = require('../common'); -var assert = require('assert'); - -// timeouts call the callback directly from cc, so need to make sure the -// domain will be used regardless -setTimeout(function() { - var domain = require('domain'); - var d = domain.create(); - d.run(function() { - process.nextTick(function() { - console.trace('in nexttick', process.domain === d) - assert.equal(process.domain, d); - }); - }); -}); diff --git a/test/simple/test-domain-http-server.js b/test/simple/test-domain-http-server.js deleted file mode 100644 index 666f5d190aca..000000000000 --- a/test/simple/test-domain-http-server.js +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var domain = require('domain'); -var http = require('http'); -var assert = require('assert'); -var common = require('../common.js'); - -var objects = { foo: 'bar', baz: {}, num: 42, arr: [1,2,3] }; -objects.baz.asdf = objects; - -var serverCaught = 0; -var clientCaught = 0; -var disposeEmit = 0; - -var server = http.createServer(function(req, res) { - var dom = domain.create(); - req.resume(); - dom.add(req); - dom.add(res); - - dom.on('error', function(er) { - serverCaught++; - console.log('horray! got a server error', er); - // try to send a 500. If that fails, oh well. - res.writeHead(500, {'content-type':'text/plain'}); - res.end(er.stack || er.message || 'Unknown error'); - }); - - var data; - dom.run(function() { - // Now, an action that has the potential to fail! - // if you request 'baz', then it'll throw a JSON circular ref error. - data = JSON.stringify(objects[req.url.replace(/[^a-z]/g, '')]); - - // this line will throw if you pick an unknown key - assert(data !== undefined, 'Data should not be undefined'); - - res.writeHead(200); - res.end(data); - }); -}); - -server.listen(common.PORT, next); - -function next() { - console.log('listening on localhost:%d', common.PORT); - - // now hit it a few times - var dom = domain.create(); - var requests = 0; - var responses = 0; - - makeReq('/'); - makeReq('/foo'); - makeReq('/arr'); - makeReq('/baz'); - makeReq('/num'); - - function makeReq(p) { - requests++; - - var dom = domain.create(); - dom.on('error', function(er) { - clientCaught++; - console.log('client error', er); - req.socket.destroy(); - }); - - var req = http.get({ host: 'localhost', port: common.PORT, path: p }); - dom.add(req); - req.on('response', function(res) { - responses++; - console.error('requests=%d responses=%d', requests, responses); - if (responses === requests) { - console.error('done, closing server'); - // no more coming. - server.close(); - } - - dom.add(res); - var d = ''; - res.on('data', function(c) { - d += c; - }); - res.on('end', function() { - console.error('trying to parse json', d); - d = JSON.parse(d); - console.log('json!', d); - }); - }); - } -} - -process.on('exit', function() { - assert.equal(serverCaught, 2); - assert.equal(clientCaught, 2); - console.log('ok'); -}); diff --git a/test/simple/test-domain-implicit-fs.js b/test/simple/test-domain-implicit-fs.js deleted file mode 100644 index c701c931582b..000000000000 --- a/test/simple/test-domain-implicit-fs.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -// Simple tests of most basic domain functionality. - -var common = require('../common'); -var assert = require('assert'); -var domain = require('domain'); -var events = require('events'); -var caught = 0; -var expectCaught = 1; - -var d = new domain.Domain(); -var e = new events.EventEmitter(); - -d.on('error', function(er) { - console.error('caught', er); - - assert.strictEqual(er.domain, d); - assert.strictEqual(er.domainThrown, true); - assert.ok(!er.domainEmitter); - assert.strictEqual(er.code, 'ENOENT'); - assert.ok(/\bthis file does not exist\b/i.test(er.path)); - assert.strictEqual(typeof er.errno, 'number'); - - caught++; -}); - -process.on('exit', function() { - console.error('exit'); - assert.equal(caught, expectCaught); - console.log('ok'); -}); - - -// implicit handling of thrown errors while in a domain, via the -// single entry points of ReqWrap and MakeCallback. Even if -// we try very hard to escape, there should be no way to, even if -// we go many levels deep through timeouts and multiple IO calls. -// Everything that happens between the domain.enter() and domain.exit() -// calls will be bound to the domain, even if multiple levels of -// handles are created. -d.run(function() { - setTimeout(function() { - var fs = require('fs'); - fs.readdir(__dirname, function() { - fs.open('this file does not exist', 'r', function(er) { - if (er) throw er; - throw new Error('should not get here!'); - }); - }); - }, 100); -}); diff --git a/test/simple/test-domain-multi.js b/test/simple/test-domain-multi.js deleted file mode 100644 index 68e4b11a6474..000000000000 --- a/test/simple/test-domain-multi.js +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -// Tests of multiple domains happening at once. - -var common = require('../common'); -var assert = require('assert'); -var domain = require('domain'); -var events = require('events'); - -var caughtA = false; -var caughtB = false; -var caughtC = false; - - -var a = domain.create(); -a.enter(); // this will be our "root" domain -a.on('error', function(er) { - caughtA = true; - console.log('This should not happen'); - throw er; -}); - - -var http = require('http'); -var server = http.createServer(function (req, res) { - // child domain of a. - var b = domain.create(); - a.add(b); - - // treat these EE objects as if they are a part of the b domain - // so, an 'error' event on them propagates to the domain, rather - // than being thrown. - b.add(req); - b.add(res); - - b.on('error', function (er) { - caughtB = true; - console.error('Error encountered', er) - if (res) { - res.writeHead(500); - res.end('An error occurred'); - } - // res.writeHead(500), res.destroy, etc. - server.close(); - }); - - // XXX this bind should not be necessary. - // the write cb behavior in http/net should use an - // event so that it picks up the domain handling. - res.write('HELLO\n', b.bind(function() { - throw new Error('this kills domain B, not A'); - })); - -}).listen(common.PORT); - -var c = domain.create(); -var req = http.get({ host: 'localhost', port: common.PORT }) - -// add the request to the C domain -c.add(req); - -req.on('response', function(res) { - console.error('got response'); - // add the response object to the C domain - c.add(res); - res.pipe(process.stdout); -}); - -c.on('error', function(er) { - caughtC = true; - console.error('Error on c', er.message); -}); - -process.on('exit', function() { - assert.equal(caughtA, false); - assert.equal(caughtB, true) - assert.equal(caughtC, true) - console.log('ok - Errors went where they were supposed to go'); -}); diff --git a/test/simple/test-domain-nested-throw.js b/test/simple/test-domain-nested-throw.js deleted file mode 100644 index e11948667532..000000000000 --- a/test/simple/test-domain-nested-throw.js +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var domain = require('domain'); - -var dispose; -switch (process.argv[2]) { - case 'true': - dispose = true; - break; - case 'false': - dispose = false; - break; - default: - parent(); - return; -} - -function parent() { - var node = process.execPath; - var spawn = require('child_process').spawn; - var opt = { stdio: 'inherit' }; - var child = spawn(node, [__filename, 'true'], opt); - child.on('exit', function(c) { - assert(!c); - child = spawn(node, [__filename, 'false'], opt); - child.on('exit', function(c) { - assert(!c); - console.log('ok'); - }); - }); -} - -var gotDomain1Error = false; -var gotDomain2Error = false; - -var threw1 = false; -var threw2 = false; - -function throw1() { - threw1 = true; - throw new Error('handled by domain1'); -} - -function throw2() { - threw2 = true; - throw new Error('handled by domain2'); -} - -function inner(throw1, throw2) { - var domain1 = domain.createDomain(); - - domain1.on('error', function (err) { - if (gotDomain1Error) { - console.error('got domain 1 twice'); - process.exit(1); - } - if (dispose) domain1.dispose(); - gotDomain1Error = true; - throw2(); - }); - - domain1.run(function () { - throw1(); - }); -} - -function outer() { - var domain2 = domain.createDomain(); - - domain2.on('error', function (err) { - if (gotDomain2Error) { - console.error('got domain 2 twice'); - process.exit(1); - } - gotDomain2Error = true; - }); - - domain2.run(function () { - inner(throw1, throw2); - }); -} - -process.on('exit', function() { - assert(gotDomain1Error); - assert(gotDomain2Error); - assert(threw1); - assert(threw2); - console.log('ok', dispose); -}); - -outer(); diff --git a/test/simple/test-domain-nested.js b/test/simple/test-domain-nested.js deleted file mode 100644 index efd672b25f94..000000000000 --- a/test/simple/test-domain-nested.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -// Make sure that the nested domains don't cause the domain stack to grow - -var assert = require('assert'); -var domain = require('domain'); - -process.on('exit', function(c) { - assert.equal(domain._stack.length, 0); -}); - -domain.create().run(function() { - domain.create().run(function() { - domain.create().run(function() { - domain.create().on("error", function(e) { - // Don't need to do anything here - }).run(function() { - throw new Error("died") - }) - }) - }) -}) diff --git a/test/simple/test-domain-safe-exit.js b/test/simple/test-domain-safe-exit.js deleted file mode 100644 index a7dcef078ba2..000000000000 --- a/test/simple/test-domain-safe-exit.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -// Make sure the domain stack doesn't get clobbered by un-matched .exit() - -var assert = require('assert'); -var domain = require('domain'); - -var a = domain.create(); -var b = domain.create(); - -a.enter(); // push -b.enter(); // push -assert.deepEqual(domain._stack, [a, b], 'b not pushed'); - -domain.create().exit(); // no-op -assert.deepEqual(domain._stack, [a, b], 'stack mangled!'); diff --git a/test/simple/test-domain-stack.js b/test/simple/test-domain-stack.js deleted file mode 100644 index eecb85b4bbba..000000000000 --- a/test/simple/test-domain-stack.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -// Make sure that the domain stack doesn't get out of hand. - -var common = require('../common'); -var assert = require('assert'); -var domain = require('domain'); -var events = require('events'); - -var a = domain.create(); -a.name = 'a'; - -a.on('error', function() { - if (domain._stack.length > 5) { - console.error('leaking!', domain._stack); - process.exit(1); - } -}); - -var foo = a.bind(function() { - throw new Error('error from foo'); -}); - -for (var i = 0; i < 1000; i++) { - process.nextTick(foo); -} - -process.on('exit', function(c) { - if (!c) console.log('ok'); -}); diff --git a/test/simple/test-domain-timers.js b/test/simple/test-domain-timers.js deleted file mode 100644 index 388673c0880a..000000000000 --- a/test/simple/test-domain-timers.js +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var domain = require('domain'); -var assert = require('assert'); -var common = require('../common.js'); - -var timeout_err, timeout, immediate_err; - -var timeoutd = domain.create(); - -timeoutd.on('error', function(e) { - timeout_err = e; - clearTimeout(timeout); -}); - -timeoutd.run(function() { - setTimeout(function() { - throw new Error('Timeout UNREFd'); - }).unref(); -}); - -var immediated = domain.create(); - -immediated.on('error', function(e) { - immediate_err = e; -}); - -immediated.run(function() { - setImmediate(function() { - throw new Error('Immediate Error'); - }); -}); - -timeout = setTimeout(function() {}, 10 * 1000); - -process.on('exit', function() { - assert.equal(timeout_err.message, 'Timeout UNREFd', - 'Domain should catch timer error'); - assert.equal(immediate_err.message, 'Immediate Error', - 'Domain should catch immediate error'); -}); diff --git a/test/simple/test-domain-top-level-error-handler-clears-stack.js b/test/simple/test-domain-top-level-error-handler-clears-stack.js deleted file mode 100644 index f95864da64e1..000000000000 --- a/test/simple/test-domain-top-level-error-handler-clears-stack.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var domain = require('domain'); - -/* - * Make sure that the domains stack is cleared after a top-level domain - * error handler exited gracefully. - */ -var d = domain.create(); - -d.on('error', function() { - process.nextTick(function() { - if (domain._stack.length !== 1) { - process.exit(1); - } - }); -}); - -d.run(function() { - throw new Error('Error from domain'); -}); diff --git a/test/simple/test-domain-top-level-error-handler-throw.js b/test/simple/test-domain-top-level-error-handler-throw.js deleted file mode 100644 index 25b261f17088..000000000000 --- a/test/simple/test-domain-top-level-error-handler-throw.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * The goal of this test is to make sure that when a top-level error - * handler throws an error following the handling of a previous error, - * the process reports the error message from the error thrown in the - * top-level error handler, not the one from the previous error. - */ - -var domainErrHandlerExMessage = 'exception from domain error handler'; -var internalExMessage = 'You should NOT see me'; - -if (process.argv[2] === 'child') { - var domain = require('domain'); - var d = domain.create(); - - d.on('error', function() { - throw new Error(domainErrHandlerExMessage); - }); - - d.run(function doStuff() { - process.nextTick(function () { - throw new Error(internalExMessage); - }); - }); -} else { - var fork = require('child_process').fork; - var assert = require('assert'); - - function test() { - var child = fork(process.argv[1], ['child'], {silent:true}); - var gotDataFromStderr = false; - var stderrOutput = ''; - if (child) { - child.stderr.on('data', function onStderrData(data) { - gotDataFromStderr = true; - stderrOutput += data.toString(); - }) - - child.on('exit', function onChildExited(exitCode, signal) { - assert(gotDataFromStderr); - assert(stderrOutput.indexOf(domainErrHandlerExMessage) !== -1); - assert(stderrOutput.indexOf(internalExMessage) === -1); - - var expectedExitCode = 7; - var expectedSignal = null; - - assert.equal(exitCode, expectedExitCode); - assert.equal(signal, expectedSignal); - }); - } - } - - test(); -} diff --git a/test/simple/test-domain-with-abort-on-uncaught-exception.js b/test/simple/test-domain-with-abort-on-uncaught-exception.js deleted file mode 100644 index d8a1cd732a44..000000000000 --- a/test/simple/test-domain-with-abort-on-uncaught-exception.js +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); - -/* - * The goal of this test is to make sure that: - * - * - Even if --abort-on-uncaught-exception is passed on the command line, - * setting up a top-level domain error handler and throwing an error - * within this domain does *not* make the process abort. The process exits - * gracefully. - * - * - When passing --abort-on-uncaught-exception on the command line and - * setting up a top-level domain error handler, an error thrown - * within this domain's error handler *does* make the process abort. - * - * - When *not* passing --abort-on-uncaught-exception on the command line and - * setting up a top-level domain error handler, an error thrown within this - * domain's error handler does *not* make the process abort, but makes it exit - * with the proper failure exit code. - * - * - When throwing an error within the top-level domain's error handler - * within a try/catch block, the process should exit gracefully, whether or - * not --abort-on-uncaught-exception is passed on the command line. - */ - -var domainErrHandlerExMessage = 'exception from domain error handler'; - -if (process.argv[2] === 'child') { - var domain = require('domain'); - var d = domain.create(); - var triggeredProcessUncaughtException = false; - - process.on('uncaughtException', function onUncaughtException() { - // The process' uncaughtException event must not be emitted when - // an error handler is setup on the top-level domain. - // Exiting with exit code of 42 here so that it would assert when - // the parent checks the child exit code. - process.exit(42); - }); - - d.on('error', function() { - // Swallowing the error on purpose if 'throwInDomainErrHandler' is not - // set - if (process.argv.indexOf('throwInDomainErrHandler') !== -1) { - if (process.argv.indexOf('useTryCatch') !== -1) { - try { - throw new Error(domainErrHandlerExMessage); - } catch (e) { - } - } else { - throw new Error(domainErrHandlerExMessage); - } - } - }); - - d.run(function doStuff() { - // Throwing from within different types of callbacks as each of them - // handles domains differently - process.nextTick(function () { - throw new Error("Error from nextTick callback"); - }); - - var fs = require('fs'); - fs.exists('/non/existing/file', function onExists(exists) { - throw new Error("Error from fs.exists callback"); - }); - - setImmediate(function onSetImmediate() { - throw new Error("Error from setImmediate callback"); - }); - - throw new Error("Error from domain.run callback"); - }); -} else { - var exec = require('child_process').exec; - - function testDomainExceptionHandling(cmdLineOption, options) { - if (typeof cmdLineOption === 'object') { - options = cmdLineOption; - cmdLineOption = undefined; - } - - var throwInDomainErrHandlerOpt; - if (options.throwInDomainErrHandler) - throwInDomainErrHandlerOpt = 'throwInDomainErrHandler'; - - var cmdToExec = ''; - if (process.platform !== 'win32') { - // Do not create core files, as it can take a lot of disk space on - // continuous testing and developers' machines - cmdToExec += 'ulimit -c 0 && '; - } - - var useTryCatchOpt; - if (options.useTryCatch) - useTryCatchOpt = 'useTryCatch'; - - cmdToExec += process.argv[0] + ' '; - cmdToExec += (cmdLineOption ? cmdLineOption : '') + ' '; - cmdToExec += process.argv[1] + ' '; - cmdToExec += ['child', throwInDomainErrHandlerOpt, useTryCatchOpt].join(' '); - - var child = exec(cmdToExec); - - if (child) { - var childTriggeredOnUncaughtExceptionHandler = false; - child.on('message', function onChildMsg(msg) { - if (msg === 'triggeredProcessUncaughtEx') { - childTriggeredOnUncaughtExceptionHandler = true; - } - }); - - child.on('exit', function onChildExited(exitCode, signal) { - // If the top-level domain's error handler does not throw, - // the process must exit gracefully, whether or not - // --abort-on-uncaught-exception was passed on the command line - var expectedExitCode = 0; - // On some platforms with KSH being the default shell (like SmartOS), - // when a process aborts, KSH exits with an exit code that is greater - // than 256, and thus the exit code emitted with the 'exit' event is - // null and the signal is set to SIGABRT. For these platforms only, - // and when the test is expected to abort, check the actual signal - // with the expected signal instead of the exit code. - var expectedSignal; - - // When throwing errors from the top-level domain error handler - // outside of a try/catch block, the process should not exit gracefully - if (!options.useTryCatch && options.throwInDomainErrHandler) { - expectedExitCode = 7; - if (cmdLineOption === '--abort-on-uncaught-exception') { - // If the top-level domain's error handler throws, and only if - // --abort-on-uncaught-exception is passed on the command line, - // the process must abort. - expectedExitCode = 134; - - // On linux, v8 raises SIGTRAP when aborting because - // the "debug break" flag is on by default - if (process.platform === 'linux') - expectedExitCode = 133; - - if (process.platform === 'sunos') { - expectedExitCode = null; - expectedSignal = 'SIGABRT'; - } - - // On Windows, v8's OS::Abort also triggers a debug breakpoint - // which makes the process exit with code -2147483645 - if (process.platform === 'win32') { - expectedExitCode = -2147483645; - } - } - } - - if (expectedSignal) - assert.equal(signal, expectedSignal) - - assert.equal(exitCode, expectedExitCode); - }); - } - } - - testDomainExceptionHandling('--abort-on-uncaught-exception', { - throwInDomainErrHandler: false, - useTryCatch: false - }); - - testDomainExceptionHandling('--abort-on-uncaught-exception', { - throwInDomainErrHandler: false, - useTryCatch: true - }); - - testDomainExceptionHandling('--abort-on-uncaught-exception', { - throwInDomainErrHandler: true, - useTryCatch: false - }); - - testDomainExceptionHandling('--abort-on-uncaught-exception', { - throwInDomainErrHandler: true, - useTryCatch: true - }); - - testDomainExceptionHandling({ - throwInDomainErrHandler: false - }); - - testDomainExceptionHandling({ - throwInDomainErrHandler: false, - useTryCatch: false - }); - - testDomainExceptionHandling({ - throwInDomainErrHandler: true, - useTryCatch: true - }); -} diff --git a/test/simple/test-domain.js b/test/simple/test-domain.js deleted file mode 100644 index f77217e4a31c..000000000000 --- a/test/simple/test-domain.js +++ /dev/null @@ -1,263 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -// Simple tests of most basic domain functionality. - -var common = require('../common'); -var assert = require('assert'); -var domain = require('domain'); -var events = require('events'); -var fs = require('fs'); -var caught = 0; -var expectCaught = 0; - -var d = new domain.Domain(); -var e = new events.EventEmitter(); - -d.on('error', function(er) { - console.error('caught', er && (er.message || er)); - - var er_message = er.message; - var er_path = er.path - - // On windows, error messages can contain full path names. If this is the - // case, remove the directory part. - if (typeof er_path === 'string') { - var slash = er_path.lastIndexOf('\\'); - if (slash !== -1) { - var dir = er_path.slice(0, slash + 1); - er_path = er_path.replace(dir, ''); - er_message = er_message.replace(dir, ''); - } - } - - switch (er_message) { - case 'emitted': - assert.equal(er.domain, d); - assert.equal(er.domainEmitter, e); - assert.equal(er.domainThrown, false); - break; - - case 'bound': - assert.ok(!er.domainEmitter); - assert.equal(er.domain, d); - assert.equal(er.domainBound, fn); - assert.equal(er.domainThrown, false); - break; - - case 'thrown': - assert.ok(!er.domainEmitter); - assert.equal(er.domain, d); - assert.equal(er.domainThrown, true); - break; - - case "ENOENT, open 'this file does not exist'": - assert.equal(er.domain, d); - assert.equal(er.domainThrown, false); - assert.equal(typeof er.domainBound, 'function'); - assert.ok(!er.domainEmitter); - assert.equal(er.code, 'ENOENT'); - assert.equal(er_path, 'this file does not exist'); - assert.equal(typeof er.errno, 'number'); - break; - - case "ENOENT, open 'stream for nonexistent file'": - assert.equal(typeof er.errno, 'number'); - assert.equal(er.code, 'ENOENT'); - assert.equal(er_path, 'stream for nonexistent file'); - assert.equal(er.domain, d); - assert.equal(er.domainEmitter, fst); - assert.ok(!er.domainBound); - assert.equal(er.domainThrown, false); - break; - - case 'implicit': - assert.equal(er.domainEmitter, implicit); - assert.equal(er.domain, d); - assert.equal(er.domainThrown, false); - assert.ok(!er.domainBound); - break; - - case 'implicit timer': - assert.equal(er.domain, d); - assert.equal(er.domainThrown, true); - assert.ok(!er.domainEmitter); - assert.ok(!er.domainBound); - break; - - case 'Cannot call method \'isDirectory\' of undefined': - assert.equal(er.domain, d); - assert.ok(!er.domainEmitter); - assert.ok(!er.domainBound); - break; - - case 'nextTick execution loop': - assert.equal(er.domain, d); - assert.ok(!er.domainEmitter); - assert.ok(!er.domainBound); - break; - - default: - console.error('unexpected error, throwing %j', er.message, er); - throw er; - } - - caught++; -}); - - - -process.on('exit', function() { - console.error('exit', caught, expectCaught); - assert.equal(caught, expectCaught, 'caught the expected number of errors'); - console.log('ok'); -}); - - - -// revert to using the domain when a callback is passed to nextTick in -// the middle of a tickCallback loop -d.run(function() { - process.nextTick(function() { - throw new Error('nextTick execution loop'); - }); -}); -expectCaught++; - - - -// catch thrown errors no matter how many times we enter the event loop -// this only uses implicit binding, except for the first function -// passed to d.run(). The rest are implicitly bound by virtue of being -// set up while in the scope of the d domain. -d.run(function() { - process.nextTick(function() { - var i = setInterval(function () { - clearInterval(i); - setTimeout(function() { - fs.stat('this file does not exist', function(er, stat) { - // uh oh! stat isn't set! - // pretty common error. - console.log(stat.isDirectory()); - }); - }); - }); - }); -}); -expectCaught++; - - - -// implicit addition of a timer created within a domain-bound context. -d.run(function() { - setTimeout(function() { - throw new Error('implicit timer'); - }); -}); -expectCaught++; - - - -// Event emitters added to the domain have their errors routed. -d.add(e); -e.emit('error', new Error('emitted')); -expectCaught++; - - - -// get rid of the `if (er) return cb(er)` malarky, by intercepting -// the cb functions to the domain, and using the intercepted function -// as a callback instead. -function fn(er) { - throw new Error('This function should never be called!'); - process.exit(1); -} - -var bound = d.intercept(fn); -bound(new Error('bound')); -expectCaught++; - - - -// intercepted should never pass first argument to callback -function fn2(data) { - assert.equal(data, 'data', 'should not be null err argument') -} - -var bound = d.intercept(fn2); -bound(null, 'data'); - -// intercepted should never pass first argument to callback -// even if arguments length is more than 2. -function fn3(data, data2) { - assert.equal(data, 'data', 'should not be null err argument'); - assert.equal(data2, 'data2', 'should not be data argument'); -} - -bound = d.intercept(fn3); -bound(null, 'data', 'data2'); - -// throwing in a bound fn is also caught, -// even if it's asynchronous, by hitting the -// global uncaughtException handler. This doesn't -// require interception, since throws are always -// caught by the domain. -function thrower() { - throw new Error('thrown'); -} -setTimeout(d.bind(thrower), 100); -expectCaught++; - - - -// Pass an intercepted function to an fs operation that fails. -fs.open('this file does not exist', 'r', d.intercept(function(er) { - console.error('should not get here!', er); - throw new Error('should not get here!'); -}, true)); -expectCaught++; - - - -// implicit addition by being created within a domain-bound context. -var implicit; - -d.run(function() { - implicit = new events.EventEmitter; -}); - -setTimeout(function() { - // escape from the domain, but implicit is still bound to it. - implicit.emit('error', new Error('implicit')); -}, 10); -expectCaught++; - - -var result = d.run(function () { - return 'return value'; -}); -assert.equal(result, 'return value'); - - -var fst = fs.createReadStream('stream for nonexistent file') -d.add(fst) -expectCaught++; diff --git a/test/simple/test-error-reporting.js b/test/simple/test-error-reporting.js deleted file mode 100644 index 22c6f97b9ec0..000000000000 --- a/test/simple/test-error-reporting.js +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; -var path = require('path'); - -var exits = 0; - -function errExec(script, callback) { - var cmd = '"' + process.argv[0] + '" "' + - path.join(common.fixturesDir, script) + '"'; - return exec(cmd, function(err, stdout, stderr) { - // There was some error - assert.ok(err); - - // More than one line of error output. - assert.ok(stderr.split('\n').length > 2); - - // Assert the script is mentioned in error output. - assert.ok(stderr.indexOf(script) >= 0); - - // Proxy the args for more tests. - callback(err, stdout, stderr); - - // Count the tests - exits++; - - console.log('.'); - }); -} - - -// Simple throw error -errExec('throws_error.js', function(err, stdout, stderr) { - assert.ok(/blah/.test(stderr)); -}); - - -// Trying to JSON.parse(undefined) -errExec('throws_error2.js', function(err, stdout, stderr) { - assert.ok(/SyntaxError/.test(stderr)); -}); - - -// Trying to JSON.parse(undefined) in nextTick -errExec('throws_error3.js', function(err, stdout, stderr) { - assert.ok(/SyntaxError/.test(stderr)); -}); - - -process.on('exit', function() { - assert.equal(3, exits); -}); diff --git a/test/simple/test-eval-require.js b/test/simple/test-eval-require.js deleted file mode 100644 index dfef416ce9f8..000000000000 --- a/test/simple/test-eval-require.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; -var path = require('path'); -var fs = require('fs'); - -var options = { - cwd: common.fixturesDir -}; -var child = spawn(process.execPath, ['-e', 'require("foo")'], options); -child.on('exit', function(code) { - assert.equal(code, 0); -}); - diff --git a/test/simple/test-eval.js b/test/simple/test-eval.js deleted file mode 100644 index 9c656a8770b2..000000000000 --- a/test/simple/test-eval.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -require('../common'); -var util = require('util'); -var assert = require('assert'); -var exec = require('child_process').exec; - -var success_count = 0; -var error_count = 0; - -var cmd = [process.execPath, '-e', '"console.error(process.argv)"', - 'foo', 'bar'].join(' '); -var expected = util.format([process.execPath, 'foo', 'bar']) + '\n'; -var child = exec(cmd, function(err, stdout, stderr) { - if (err) { - console.log(err.toString()); - ++error_count; - return; - } - assert.equal(stderr, expected); - ++success_count; -}); - -process.on('exit', function() { - assert.equal(1, success_count); - assert.equal(0, error_count); -}); - diff --git a/test/simple/test-event-emitter-add-listeners.js b/test/simple/test-event-emitter-add-listeners.js deleted file mode 100644 index 0806e049d48c..000000000000 --- a/test/simple/test-event-emitter-add-listeners.js +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -var e = new events.EventEmitter(); - -var events_new_listener_emited = []; -var listeners_new_listener_emited = []; -var times_hello_emited = 0; - -// sanity check -assert.equal(e.addListener, e.on); - -e.on('newListener', function(event, listener) { - console.log('newListener: ' + event); - events_new_listener_emited.push(event); - listeners_new_listener_emited.push(listener); -}); - -function hello(a, b) { - console.log('hello'); - times_hello_emited += 1; - assert.equal('a', a); - assert.equal('b', b); -} -e.on('hello', hello); - -var foo = function() {}; -e.once('foo', foo); - -console.log('start'); - -e.emit('hello', 'a', 'b'); - - -// just make sure that this doesn't throw: -var f = new events.EventEmitter(); -f.setMaxListeners(0); - - -process.on('exit', function() { - assert.deepEqual(['hello', 'foo'], events_new_listener_emited); - assert.deepEqual([hello, foo], listeners_new_listener_emited); - assert.equal(1, times_hello_emited); -}); - - diff --git a/test/simple/test-event-emitter-check-listener-leaks.js b/test/simple/test-event-emitter-check-listener-leaks.js deleted file mode 100644 index 7d9c203243c5..000000000000 --- a/test/simple/test-event-emitter-check-listener-leaks.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -var e = new events.EventEmitter(); - -// default -for (var i = 0; i < 10; i++) { - e.on('default', function() {}); -} -assert.ok(!e._events['default'].hasOwnProperty('warned')); -e.on('default', function() {}); -assert.ok(e._events['default'].warned); - -// specific -e.setMaxListeners(5); -for (var i = 0; i < 5; i++) { - e.on('specific', function() {}); -} -assert.ok(!e._events['specific'].hasOwnProperty('warned')); -e.on('specific', function() {}); -assert.ok(e._events['specific'].warned); - -// only one -e.setMaxListeners(1); -e.on('only one', function() {}); -assert.ok(!e._events['only one'].hasOwnProperty('warned')); -e.on('only one', function() {}); -assert.ok(e._events['only one'].hasOwnProperty('warned')); - -// unlimited -e.setMaxListeners(0); -for (var i = 0; i < 1000; i++) { - e.on('unlimited', function() {}); -} -assert.ok(!e._events['unlimited'].hasOwnProperty('warned')); - diff --git a/test/simple/test-event-emitter-listeners-side-effects.js b/test/simple/test-event-emitter-listeners-side-effects.js deleted file mode 100644 index c6218e0598a0..000000000000 --- a/test/simple/test-event-emitter-listeners-side-effects.js +++ /dev/null @@ -1,61 +0,0 @@ - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -var EventEmitter = require('events').EventEmitter; -var assert = require('assert'); - -var e = new EventEmitter; -var fl; // foo listeners - -fl = e.listeners('foo'); -assert(Array.isArray(fl)); -assert(fl.length === 0); -assert.deepEqual(e._events, {}); - -e.on('foo', assert.fail); -fl = e.listeners('foo'); -assert(e._events.foo === assert.fail); -assert(Array.isArray(fl)); -assert(fl.length === 1); -assert(fl[0] === assert.fail); - -e.listeners('bar'); -assert(!e._events.hasOwnProperty('bar')); - -e.on('foo', assert.ok); -fl = e.listeners('foo'); - -assert(Array.isArray(e._events.foo)); -assert(e._events.foo.length === 2); -assert(e._events.foo[0] === assert.fail); -assert(e._events.foo[1] === assert.ok); - -assert(Array.isArray(fl)); -assert(fl.length === 2); -assert(fl[0] === assert.fail); -assert(fl[1] === assert.ok); - -console.log('ok'); diff --git a/test/simple/test-event-emitter-listeners.js b/test/simple/test-event-emitter-listeners.js deleted file mode 100644 index 3e622835b850..000000000000 --- a/test/simple/test-event-emitter-listeners.js +++ /dev/null @@ -1,52 +0,0 @@ - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -function listener() {} -function listener2() {} - -var e1 = new events.EventEmitter(); -e1.on('foo', listener); -var fooListeners = e1.listeners('foo'); -assert.deepEqual(e1.listeners('foo'), [listener]); -e1.removeAllListeners('foo'); -assert.deepEqual(e1.listeners('foo'), []); -assert.deepEqual(fooListeners, [listener]); - -var e2 = new events.EventEmitter(); -e2.on('foo', listener); -var e2ListenersCopy = e2.listeners('foo'); -assert.deepEqual(e2ListenersCopy, [listener]); -assert.deepEqual(e2.listeners('foo'), [listener]); -e2ListenersCopy.push(listener2); -assert.deepEqual(e2.listeners('foo'), [listener]); -assert.deepEqual(e2ListenersCopy, [listener, listener2]); - -var e3 = new events.EventEmitter(); -e3.on('foo', listener); -var e3ListenersCopy = e3.listeners('foo'); -e3.on('foo', listener2); -assert.deepEqual(e3.listeners('foo'), [listener, listener2]); -assert.deepEqual(e3ListenersCopy, [listener]); diff --git a/test/simple/test-event-emitter-max-listeners.js b/test/simple/test-event-emitter-max-listeners.js deleted file mode 100644 index dfc3e1352d0e..000000000000 --- a/test/simple/test-event-emitter-max-listeners.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -var gotEvent = false; - -process.on('exit', function() { - assert(gotEvent); -}); - -var e = new events.EventEmitter(); - -e.on('maxListeners', function() { - gotEvent = true; -}); - -// Should not corrupt the 'maxListeners' queue. -e.setMaxListeners(42); - -assert.throws(function() { - e.setMaxListeners(NaN); -}); - -assert.throws(function() { - e.setMaxListeners(-1); -}); - -assert.throws(function() { - e.setMaxListeners("and even this"); -}); - -e.emit('maxListeners'); diff --git a/test/simple/test-event-emitter-memory-leak.js b/test/simple/test-event-emitter-memory-leak.js deleted file mode 100644 index 2cb56124cd21..000000000000 --- a/test/simple/test-event-emitter-memory-leak.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Flags: --expose-gc - -// Add and remove a lot of different events to an EventEmitter, then check -// that we didn't leak the event names. -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -assert.equal(typeof gc, 'function', 'Run this test with --expose-gc'); -gc(); - -var before = process.memoryUsage().heapUsed; -var e = new events.EventEmitter(); - -for (var i = 0; i < 2.5e5; ++i) { - var name = 'a-pretty-long-event-name-' + i; - e.on(name, assert.fail); - e.removeListener(name, assert.fail); -} -gc(); - -var after = process.memoryUsage().heapUsed; -assert(after - before < 1024*1024, 'EventEmitter leaks event names.'); diff --git a/test/simple/test-event-emitter-method-names.js b/test/simple/test-event-emitter-method-names.js deleted file mode 100644 index e7c0f88e7a5c..000000000000 --- a/test/simple/test-event-emitter-method-names.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -var E = events.EventEmitter.prototype; -assert.equal(E.constructor.name, 'EventEmitter'); -assert.equal(E.on, E.addListener); // Same method. -Object.getOwnPropertyNames(E).forEach(function(name) { - if (name === 'constructor' || name === 'on') return; - assert.equal(E[name].name, name); -}); diff --git a/test/simple/test-event-emitter-modify-in-emit.js b/test/simple/test-event-emitter-modify-in-emit.js deleted file mode 100644 index 738af098cd45..000000000000 --- a/test/simple/test-event-emitter-modify-in-emit.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -var callbacks_called = []; - -var e = new events.EventEmitter(); - -function callback1() { - callbacks_called.push('callback1'); - e.on('foo', callback2); - e.on('foo', callback3); - e.removeListener('foo', callback1); -} - -function callback2() { - callbacks_called.push('callback2'); - e.removeListener('foo', callback2); -} - -function callback3() { - callbacks_called.push('callback3'); - e.removeListener('foo', callback3); -} - -e.on('foo', callback1); -assert.equal(1, e.listeners('foo').length); - -e.emit('foo'); -assert.equal(2, e.listeners('foo').length); -assert.deepEqual(['callback1'], callbacks_called); - -e.emit('foo'); -assert.equal(0, e.listeners('foo').length); -assert.deepEqual(['callback1', 'callback2', 'callback3'], callbacks_called); - -e.emit('foo'); -assert.equal(0, e.listeners('foo').length); -assert.deepEqual(['callback1', 'callback2', 'callback3'], callbacks_called); - -e.on('foo', callback1); -e.on('foo', callback2); -assert.equal(2, e.listeners('foo').length); -e.removeAllListeners('foo'); -assert.equal(0, e.listeners('foo').length); - -// Verify that removing callbacks while in emit allows emits to propagate to -// all listeners -callbacks_called = []; - -e.on('foo', callback2); -e.on('foo', callback3); -assert.equal(2, e.listeners('foo').length); -e.emit('foo'); -assert.deepEqual(['callback2', 'callback3'], callbacks_called); -assert.equal(0, e.listeners('foo').length); diff --git a/test/simple/test-event-emitter-no-error-provided-to-error-event.js b/test/simple/test-event-emitter-no-error-provided-to-error-event.js deleted file mode 100644 index 92d9f8ad011f..000000000000 --- a/test/simple/test-event-emitter-no-error-provided-to-error-event.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); -var domain = require('domain'); - -var errorCatched = false; - -var e = new events.EventEmitter(); - -var d = domain.create(); -d.add(e); -d.on('error', function (er) { - assert(er instanceof TypeError, 'type error created'); - errorCatched = true; -}); - -e.emit('error'); - -process.on('exit', function () { - assert(errorCatched, 'error got catched'); -}); diff --git a/test/simple/test-event-emitter-num-args.js b/test/simple/test-event-emitter-num-args.js deleted file mode 100644 index 037c56965b9d..000000000000 --- a/test/simple/test-event-emitter-num-args.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -var e = new events.EventEmitter(), - num_args_emited = []; - -e.on('numArgs', function() { - var numArgs = arguments.length; - console.log('numArgs: ' + numArgs); - num_args_emited.push(numArgs); -}); - -console.log('start'); - -e.emit('numArgs'); -e.emit('numArgs', null); -e.emit('numArgs', null, null); -e.emit('numArgs', null, null, null); -e.emit('numArgs', null, null, null, null); -e.emit('numArgs', null, null, null, null, null); - -process.on('exit', function() { - assert.deepEqual([0, 1, 2, 3, 4, 5], num_args_emited); -}); - - diff --git a/test/simple/test-event-emitter-once.js b/test/simple/test-event-emitter-once.js deleted file mode 100644 index 2eaebcc7a5e4..000000000000 --- a/test/simple/test-event-emitter-once.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -var e = new events.EventEmitter(); -var times_hello_emited = 0; - -e.once('hello', function(a, b) { - times_hello_emited++; -}); - -e.emit('hello', 'a', 'b'); -e.emit('hello', 'a', 'b'); -e.emit('hello', 'a', 'b'); -e.emit('hello', 'a', 'b'); - -var remove = function() { - assert.fail(1, 0, 'once->foo should not be emitted', '!'); -}; - -e.once('foo', remove); -e.removeListener('foo', remove); -e.emit('foo'); - -process.on('exit', function() { - assert.equal(1, times_hello_emited); -}); - -var times_recurse_emitted = 0; - -e.once('e', function() { - e.emit('e'); - times_recurse_emitted++; -}); - -e.once('e', function() { - times_recurse_emitted++; -}); - -e.emit('e'); - -process.on('exit', function() { - assert.equal(2, times_recurse_emitted); -}); diff --git a/test/simple/test-event-emitter-remove-all-listeners.js b/test/simple/test-event-emitter-remove-all-listeners.js deleted file mode 100644 index f9848d682314..000000000000 --- a/test/simple/test-event-emitter-remove-all-listeners.js +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - - -function expect(expected) { - var actual = []; - process.on('exit', function() { - assert.deepEqual(actual.sort(), expected.sort()); - }); - function listener(name) { - actual.push(name) - } - return common.mustCall(listener, expected.length); -} - -function listener() {} - -var e1 = new events.EventEmitter(); -e1.on('foo', listener); -e1.on('bar', listener); -e1.on('baz', listener); -e1.on('baz', listener); -var fooListeners = e1.listeners('foo'); -var barListeners = e1.listeners('bar'); -var bazListeners = e1.listeners('baz'); -e1.on('removeListener', expect(['bar', 'baz', 'baz'])); -e1.removeAllListeners('bar'); -e1.removeAllListeners('baz'); -assert.deepEqual(e1.listeners('foo'), [listener]); -assert.deepEqual(e1.listeners('bar'), []); -assert.deepEqual(e1.listeners('baz'), []); -// after calling removeAllListeners, -// the old listeners array should stay unchanged -assert.deepEqual(fooListeners, [listener]); -assert.deepEqual(barListeners, [listener]); -assert.deepEqual(bazListeners, [listener, listener]); -// after calling removeAllListeners, -// new listeners arrays are different from the old -assert.notEqual(e1.listeners('bar'), barListeners); -assert.notEqual(e1.listeners('baz'), bazListeners); - -var e2 = new events.EventEmitter(); -e2.on('foo', listener); -e2.on('bar', listener); -// expect LIFO order -e2.on('removeListener', expect(['foo', 'bar', 'removeListener'])); -e2.on('removeListener', expect(['foo', 'bar'])); -e2.removeAllListeners(); -console.error(e2); -assert.deepEqual([], e2.listeners('foo')); -assert.deepEqual([], e2.listeners('bar')); - -var e3 = new events.EventEmitter(); -e3.on('removeListener', listener); -// check for regression where removeAllListeners throws when -// there exists a removeListener listener, but there exists -// no listeners for the provided event type -assert.doesNotThrow(e3.removeAllListeners.bind(e3, 'foo')); diff --git a/test/simple/test-event-emitter-remove-listeners.js b/test/simple/test-event-emitter-remove-listeners.js deleted file mode 100644 index 78133a4f34db..000000000000 --- a/test/simple/test-event-emitter-remove-listeners.js +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -var count = 0; - -function listener1() { - console.log('listener1'); - count++; -} - -function listener2() { - console.log('listener2'); - count++; -} - -function listener3() { - console.log('listener3'); - count++; -} - -function remove1() { - assert(0); -} - -function remove2() { - assert(0); -} - -var e1 = new events.EventEmitter(); -e1.on('hello', listener1); -e1.on('removeListener', common.mustCall(function(name, cb) { - assert.equal(name, 'hello'); - assert.equal(cb, listener1); -})); -e1.removeListener('hello', listener1); -assert.deepEqual([], e1.listeners('hello')); - -var e2 = new events.EventEmitter(); -e2.on('hello', listener1); -e2.on('removeListener', assert.fail); -e2.removeListener('hello', listener2); -assert.deepEqual([listener1], e2.listeners('hello')); - -var e3 = new events.EventEmitter(); -e3.on('hello', listener1); -e3.on('hello', listener2); -e3.on('removeListener', common.mustCall(function(name, cb) { - assert.equal(name, 'hello'); - assert.equal(cb, listener1); -})); -e3.removeListener('hello', listener1); -assert.deepEqual([listener2], e3.listeners('hello')); - -var e4 = new events.EventEmitter(); -e4.on('removeListener', common.mustCall(function(name, cb) { - if (cb !== remove1) return; - this.removeListener('quux', remove2); - this.emit('quux'); -}, 2)); -e4.on('quux', remove1); -e4.on('quux', remove2); -e4.removeListener('quux', remove1); diff --git a/test/simple/test-event-emitter-set-max-listeners-side-effects.js b/test/simple/test-event-emitter-set-max-listeners-side-effects.js deleted file mode 100644 index 604129796eaf..000000000000 --- a/test/simple/test-event-emitter-set-max-listeners-side-effects.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var events = require('events'); - -var e = new events.EventEmitter; - -assert.deepEqual(e._events, {}); -e.setMaxListeners(5); -assert.deepEqual(e._events, {}); diff --git a/test/simple/test-event-emitter-subclass.js b/test/simple/test-event-emitter-subclass.js deleted file mode 100644 index 8a2e9c156446..000000000000 --- a/test/simple/test-event-emitter-subclass.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var EventEmitter = require('events').EventEmitter; -var util = require('util'); - -util.inherits(MyEE, EventEmitter); - -function MyEE(cb) { - this.once(1, cb); - this.emit(1); - this.removeAllListeners(); - EventEmitter.call(this); -} - -var called = false; -var myee = new MyEE(function() { - called = true; -}); - - -util.inherits(ErrorEE, EventEmitter); -function ErrorEE() { - this.emit('error', new Error('blerg')); -} - -assert.throws(function() { - new ErrorEE(); -}, /blerg/); - -process.on('exit', function() { - assert(called); - assert.deepEqual(myee._events, {}); - console.log('ok'); -}); diff --git a/test/simple/test-exception-handler.js b/test/simple/test-exception-handler.js deleted file mode 100644 index 38137b834052..000000000000 --- a/test/simple/test-exception-handler.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var MESSAGE = 'catch me if you can'; -var caughtException = false; - -process.on('uncaughtException', function(e) { - console.log('uncaught exception! 1'); - assert.equal(MESSAGE, e.message); - caughtException = true; -}); - -process.on('uncaughtException', function(e) { - console.log('uncaught exception! 2'); - assert.equal(MESSAGE, e.message); - caughtException = true; -}); - -setTimeout(function() { - throw new Error(MESSAGE); -}, 10); - -process.on('exit', function() { - console.log('exit'); - assert.equal(true, caughtException); -}); diff --git a/test/simple/test-exception-handler2.js b/test/simple/test-exception-handler2.js deleted file mode 100644 index 6b8afa909f20..000000000000 --- a/test/simple/test-exception-handler2.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -process.on('uncaughtException', function(err) { - console.log('Caught exception: ' + err); -}); - -var timeoutFired = false; -setTimeout(function() { - console.log('This will still run.'); - timeoutFired = true; -}, 500); - -process.on('exit', function() { - assert.ok(timeoutFired); -}); - -// Intentionally cause an exception, but don't catch it. -nonexistentFunc(); -console.log('This will not run.'); - diff --git a/test/simple/test-exec-max-buffer.js b/test/simple/test-exec-max-buffer.js deleted file mode 100644 index 3157fc73fa9f..000000000000 --- a/test/simple/test-exec-max-buffer.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var exec = require('child_process').exec; -var assert = require('assert'); - -var cmd = 'echo "hello world"'; - -exec(cmd, { maxBuffer: 5 }, function(err, stdout, stderr) { - assert.ok(err); - assert.ok(/maxBuffer/.test(err.message)); -}); diff --git a/test/simple/test-executable-path.js b/test/simple/test-executable-path.js deleted file mode 100644 index 8d82b745010a..000000000000 --- a/test/simple/test-executable-path.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var match = false; - -var isDebug = process.features.debug; - -var debugPaths = [path.normalize(path.join(__dirname, '..', '..', - 'out', 'Debug', 'node')), - path.normalize(path.join(__dirname, '..', '..', - 'Debug', 'node'))]; -var defaultPaths = [path.normalize(path.join(__dirname, '..', '..', - 'out', 'Release', 'node')), - path.normalize(path.join(__dirname, '..', '..', - 'Release', 'node'))]; - -console.error('debugPaths: ' + debugPaths); -console.error('defaultPaths: ' + defaultPaths); -console.error('process.execPath: ' + process.execPath); - -if (isDebug) { - debugPaths.forEach(function(path) { - match = match || process.execPath.indexOf(path) == 0; - }); -} else { - defaultPaths.forEach(function(path) { - match = match || process.execPath.indexOf(path) == 0; - }); -} - -assert.ok(match); diff --git a/test/simple/test-file-read-noexist.js b/test/simple/test-file-read-noexist.js deleted file mode 100644 index aa5e761b4f56..000000000000 --- a/test/simple/test-file-read-noexist.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); -var got_error = false; - -var filename = path.join(common.fixturesDir, 'does_not_exist.txt'); -fs.readFile(filename, 'raw', function(err, content) { - if (err) { - got_error = true; - } else { - common.debug('cat returned some content: ' + content); - common.debug('this shouldn\'t happen as the file doesn\'t exist...'); - assert.equal(true, false); - } -}); - -process.on('exit', function() { - console.log('done'); - assert.equal(true, got_error); -}); diff --git a/test/simple/test-file-write-stream.js b/test/simple/test-file-write-stream.js deleted file mode 100644 index d4d146a84a8c..000000000000 --- a/test/simple/test-file-write-stream.js +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var path = require('path'); -var fs = require('fs'); -var fn = path.join(common.tmpDir, 'write.txt'); -var file = fs.createWriteStream(fn, { - highWaterMark: 10 - }); - -var EXPECTED = '012345678910'; - -var callbacks = { - open: -1, - drain: -2, - close: -1 - }; - -file - .on('open', function(fd) { - console.error('open!'); - callbacks.open++; - assert.equal('number', typeof fd); - }) - .on('error', function(err) { - throw err; - console.error('error!', err.stack); - }) - .on('drain', function() { - console.error('drain!', callbacks.drain); - callbacks.drain++; - if (callbacks.drain == -1) { - assert.equal(EXPECTED, fs.readFileSync(fn, 'utf8')); - file.write(EXPECTED); - } else if (callbacks.drain == 0) { - assert.equal(EXPECTED + EXPECTED, fs.readFileSync(fn, 'utf8')); - file.end(); - } - }) - .on('close', function() { - console.error('close!'); - assert.strictEqual(file.bytesWritten, EXPECTED.length * 2); - - callbacks.close++; - assert.throws(function() { - console.error('write after end should not be allowed'); - file.write('should not work anymore'); - }); - - fs.unlinkSync(fn); - }); - -for (var i = 0; i < 11; i++) { - (function(i) { - file.write('' + i); - })(i); -} - -process.on('exit', function() { - for (var k in callbacks) { - assert.equal(0, callbacks[k], k + ' count off by ' + callbacks[k]); - } - console.log('ok'); -}); diff --git a/test/simple/test-file-write-stream2.js b/test/simple/test-file-write-stream2.js deleted file mode 100644 index 68361bb52b65..000000000000 --- a/test/simple/test-file-write-stream2.js +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var path = require('path'); -var fs = require('fs'); -var util = require('util'); - - -var filepath = path.join(common.tmpDir, 'write.txt'); -var file; - -var EXPECTED = '012345678910'; - -var cb_expected = 'write open drain write drain close error '; -var cb_occurred = ''; - -var countDrains = 0; - - -process.on('exit', function() { - removeTestFile(); - if (cb_occurred !== cb_expected) { - console.log(' Test callback events missing or out of order:'); - console.log(' expected: %j', cb_expected); - console.log(' occurred: %j', cb_occurred); - assert.strictEqual(cb_occurred, cb_expected, - 'events missing or out of order: "' + - cb_occurred + '" !== "' + cb_expected + '"'); - } else { - console.log('ok'); - } -}); - -function removeTestFile() { - try { - fs.unlinkSync(filepath); - } catch (e) {} -} - - -removeTestFile(); - -// drain at 0, return false at 10. -file = fs.createWriteStream(filepath, { - highWaterMark: 11 -}); - -file.on('open', function(fd) { - console.error('open'); - cb_occurred += 'open '; - assert.equal(typeof fd, 'number'); -}); - -file.on('drain', function() { - console.error('drain'); - cb_occurred += 'drain '; - ++countDrains; - if (countDrains === 1) { - console.error('drain=1, write again'); - assert.equal(fs.readFileSync(filepath, 'utf8'), EXPECTED); - console.error('ondrain write ret=%j', file.write(EXPECTED)); - cb_occurred += 'write '; - } else if (countDrains == 2) { - console.error('second drain, end'); - assert.equal(fs.readFileSync(filepath, 'utf8'), EXPECTED + EXPECTED); - file.end(); - } -}); - -file.on('close', function() { - cb_occurred += 'close '; - assert.strictEqual(file.bytesWritten, EXPECTED.length * 2); - file.write('should not work anymore'); -}); - - -file.on('error', function(err) { - cb_occurred += 'error '; - assert.ok(err.message.indexOf('write after end') >= 0); -}); - - -for (var i = 0; i < 11; i++) { - var ret = file.write(i + ''); - console.error('%d %j', i, ret); - - // return false when i hits 10 - assert(ret === (i != 10)); -} -cb_occurred += 'write '; diff --git a/test/simple/test-file-write-stream3.js b/test/simple/test-file-write-stream3.js deleted file mode 100644 index 013946217bdb..000000000000 --- a/test/simple/test-file-write-stream3.js +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var path = require('path'), - fs = require('fs'), - util = require('util'); - - -var filepath = path.join(common.tmpDir, 'write_pos.txt'); - - -var cb_expected = 'write open close write open close write open close ', - cb_occurred = ''; - -var fileDataInitial = 'abcdefghijklmnopqrstuvwxyz'; - -var fileDataExpected_1 = 'abcdefghijklmnopqrstuvwxyz'; -var fileDataExpected_2 = 'abcdefghij123456qrstuvwxyz'; -var fileDataExpected_3 = 'abcdefghij\u2026\u2026qrstuvwxyz'; - - -process.on('exit', function() { - removeTestFile(); - if (cb_occurred !== cb_expected) { - console.log(' Test callback events missing or out of order:'); - console.log(' expected: %j', cb_expected); - console.log(' occurred: %j', cb_occurred); - assert.strictEqual(cb_occurred, cb_expected, - 'events missing or out of order: "' + - cb_occurred + '" !== "' + cb_expected + '"'); - } -}); - -function removeTestFile() { - try { - fs.unlinkSync(filepath); - } catch (ex) { } -} - - -removeTestFile(); - - -function run_test_1() { - var file, buffer, options; - - options = {}; - file = fs.createWriteStream(filepath, options); - console.log(' (debug: start ', file.start); - console.log(' (debug: pos ', file.pos); - - file.on('open', function(fd) { - cb_occurred += 'open '; - }); - - file.on('close', function() { - cb_occurred += 'close '; - console.log(' (debug: bytesWritten ', file.bytesWritten); - console.log(' (debug: start ', file.start); - console.log(' (debug: pos ', file.pos); - assert.strictEqual(file.bytesWritten, buffer.length); - var fileData = fs.readFileSync(filepath, 'utf8'); - console.log(' (debug: file data ', fileData); - console.log(' (debug: expected ', fileDataExpected_1); - assert.equal(fileData, fileDataExpected_1); - - run_test_2(); - }); - - file.on('error', function(err) { - cb_occurred += 'error '; - console.log(' (debug: err event ', err); - throw err; - }); - - buffer = new Buffer(fileDataInitial); - file.write(buffer); - cb_occurred += 'write '; - - file.end(); -} - - -function run_test_2() { - var file, buffer, options; - - buffer = new Buffer('123456'); - - options = { start: 10, - flags: 'r+' }; - file = fs.createWriteStream(filepath, options); - console.log(' (debug: start ', file.start); - console.log(' (debug: pos ', file.pos); - - file.on('open', function(fd) { - cb_occurred += 'open '; - }); - - file.on('close', function() { - cb_occurred += 'close '; - console.log(' (debug: bytesWritten ', file.bytesWritten); - console.log(' (debug: start ', file.start); - console.log(' (debug: pos ', file.pos); - assert.strictEqual(file.bytesWritten, buffer.length); - var fileData = fs.readFileSync(filepath, 'utf8'); - console.log(' (debug: file data ', fileData); - console.log(' (debug: expected ', fileDataExpected_2); - assert.equal(fileData, fileDataExpected_2); - - run_test_3(); - }); - - file.on('error', function(err) { - cb_occurred += 'error '; - console.log(' (debug: err event ', err); - throw err; - }); - - file.write(buffer); - cb_occurred += 'write '; - - file.end(); -} - - -function run_test_3() { - var file, buffer, options; - - var data = '\u2026\u2026', // 3 bytes * 2 = 6 bytes in UTF-8 - fileData; - - options = { start: 10, - flags: 'r+' }; - file = fs.createWriteStream(filepath, options); - console.log(' (debug: start ', file.start); - console.log(' (debug: pos ', file.pos); - - file.on('open', function(fd) { - cb_occurred += 'open '; - }); - - file.on('close', function() { - cb_occurred += 'close '; - console.log(' (debug: bytesWritten ', file.bytesWritten); - console.log(' (debug: start ', file.start); - console.log(' (debug: pos ', file.pos); - assert.strictEqual(file.bytesWritten, data.length * 3); - fileData = fs.readFileSync(filepath, 'utf8'); - console.log(' (debug: file data ', fileData); - console.log(' (debug: expected ', fileDataExpected_3); - assert.equal(fileData, fileDataExpected_3); - - run_test_4(); - }); - - file.on('error', function(err) { - cb_occurred += 'error '; - console.log(' (debug: err event ', err); - throw err; - }); - - file.write(data, 'utf8'); - cb_occurred += 'write '; - - file.end(); -} - - -function run_test_4() { - var file, options; - - options = { start: -5, - flags: 'r+' }; - - // Error: start must be >= zero - assert.throws( - function() { - file = fs.createWriteStream(filepath, options); - }, - /start must be/ - ); - -} - -run_test_1(); diff --git a/test/simple/test-force-repl.js b/test/simple/test-force-repl.js deleted file mode 100644 index 60ba3485bb20..000000000000 --- a/test/simple/test-force-repl.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; - -// spawn a node child process in "interactive" mode (force the repl) -var cp = spawn(process.execPath, ['-i']); -var gotToEnd = false; -var timeoutId = setTimeout(function() { - throw new Error('timeout!'); -}, 1000); // give node + the repl 1 second to boot up - -cp.stdout.setEncoding('utf8'); - -cp.stdout.once('data', function(b) { - clearTimeout(timeoutId); - assert.equal(b, '> '); - gotToEnd = true; - cp.kill(); -}); - -process.on('exit', function() { - assert(gotToEnd); -}); diff --git a/test/simple/test-fs-append-file-sync.js b/test/simple/test-fs-append-file-sync.js deleted file mode 100644 index 7bc6a0199fa8..000000000000 --- a/test/simple/test-fs-append-file-sync.js +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var join = require('path').join; -var fs = require('fs'); - -var currentFileData = 'ABCD'; - -var num = 220; -var data = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' + - '广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' + - '南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' + - '前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + - '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' + - '历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' + - '它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n'; - -// test that empty file will be created and have content added -var filename = join(common.tmpDir, 'append-sync.txt'); - -common.error('appending to ' + filename); -fs.appendFileSync(filename, data); - -var fileData = fs.readFileSync(filename); -console.error('filedata is a ' + typeof fileData); - -assert.equal(Buffer.byteLength(data), fileData.length); - -// test that appends data to a non empty file -var filename2 = join(common.tmpDir, 'append-sync2.txt'); -fs.writeFileSync(filename2, currentFileData); - -common.error('appending to ' + filename2); -fs.appendFileSync(filename2, data); - -var fileData2 = fs.readFileSync(filename2); - -assert.equal(Buffer.byteLength(data) + currentFileData.length, - fileData2.length); - -// test that appendFileSync accepts buffers -var filename3 = join(common.tmpDir, 'append-sync3.txt'); -fs.writeFileSync(filename3, currentFileData); - -common.error('appending to ' + filename3); - -var buf = new Buffer(data, 'utf8'); -fs.appendFileSync(filename3, buf); - -var fileData3 = fs.readFileSync(filename3); - -assert.equal(buf.length + currentFileData.length, fileData3.length); - -// test that appendFile accepts numbers. -var filename4 = join(common.tmpDir, 'append-sync4.txt'); -fs.writeFileSync(filename4, currentFileData, { mode: m }); - -common.error('appending to ' + filename4); -var m = 0600; -fs.appendFileSync(filename4, num, { mode: m }); - -// windows permissions aren't unix -if (process.platform !== 'win32') { - var st = fs.statSync(filename4); - assert.equal(st.mode & 0700, m); -} - -var fileData4 = fs.readFileSync(filename4); - -assert.equal(Buffer.byteLength('' + num) + currentFileData.length, - fileData4.length); - -//exit logic for cleanup - -process.on('exit', function() { - common.error('done'); - - fs.unlinkSync(filename); - fs.unlinkSync(filename2); - fs.unlinkSync(filename3); - fs.unlinkSync(filename4); -}); diff --git a/test/simple/test-fs-append-file.js b/test/simple/test-fs-append-file.js deleted file mode 100644 index 450c8d3b9e82..000000000000 --- a/test/simple/test-fs-append-file.js +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var join = require('path').join; - -var filename = join(common.tmpDir, 'append.txt'); - -common.error('appending to ' + filename); - -var currentFileData = 'ABCD'; - -var n = 220; -var s = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' + - '广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' + - '南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' + - '前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + - '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' + - '历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' + - '它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n'; - -var ncallbacks = 0; - -// test that empty file will be created and have content added -fs.appendFile(filename, s, function(e) { - if (e) throw e; - - ncallbacks++; - common.error('appended to file'); - - fs.readFile(filename, function(e, buffer) { - if (e) throw e; - common.error('file read'); - ncallbacks++; - assert.equal(Buffer.byteLength(s), buffer.length); - }); -}); - -// test that appends data to a non empty file -var filename2 = join(common.tmpDir, 'append2.txt'); -fs.writeFileSync(filename2, currentFileData); - -fs.appendFile(filename2, s, function(e) { - if (e) throw e; - - ncallbacks++; - common.error('appended to file2'); - - fs.readFile(filename2, function(e, buffer) { - if (e) throw e; - common.error('file2 read'); - ncallbacks++; - assert.equal(Buffer.byteLength(s) + currentFileData.length, buffer.length); - }); -}); - -// test that appendFile accepts buffers -var filename3 = join(common.tmpDir, 'append3.txt'); -fs.writeFileSync(filename3, currentFileData); - -var buf = new Buffer(s, 'utf8'); -common.error('appending to ' + filename3); - -fs.appendFile(filename3, buf, function(e) { - if (e) throw e; - - ncallbacks++; - common.error('appended to file3'); - - fs.readFile(filename3, function(e, buffer) { - if (e) throw e; - common.error('file3 read'); - ncallbacks++; - assert.equal(buf.length + currentFileData.length, buffer.length); - }); -}); - -// test that appendFile accepts numbers. -var filename4 = join(common.tmpDir, 'append4.txt'); -fs.writeFileSync(filename4, currentFileData); - -common.error('appending to ' + filename4); - -var m = 0600; -fs.appendFile(filename4, n, { mode: m }, function(e) { - if (e) throw e; - - ncallbacks++; - common.error('appended to file4'); - - // windows permissions aren't unix - if (process.platform !== 'win32') { - var st = fs.statSync(filename4); - assert.equal(st.mode & 0700, m); - } - - fs.readFile(filename4, function(e, buffer) { - if (e) throw e; - common.error('file4 read'); - ncallbacks++; - assert.equal(Buffer.byteLength('' + n) + currentFileData.length, - buffer.length); - }); -}); - -process.on('exit', function() { - common.error('done'); - assert.equal(8, ncallbacks); - - fs.unlinkSync(filename); - fs.unlinkSync(filename2); - fs.unlinkSync(filename3); - fs.unlinkSync(filename4); -}); diff --git a/test/simple/test-fs-chmod.js b/test/simple/test-fs-chmod.js deleted file mode 100644 index 12fd820f3aa1..000000000000 --- a/test/simple/test-fs-chmod.js +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); -var got_error = false; -var success_count = 0; -var mode_async; -var mode_sync; -var is_windows = process.platform === 'win32'; - -// Need to hijack fs.open/close to make sure that things -// get closed once they're opened. -fs._open = fs.open; -fs._openSync = fs.openSync; -fs.open = open; -fs.openSync = openSync; -fs._close = fs.close; -fs._closeSync = fs.closeSync; -fs.close = close; -fs.closeSync = closeSync; - -var openCount = 0; - -function open() { - openCount++; - return fs._open.apply(fs, arguments); -} - -function openSync() { - openCount++; - return fs._openSync.apply(fs, arguments); -} - -function close() { - openCount--; - return fs._close.apply(fs, arguments); -} - -function closeSync() { - openCount--; - return fs._closeSync.apply(fs, arguments); -} - - -// On Windows chmod is only able to manipulate read-only bit -if (is_windows) { - mode_async = 0400; // read-only - mode_sync = 0600; // read-write -} else { - mode_async = 0777; - mode_sync = 0644; -} - -var file1 = path.join(common.fixturesDir, 'a.js'), - file2 = path.join(common.fixturesDir, 'a1.js'); - -fs.chmod(file1, mode_async.toString(8), function(err) { - if (err) { - got_error = true; - } else { - console.log(fs.statSync(file1).mode); - - if (is_windows) { - assert.ok((fs.statSync(file1).mode & 0777) & mode_async); - } else { - assert.equal(mode_async, fs.statSync(file1).mode & 0777); - } - - fs.chmodSync(file1, mode_sync); - if (is_windows) { - assert.ok((fs.statSync(file1).mode & 0777) & mode_sync); - } else { - assert.equal(mode_sync, fs.statSync(file1).mode & 0777); - } - success_count++; - } -}); - -fs.open(file2, 'a', function(err, fd) { - if (err) { - got_error = true; - console.error(err.stack); - return; - } - fs.fchmod(fd, mode_async.toString(8), function(err) { - if (err) { - got_error = true; - } else { - console.log(fs.fstatSync(fd).mode); - - if (is_windows) { - assert.ok((fs.fstatSync(fd).mode & 0777) & mode_async); - } else { - assert.equal(mode_async, fs.fstatSync(fd).mode & 0777); - } - - fs.fchmodSync(fd, mode_sync); - if (is_windows) { - assert.ok((fs.fstatSync(fd).mode & 0777) & mode_sync); - } else { - assert.equal(mode_sync, fs.fstatSync(fd).mode & 0777); - } - success_count++; - fs.close(fd); - } - }); -}); - -// lchmod -if (fs.lchmod) { - var link = path.join(common.tmpDir, 'symbolic-link'); - - try { - fs.unlinkSync(link); - } catch (er) {} - fs.symlinkSync(file2, link); - - fs.lchmod(link, mode_async, function(err) { - if (err) { - got_error = true; - } else { - console.log(fs.lstatSync(link).mode); - assert.equal(mode_async, fs.lstatSync(link).mode & 0777); - - fs.lchmodSync(link, mode_sync); - assert.equal(mode_sync, fs.lstatSync(link).mode & 0777); - success_count++; - } - }); -} else { - success_count++; -} - - -process.on('exit', function() { - assert.equal(3, success_count); - assert.equal(0, openCount); - assert.equal(false, got_error); -}); - diff --git a/test/simple/test-fs-empty-readStream.js b/test/simple/test-fs-empty-readStream.js deleted file mode 100644 index d181c219820a..000000000000 --- a/test/simple/test-fs-empty-readStream.js +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); - -var emptyFile = path.join(common.fixturesDir, 'empty.txt'); - -fs.open(emptyFile, 'r', function (error, fd) { - assert.ifError(error); - - var read = fs.createReadStream(emptyFile, { 'fd': fd }); - - read.once('data', function () { - throw new Error('data event should not emit'); - }); - - var readEmit = false; - read.once('end', function () { - readEmit = true; - console.error('end event 1'); - }); - - setTimeout(function () { - assert.equal(readEmit, true); - }, 50); -}); - -fs.open(emptyFile, 'r', function (error, fd) { - assert.ifError(error); - - var read = fs.createReadStream(emptyFile, { 'fd': fd }); - read.pause(); - - read.once('data', function () { - throw new Error('data event should not emit'); - }); - - var readEmit = false; - read.once('end', function () { - readEmit = true; - console.error('end event 2'); - }); - - setTimeout(function () { - assert.equal(readEmit, false); - }, 50); -}); diff --git a/test/simple/test-fs-error-messages.js b/test/simple/test-fs-error-messages.js deleted file mode 100644 index 773faa69d742..000000000000 --- a/test/simple/test-fs-error-messages.js +++ /dev/null @@ -1,216 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -var path = require('path'), - fs = require('fs'), - fn = path.join(common.fixturesDir, 'non-existent'), - existingFile = path.join(common.fixturesDir, 'exit.js'), - existingFile2 = path.join(common.fixturesDir, 'create-file.js'), - existingDir = path.join(common.fixturesDir, 'empty'), - existingDir2 = path.join(common.fixturesDir, 'keys'); - -// ASYNC_CALL - -fs.stat(fn, function(err) { - assert.equal(fn, err.path); - assert.ok(0 <= err.message.indexOf(fn)); -}); - -fs.lstat(fn, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); -}); - -fs.readlink(fn, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); -}); - -fs.link(fn, 'foo', function(err) { - assert.ok(0 <= err.message.indexOf(fn)); -}); - -fs.link(existingFile, existingFile2, function(err) { - assert.ok(0 <= err.message.indexOf(existingFile2)); -}); - -fs.unlink(fn, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); -}); - -fs.rename(fn, 'foo', function(err) { - assert.ok(0 <= err.message.indexOf(fn)); -}); - -fs.rename(existingDir, existingDir2, function(err) { - assert.ok(0 <= err.message.indexOf(existingDir2)); -}); - -fs.rmdir(fn, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); -}); - -fs.mkdir(existingFile, 0666, function(err) { - assert.ok(0 <= err.message.indexOf(existingFile)); -}); - -fs.rmdir(existingFile, function(err) { - assert.ok(0 <= err.message.indexOf(existingFile)); -}); - -fs.chmod(fn, 0666, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); -}); - -fs.open(fn, 'r', 0666, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); -}); - -fs.readFile(fn, function(err) { - assert.ok(0 <= err.message.indexOf(fn)); -}); - -// Sync - -var errors = [], - expected = 0; - -try { - ++expected; - fs.statSync(fn); -} catch (err) { - errors.push('stat'); - assert.ok(0 <= err.message.indexOf(fn)); -} - -try { - ++expected; - fs.mkdirSync(existingFile, 0666); -} catch (err) { - errors.push('mkdir'); - assert.ok(0 <= err.message.indexOf(existingFile)); -} - -try { - ++expected; - fs.chmodSync(fn, 0666); -} catch (err) { - errors.push('chmod'); - assert.ok(0 <= err.message.indexOf(fn)); -} - -try { - ++expected; - fs.lstatSync(fn); -} catch (err) { - errors.push('lstat'); - assert.ok(0 <= err.message.indexOf(fn)); -} - -try { - ++expected; - fs.readlinkSync(fn); -} catch (err) { - errors.push('readlink'); - assert.ok(0 <= err.message.indexOf(fn)); -} - -try { - ++expected; - fs.linkSync(fn, 'foo'); -} catch (err) { - errors.push('link'); - assert.ok(0 <= err.message.indexOf(fn)); -} - -try { - ++expected; - fs.linkSync(existingFile, existingFile2); -} catch (err) { - errors.push('link'); - assert.ok(0 <= err.message.indexOf(existingFile2)); -} - -try { - ++expected; - fs.unlinkSync(fn); -} catch (err) { - errors.push('unlink'); - assert.ok(0 <= err.message.indexOf(fn)); -} - -try { - ++expected; - fs.rmdirSync(fn); -} catch (err) { - errors.push('rmdir'); - assert.ok(0 <= err.message.indexOf(fn)); -} - -try { - ++expected; - fs.rmdirSync(existingFile); -} catch (err) { - errors.push('rmdir'); - assert.ok(0 <= err.message.indexOf(existingFile)); -} - -try { - ++expected; - fs.openSync(fn, 'r'); -} catch (err) { - errors.push('opens'); - assert.ok(0 <= err.message.indexOf(fn)); -} - -try { - ++expected; - fs.renameSync(fn, 'foo'); -} catch (err) { - errors.push('rename'); - assert.ok(0 <= err.message.indexOf(fn)); -} - -try { - ++expected; - fs.renameSync(existingDir, existingDir2); -} catch (err) { - errors.push('rename'); - assert.ok(0 <= err.message.indexOf(existingDir2)); -} - -try { - ++expected; - fs.readdirSync(fn); -} catch (err) { - errors.push('readdir'); - assert.ok(0 <= err.message.indexOf(fn)); -} - -process.on('exit', function() { - assert.equal(expected, errors.length, - 'Test fs sync exceptions raised, got ' + errors.length + - ' expected ' + expected); -}); diff --git a/test/simple/test-fs-exists.js b/test/simple/test-fs-exists.js deleted file mode 100644 index 377573056937..000000000000 --- a/test/simple/test-fs-exists.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var f = __filename; -var exists; -var doesNotExist; - -fs.exists(f, function(y) { - exists = y; -}); - -fs.exists(f + '-NO', function(y) { - doesNotExist = y; -}); - -assert(fs.existsSync(f)); -assert(!fs.existsSync(f + '-NO')); - -process.on('exit', function() { - assert.strictEqual(exists, true); - assert.strictEqual(doesNotExist, false); -}); diff --git a/test/simple/test-fs-fsync.js b/test/simple/test-fs-fsync.js deleted file mode 100644 index e624ed7d65d3..000000000000 --- a/test/simple/test-fs-fsync.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var path = require('path'); -var fs = require('fs'); -var successes = 0; - -var file = path.join(common.fixturesDir, 'a.js'); - -common.error('open ' + file); - -fs.open(file, 'a', 0777, function(err, fd) { - common.error('fd ' + fd); - if (err) throw err; - - fs.fdatasyncSync(fd); - common.error('fdatasync SYNC: ok'); - successes++; - - fs.fsyncSync(fd); - common.error('fsync SYNC: ok'); - successes++; - - fs.fdatasync(fd, function(err) { - if (err) throw err; - common.error('fdatasync ASYNC: ok'); - successes++; - fs.fsync(fd, function(err) { - if (err) throw err; - common.error('fsync ASYNC: ok'); - successes++; - }); - }); -}); - -process.on('exit', function() { - assert.equal(4, successes); -}); diff --git a/test/simple/test-fs-long-path.js b/test/simple/test-fs-long-path.js deleted file mode 100644 index 67f042976e84..000000000000 --- a/test/simple/test-fs-long-path.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); - -var successes = 0; - -// make a path that will be at least 260 chars long. -var fileNameLen = Math.max(260 - common.tmpDir.length - 1, 1); -var fileName = path.join(common.tmpDir, new Array(fileNameLen + 1).join('x')); -var fullPath = path.resolve(fileName); - -try { - fs.unlinkSync(fullPath); -} -catch (e) { - // Ignore. -} - -console.log({ - filenameLength: fileName.length, - fullPathLength: fullPath.length -}); - -fs.writeFile(fullPath, 'ok', function(err) { - if (err) throw err; - successes++; - - fs.stat(fullPath, function(err, stats) { - if (err) throw err; - successes++; - }); -}); - -process.on('exit', function() { - fs.unlinkSync(fullPath); - assert.equal(2, successes); -}); diff --git a/test/simple/test-fs-mkdir.js b/test/simple/test-fs-mkdir.js deleted file mode 100644 index d99cd371b378..000000000000 --- a/test/simple/test-fs-mkdir.js +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); - -function unlink(pathname) { - try { - fs.rmdirSync(pathname); - } catch (e) { - } -} - -(function() { - var ncalls = 0; - var pathname = common.tmpDir + '/test1'; - - unlink(pathname); - - fs.mkdir(pathname, function(err) { - assert.equal(err, null); - assert.equal(fs.existsSync(pathname), true); - ncalls++; - }); - - process.on('exit', function() { - unlink(pathname); - assert.equal(ncalls, 1); - }); -})(); - -(function() { - var ncalls = 0; - var pathname = common.tmpDir + '/test2'; - - unlink(pathname); - - fs.mkdir(pathname, 511 /*=0777*/, function(err) { - assert.equal(err, null); - assert.equal(fs.existsSync(pathname), true); - ncalls++; - }); - - process.on('exit', function() { - unlink(pathname); - assert.equal(ncalls, 1); - }); -})(); - -(function() { - var pathname = common.tmpDir + '/test3'; - - unlink(pathname); - fs.mkdirSync(pathname); - - var exists = fs.existsSync(pathname); - unlink(pathname); - - assert.equal(exists, true); -})(); - -// Keep the event loop alive so the async mkdir() requests -// have a chance to run (since they don't ref the event loop). -process.nextTick(function() {}); diff --git a/test/simple/test-fs-non-number-arguments-throw.js b/test/simple/test-fs-non-number-arguments-throw.js deleted file mode 100644 index 7a1e7bdb5285..000000000000 --- a/test/simple/test-fs-non-number-arguments-throw.js +++ /dev/null @@ -1,24 +0,0 @@ -var assert = require('assert'), - fs = require('fs'), - saneEmitter, - sanity = 'ire(\'assert\')'; - -saneEmitter = fs.createReadStream(__filename, { start: 17, end: 29 }); - -assert.throws(function () { - fs.createReadStream(__filename, { start: "17", end: 29 }); -}, "start as string didn't throw an error for createReadStream"); - -assert.throws(function () { - fs.createReadStream(__filename, { start: 17, end: "29" }); -}, "end as string didn't throw an error"); - -assert.throws(function () { - fs.createWriteStream(__filename, { start: "17" }); -}, "start as string didn't throw an error for createWriteStream"); - -saneEmitter.on('data', function (data) { - // a sanity check when using numbers instead of strings - assert.strictEqual(sanity, data.toString('utf8'), 'read ' + - data.toString('utf8') + ' instead of ' + sanity); -}); diff --git a/test/simple/test-fs-null-bytes.js b/test/simple/test-fs-null-bytes.js deleted file mode 100644 index 5dec223ba875..000000000000 --- a/test/simple/test-fs-null-bytes.js +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); - -function check(async, sync) { - var expected = /Path must be a string without null bytes./; - var argsSync = Array.prototype.slice.call(arguments, 2); - var argsAsync = argsSync.concat(function(er) { - assert(er && er.message.match(expected)); - }); - - if (sync) - assert.throws(function() { - console.error(sync.name, argsSync); - sync.apply(null, argsSync); - }, expected); - - if (async) - async.apply(null, argsAsync); -} - -check(fs.appendFile, fs.appendFileSync, 'foo\u0000bar'); -check(fs.chmod, fs.chmodSync, 'foo\u0000bar', '0644'); -check(fs.chown, fs.chownSync, 'foo\u0000bar', 12, 34); -check(fs.link, fs.linkSync, 'foo\u0000bar', 'foobar'); -check(fs.link, fs.linkSync, 'foobar', 'foo\u0000bar'); -check(fs.lstat, fs.lstatSync, 'foo\u0000bar'); -check(fs.mkdir, fs.mkdirSync, 'foo\u0000bar', '0755'); -check(fs.open, fs.openSync, 'foo\u0000bar', 'r'); -check(fs.readFile, fs.readFileSync, 'foo\u0000bar'); -check(fs.readdir, fs.readdirSync, 'foo\u0000bar'); -check(fs.readlink, fs.readlinkSync, 'foo\u0000bar'); -check(fs.realpath, fs.realpathSync, 'foo\u0000bar'); -check(fs.rename, fs.renameSync, 'foo\u0000bar', 'foobar'); -check(fs.rename, fs.renameSync, 'foobar', 'foo\u0000bar'); -check(fs.rmdir, fs.rmdirSync, 'foo\u0000bar'); -check(fs.stat, fs.statSync, 'foo\u0000bar'); -check(fs.symlink, fs.symlinkSync, 'foo\u0000bar', 'foobar'); -check(fs.symlink, fs.symlinkSync, 'foobar', 'foo\u0000bar'); -check(fs.truncate, fs.truncateSync, 'foo\u0000bar'); -check(fs.unlink, fs.unlinkSync, 'foo\u0000bar'); -check(null, fs.unwatchFile, 'foo\u0000bar', assert.fail); -check(fs.utimes, fs.utimesSync, 'foo\u0000bar', 0, 0); -check(null, fs.watch, 'foo\u0000bar', assert.fail); -check(null, fs.watchFile, 'foo\u0000bar', assert.fail); -check(fs.writeFile, fs.writeFileSync, 'foo\u0000bar'); - -// an 'error' for exists means that it doesn't exist. -// one of many reasons why this file is the absolute worst. -fs.exists('foo\u0000bar', function(exists) { - assert(!exists); -}); -assert(!fs.existsSync('foo\u0000bar')); - diff --git a/test/simple/test-fs-open-flags.js b/test/simple/test-fs-open-flags.js deleted file mode 100644 index e1c6c3be99ee..000000000000 --- a/test/simple/test-fs-open-flags.js +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var constants = require('constants'); -var fs = require('fs'); - -var O_APPEND = constants.O_APPEND || 0; -var O_CREAT = constants.O_CREAT || 0; -var O_DIRECTORY = constants.O_DIRECTORY || 0; -var O_EXCL = constants.O_EXCL || 0; -var O_NOCTTY = constants.O_NOCTTY || 0; -var O_NOFOLLOW = constants.O_NOFOLLOW || 0; -var O_RDONLY = constants.O_RDONLY || 0; -var O_RDWR = constants.O_RDWR || 0; -var O_SYMLINK = constants.O_SYMLINK || 0; -var O_SYNC = constants.O_SYNC || 0; -var O_TRUNC = constants.O_TRUNC || 0; -var O_WRONLY = constants.O_WRONLY || 0; - -assert.equal(fs._stringToFlags('r'), O_RDONLY); -assert.equal(fs._stringToFlags('r+'), O_RDWR); -assert.equal(fs._stringToFlags('w'), O_TRUNC | O_CREAT | O_WRONLY); -assert.equal(fs._stringToFlags('w+'), O_TRUNC | O_CREAT | O_RDWR); -assert.equal(fs._stringToFlags('a'), O_APPEND | O_CREAT | O_WRONLY); -assert.equal(fs._stringToFlags('a+'), O_APPEND | O_CREAT | O_RDWR); - -assert.equal(fs._stringToFlags('wx'), O_TRUNC | O_CREAT | O_WRONLY | O_EXCL); -assert.equal(fs._stringToFlags('xw'), O_TRUNC | O_CREAT | O_WRONLY | O_EXCL); -assert.equal(fs._stringToFlags('wx+'), O_TRUNC | O_CREAT | O_RDWR | O_EXCL); -assert.equal(fs._stringToFlags('xw+'), O_TRUNC | O_CREAT | O_RDWR | O_EXCL); -assert.equal(fs._stringToFlags('ax'), O_APPEND | O_CREAT | O_WRONLY | O_EXCL); -assert.equal(fs._stringToFlags('xa'), O_APPEND | O_CREAT | O_WRONLY | O_EXCL); -assert.equal(fs._stringToFlags('ax+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL); -assert.equal(fs._stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL); - -('+ +a +r +w rw wa war raw r++ a++ w++' + - 'x +x x+ rx rx+ wxx wax xwx xxx').split(' ').forEach(function(flags) { - assert.throws(function() { fs._stringToFlags(flags); }); -}); diff --git a/test/simple/test-fs-open.js b/test/simple/test-fs-open.js deleted file mode 100644 index e334de9895b9..000000000000 --- a/test/simple/test-fs-open.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var constants = require('constants'); -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); - -var caughtException = false; -try { - // should throw ENOENT, not EBADF - // see https://github.com/joyent/node/pull/1228 - fs.openSync('/path/to/file/that/does/not/exist', 'r'); -} -catch (e) { - assert.equal(e.code, 'ENOENT'); - caughtException = true; -} -assert.ok(caughtException); - -var openFd; -fs.open(__filename, 'r', function(err, fd) { - if (err) { - throw err; - } - openFd = fd; -}); - -var openFd2; -fs.open(__filename, 'rs', function(err, fd) { - if (err) { - throw err; - } - openFd2 = fd; -}); - -process.on('exit', function() { - assert.ok(openFd); - assert.ok(openFd2); -}); - diff --git a/test/simple/test-fs-read-buffer.js b/test/simple/test-fs-read-buffer.js deleted file mode 100644 index 96f700363a27..000000000000 --- a/test/simple/test-fs-read-buffer.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'), - Buffer = require('buffer').Buffer, - fs = require('fs'), - filepath = path.join(common.fixturesDir, 'x.txt'), - fd = fs.openSync(filepath, 'r'), - expected = 'xyz\n', - bufferAsync = new Buffer(expected.length), - bufferSync = new Buffer(expected.length), - readCalled = 0; - -fs.read(fd, bufferAsync, 0, expected.length, 0, function(err, bytesRead) { - readCalled++; - - assert.equal(bytesRead, expected.length); - assert.deepEqual(bufferAsync, new Buffer(expected)); -}); - -var r = fs.readSync(fd, bufferSync, 0, expected.length, 0); -assert.deepEqual(bufferSync, new Buffer(expected)); -assert.equal(r, expected.length); - -process.on('exit', function() { - assert.equal(readCalled, 1); -}); diff --git a/test/simple/test-fs-read-file-sync-hostname.js b/test/simple/test-fs-read-file-sync-hostname.js deleted file mode 100644 index 758e2aedd897..000000000000 --- a/test/simple/test-fs-read-file-sync-hostname.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); - -// test reading from hostname -if (process.platform === 'linux2') { - var hostname = fs.readFileSync('/proc/sys/kernel/hostname'); - assert.ok(hostname.length > 0); -} diff --git a/test/simple/test-fs-read-file-sync.js b/test/simple/test-fs-read-file-sync.js deleted file mode 100644 index 518d32cc18ff..000000000000 --- a/test/simple/test-fs-read-file-sync.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); - -var fn = path.join(common.fixturesDir, 'elipses.txt'); - -var s = fs.readFileSync(fn, 'utf8'); -for (var i = 0; i < s.length; i++) { - assert.equal('\u2026', s[i]); -} -assert.equal(10000, s.length); diff --git a/test/simple/test-fs-read-stream-err.js b/test/simple/test-fs-read-stream-err.js deleted file mode 100644 index 54aa21799ea8..000000000000 --- a/test/simple/test-fs-read-stream-err.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); - -var stream = fs.createReadStream(__filename, { - bufferSize: 64 -}); -var err = new Error('BAM'); - -stream.on('error', common.mustCall(function errorHandler(err_) { - console.error('error event'); - process.nextTick(function() { - assert.equal(stream.fd, null); - assert.equal(err_, err); - }); -})); - -fs.close = common.mustCall(function(fd_, cb) { - assert.equal(fd_, stream.fd); - process.nextTick(cb); -}); - -var read = fs.read; -fs.read = function() { - // first time is ok. - read.apply(fs, arguments); - // then it breaks - fs.read = function() { - var cb = arguments[arguments.length - 1]; - process.nextTick(function() { - cb(err); - }); - // and should not be called again! - fs.read = function() { - throw new Error('BOOM!'); - }; - }; -}; - -stream.on('data', function(buf) { - stream.on('data', assert.fail); // no more 'data' events should follow -}); diff --git a/test/simple/test-fs-read-stream-fd.js b/test/simple/test-fs-read-stream-fd.js deleted file mode 100644 index 835ed97271de..000000000000 --- a/test/simple/test-fs-read-stream-fd.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var fs = require('fs'); -var assert = require('assert'); -var path = require('path'); - -var common = require('../common'); - -var file = path.join(common.tmpDir, '/read_stream_fd_test.txt'); -var input = 'hello world'; -var output = ''; -var fd, stream; - -fs.writeFileSync(file, input); -fd = fs.openSync(file, 'r'); - -stream = fs.createReadStream(null, { fd: fd, encoding: 'utf8' }); -stream.on('data', function(data) { - output += data; -}); - -process.on('exit', function() { - fs.unlinkSync(file); - assert.equal(output, input); -}); diff --git a/test/simple/test-fs-read-stream-resume.js b/test/simple/test-fs-read-stream-resume.js deleted file mode 100644 index c3ace49e9ffc..000000000000 --- a/test/simple/test-fs-read-stream-resume.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var fs = require('fs'); -var path = require('path'); - -var file = path.join(common.fixturesDir, 'x.txt'); -var data = ''; -var first = true; - -var stream = fs.createReadStream(file); -stream.setEncoding('utf8'); -stream.on('data', function(chunk) { - data += chunk; - if (first) { - first = false; - stream.resume(); - } -}); - -process.nextTick(function() { - stream.pause(); - setTimeout(function() { - stream.resume(); - }, 100); -}); - -process.on('exit', function() { - assert.equal(data, 'xyz\n'); -}); diff --git a/test/simple/test-fs-read-stream.js b/test/simple/test-fs-read-stream.js deleted file mode 100644 index 4d1eebb2c178..000000000000 --- a/test/simple/test-fs-read-stream.js +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -// TODO Improved this test. test_ca.pem is too small. A proper test would -// great a large utf8 (with multibyte chars) file and stream it in, -// performing sanity checks throughout. - -var path = require('path'); -var fs = require('fs'); -var fn = path.join(common.fixturesDir, 'elipses.txt'); -var rangeFile = path.join(common.fixturesDir, 'x.txt'); - -var callbacks = { open: 0, end: 0, close: 0 }; - -var paused = false; - -var file = fs.ReadStream(fn); - -file.on('open', function(fd) { - file.length = 0; - callbacks.open++; - assert.equal('number', typeof fd); - assert.ok(file.readable); - - // GH-535 - file.pause(); - file.resume(); - file.pause(); - file.resume(); -}); - -file.on('data', function(data) { - assert.ok(data instanceof Buffer); - assert.ok(!paused); - file.length += data.length; - - paused = true; - file.pause(); - - setTimeout(function() { - paused = false; - file.resume(); - }, 10); -}); - - -file.on('end', function(chunk) { - callbacks.end++; -}); - - -file.on('close', function() { - callbacks.close++; - - //assert.equal(fs.readFileSync(fn), fileContent); -}); - -var file3 = fs.createReadStream(fn, {encoding: 'utf8'}); -file3.length = 0; -file3.on('data', function(data) { - assert.equal('string', typeof(data)); - file3.length += data.length; - - for (var i = 0; i < data.length; i++) { - // http://www.fileformat.info/info/unicode/char/2026/index.htm - assert.equal('\u2026', data[i]); - } -}); - -file3.on('close', function() { - callbacks.close++; -}); - -process.on('exit', function() { - assert.equal(1, callbacks.open); - assert.equal(1, callbacks.end); - assert.equal(2, callbacks.close); - assert.equal(30000, file.length); - assert.equal(10000, file3.length); - console.error('ok'); -}); - -var file4 = fs.createReadStream(rangeFile, {bufferSize: 1, start: 1, end: 2}); -var contentRead = ''; -file4.on('data', function(data) { - contentRead += data.toString('utf-8'); -}); -file4.on('end', function(data) { - assert.equal(contentRead, 'yz'); -}); - -var file5 = fs.createReadStream(rangeFile, {bufferSize: 1, start: 1}); -file5.data = ''; -file5.on('data', function(data) { - file5.data += data.toString('utf-8'); -}); -file5.on('end', function() { - assert.equal(file5.data, 'yz\n'); -}); - -// https://github.com/joyent/node/issues/2320 -var file6 = fs.createReadStream(rangeFile, {bufferSize: 1.23, start: 1}); -file6.data = ''; -file6.on('data', function(data) { - file6.data += data.toString('utf-8'); -}); -file6.on('end', function() { - assert.equal(file6.data, 'yz\n'); -}); - -assert.throws(function() { - fs.createReadStream(rangeFile, {start: 10, end: 2}); -}, /start must be <= end/); - -var stream = fs.createReadStream(rangeFile, { start: 0, end: 0 }); -stream.data = ''; - -stream.on('data', function(chunk) { - stream.data += chunk; -}); - -stream.on('end', function() { - assert.equal('x', stream.data); -}); - -// pause and then resume immediately. -var pauseRes = fs.createReadStream(rangeFile); -pauseRes.pause(); -pauseRes.resume(); - -var file7 = fs.createReadStream(rangeFile, {autoClose: false }); -file7.on('data', function() {}); -file7.on('end', function() { - process.nextTick(function() { - assert(!file7.closed); - assert(!file7.destroyed); - file7Next(); - }); -}); - -function file7Next(){ - // This will tell us if the fd is usable again or not. - file7 = fs.createReadStream(null, {fd: file7.fd, start: 0 }); - file7.data = ''; - file7.on('data', function(data) { - file7.data += data; - }); - file7.on('end', function(err) { - assert.equal(file7.data, 'xyz\n'); - }); -} - -// Just to make sure autoClose won't close the stream because of error. -var file8 = fs.createReadStream(null, {fd: 13337, autoClose: false }); -file8.on('data', function() {}); -file8.on('error', common.mustCall(function() {})); - -// Make sure stream is destroyed when file does not exist. -var file9 = fs.createReadStream('/path/to/file/that/does/not/exist'); -file9.on('data', function() {}); -file9.on('error', common.mustCall(function() {})); - -process.on('exit', function() { - assert(file7.closed); - assert(file7.destroyed); - - assert(!file8.closed); - assert(!file8.destroyed); - assert(file8.fd); - - assert(!file9.closed); - assert(file9.destroyed); -}); diff --git a/test/simple/test-fs-read.js b/test/simple/test-fs-read.js deleted file mode 100644 index 4a90f9091e79..000000000000 --- a/test/simple/test-fs-read.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'), - fs = require('fs'), - filepath = path.join(common.fixturesDir, 'x.txt'), - fd = fs.openSync(filepath, 'r'), - expected = 'xyz\n', - readCalled = 0; - -fs.read(fd, expected.length, 0, 'utf-8', function(err, str, bytesRead) { - readCalled++; - - assert.ok(!err); - assert.equal(str, expected); - assert.equal(bytesRead, expected.length); -}); - -var r = fs.readSync(fd, expected.length, 0, 'utf-8'); -assert.equal(r[0], expected); -assert.equal(r[1], expected.length); - -process.on('exit', function() { - assert.equal(readCalled, 1); -}); diff --git a/test/simple/test-fs-readfile-empty.js b/test/simple/test-fs-readfile-empty.js deleted file mode 100644 index 31b83567ee44..000000000000 --- a/test/simple/test-fs-readfile-empty.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var path = require('path'), - fs = require('fs'), - fn = path.join(common.fixturesDir, 'empty.txt'); - -fs.readFile(fn, function(err, data) { - assert.ok(data); -}); - -fs.readFile(fn, 'utf8', function(err, data) { - assert.strictEqual('', data); -}); - -assert.ok(fs.readFileSync(fn)); -assert.strictEqual('', fs.readFileSync(fn, 'utf8')); diff --git a/test/simple/test-fs-readfile-error.js b/test/simple/test-fs-readfile-error.js deleted file mode 100644 index 97d2f06a611b..000000000000 --- a/test/simple/test-fs-readfile-error.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; -var path = require('path'); - -var callbacks = 0; - -function test(env, cb) { - var filename = path.join(common.fixturesDir, 'test-fs-readfile-error.js'); - var execPath = process.execPath + ' --throw-deprecation ' + filename; - var options = { env: env || {} }; - exec(execPath, options, function(err, stdout, stderr) { - assert(err); - assert.equal(stdout, ''); - assert.notEqual(stderr, ''); - cb('' + stderr); - }); -} - -test({ NODE_DEBUG: '' }, function(data) { - assert(/EISDIR/.test(data)); - assert(!/test-fs-readfile-error/.test(data)); - callbacks++; -}); - -test({ NODE_DEBUG: 'fs' }, function(data) { - assert(/EISDIR/.test(data)); - assert(/test-fs-readfile-error/.test(data)); - callbacks++; -}); - -process.on('exit', function() { - assert.equal(callbacks, 2); -}); - -(function() { - console.error('the warnings are normal here.'); - // just make sure that this doesn't crash the process. - var fs = require('fs'); - fs.readFile(__dirname); - fs.readdir(__filename); - fs.unlink('gee-i-sure-hope-this-file-isnt-important-or-existing'); -})(); diff --git a/test/simple/test-fs-readfile-pipe.js b/test/simple/test-fs-readfile-pipe.js deleted file mode 100644 index 8ca165144ff6..000000000000 --- a/test/simple/test-fs-readfile-pipe.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// simulate `cat readfile.js | node readfile.js` - -// TODO: Have some way to make this work on windows. -if (process.platform === 'win32') { - console.error('No /dev/stdin on windows. Skipping test.'); - process.exit(); -} - -var fs = require('fs'); - -var dataExpected = fs.readFileSync(__filename, 'utf8'); - -if (process.argv[2] === 'child') { - fs.readFile('/dev/stdin', function(er, data) { - if (er) throw er; - process.stdout.write(data); - }); - return; -} - -var exec = require('child_process').exec; -var f = JSON.stringify(__filename); -var node = JSON.stringify(process.execPath); -var cmd = 'cat ' + f + ' | ' + node + ' ' + f + ' child'; -exec(cmd, function(err, stdout, stderr) { - if (err) console.error(err); - assert(!err, 'it exits normally'); - assert(stdout === dataExpected, 'it reads the file and outputs it'); - assert(stderr === '', 'it does not write to stderr'); - console.log('ok'); -}); diff --git a/test/simple/test-fs-readfile-unlink.js b/test/simple/test-fs-readfile-unlink.js deleted file mode 100644 index 0bb4a67f7810..000000000000 --- a/test/simple/test-fs-readfile-unlink.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'), - common = require('../common'), - fs = require('fs'), - path = require('path'), - dirName = path.resolve(common.fixturesDir, 'test-readfile-unlink'), - fileName = path.resolve(dirName, 'test.bin'); - -var buf = new Buffer(512 * 1024); -buf.fill(42); - -try { - fs.mkdirSync(dirName); -} catch (e) { - // Ignore if the directory already exists. - if (e.code != 'EEXIST') throw e; -} - -fs.writeFileSync(fileName, buf); - -fs.readFile(fileName, function(err, data) { - assert.ifError(err); - assert(data.length == buf.length); - assert.strictEqual(buf[0], 42); - - fs.unlinkSync(fileName); - fs.rmdirSync(dirName); -}); diff --git a/test/simple/test-fs-readfile-zero-byte-liar.js b/test/simple/test-fs-readfile-zero-byte-liar.js deleted file mode 100644 index 60f41226f1bb..000000000000 --- a/test/simple/test-fs-readfile-zero-byte-liar.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); - -var dataExpected = fs.readFileSync(__filename, 'utf8'); - -// sometimes stat returns size=0, but it's a lie. -fs._fstat = fs.fstat; -fs._fstatSync = fs.fstatSync; - -fs.fstat = function(fd, cb) { - fs._fstat(fd, function(er, st) { - if (er) return cb(er); - st.size = 0; - return cb(er, st); - }); -}; - -fs.fstatSync = function(fd) { - var st = fs._fstatSync; - st.size = 0; - return st; -}; - -var d = fs.readFileSync(__filename, 'utf8'); -assert.equal(d, dataExpected); - -var called = false; -fs.readFile(__filename, 'utf8', function (er, d) { - assert.equal(d, dataExpected); - called = true; -}); - -process.on('exit', function() { - assert(called); - console.log("ok"); -}); diff --git a/test/simple/test-fs-realpath.js b/test/simple/test-fs-realpath.js deleted file mode 100644 index 2f126ea30049..000000000000 --- a/test/simple/test-fs-realpath.js +++ /dev/null @@ -1,594 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); -var exec = require('child_process').exec; -var async_completed = 0, async_expected = 0, unlink = []; -var isWindows = process.platform === 'win32'; -var skipSymlinks = false; - -var root = '/'; -if (isWindows) { - // something like "C:\\" - root = process.cwd().substr(0, 3); - - // On Windows, creating symlinks requires admin privileges. - // We'll only try to run symlink test if we have enough privileges. - try { - exec('whoami /priv', function(err, o) { - if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') == -1) { - skipSymlinks = true; - } - runTest(); - }); - } catch (er) { - // better safe than sorry - skipSymlinks = true; - process.nextTick(runTest); - } -} else { - process.nextTick(runTest); -} - - -function tmp(p) { - return path.join(common.tmpDir, p); -} - -var fixturesAbsDir = common.fixturesDir; -var tmpAbsDir = common.tmpDir; - -console.error("absolutes\n%s\n%s", fixturesAbsDir, tmpAbsDir); - -function asynctest(testBlock, args, callback, assertBlock) { - async_expected++; - testBlock.apply(testBlock, args.concat(function(err) { - var ignoreError = false; - if (assertBlock) { - try { - ignoreError = assertBlock.apply(assertBlock, arguments); - } - catch (e) { - err = e; - } - } - async_completed++; - callback(ignoreError ? null : err); - })); -} - -// sub-tests: -function test_simple_error_callback(cb) { - var ncalls = 0; - - fs.realpath('/this/path/does/not/exist', function(err, s) { - assert(err); - assert(!s); - ncalls++; - cb(); - }); - - process.on('exit', function() { - assert.equal(ncalls, 1); - }); -} - -function test_simple_relative_symlink(callback) { - console.log('test_simple_relative_symlink'); - if (skipSymlinks) { - console.log('skipping symlink test (no privs)'); - return runNextTest(); - } - var entry = common.tmpDir + '/symlink', - expected = common.tmpDir + '/cycles/root.js'; - [ - [entry, '../tmp/cycles/root.js'] - ].forEach(function(t) { - try {fs.unlinkSync(t[0]);}catch (e) {} - console.log('fs.symlinkSync(%j, %j, %j)', t[1], t[0], 'file'); - fs.symlinkSync(t[1], t[0], 'file'); - unlink.push(t[0]); - }); - var result = fs.realpathSync(entry); - assert.equal(result, path.resolve(expected), - 'got ' + common.inspect(result) + ' expected ' + - common.inspect(expected)); - asynctest(fs.realpath, [entry], callback, function(err, result) { - assert.equal(result, path.resolve(expected), - 'got ' + - common.inspect(result) + - ' expected ' + - common.inspect(expected)); - }); -} - -function test_simple_absolute_symlink(callback) { - console.log('test_simple_absolute_symlink'); - - // this one should still run, even if skipSymlinks is set, - // because it uses a junction. - var type = skipSymlinks ? 'junction' : 'dir'; - - console.log('using type=%s', type); - - var entry = tmpAbsDir + '/symlink', - expected = fixturesAbsDir + '/nested-index/one'; - [ - [entry, expected] - ].forEach(function(t) { - try {fs.unlinkSync(t[0]);} catch (e) {} - console.error('fs.symlinkSync(%j, %j, %j)', t[1], t[0], type); - fs.symlinkSync(t[1], t[0], type); - unlink.push(t[0]); - }); - var result = fs.realpathSync(entry); - assert.equal(result, path.resolve(expected), - 'got ' + - common.inspect(result) + - ' expected ' + - common.inspect(expected)); - asynctest(fs.realpath, [entry], callback, function(err, result) { - assert.equal(result, path.resolve(expected), - 'got ' + - common.inspect(result) + - ' expected ' + - common.inspect(expected)); - }); -} - -function test_deep_relative_file_symlink(callback) { - console.log('test_deep_relative_file_symlink'); - if (skipSymlinks) { - console.log('skipping symlink test (no privs)'); - return runNextTest(); - } - - var expected = path.join(common.fixturesDir, 'cycles', 'root.js'); - var linkData1 = '../../cycles/root.js'; - var linkPath1 = path.join(common.fixturesDir, - 'nested-index', 'one', 'symlink1.js'); - try {fs.unlinkSync(linkPath1);} catch (e) {} - fs.symlinkSync(linkData1, linkPath1, 'file'); - - var linkData2 = '../one/symlink1.js'; - var entry = path.join(common.fixturesDir, - 'nested-index', 'two', 'symlink1-b.js'); - try {fs.unlinkSync(entry);} catch (e) {} - fs.symlinkSync(linkData2, entry, 'file'); - unlink.push(linkPath1); - unlink.push(entry); - - assert.equal(fs.realpathSync(entry), path.resolve(expected)); - asynctest(fs.realpath, [entry], callback, function(err, result) { - assert.equal(result, path.resolve(expected), - 'got ' + - common.inspect(result) + - ' expected ' + - common.inspect(path.resolve(expected))); - }); -} - -function test_deep_relative_dir_symlink(callback) { - console.log('test_deep_relative_dir_symlink'); - if (skipSymlinks) { - console.log('skipping symlink test (no privs)'); - return runNextTest(); - } - var expected = path.join(common.fixturesDir, 'cycles', 'folder'); - var linkData1b = '../../cycles/folder'; - var linkPath1b = path.join(common.fixturesDir, - 'nested-index', 'one', 'symlink1-dir'); - try {fs.unlinkSync(linkPath1b);} catch (e) {} - fs.symlinkSync(linkData1b, linkPath1b, 'dir'); - - var linkData2b = '../one/symlink1-dir'; - var entry = path.join(common.fixturesDir, - 'nested-index', 'two', 'symlink12-dir'); - try {fs.unlinkSync(entry);} catch (e) {} - fs.symlinkSync(linkData2b, entry, 'dir'); - unlink.push(linkPath1b); - unlink.push(entry); - - assert.equal(fs.realpathSync(entry), path.resolve(expected)); - - asynctest(fs.realpath, [entry], callback, function(err, result) { - assert.equal(result, path.resolve(expected), - 'got ' + - common.inspect(result) + - ' expected ' + - common.inspect(path.resolve(expected))); - }); -} - -function test_cyclic_link_protection(callback) { - console.log('test_cyclic_link_protection'); - if (skipSymlinks) { - console.log('skipping symlink test (no privs)'); - return runNextTest(); - } - var entry = common.tmpDir + '/cycles/realpath-3a'; - [ - [entry, '../cycles/realpath-3b'], - [common.tmpDir + '/cycles/realpath-3b', '../cycles/realpath-3c'], - [common.tmpDir + '/cycles/realpath-3c', '../cycles/realpath-3a'] - ].forEach(function(t) { - try {fs.unlinkSync(t[0]);} catch (e) {} - fs.symlinkSync(t[1], t[0], 'dir'); - unlink.push(t[0]); - }); - assert.throws(function() { fs.realpathSync(entry); }); - asynctest(fs.realpath, [entry], callback, function(err, result) { - assert.ok(err && true); - return true; - }); -} - -function test_cyclic_link_overprotection(callback) { - console.log('test_cyclic_link_overprotection'); - if (skipSymlinks) { - console.log('skipping symlink test (no privs)'); - return runNextTest(); - } - var cycles = common.tmpDir + '/cycles'; - var expected = fs.realpathSync(cycles); - var folder = cycles + '/folder'; - var link = folder + '/cycles'; - var testPath = cycles; - for (var i = 0; i < 10; i++) testPath += '/folder/cycles'; - try {fs.unlinkSync(link)} catch (ex) {} - fs.symlinkSync(cycles, link, 'dir'); - unlink.push(link); - assert.equal(fs.realpathSync(testPath), path.resolve(expected)); - asynctest(fs.realpath, [testPath], callback, function(er, res) { - assert.equal(res, path.resolve(expected)); - }); -} - -function test_relative_input_cwd(callback) { - console.log('test_relative_input_cwd'); - - // we need to get the relative path to the tmp dir from cwd. - // When the test runner is running it, that will be .../node/test - // but it's more common to run `./node test/.../`, so detect it here. - var entrydir = process.cwd(); - var entry = common.tmpDir.substr(entrydir.length + 1) + '/cycles/realpath-3a'; - var expected = common.tmpDir + '/cycles/root.js'; - [ - [entry, '../cycles/realpath-3b'], - [common.tmpDir + '/cycles/realpath-3b', '../cycles/realpath-3c'], - [common.tmpDir + '/cycles/realpath-3c', 'root.js'] - ].forEach(function(t) { - var fn = t[0]; - console.error('fn=%j', fn); - try {fs.unlinkSync(fn);} catch (e) {} - var b = path.basename(t[1]); - var type = (b === 'root.js' ? 'file' : 'dir'); - console.log('fs.symlinkSync(%j, %j, %j)', t[1], fn, type); - fs.symlinkSync(t[1], fn, 'file'); - unlink.push(fn); - }); - - var origcwd = process.cwd(); - process.chdir(entrydir); - assert.equal(fs.realpathSync(entry), path.resolve(expected)); - asynctest(fs.realpath, [entry], callback, function(err, result) { - process.chdir(origcwd); - assert.equal(result, path.resolve(expected), - 'got ' + - common.inspect(result) + - ' expected ' + - common.inspect(path.resolve(expected))); - return true; - }); -} - -function test_deep_symlink_mix(callback) { - console.log('test_deep_symlink_mix'); - if (isWindows) { - // This one is a mix of files and directories, and it's quite tricky - // to get the file/dir links sorted out correctly. - console.log('skipping symlink test (no way to work on windows)'); - return runNextTest(); - } - - // todo: check to see that common.fixturesDir is not rooted in the - // same directory as our test symlink. - /* - /tmp/node-test-realpath-f1 -> ../tmp/node-test-realpath-d1/foo - /tmp/node-test-realpath-d1 -> ../node-test-realpath-d2 - /tmp/node-test-realpath-d2/foo -> ../node-test-realpath-f2 - /tmp/node-test-realpath-f2 - -> /node/test/fixtures/nested-index/one/realpath-c - /node/test/fixtures/nested-index/one/realpath-c - -> /node/test/fixtures/nested-index/two/realpath-c - /node/test/fixtures/nested-index/two/realpath-c -> ../../cycles/root.js - /node/test/fixtures/cycles/root.js (hard) - */ - var entry = tmp('node-test-realpath-f1'); - try { fs.unlinkSync(tmp('node-test-realpath-d2/foo')); } catch (e) {} - try { fs.rmdirSync(tmp('node-test-realpath-d2')); } catch (e) {} - fs.mkdirSync(tmp('node-test-realpath-d2'), 0700); - try { - [ - [entry, '../tmp/node-test-realpath-d1/foo'], - [tmp('node-test-realpath-d1'), '../tmp/node-test-realpath-d2'], - [tmp('node-test-realpath-d2/foo'), '../node-test-realpath-f2'], - [tmp('node-test-realpath-f2'), fixturesAbsDir + - '/nested-index/one/realpath-c'], - [fixturesAbsDir + '/nested-index/one/realpath-c', fixturesAbsDir + - '/nested-index/two/realpath-c'], - [fixturesAbsDir + '/nested-index/two/realpath-c', - '../../../tmp/cycles/root.js'] - ].forEach(function(t) { - //common.debug('setting up '+t[0]+' -> '+t[1]); - try { fs.unlinkSync(t[0]); } catch (e) {} - fs.symlinkSync(t[1], t[0]); - unlink.push(t[0]); - }); - } finally { - unlink.push(tmp('node-test-realpath-d2')); - } - var expected = tmpAbsDir + '/cycles/root.js'; - assert.equal(fs.realpathSync(entry), path.resolve(expected)); - asynctest(fs.realpath, [entry], callback, function(err, result) { - assert.equal(result, path.resolve(expected), - 'got ' + - common.inspect(result) + - ' expected ' + - common.inspect(path.resolve(expected))); - return true; - }); -} - -function test_non_symlinks(callback) { - console.log('test_non_symlinks'); - var entrydir = path.dirname(tmpAbsDir); - var entry = tmpAbsDir.substr(entrydir.length + 1) + '/cycles/root.js'; - var expected = tmpAbsDir + '/cycles/root.js'; - var origcwd = process.cwd(); - process.chdir(entrydir); - assert.equal(fs.realpathSync(entry), path.resolve(expected)); - asynctest(fs.realpath, [entry], callback, function(err, result) { - process.chdir(origcwd); - assert.equal(result, path.resolve(expected), - 'got ' + - common.inspect(result) + - ' expected ' + - common.inspect(path.resolve(expected))); - return true; - }); -} - -var upone = path.join(process.cwd(), '..'); -function test_escape_cwd(cb) { - console.log('test_escape_cwd'); - asynctest(fs.realpath, ['..'], cb, function(er, uponeActual) { - assert.equal(upone, uponeActual, - 'realpath("..") expected: ' + path.resolve(upone) + ' actual:' + uponeActual); - }); -} -var uponeActual = fs.realpathSync('..'); -assert.equal(upone, uponeActual, - 'realpathSync("..") expected: ' + path.resolve(upone) + ' actual:' + uponeActual); - - -// going up with .. multiple times -// . -// `-- a/ -// |-- b/ -// | `-- e -> .. -// `-- d -> .. -// realpath(a/b/e/d/a/b/e/d/a) ==> a -function test_up_multiple(cb) { - console.error('test_up_multiple'); - if (skipSymlinks) { - console.log('skipping symlink test (no privs)'); - return runNextTest(); - } - fs.mkdirSync(tmp('a'), 0755); - fs.mkdirSync(tmp('a/b'), 0755); - fs.symlinkSync('..', tmp('a/d'), 'dir'); - unlink.push(tmp('a/d')); - fs.symlinkSync('..', tmp('a/b/e'), 'dir'); - unlink.push(tmp('a/b/e')); - - var abedabed = tmp('abedabed'.split('').join('/')); - var abedabed_real = tmp(''); - - var abedabeda = tmp('abedabeda'.split('').join('/')); - var abedabeda_real = tmp('a'); - - assert.equal(fs.realpathSync(abedabeda), abedabeda_real); - assert.equal(fs.realpathSync(abedabed), abedabed_real); - fs.realpath(abedabeda, function (er, real) { - if (er) throw er; - assert.equal(abedabeda_real, real); - fs.realpath(abedabed, function (er, real) { - if (er) throw er; - assert.equal(abedabed_real, real); - cb(); - }); - }); -} - - -// absolute symlinks with children. -// . -// `-- a/ -// |-- b/ -// | `-- c/ -// | `-- x.txt -// `-- link -> /tmp/node-test-realpath-abs-kids/a/b/ -// realpath(root+'/a/link/c/x.txt') ==> root+'/a/b/c/x.txt' -function test_abs_with_kids(cb) { - console.log('test_abs_with_kids'); - - // this one should still run, even if skipSymlinks is set, - // because it uses a junction. - var type = skipSymlinks ? 'junction' : 'dir'; - - console.log('using type=%s', type); - - var root = tmpAbsDir + '/node-test-realpath-abs-kids'; - function cleanup() { - ['/a/b/c/x.txt', - '/a/link' - ].forEach(function(file) { - try {fs.unlinkSync(root + file)} catch (ex) {} - }); - ['/a/b/c', - '/a/b', - '/a', - '' - ].forEach(function(folder) { - try {fs.rmdirSync(root + folder)} catch (ex) {} - }); - } - function setup() { - cleanup(); - ['', - '/a', - '/a/b', - '/a/b/c' - ].forEach(function(folder) { - console.log('mkdir ' + root + folder); - fs.mkdirSync(root + folder, 0700); - }); - fs.writeFileSync(root + '/a/b/c/x.txt', 'foo'); - fs.symlinkSync(root + '/a/b', root + '/a/link', type); - } - setup(); - var linkPath = root + '/a/link/c/x.txt'; - var expectPath = root + '/a/b/c/x.txt'; - var actual = fs.realpathSync(linkPath); - // console.log({link:linkPath,expect:expectPath,actual:actual},'sync'); - assert.equal(actual, path.resolve(expectPath)); - asynctest(fs.realpath, [linkPath], cb, function(er, actual) { - // console.log({link:linkPath,expect:expectPath,actual:actual},'async'); - assert.equal(actual, path.resolve(expectPath)); - cleanup(); - }); -} - -function test_lying_cache_liar(cb) { - var n = 2; - - // this should not require *any* stat calls, since everything - // checked by realpath will be found in the cache. - console.log('test_lying_cache_liar'); - var cache = { '/foo/bar/baz/bluff' : '/foo/bar/bluff', - '/1/2/3/4/5/6/7' : '/1', - '/a' : '/a', - '/a/b' : '/a/b', - '/a/b/c' : '/a/b', - '/a/b/d' : '/a/b/d' }; - if (isWindows) { - var wc = {}; - Object.keys(cache).forEach(function(k) { - wc[ path.resolve(k) ] = path.resolve(cache[k]); - }); - cache = wc; - } - - var bluff = path.resolve('/foo/bar/baz/bluff'); - var rps = fs.realpathSync(bluff, cache); - assert.equal(cache[bluff], rps); - var nums = path.resolve('/1/2/3/4/5/6/7'); - var called = false; // no sync cb calling! - fs.realpath(nums, cache, function(er, rp) { - called = true; - assert.equal(cache[nums], rp); - if (--n === 0) cb(); - }); - assert(called === false); - - var test = path.resolve('/a/b/c/d'), - expect = path.resolve('/a/b/d'); - var actual = fs.realpathSync(test, cache); - assert.equal(expect, actual); - fs.realpath(test, cache, function(er, actual) { - assert.equal(expect, actual); - if (--n === 0) cb(); - }); -} - -// ---------------------------------------------------------------------------- - -var tests = [ - test_simple_error_callback, - test_simple_relative_symlink, - test_simple_absolute_symlink, - test_deep_relative_file_symlink, - test_deep_relative_dir_symlink, - test_cyclic_link_protection, - test_cyclic_link_overprotection, - test_relative_input_cwd, - test_deep_symlink_mix, - test_non_symlinks, - test_escape_cwd, - test_abs_with_kids, - test_lying_cache_liar, - test_up_multiple -]; -var numtests = tests.length; -var testsRun = 0; -function runNextTest(err) { - if (err) throw err; - var test = tests.shift(); - if (!test) { - return console.log(numtests + - ' subtests completed OK for fs.realpath'); - } - testsRun++; - test(runNextTest); -} - - -assert.equal(root, fs.realpathSync('/')); -fs.realpath('/', function(err, result) { - assert.equal(null, err); - assert.equal(root, result); -}); - - -function runTest() { - var tmpDirs = ['cycles', 'cycles/folder']; - tmpDirs.forEach(function(t) { - t = tmp(t); - var s; - try { s = fs.statSync(t); } catch (ex) {} - if (s) return; - fs.mkdirSync(t, 0700); - }); - fs.writeFileSync(tmp('cycles/root.js'), "console.error('roooot!');"); - console.error('start tests'); - runNextTest(); -} - - -process.on('exit', function() { - assert.equal(numtests, testsRun); - unlink.forEach(function(path) { try {fs.unlinkSync(path);} catch (e) {} }); - assert.equal(async_completed, async_expected); -}); diff --git a/test/simple/test-fs-sir-writes-alot.js b/test/simple/test-fs-sir-writes-alot.js deleted file mode 100644 index e16f56bdc82e..000000000000 --- a/test/simple/test-fs-sir-writes-alot.js +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var fs = require('fs'); -var assert = require('assert'); -var join = require('path').join; - -var filename = join(common.tmpDir, 'out.txt'); - -try { - fs.unlinkSync(filename); -} catch (e) { - // might not exist, that's okay. -} - -var fd = fs.openSync(filename, 'w'); - -var line = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa\n'; - -var N = 10240, complete = 0; -for (var i = 0; i < N; i++) { - // Create a new buffer for each write. Before the write is actually - // executed by the thread pool, the buffer will be collected. - var buffer = new Buffer(line); - fs.write(fd, buffer, 0, buffer.length, null, function(er, written) { - complete++; - if (complete === N) { - fs.closeSync(fd); - var s = fs.createReadStream(filename); - s.on('data', testBuffer); - } - }); -} - -var bytesChecked = 0; - -function testBuffer(b) { - for (var i = 0; i < b.length; i++) { - bytesChecked++; - if (b[i] !== 'a'.charCodeAt(0) && b[i] !== '\n'.charCodeAt(0)) { - throw new Error('invalid char ' + i + ',' + b[i]); - } - } -} - -process.on('exit', function() { - // Probably some of the writes are going to overlap, so we can't assume - // that we get (N * line.length). Let's just make sure we've checked a - // few... - assert.ok(bytesChecked > 1000); -}); - diff --git a/test/simple/test-fs-stat.js b/test/simple/test-fs-stat.js deleted file mode 100644 index 90b0ba52d4a2..000000000000 --- a/test/simple/test-fs-stat.js +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var got_error = false; -var success_count = 0; - -fs.stat('.', function(err, stats) { - if (err) { - got_error = true; - } else { - console.dir(stats); - assert.ok(stats.mtime instanceof Date); - success_count++; - } - assert(this === global); -}); - -fs.lstat('.', function(err, stats) { - if (err) { - got_error = true; - } else { - console.dir(stats); - assert.ok(stats.mtime instanceof Date); - success_count++; - } - assert(this === global); -}); - -// fstat -fs.open('.', 'r', undefined, function(err, fd) { - assert.ok(!err); - assert.ok(fd); - - fs.fstat(fd, function(err, stats) { - if (err) { - got_error = true; - } else { - console.dir(stats); - assert.ok(stats.mtime instanceof Date); - success_count++; - fs.close(fd); - } - assert(this === global); - }); - - assert(this === global); -}); - -// fstatSync -fs.open('.', 'r', undefined, function(err, fd) { - var stats; - try { - stats = fs.fstatSync(fd); - } catch (err) { - got_error = true; - } - if (stats) { - console.dir(stats); - assert.ok(stats.mtime instanceof Date); - success_count++; - } - fs.close(fd); -}); - -console.log('stating: ' + __filename); -fs.stat(__filename, function(err, s) { - if (err) { - got_error = true; - } else { - console.dir(s); - success_count++; - - console.log('isDirectory: ' + JSON.stringify(s.isDirectory())); - assert.equal(false, s.isDirectory()); - - console.log('isFile: ' + JSON.stringify(s.isFile())); - assert.equal(true, s.isFile()); - - console.log('isSocket: ' + JSON.stringify(s.isSocket())); - assert.equal(false, s.isSocket()); - - console.log('isBlockDevice: ' + JSON.stringify(s.isBlockDevice())); - assert.equal(false, s.isBlockDevice()); - - console.log('isCharacterDevice: ' + JSON.stringify(s.isCharacterDevice())); - assert.equal(false, s.isCharacterDevice()); - - console.log('isFIFO: ' + JSON.stringify(s.isFIFO())); - assert.equal(false, s.isFIFO()); - - console.log('isSymbolicLink: ' + JSON.stringify(s.isSymbolicLink())); - assert.equal(false, s.isSymbolicLink()); - - assert.ok(s.mtime instanceof Date); - } -}); - -process.on('exit', function() { - assert.equal(5, success_count); - assert.equal(false, got_error); -}); - diff --git a/test/simple/test-fs-stream-double-close.js b/test/simple/test-fs-stream-double-close.js deleted file mode 100644 index 89386b6e6462..000000000000 --- a/test/simple/test-fs-stream-double-close.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); - -test1(fs.createReadStream(__filename)); -test2(fs.createReadStream(__filename)); -test3(fs.createReadStream(__filename)); - -test1(fs.createWriteStream(common.tmpDir + '/dummy1')); -test2(fs.createWriteStream(common.tmpDir + '/dummy2')); -test3(fs.createWriteStream(common.tmpDir + '/dummy3')); - -function test1(stream) { - stream.destroy(); - stream.destroy(); -} - -function test2(stream) { - stream.destroy(); - stream.on('open', function(fd) { - stream.destroy(); - open_cb_called++; - }); - process.on('exit', function() { - assert.equal(open_cb_called, 1); - }); - var open_cb_called = 0; -} - -function test3(stream) { - stream.on('open', function(fd) { - stream.destroy(); - stream.destroy(); - open_cb_called++; - }); - process.on('exit', function() { - assert.equal(open_cb_called, 1); - }); - var open_cb_called = 0; -} diff --git a/test/simple/test-fs-symlink-dir-junction.js b/test/simple/test-fs-symlink-dir-junction.js deleted file mode 100644 index c675b920e3ee..000000000000 --- a/test/simple/test-fs-symlink-dir-junction.js +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); -var completed = 0; -var expected_tests = 4; - -// test creating and reading symbolic link -var linkData = path.join(common.fixturesDir, 'cycles/'); -var linkPath = path.join(common.tmpDir, 'cycles_link'); - -// Delete previously created link -try { - fs.unlinkSync(linkPath); -} catch (e) {} - -console.log('linkData: ' + linkData); -console.log('linkPath: ' + linkPath); - -fs.symlink(linkData, linkPath, 'junction', function(err) { - if (err) throw err; - completed++; - - fs.lstat(linkPath, function(err, stats) { - if (err) throw err; - assert.ok(stats.isSymbolicLink()); - completed++; - - fs.readlink(linkPath, function(err, destination) { - if (err) throw err; - assert.equal(destination, linkData); - completed++; - - fs.unlink(linkPath, function(err) { - if (err) throw err; - assert(!fs.existsSync(linkPath)); - assert(fs.existsSync(linkData)); - completed++; - }); - }); - }); -}); - -process.on('exit', function() { - assert.equal(completed, expected_tests); -}); - diff --git a/test/simple/test-fs-symlink.js b/test/simple/test-fs-symlink.js deleted file mode 100644 index 6b23b1e1c104..000000000000 --- a/test/simple/test-fs-symlink.js +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); -var exec = require('child_process').exec; -var completed = 0; -var expected_tests = 2; - -var is_windows = process.platform === 'win32'; - -var runtest = function(skip_symlinks) { - if (!skip_symlinks) { - // test creating and reading symbolic link - var linkData = path.join(common.fixturesDir, '/cycles/root.js'); - var linkPath = path.join(common.tmpDir, 'symlink1.js'); - - // Delete previously created link - try { - fs.unlinkSync(linkPath); - } catch (e) {} - - fs.symlink(linkData, linkPath, function(err) { - if (err) throw err; - console.log('symlink done'); - // todo: fs.lstat? - fs.readlink(linkPath, function(err, destination) { - if (err) throw err; - assert.equal(destination, linkData); - completed++; - }); - }); - } - - // test creating and reading hard link - var srcPath = path.join(common.fixturesDir, 'cycles', 'root.js'); - var dstPath = path.join(common.tmpDir, 'link1.js'); - - // Delete previously created link - try { - fs.unlinkSync(dstPath); - } catch (e) {} - - fs.link(srcPath, dstPath, function(err) { - if (err) throw err; - console.log('hard link done'); - var srcContent = fs.readFileSync(srcPath, 'utf8'); - var dstContent = fs.readFileSync(dstPath, 'utf8'); - assert.equal(srcContent, dstContent); - completed++; - }); -}; - -if (is_windows) { - // On Windows, creating symlinks requires admin privileges. - // We'll only try to run symlink test if we have enough privileges. - exec('whoami /priv', function(err, o) { - if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') == -1) { - expected_tests = 1; - runtest(true); - } else { - runtest(false); - } - }); -} else { - runtest(false); -} - -process.on('exit', function() { - assert.equal(completed, expected_tests); -}); - diff --git a/test/simple/test-fs-sync-fd-leak.js b/test/simple/test-fs-sync-fd-leak.js deleted file mode 100644 index fe932c7dfa0b..000000000000 --- a/test/simple/test-fs-sync-fd-leak.js +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); - -// ensure that (read|write|append)FileSync() closes the file descriptor -fs.openSync = function() { - return 42; -}; -fs.closeSync = function(fd) { - assert.equal(fd, 42); - close_called++; -}; -fs.readSync = function() { - throw new Error('BAM'); -}; -fs.writeSync = function() { - throw new Error('BAM'); -}; - -fs.fstatSync = function() { - throw new Error('BAM'); -}; - -ensureThrows(function() { - fs.readFileSync('dummy'); -}); -ensureThrows(function() { - fs.writeFileSync('dummy', 'xxx'); -}); -ensureThrows(function() { - fs.appendFileSync('dummy', 'xxx'); -}); - -var close_called = 0; -function ensureThrows(cb) { - var got_exception = false; - - close_called = 0; - try { - cb(); - } catch (e) { - assert.equal(e.message, 'BAM'); - got_exception = true; - } - - assert.equal(close_called, 1); - assert.equal(got_exception, true); -} diff --git a/test/simple/test-fs-truncate-GH-6233.js b/test/simple/test-fs-truncate-GH-6233.js deleted file mode 100644 index 472afdcab9c4..000000000000 --- a/test/simple/test-fs-truncate-GH-6233.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); - -var filename = common.tmpDir + '/truncate-file.txt'; - -// Synchronous test. -(function() { - fs.writeFileSync(filename, '0123456789'); - assert.equal(fs.readFileSync(filename).toString(), '0123456789'); - fs.truncateSync(filename, 5); - assert.equal(fs.readFileSync(filename).toString(), '01234'); -})(); - -// Asynchronous test. -(function() { - fs.writeFileSync(filename, '0123456789'); - assert.equal(fs.readFileSync(filename).toString(), '0123456789'); - fs.truncate(filename, 5, common.mustCall(function(err) { - if (err) throw err; - assert.equal(fs.readFileSync(filename).toString(), '01234'); - })); -})(); diff --git a/test/simple/test-fs-truncate.js b/test/simple/test-fs-truncate.js deleted file mode 100644 index 09476b2ad8a1..000000000000 --- a/test/simple/test-fs-truncate.js +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); -var tmp = common.tmpDir; -var filename = path.resolve(tmp, 'truncate-file.txt'); -var data = new Buffer(1024 * 16); -data.fill('x'); - -var stat; - -// truncateSync -fs.writeFileSync(filename, data); -stat = fs.statSync(filename); -assert.equal(stat.size, 1024 * 16); - -fs.truncateSync(filename, 1024); -stat = fs.statSync(filename); -assert.equal(stat.size, 1024); - -fs.truncateSync(filename); -stat = fs.statSync(filename); -assert.equal(stat.size, 0); - -// ftruncateSync -fs.writeFileSync(filename, data); -var fd = fs.openSync(filename, 'r+'); - -stat = fs.statSync(filename); -assert.equal(stat.size, 1024 * 16); - -fs.ftruncateSync(fd, 1024); -stat = fs.statSync(filename); -assert.equal(stat.size, 1024); - -fs.ftruncateSync(fd); -stat = fs.statSync(filename); -assert.equal(stat.size, 0); - -fs.closeSync(fd); - -// async tests -var success = 0; -testTruncate(function(er) { - if (er) throw er; - success++; - testFtruncate(function(er) { - if (er) throw er; - success++; - }); -}); - -process.on('exit', function() { - assert.equal(success, 2); - console.log('ok'); -}); - -function testTruncate(cb) { - fs.writeFile(filename, data, function(er) { - if (er) return cb(er); - fs.stat(filename, function(er, stat) { - if (er) return cb(er); - assert.equal(stat.size, 1024 * 16); - - fs.truncate(filename, 1024, function(er) { - if (er) return cb(er); - fs.stat(filename, function(er, stat) { - if (er) return cb(er); - assert.equal(stat.size, 1024); - - fs.truncate(filename, function(er) { - if (er) return cb(er); - fs.stat(filename, function(er, stat) { - if (er) return cb(er); - assert.equal(stat.size, 0); - cb(); - }); - }); - }); - }); - }); - }); -} - - -function testFtruncate(cb) { - fs.writeFile(filename, data, function(er) { - if (er) return cb(er); - fs.stat(filename, function(er, stat) { - if (er) return cb(er); - assert.equal(stat.size, 1024 * 16); - - fs.open(filename, 'w', function(er, fd) { - if (er) return cb(er); - fs.ftruncate(fd, 1024, function(er) { - if (er) return cb(er); - fs.stat(filename, function(er, stat) { - if (er) return cb(er); - assert.equal(stat.size, 1024); - - fs.ftruncate(fd, function(er) { - if (er) return cb(er); - fs.stat(filename, function(er, stat) { - if (er) return cb(er); - assert.equal(stat.size, 0); - fs.close(fd, cb); - }); - }); - }); - }); - }); - }); - }); -} diff --git a/test/simple/test-fs-utimes.js b/test/simple/test-fs-utimes.js deleted file mode 100644 index eae80238bc14..000000000000 --- a/test/simple/test-fs-utimes.js +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var util = require('util'); -var fs = require('fs'); - -var is_windows = process.platform === 'win32'; - -var tests_ok = 0; -var tests_run = 0; - -function stat_resource(resource) { - if (typeof resource == 'string') { - return fs.statSync(resource); - } else { - // ensure mtime has been written to disk - fs.fsyncSync(resource); - return fs.fstatSync(resource); - } -} - -function check_mtime(resource, mtime) { - var mtime = fs._toUnixTimestamp(mtime); - var stats = stat_resource(resource); - var real_mtime = fs._toUnixTimestamp(stats.mtime); - // check up to single-second precision - // sub-second precision is OS and fs dependant - return Math.floor(mtime) == Math.floor(real_mtime); -} - -function expect_errno(syscall, resource, err, errno) { - if (err && (err.code === errno || err.code === 'ENOSYS')) { - tests_ok++; - } else { - console.log('FAILED:', arguments.callee.name, util.inspect(arguments)); - } -} - -function expect_ok(syscall, resource, err, atime, mtime) { - if (!err && check_mtime(resource, mtime) || - err && err.code === 'ENOSYS') { - tests_ok++; - } else { - console.log('FAILED:', arguments.callee.name, util.inspect(arguments)); - } -} - -// the tests assume that __filename belongs to the user running the tests -// this should be a fairly safe assumption; testing against a temp file -// would be even better though (node doesn't have such functionality yet) -function runTest(atime, mtime, callback) { - - var fd, err; - // - // test synchronized code paths, these functions throw on failure - // - function syncTests() { - fs.utimesSync(__filename, atime, mtime); - expect_ok('utimesSync', __filename, undefined, atime, mtime); - tests_run++; - - // some systems don't have futimes - // if there's an error, it should be ENOSYS - try { - tests_run++; - fs.futimesSync(fd, atime, mtime); - expect_ok('futimesSync', fd, undefined, atime, mtime); - } catch (ex) { - expect_errno('futimesSync', fd, ex, 'ENOSYS'); - } - - var err; - err = undefined; - try { - fs.utimesSync('foobarbaz', atime, mtime); - } catch (ex) { - err = ex; - } - expect_errno('utimesSync', 'foobarbaz', err, 'ENOENT'); - tests_run++; - - err = undefined; - try { - fs.futimesSync(-1, atime, mtime); - } catch (ex) { - err = ex; - } - expect_errno('futimesSync', -1, err, 'EBADF'); - tests_run++; - } - - // - // test async code paths - // - fs.utimes(__filename, atime, mtime, function(err) { - expect_ok('utimes', __filename, err, atime, mtime); - - fs.utimes('foobarbaz', atime, mtime, function(err) { - expect_errno('utimes', 'foobarbaz', err, 'ENOENT'); - - // don't close this fd - if (is_windows) { - fd = fs.openSync(__filename, 'r+'); - } else { - fd = fs.openSync(__filename, 'r'); - } - - fs.futimes(fd, atime, mtime, function(err) { - expect_ok('futimes', fd, err, atime, mtime); - - fs.futimes(-1, atime, mtime, function(err) { - expect_errno('futimes', -1, err, 'EBADF'); - syncTests(); - callback(); - }); - tests_run++; - }); - tests_run++; - }); - tests_run++; - }); - tests_run++; -} - -var stats = fs.statSync(__filename); - -runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() { - runTest(new Date(), new Date(), function() { - runTest(123456.789, 123456.789, function() { - runTest(stats.mtime, stats.mtime, function() { - // done - }); - }); - }); -}); - -process.on('exit', function() { - console.log('Tests run / ok:', tests_run, '/', tests_ok); - assert.equal(tests_ok, tests_run); -}); diff --git a/test/simple/test-fs-watch.js b/test/simple/test-fs-watch.js deleted file mode 100644 index 88c33591243f..000000000000 --- a/test/simple/test-fs-watch.js +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); - -var expectFilePath = process.platform === 'win32' || - process.platform === 'linux' || - process.platform === 'darwin'; - -var watchSeenOne = 0; -var watchSeenTwo = 0; -var watchSeenThree = 0; - -var testDir = common.tmpDir; - -var filenameOne = 'watch.txt'; -var filepathOne = path.join(testDir, filenameOne); - -var filenameTwo = 'hasOwnProperty'; -var filepathTwo = filenameTwo; -var filepathTwoAbs = path.join(testDir, filenameTwo); - -var filenameThree = 'newfile.txt'; -var testsubdir = path.join(testDir, 'testsubdir'); -var filepathThree = path.join(testsubdir, filenameThree); - - -process.on('exit', function() { - assert.ok(watchSeenOne > 0); - assert.ok(watchSeenTwo > 0); - assert.ok(watchSeenThree > 0); -}); - -// Clean up stale files (if any) from previous run. -try { fs.unlinkSync(filepathOne); } catch (e) { } -try { fs.unlinkSync(filepathTwoAbs); } catch (e) { } -try { fs.unlinkSync(filepathThree); } catch (e) { } -try { fs.rmdirSync(testsubdir); } catch (e) { } - -fs.writeFileSync(filepathOne, 'hello'); - -assert.doesNotThrow( - function() { - var watcher = fs.watch(filepathOne) - watcher.on('change', function(event, filename) { - assert.equal('change', event); - - // darwin only shows the file path for subdir watching, - // not for individual file watching. - if (expectFilePath && process.platform !== 'darwin') { - assert.equal('watch.txt', filename); - } else { - assert.equal(null, filename); - } - watcher.close(); - ++watchSeenOne; - }); - } -); - -setTimeout(function() { - fs.writeFileSync(filepathOne, 'world'); -}, 1000); - - -process.chdir(testDir); - -fs.writeFileSync(filepathTwoAbs, 'howdy'); - -assert.doesNotThrow( - function() { - var watcher = fs.watch(filepathTwo, function(event, filename) { - assert.equal('change', event); - - // darwin only shows the file path for subdir watching, - // not for individual file watching. - if (expectFilePath && process.platform !== 'darwin') { - assert.equal('hasOwnProperty', filename); - } else { - assert.equal(null, filename); - } - watcher.close(); - ++watchSeenTwo; - }); - } -); - -setTimeout(function() { - fs.writeFileSync(filepathTwoAbs, 'pardner'); -}, 1000); - -try { fs.unlinkSync(filepathThree); } catch (e) {} -try { fs.mkdirSync(testsubdir, 0700); } catch (e) {} - -assert.doesNotThrow( - function() { - var watcher = fs.watch(testsubdir, function(event, filename) { - var renameEv = process.platform === 'sunos' ? 'change' : 'rename'; - assert.equal(renameEv, event); - if (expectFilePath) { - assert.equal('newfile.txt', filename); - } else { - assert.equal(null, filename); - } - watcher.close(); - ++watchSeenThree; - }); - } -); - -setTimeout(function() { - var fd = fs.openSync(filepathThree, 'w'); - fs.closeSync(fd); -}, 1000); - -// https://github.com/joyent/node/issues/2293 - non-persistent watcher should -// not block the event loop -fs.watch(__filename, {persistent: false}, function() { - assert(0); -}); diff --git a/test/simple/test-fs-write-buffer.js b/test/simple/test-fs-write-buffer.js deleted file mode 100644 index 46013bd87b6d..000000000000 --- a/test/simple/test-fs-write-buffer.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'), - Buffer = require('buffer').Buffer, - fs = require('fs'), - filename = path.join(common.tmpDir, 'write.txt'), - expected = new Buffer('hello'), - openCalled = 0, - writeCalled = 0; - - -fs.open(filename, 'w', 0644, function(err, fd) { - openCalled++; - if (err) throw err; - - fs.write(fd, expected, 0, expected.length, null, function(err, written) { - writeCalled++; - if (err) throw err; - - assert.equal(expected.length, written); - fs.closeSync(fd); - - var found = fs.readFileSync(filename, 'utf8'); - assert.deepEqual(expected.toString(), found); - fs.unlinkSync(filename); - }); -}); - -process.on('exit', function() { - assert.equal(1, openCalled); - assert.equal(1, writeCalled); -}); - diff --git a/test/simple/test-fs-write-file-buffer.js b/test/simple/test-fs-write-file-buffer.js deleted file mode 100644 index dfe7cf5f3035..000000000000 --- a/test/simple/test-fs-write-file-buffer.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var join = require('path').join; -var util = require('util'); -var fs = require('fs'); - -var data = [ - '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcH', - 'Bw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/', - '2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e', - 'Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCAAQABADASIAAhEBAxEB/8QA', - 'HwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUF', - 'BAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK', - 'FhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1', - 'dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXG', - 'x8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEB', - 'AQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAEC', - 'AxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRom', - 'JygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOE', - 'hYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU', - '1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDhfBUFl/wk', - 'OmPqKJJZw3aiZFBw4z93jnkkc9u9dj8XLfSI/EBt7DTo7ea2Ox5YXVo5FC7g', - 'Tjq24nJPXNVtO0KATRvNHCIg3zoWJWQHqp+o4pun+EtJ0zxBq8mnLJa2d1L5', - '0NvnKRjJBUE5PAx3NYxxUY0pRtvYHSc5Ka2X9d7H/9k=']; - -data = data.join('\n'); - -var buf = new Buffer(data, 'base64'); -fs.writeFileSync(join(common.tmpDir, 'test.jpg'), buf); - -util.log('Done!'); diff --git a/test/simple/test-fs-write-file-sync.js b/test/simple/test-fs-write-file-sync.js deleted file mode 100644 index 3e723425ac6a..000000000000 --- a/test/simple/test-fs-write-file-sync.js +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); -var isWindows = process.platform === 'win32'; -var openCount = 0; -var mode; -var content; - -// Need to hijack fs.open/close to make sure that things -// get closed once they're opened. -fs._openSync = fs.openSync; -fs.openSync = openSync; -fs._closeSync = fs.closeSync; -fs.closeSync = closeSync; - -// Reset the umask for testing -var mask = process.umask(0000); - -// On Windows chmod is only able to manipulate read-only bit. Test if creating -// the file in read-only mode works. -if (isWindows) { - mode = 0444; -} else { - mode = 0755; -} - -// Test writeFileSync -var file1 = path.join(common.tmpDir, 'testWriteFileSync.txt'); -removeFile(file1); - -fs.writeFileSync(file1, '123', {mode: mode}); - -content = fs.readFileSync(file1, {encoding: 'utf8'}); -assert.equal('123', content); - -assert.equal(mode, fs.statSync(file1).mode & 0777); - -removeFile(file1); - -// Test appendFileSync -var file2 = path.join(common.tmpDir, 'testAppendFileSync.txt'); -removeFile(file2); - -fs.appendFileSync(file2, 'abc', {mode: mode}); - -content = fs.readFileSync(file2, {encoding: 'utf8'}); -assert.equal('abc', content); - -assert.equal(mode, fs.statSync(file2).mode & mode); - -removeFile(file2); - -// Verify that all opened files were closed. -assert.equal(0, openCount); - -// Removes a file if it exists. -function removeFile(file) { - try { - if (isWindows) - fs.chmodSync(file, 0666); - fs.unlinkSync(file); - } catch (err) { - if (err && err.code !== 'ENOENT') - throw err; - } -} - -function openSync() { - openCount++; - return fs._openSync.apply(fs, arguments); -} - -function closeSync() { - openCount--; - return fs._closeSync.apply(fs, arguments); -} diff --git a/test/simple/test-fs-write-file.js b/test/simple/test-fs-write-file.js deleted file mode 100644 index b70ea444cf4b..000000000000 --- a/test/simple/test-fs-write-file.js +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var join = require('path').join; - -var filename = join(common.tmpDir, 'test.txt'); - -common.error('writing to ' + filename); - -var n = 220; -var s = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' + - '广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' + - '南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' + - '前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + - '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' + - '历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' + - '它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n'; - -var ncallbacks = 0; - -fs.writeFile(filename, s, function(e) { - if (e) throw e; - - ncallbacks++; - common.error('file written'); - - fs.readFile(filename, function(e, buffer) { - if (e) throw e; - common.error('file read'); - ncallbacks++; - assert.equal(Buffer.byteLength(s), buffer.length); - }); -}); - -// test that writeFile accepts buffers -var filename2 = join(common.tmpDir, 'test2.txt'); -var buf = new Buffer(s, 'utf8'); -common.error('writing to ' + filename2); - -fs.writeFile(filename2, buf, function(e) { - if (e) throw e; - - ncallbacks++; - common.error('file2 written'); - - fs.readFile(filename2, function(e, buffer) { - if (e) throw e; - common.error('file2 read'); - ncallbacks++; - assert.equal(buf.length, buffer.length); - }); -}); - -// test that writeFile accepts numbers. -var filename3 = join(common.tmpDir, 'test3.txt'); -common.error('writing to ' + filename3); - -var m = 0600; -fs.writeFile(filename3, n, { mode: m }, function(e) { - if (e) throw e; - - // windows permissions aren't unix - if (process.platform !== 'win32') { - var st = fs.statSync(filename3); - assert.equal(st.mode & 0700, m); - } - - ncallbacks++; - common.error('file3 written'); - - fs.readFile(filename3, function(e, buffer) { - if (e) throw e; - common.error('file3 read'); - ncallbacks++; - assert.equal(Buffer.byteLength('' + n), buffer.length); - }); -}); - - -process.on('exit', function() { - common.error('done'); - assert.equal(6, ncallbacks); - - fs.unlinkSync(filename); - fs.unlinkSync(filename2); - fs.unlinkSync(filename3); -}); diff --git a/test/simple/test-fs-write-stream-change-open.js b/test/simple/test-fs-write-stream-change-open.js deleted file mode 100644 index d025e8da35ae..000000000000 --- a/test/simple/test-fs-write-stream-change-open.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var path = require('path'), - fs = require('fs'); - -var file = path.join(common.tmpDir, 'write.txt'); - -var stream = fs.WriteStream(file), - _fs_close = fs.close, - _fs_open = fs.open; - -// change the fs.open with an identical function after the WriteStream -// has pushed it onto its internal action queue, but before it's -// returned. This simulates AOP-style extension of the fs lib. -fs.open = function() { - return _fs_open.apply(fs, arguments); -}; - -fs.close = function(fd) { - assert.ok(fd, 'fs.close must not be called with an undefined fd.'); - fs.close = _fs_close; - fs.open = _fs_open; -} - -stream.write('foo'); -stream.end(); - -process.on('exit', function() { - assert.equal(fs.open, _fs_open); -}); diff --git a/test/simple/test-fs-write-stream-end.js b/test/simple/test-fs-write-stream-end.js deleted file mode 100644 index 7bbc5d68e0ee..000000000000 --- a/test/simple/test-fs-write-stream-end.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); - -(function() { - var file = path.join(common.tmpDir, 'write-end-test0.txt'); - var stream = fs.createWriteStream(file); - stream.end(); - stream.on('close', common.mustCall(function() { })); -})(); - -(function() { - var file = path.join(common.tmpDir, 'write-end-test1.txt'); - var stream = fs.createWriteStream(file); - stream.end('a\n', 'utf8'); - stream.on('close', common.mustCall(function() { - var content = fs.readFileSync(file, 'utf8'); - assert.equal(content, 'a\n'); - })); -})(); diff --git a/test/simple/test-fs-write-stream-err.js b/test/simple/test-fs-write-stream-err.js deleted file mode 100644 index 53ef4e34e8be..000000000000 --- a/test/simple/test-fs-write-stream-err.js +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); - -var stream = fs.createWriteStream(common.tmpDir + '/out', { - highWaterMark: 10 -}); -var err = new Error('BAM'); - -var write = fs.write; -var writeCalls = 0; -fs.write = function() { - switch (writeCalls++) { - case 0: - console.error('first write'); - // first time is ok. - return write.apply(fs, arguments); - case 1: - // then it breaks - console.error('second write'); - var cb = arguments[arguments.length - 1]; - return process.nextTick(function() { - cb(err); - }); - default: - // and should not be called again! - throw new Error('BOOM!'); - } -}; - -fs.close = common.mustCall(function(fd_, cb) { - console.error('fs.close', fd_, stream.fd); - assert.equal(fd_, stream.fd); - process.nextTick(cb); -}); - -stream.on('error', common.mustCall(function(err_) { - console.error('error handler'); - assert.equal(stream.fd, null); - assert.equal(err_, err); -})); - - -stream.write(new Buffer(256), function() { - console.error('first cb'); - stream.write(new Buffer(256), common.mustCall(function(err_) { - console.error('second cb'); - assert.equal(err_, err); - })); -}); diff --git a/test/simple/test-fs-write-stream.js b/test/simple/test-fs-write-stream.js deleted file mode 100644 index da75e26f8fd2..000000000000 --- a/test/simple/test-fs-write-stream.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var path = require('path'), - fs = require('fs'); - -var file = path.join(common.tmpDir, 'write.txt'); - -(function() { - var stream = fs.WriteStream(file), - _fs_close = fs.close; - - fs.close = function(fd) { - assert.ok(fd, 'fs.close must not be called without an undefined fd.'); - fs.close = _fs_close; - } - stream.destroy(); -})(); - -(function() { - var stream = fs.createWriteStream(file); - - stream.on('drain', function() { - assert.fail('\'drain\' event must not be emitted before ' + - 'stream.write() has been called at least once.'); - }); - stream.destroy(); -})(); - diff --git a/test/simple/test-fs-write-sync.js b/test/simple/test-fs-write-sync.js deleted file mode 100644 index c3dbfe3ba635..000000000000 --- a/test/simple/test-fs-write-sync.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); -var fn = path.join(common.tmpDir, 'write.txt'); - - -var foo = 'foo'; -var fd = fs.openSync(fn, 'w'); - -var written = fs.writeSync(fd, ''); -assert.strictEqual(0, written); - -fs.writeSync(fd, foo); - -var bar = 'bár'; -written = fs.writeSync(fd, new Buffer(bar), 0, Buffer.byteLength(bar)); -assert.ok(written > 3); -fs.closeSync(fd); - -assert.equal(fs.readFileSync(fn), 'foobár'); diff --git a/test/simple/test-fs-write.js b/test/simple/test-fs-write.js deleted file mode 100644 index 3d7a357a9a89..000000000000 --- a/test/simple/test-fs-write.js +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var Buffer = require('buffer').Buffer; -var fs = require('fs'); -var fn = path.join(common.tmpDir, 'write.txt'); -var fn2 = path.join(common.tmpDir, 'write2.txt'); -var expected = 'ümlaut.'; -var constants = require('constants'); -var found, found2; - -fs.open(fn, 'w', 0644, function(err, fd) { - if (err) throw err; - console.log('open done'); - fs.write(fd, '', 0, 'utf8', function(err, written) { - assert.equal(0, written); - }); - fs.write(fd, expected, 0, 'utf8', function(err, written) { - console.log('write done'); - if (err) throw err; - assert.equal(Buffer.byteLength(expected), written); - fs.closeSync(fd); - found = fs.readFileSync(fn, 'utf8'); - console.log('expected: "%s"', expected); - console.log('found: "%s"', found); - fs.unlinkSync(fn); - }); -}); - - -fs.open(fn2, constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC, 0644, - function(err, fd) { - if (err) throw err; - console.log('open done'); - fs.write(fd, '', 0, 'utf8', function(err, written) { - assert.equal(0, written); - }); - fs.write(fd, expected, 0, 'utf8', function(err, written) { - console.log('write done'); - if (err) throw err; - assert.equal(Buffer.byteLength(expected), written); - fs.closeSync(fd); - found2 = fs.readFileSync(fn2, 'utf8'); - console.log('expected: "%s"', expected); - console.log('found: "%s"', found2); - fs.unlinkSync(fn2); - }); - }); - - -process.on('exit', function() { - assert.equal(expected, found); - assert.equal(expected, found2); -}); - diff --git a/test/simple/test-global.js b/test/simple/test-global.js deleted file mode 100644 index 4cc9799ba5d7..000000000000 --- a/test/simple/test-global.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -common.globalCheck = false; - -baseFoo = 'foo'; -global.baseBar = 'bar'; - -assert.equal('foo', global.baseFoo, 'x -> global.x in base level not working'); - -assert.equal('bar', baseBar, 'global.x -> x in base level not working'); - -var module = require('../fixtures/global/plain'), - fooBar = module.fooBar; - -assert.equal('foo', fooBar.foo, 'x -> global.x in sub level not working'); - -assert.equal('bar', fooBar.bar, 'global.x -> x in sub level not working'); diff --git a/test/simple/test-http-1.0-keep-alive.js b/test/simple/test-http-1.0-keep-alive.js deleted file mode 100644 index 851409d28bbf..000000000000 --- a/test/simple/test-http-1.0-keep-alive.js +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -// Check that our HTTP server correctly handles HTTP/1.0 keep-alive requests. -check([{ - name: 'keep-alive, no TE header', - requests: [{ - expectClose: true, - data: 'POST / HTTP/1.0\r\n' + - 'Connection: keep-alive\r\n' + - '\r\n' - }, { - expectClose: true, - data: 'POST / HTTP/1.0\r\n' + - 'Connection: keep-alive\r\n' + - '\r\n' - }], - responses: [{ - headers: {'Connection': 'keep-alive'}, - chunks: ['OK'] - }, { - chunks: [] - }] -}, { - name: 'keep-alive, with TE: chunked', - requests: [{ - expectClose: false, - data: 'POST / HTTP/1.0\r\n' + - 'Connection: keep-alive\r\n' + - 'TE: chunked\r\n' + - '\r\n' - }, { - expectClose: true, - data: 'POST / HTTP/1.0\r\n' + - '\r\n' - }], - responses: [{ - headers: {'Connection': 'keep-alive'}, - chunks: ['OK'] - }, { - chunks: [] - }] -}, { - name: 'keep-alive, with Transfer-Encoding: chunked', - requests: [{ - expectClose: false, - data: 'POST / HTTP/1.0\r\n' + - 'Connection: keep-alive\r\n' + - '\r\n' - }, { - expectClose: true, - data: 'POST / HTTP/1.0\r\n' + - '\r\n' - }], - responses: [{ - headers: {'Connection': 'keep-alive', - 'Transfer-Encoding': 'chunked'}, - chunks: ['OK'] - }, { - chunks: [] - }] -}, { - name: 'keep-alive, with Content-Length', - requests: [{ - expectClose: false, - data: 'POST / HTTP/1.0\r\n' + - 'Connection: keep-alive\r\n' + - '\r\n' - }, { - expectClose: true, - data: 'POST / HTTP/1.0\r\n' + - '\r\n' - }], - responses: [{ - headers: {'Connection': 'keep-alive', - 'Content-Length': '2'}, - chunks: ['OK'] - }, { - chunks: [] - }] -}]); - -function check(tests) { - var test = tests[0]; - if (test) http.createServer(server).listen(common.PORT, '127.0.0.1', client); - var current = 0; - - function next() { - check(tests.slice(1)); - } - - function server(req, res) { - if (current + 1 === test.responses.length) this.close(); - var ctx = test.responses[current]; - console.error('< SERVER SENDING RESPONSE', ctx); - res.writeHead(200, ctx.headers); - ctx.chunks.slice(0, -1).forEach(function(chunk) { res.write(chunk) }); - res.end(ctx.chunks[ctx.chunks.length - 1]); - } - - function client() { - if (current === test.requests.length) return next(); - var conn = net.createConnection(common.PORT, '127.0.0.1', connected); - - function connected() { - var ctx = test.requests[current]; - console.error(' > CLIENT SENDING REQUEST', ctx); - conn.setEncoding('utf8'); - conn.write(ctx.data); - - function onclose() { - console.error(' > CLIENT CLOSE'); - if (!ctx.expectClose) throw new Error('unexpected close'); - client(); - } - conn.on('close', onclose); - - function ondata(s) { - console.error(' > CLIENT ONDATA %j %j', s.length, s.toString()); - current++; - if (ctx.expectClose) return; - conn.removeListener('close', onclose); - conn.removeListener('data', ondata);; - connected(); - } - conn.on('data', ondata); - } - } -} diff --git a/test/simple/test-http-1.0.js b/test/simple/test-http-1.0.js deleted file mode 100644 index f5f3aef0a6b0..000000000000 --- a/test/simple/test-http-1.0.js +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); - -var body = 'hello world\n'; - -var common_port = common.PORT; - -function test(handler, request_generator, response_validator) { - var port = common_port++; - var server = http.createServer(handler); - - var client_got_eof = false; - var server_response = { - data: '', - chunks: [] - }; - - function cleanup() { - server.close(); - response_validator(server_response, client_got_eof, true); - } - var timer = setTimeout(cleanup, 1000); - process.on('exit', cleanup); - - server.listen(port); - server.on('listening', function() { - var c = net.createConnection(port); - - c.setEncoding('utf8'); - - c.on('connect', function() { - c.write(request_generator()); - }); - - c.on('data', function(chunk) { - server_response.data += chunk; - server_response.chunks.push(chunk); - }); - - c.on('end', function() { - client_got_eof = true; - c.end(); - server.close(); - clearTimeout(timer); - process.removeListener('exit', cleanup); - response_validator(server_response, client_got_eof, false); - }); - }); -} - -(function() { - function handler(req, res) { - assert.equal('1.0', req.httpVersion); - assert.equal(1, req.httpVersionMajor); - assert.equal(0, req.httpVersionMinor); - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end(body); - } - - function request_generator() { - return 'GET / HTTP/1.0\r\n\r\n'; - } - - function response_validator(server_response, client_got_eof, timed_out) { - var m = server_response.data.split('\r\n\r\n'); - assert.equal(m[1], body); - assert.equal(true, client_got_eof); - assert.equal(false, timed_out); - } - - test(handler, request_generator, response_validator); -})(); - -// -// Don't send HTTP/1.1 status lines to HTTP/1.0 clients. -// -// https://github.com/joyent/node/issues/1234 -// -(function() { - function handler(req, res) { - assert.equal('1.0', req.httpVersion); - assert.equal(1, req.httpVersionMajor); - assert.equal(0, req.httpVersionMinor); - res.sendDate = false; - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('Hello, '); res._send(''); - res.write('world!'); res._send(''); - res.end(); - } - - function request_generator() { - return ('GET / HTTP/1.0\r\n' + - 'User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 ' + - 'OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15\r\n' + - 'Host: 127.0.0.1:1337\r\n' + - 'Accept: */*\r\n' + - '\r\n'); - } - - function response_validator(server_response, client_got_eof, timed_out) { - var expected_response = ('HTTP/1.1 200 OK\r\n' + - 'Content-Type: text/plain\r\n' + - 'Connection: close\r\n' + - '\r\n' + - 'Hello, world!'); - - assert.equal(expected_response, server_response.data); - assert.equal(1, server_response.chunks.length); - assert.equal(true, client_got_eof); - assert.equal(false, timed_out); - } - - test(handler, request_generator, response_validator); -})(); - -(function() { - function handler(req, res) { - assert.equal('1.1', req.httpVersion); - assert.equal(1, req.httpVersionMajor); - assert.equal(1, req.httpVersionMinor); - res.sendDate = false; - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('Hello, '); res._send(''); - res.write('world!'); res._send(''); - res.end(); - } - - function request_generator() { - return ('GET / HTTP/1.1\r\n' + - 'User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 ' + - 'OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15\r\n' + - 'Connection: close\r\n' + - 'Host: 127.0.0.1:1337\r\n' + - 'Accept: */*\r\n' + - '\r\n'); - } - - function response_validator(server_response, client_got_eof, timed_out) { - var expected_response = ('HTTP/1.1 200 OK\r\n' + - 'Content-Type: text/plain\r\n' + - 'Connection: close\r\n' + - 'Transfer-Encoding: chunked\r\n' + - '\r\n' + - '7\r\n' + - 'Hello, \r\n' + - '6\r\n' + - 'world!\r\n' + - '0\r\n' + - '\r\n'); - - assert.equal(expected_response, server_response.data); - assert.equal(1, server_response.chunks.length); - assert.equal(true, client_got_eof); - assert.equal(false, timed_out); - } - - test(handler, request_generator, response_validator); -})(); diff --git a/test/simple/test-http-304.js b/test/simple/test-http-304.js deleted file mode 100644 index fcef21aee745..000000000000 --- a/test/simple/test-http-304.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); -var childProcess = require('child_process'); - -var s = http.createServer(function(request, response) { - response.writeHead(304); - response.end(); -}); - -s.listen(common.PORT, function() { - childProcess.exec('curl -i http://127.0.0.1:' + common.PORT + '/', - function(err, stdout, stderr) { - if (err) throw err; - s.close(); - common.error('curled response correctly'); - common.error(common.inspect(stdout)); - }); -}); - -console.log('Server running at http://127.0.0.1:' + common.PORT + '/'); diff --git a/test/simple/test-http-abort-before-end.js b/test/simple/test-http-abort-before-end.js deleted file mode 100644 index 11e424fbe1a9..000000000000 --- a/test/simple/test-http-abort-before-end.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var http = require('http'); -var assert = require('assert'); - -var server = http.createServer(function(req, res) { - assert(false); // should not be called -}); - -server.listen(common.PORT, function() { - var req = http.request({method: 'GET', host: '127.0.0.1', port: common.PORT}); - - req.on('error', function(ex) { - // https://github.com/joyent/node/issues/1399#issuecomment-2597359 - // abort() should emit an Error, not the net.Socket object - assert(ex instanceof Error); - }); - - req.abort(); - req.end(); - - server.close(); -}); diff --git a/test/simple/test-http-abort-client.js b/test/simple/test-http-abort-client.js deleted file mode 100644 index f15238af1601..000000000000 --- a/test/simple/test-http-abort-client.js +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var http = require('http'); -var assert = require('assert'); - -var server = http.Server(function(req, res) { - console.log('Server accepted request.'); - res.writeHead(200); - res.write('Part of my res.'); - - res.destroy(); -}); - -var responseClose = false; - -server.listen(common.PORT, function() { - var client = http.get({ - port: common.PORT, - headers: { connection: 'keep-alive' } - - }, function(res) { - server.close(); - - console.log('Got res: ' + res.statusCode); - console.dir(res.headers); - - res.on('data', function(chunk) { - console.log('Read ' + chunk.length + ' bytes'); - console.log(' chunk=%j', chunk.toString()); - }); - - res.on('end', function() { - console.log('Response ended.'); - }); - - res.on('aborted', function() { - console.log('Response aborted.'); - }); - - res.socket.on('close', function() { - console.log('socket closed, but not res'); - }) - - // it would be nice if this worked: - res.on('close', function() { - console.log('Response aborted'); - responseClose = true; - }); - }); -}); - - -process.on('exit', function() { - assert.ok(responseClose); -}); diff --git a/test/simple/test-http-abort-stream-end.js b/test/simple/test-http-abort-stream-end.js deleted file mode 100644 index e2ffa4590a61..000000000000 --- a/test/simple/test-http-abort-stream-end.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); - -var maxSize = 1024; -var size = 0; - -var s = http.createServer(function(req, res) { - this.close(); - - res.writeHead(200, {'Content-Type': 'text/plain'}); - for (var i = 0; i < maxSize; i++) { - res.write('x' + i); - } - res.end(); -}); - -var aborted = false; -s.listen(common.PORT, function() { - var req = http.get('http://localhost:' + common.PORT, function(res) { - res.on('data', function(chunk) { - size += chunk.length; - assert(!aborted, 'got data after abort'); - if (size > maxSize) { - aborted = true; - req.abort(); - size = maxSize; - } - }); - }); - - req.end(); -}); - -process.on('exit', function() { - assert(aborted); - assert.equal(size, maxSize); - console.log('ok'); -}); diff --git a/test/simple/test-http-after-connect.js b/test/simple/test-http-after-connect.js deleted file mode 100644 index d6451bb85d05..000000000000 --- a/test/simple/test-http-after-connect.js +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var serverConnected = false; -var serverRequests = 0; -var clientResponses = 0; - -var server = http.createServer(function(req, res) { - common.debug('Server got GET request'); - ++serverRequests; - res.writeHead(200); - res.write(''); - setTimeout(function() { - res.end(req.url); - }, 50); -}); -server.on('connect', function(req, socket, firstBodyChunk) { - common.debug('Server got CONNECT request'); - serverConnected = true; - socket.write('HTTP/1.1 200 Connection established\r\n\r\n'); - socket.on('end', function() { - socket.end(); - }); -}); -server.listen(common.PORT, function() { - var req = http.request({ - port: common.PORT, - method: 'CONNECT', - path: 'google.com:80' - }); - req.on('connect', function(res, socket, firstBodyChunk) { - common.debug('Client got CONNECT response'); - socket.end(); - socket.on('end', function() { - doRequest(0); - doRequest(1); - }); - }); - req.end(); -}); - -function doRequest(i) { - var req = http.get({ - port: common.PORT, - path: '/request' + i - }, function(res) { - common.debug('Client got GET response'); - var data = ''; - res.setEncoding('utf8'); - res.on('data', function(chunk) { - data += chunk; - }); - res.on('end', function() { - assert.equal(data, '/request' + i); - ++clientResponses; - if (clientResponses === 2) { - server.close(); - } - }); - }); -} - -process.on('exit', function() { - assert(serverConnected); - assert.equal(serverRequests, 2); - assert.equal(clientResponses, 2); -}); diff --git a/test/simple/test-http-agent-destroyed-socket.js b/test/simple/test-http-agent-destroyed-socket.js deleted file mode 100644 index 960b3a365e34..000000000000 --- a/test/simple/test-http-agent-destroyed-socket.js +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var server = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end('Hello World\n'); -}).listen(common.PORT); - -var agent = new http.Agent({maxSockets: 1}); - -agent.on('free', function(socket, host, port) { - console.log('freeing socket. destroyed? ', socket.destroyed); -}); - -var requestOptions = { - agent: agent, - host: 'localhost', - port: common.PORT, - path: '/' -}; - -var request1 = http.get(requestOptions, function(response) { - // assert request2 is queued in the agent - var key = 'localhost:' + common.PORT; - assert(agent.requests[key].length === 1); - console.log('got response1'); - request1.socket.on('close', function() { - console.log('request1 socket closed'); - }); - response.pipe(process.stdout); - response.on('end', function() { - console.log('response1 done'); - ///////////////////////////////// - // - // THE IMPORTANT PART - // - // It is possible for the socket to get destroyed and other work - // to run before the 'close' event fires because it happens on - // nextTick. This example is contrived because it destroys the - // socket manually at just the right time, but at Voxer we have - // seen cases where the socket is destroyed by non-user code - // then handed out again by an agent *before* the 'close' event - // is triggered. - request1.socket.destroy(); - - response.once('close', function() { - // assert request2 was removed from the queue - assert(!agent.requests[key]); - console.log("waiting for request2.onSocket's nextTick"); - process.nextTick(function() { - // assert that the same socket was not assigned to request2, - // since it was destroyed. - assert(request1.socket !== request2.socket); - assert(!request2.socket.destroyed, 'the socket is destroyed'); - }); - }); - }); -}); - -var request2 = http.get(requestOptions, function(response) { - assert(!request2.socket.destroyed); - assert(request1.socket.destroyed); - // assert not reusing the same socket, since it was destroyed. - assert(request1.socket !== request2.socket); - console.log('got response2'); - var gotClose = false; - var gotResponseEnd = false; - request2.socket.on('close', function() { - console.log('request2 socket closed'); - gotClose = true; - done(); - }); - response.pipe(process.stdout); - response.on('end', function() { - console.log('response2 done'); - gotResponseEnd = true; - done(); - }); - - function done() { - if (gotResponseEnd && gotClose) - server.close(); - } -}); diff --git a/test/simple/test-http-agent-null.js b/test/simple/test-http-agent-null.js deleted file mode 100644 index 8ae71d50887e..000000000000 --- a/test/simple/test-http-agent-null.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -var request = 0; -var response = 0; -process.on('exit', function() { - assert.equal(request, 1, 'http server "request" callback was not called'); - assert.equal(response, 1, 'http request "response" callback was not called'); -}); - -var server = http.createServer(function(req, res) { - request++; - res.end(); -}).listen(function() { - var options = { - agent: null, - port: this.address().port - }; - http.get(options, function(res) { - response++; - res.resume(); - server.close(); - }); -}); diff --git a/test/simple/test-http-agent.js b/test/simple/test-http-agent.js deleted file mode 100644 index fc66dc49f855..000000000000 --- a/test/simple/test-http-agent.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var server = http.Server(function(req, res) { - res.writeHead(200); - res.end('hello world\n'); -}); - -var responses = 0; -var N = 10; -var M = 10; - -server.listen(common.PORT, function() { - for (var i = 0; i < N; i++) { - setTimeout(function() { - for (var j = 0; j < M; j++) { - http.get({ port: common.PORT, path: '/' }, function(res) { - console.log('%d %d', responses, res.statusCode); - if (++responses == N * M) { - console.error('Received all responses, closing server'); - server.close(); - } - res.resume(); - }).on('error', function(e) { - console.log('Error!', e); - process.exit(1); - }); - } - }, i); - } -}); - - -process.on('exit', function() { - assert.equal(N * M, responses); -}); diff --git a/test/simple/test-http-allow-req-after-204-res.js b/test/simple/test-http-allow-req-after-204-res.js deleted file mode 100644 index 225ff299e9a2..000000000000 --- a/test/simple/test-http-allow-req-after-204-res.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var http = require('http'); -var assert = require('assert'); - -// first 204 or 304 works, subsequent anything fails -var codes = [204, 200]; - -// Methods don't really matter, but we put in something realistic. -var methods = ['DELETE', 'DELETE']; - -var server = http.createServer(function(req, res) { - var code = codes.shift(); - assert.equal('number', typeof code); - assert.ok(code > 0); - console.error('writing %d response', code); - res.writeHead(code, {}); - res.end(); -}); - -function nextRequest() { - var method = methods.shift(); - console.error('writing request: %s', method); - - var request = http.request({ - port: common.PORT, - method: method, - path: '/' - }, function(response) { - response.on('end', function() { - if (methods.length == 0) { - console.error('close server'); - server.close(); - } else { - // throws error: - nextRequest(); - // works just fine: - //process.nextTick(nextRequest); - } - }); - response.resume(); - }); - request.end(); -} - -server.listen(common.PORT, nextRequest); diff --git a/test/simple/test-http-bind-twice.js b/test/simple/test-http-bind-twice.js deleted file mode 100644 index 59d69efaa21d..000000000000 --- a/test/simple/test-http-bind-twice.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var gotError = false; - -process.on('exit', function() { - assert(gotError); -}); - -function dontCall() { - assert(false); -} - -var server1 = http.createServer(dontCall); -server1.listen(common.PORT, '127.0.0.1', function() {}); - -var server2 = http.createServer(dontCall); -server2.listen(common.PORT, '127.0.0.1', dontCall); - -server2.on('error', function(e) { - assert.equal(e.code, 'EADDRINUSE'); - server1.close(); - gotError = true; -}); - diff --git a/test/simple/test-http-blank-header.js b/test/simple/test-http-blank-header.js deleted file mode 100644 index bd9be86102c1..000000000000 --- a/test/simple/test-http-blank-header.js +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -var gotReq = false; - -var server = http.createServer(function(req, res) { - common.error('got req'); - gotReq = true; - assert.equal('GET', req.method); - assert.equal('/blah', req.url); - assert.deepEqual({ - host: 'mapdevel.trolologames.ru:443', - origin: 'http://mapdevel.trolologames.ru', - cookie: '' - }, req.headers); -}); - - -server.listen(common.PORT, function() { - var c = net.createConnection(common.PORT); - - c.on('connect', function() { - common.error('client wrote message'); - c.write('GET /blah HTTP/1.1\r\n' + - 'Host: mapdevel.trolologames.ru:443\r\n' + - 'Cookie:\r\n' + - 'Origin: http://mapdevel.trolologames.ru\r\n' + - '\r\n\r\nhello world' - ); - }); - - c.on('end', function() { - c.end(); - }); - - c.on('close', function() { - common.error('client close'); - server.close(); - }); -}); - - -process.on('exit', function() { - assert.ok(gotReq); -}); diff --git a/test/simple/test-http-buffer-sanity.js b/test/simple/test-http-buffer-sanity.js deleted file mode 100644 index 2e650d9b2fa5..000000000000 --- a/test/simple/test-http-buffer-sanity.js +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var util = require('util'); - -var bufferSize = 5 * 1024 * 1024; -var measuredSize = 0; - -var buffer = Buffer(bufferSize); -for (var i = 0; i < buffer.length; i++) { - buffer[i] = i % 256; -} - - -var web = http.Server(function(req, res) { - web.close(); - - console.log(req.headers); - - var i = 0; - - req.on('data', function(d) { - process.stdout.write(','); - measuredSize += d.length; - for (var j = 0; j < d.length; j++) { - assert.equal(buffer[i], d[j]); - i++; - } - }); - - - req.on('end', function() { - res.writeHead(200); - res.write('thanks'); - res.end(); - console.log('response with \'thanks\''); - }); - - req.connection.on('error', function(e) { - console.log('http server-side error: ' + e.message); - process.exit(1); - }); -}); - -var gotThanks = false; - -web.listen(common.PORT, function() { - console.log('Making request'); - - var req = http.request({ - port: common.PORT, - method: 'GET', - path: '/', - headers: { 'content-length': buffer.length } - }, function(res) { - console.log('Got response'); - res.setEncoding('utf8'); - res.on('data', function(string) { - assert.equal('thanks', string); - gotThanks = true; - }); - }); - req.end(buffer); -}); - - -process.on('exit', function() { - assert.equal(bufferSize, measuredSize); - assert.ok(gotThanks); -}); diff --git a/test/simple/test-http-byteswritten.js b/test/simple/test-http-byteswritten.js deleted file mode 100644 index ff842414cfcf..000000000000 --- a/test/simple/test-http-byteswritten.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var http = require('http'); - -var body = 'hello world\n'; - -var httpServer = http.createServer(function(req, res) { - res.on('finish', function() { - assert(typeof(req.connection.bytesWritten) === 'number'); - assert(req.connection.bytesWritten > 0); - httpServer.close(); - console.log('ok'); - }); - res.writeHead(200, { 'Content-Type': 'text/plain' }); - - // Write 1.5mb to cause some requests to buffer - // Also, mix up the encodings a bit. - var chunk = new Array(1024 + 1).join('7'); - var bchunk = new Buffer(chunk); - for (var i = 0; i < 1024; i++) { - res.write(chunk); - res.write(bchunk); - res.write(chunk, 'hex'); - } - // Get .bytesWritten while buffer is not empty - assert(res.connection.bytesWritten > 0); - - res.end(body); -}); - -httpServer.listen(common.PORT, function() { - http.get({ port: common.PORT }); -}); - diff --git a/test/simple/test-http-chunked-304.js b/test/simple/test-http-chunked-304.js deleted file mode 100644 index 24c5fa151097..000000000000 --- a/test/simple/test-http-chunked-304.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -// RFC 2616, section 10.2.5: -// -// The 204 response MUST NOT contain a message-body, and thus is always -// terminated by the first empty line after the header fields. -// -// Likewise for 304 responses. Verify that no empty chunk is sent when -// the user explicitly sets a Transfer-Encoding header. - -test(204, function() { - test(304); -}); - -function test(statusCode, next) { - var server = http.createServer(function(req, res) { - res.writeHead(statusCode, { 'Transfer-Encoding': 'chunked' }); - res.end(); - server.close(); - }); - - server.listen(common.PORT, function() { - var conn = net.createConnection(common.PORT, function() { - conn.write('GET / HTTP/1.1\r\n\r\n'); - - var resp = ''; - conn.setEncoding('utf8'); - conn.on('data', function(data) { - resp += data; - }); - - conn.on('end', common.mustCall(function() { - assert.equal(/^Connection: close\r\n$/m.test(resp), true); - assert.equal(/^0\r\n$/m.test(resp), false); - if (next) process.nextTick(next); - })); - }); - }); -} diff --git a/test/simple/test-http-chunked.js b/test/simple/test-http-chunked.js deleted file mode 100644 index c5def3de78db..000000000000 --- a/test/simple/test-http-chunked.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var UTF8_STRING = '南越国是前203年至前111年存在于岭南地区的一个国家,' + - '国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、' + - '贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,' + - '由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,' + - '南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + - '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。' + - '南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,' + - '采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,' + - '有效的改善了岭南地区落后的政治、经济现状。'; - -var server = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Type': 'text/plain; charset=utf8'}); - res.end(UTF8_STRING, 'utf8'); -}); -server.listen(common.PORT, function() { - var data = ''; - var get = http.get({ - path: '/', - host: 'localhost', - port: common.PORT - }, function(x) { - x.setEncoding('utf8'); - x.on('data', function(c) {data += c}); - x.on('error', function(e) { - throw e; - }); - x.on('end', function() { - assert.equal('string', typeof data); - console.log('here is the response:'); - assert.equal(UTF8_STRING, data); - console.log(data); - server.close(); - }); - }); - get.on('error', function(e) {throw e}); - get.end(); - -}); diff --git a/test/simple/test-http-client-abort.js b/test/simple/test-http-client-abort.js deleted file mode 100644 index c9b5eb071ff3..000000000000 --- a/test/simple/test-http-client-abort.js +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var clientAborts = 0; - -var server = http.Server(function(req, res) { - console.log('Got connection'); - res.writeHead(200); - res.write('Working on it...'); - - // I would expect an error event from req or res that the client aborted - // before completing the HTTP request / response cycle, or maybe a new - // event like "aborted" or something. - req.on('aborted', function() { - clientAborts++; - console.log('Got abort ' + clientAborts); - if (clientAborts === N) { - console.log('All aborts detected, you win.'); - server.close(); - } - }); - - // since there is already clientError, maybe that would be appropriate, - // since "error" is magical - req.on('clientError', function() { - console.log('Got clientError'); - }); -}); - -var responses = 0; -var N = http.Agent.defaultMaxSockets - 1; -var requests = []; - -server.listen(common.PORT, function() { - console.log('Server listening.'); - - for (var i = 0; i < N; i++) { - console.log('Making client ' + i); - var options = { port: common.PORT, path: '/?id=' + i }; - var req = http.get(options, function(res) { - console.log('Client response code ' + res.statusCode); - - if (++responses == N) { - console.log('All clients connected, destroying.'); - requests.forEach(function(outReq) { - console.log('abort'); - outReq.abort(); - }); - } - }); - - requests.push(req); - } -}); - -process.on('exit', function() { - assert.equal(N, clientAborts); -}); diff --git a/test/simple/test-http-client-abort2.js b/test/simple/test-http-client-abort2.js deleted file mode 100644 index 17efb7e086f8..000000000000 --- a/test/simple/test-http-client-abort2.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var server = http.createServer(function(req, res) { - res.end('Hello'); -}); - -server.listen(common.PORT, function() { - var req = http.get({port: common.PORT}, function(res) { - res.on('data', function(data) { - req.abort(); - server.close(); - }); - }); -}); - diff --git a/test/simple/test-http-client-agent.js b/test/simple/test-http-client-agent.js deleted file mode 100644 index aedf64ba7060..000000000000 --- a/test/simple/test-http-client-agent.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var name = 'localhost:' + common.PORT; -var max = 3; -var count = 0; - -var server = http.Server(function(req, res) { - if (req.url === '/0') { - setTimeout(function() { - res.writeHead(200); - res.end('Hello, World!'); - }, 100); - } else { - res.writeHead(200); - res.end('Hello, World!'); - } -}); -server.listen(common.PORT, function() { - for (var i = 0; i < max; ++i) { - request(i); - } -}); - -function request(i) { - var req = http.get({ - port: common.PORT, - path: '/' + i - }, function(res) { - var socket = req.socket; - socket.on('close', function() { - ++count; - if (count < max) { - assert.equal(http.globalAgent.sockets[name].length, max - count); - assert.equal(http.globalAgent.sockets[name].indexOf(socket), -1); - } else { - assert(!http.globalAgent.sockets.hasOwnProperty(name)); - assert(!http.globalAgent.requests.hasOwnProperty(name)); - server.close(); - } - }); - res.resume(); - }); -} - -process.on('exit', function() { - assert.equal(count, max); -}); diff --git a/test/simple/test-http-client-get-url.js b/test/simple/test-http-client-get-url.js deleted file mode 100644 index 451f5eeaa9b7..000000000000 --- a/test/simple/test-http-client-get-url.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var seen_req = false; - -var server = http.createServer(function(req, res) { - assert.equal('GET', req.method); - assert.equal('/foo?bar', req.url); - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('hello\n'); - res.end(); - server.close(); - seen_req = true; -}); - -server.listen(common.PORT, function() { - http.get('http://127.0.0.1:' + common.PORT + '/foo?bar'); -}); - -process.on('exit', function() { - assert(seen_req); -}); diff --git a/test/simple/test-http-client-parse-error.js b/test/simple/test-http-client-parse-error.js deleted file mode 100644 index 9896ca2251fb..000000000000 --- a/test/simple/test-http-client-parse-error.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); -var net = require('net'); - -var connects = 0; -var parseErrors = 0; - -// Create a TCP server -net.createServer(function(c) { - console.log('connection'); - if (++connects === 1) { - c.end('HTTP/1.1 302 Object Moved\r\nContent-Length: 0\r\n\r\nhi world'); - } else { - c.end('bad http - should trigger parse error\r\n'); - this.close(); - } -}).listen(common.PORT, '127.0.0.1', function() { - for (var i = 0; i < 2; i++) { - http.request({ - host: '127.0.0.1', - port: common.PORT, - method: 'GET', - path: '/' - }).on('error', function(e) { - console.log('got error from client'); - assert.ok(e.message.indexOf('Parse Error') >= 0); - assert.equal(e.code, 'HPE_INVALID_CONSTANT'); - parseErrors++; - }).end(); - } -}); - -process.on('exit', function() { - assert.equal(connects, 2); - assert.equal(parseErrors, 2); -}); diff --git a/test/simple/test-http-client-pipe-end.js b/test/simple/test-http-client-pipe-end.js deleted file mode 100644 index 51edebbe1a78..000000000000 --- a/test/simple/test-http-client-pipe-end.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// see https://github.com/joyent/node/issues/3257 - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var server = http.createServer(function(req, res) { - req.resume(); - req.once('end', function() { - res.writeHead(200); - res.end(); - server.close(); - }); -}); - -server.listen(common.PIPE, function() { - var req = http.request({ - socketPath: common.PIPE, - headers: {'Content-Length':'1'}, - method: 'POST', - path: '/' - }); - - req.write('.'); - - sched(function() { req.end() }, 5); -}); - -// schedule a callback after `ticks` event loop ticks -function sched(cb, ticks) { - function fn() { - if (--ticks) - setImmediate(fn); - else - cb(); - } - setImmediate(fn); -} diff --git a/test/simple/test-http-client-race-2.js b/test/simple/test-http-client-race-2.js deleted file mode 100644 index 6b7c508c3d9c..000000000000 --- a/test/simple/test-http-client-race-2.js +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); - -// -// Slight variation on test-http-client-race to test for another race -// condition involving the parsers FreeList used internally by http.Client. -// - -var body1_s = '1111111111111111'; -var body2_s = '22222'; -var body3_s = '3333333333333333333'; - -var server = http.createServer(function(req, res) { - var pathname = url.parse(req.url).pathname; - - var body; - switch (pathname) { - case '/1': body = body1_s; break; - case '/2': body = body2_s; break; - default: body = body3_s; - } - - res.writeHead(200, - {'Content-Type': 'text/plain', 'Content-Length': body.length}); - res.end(body); -}); -server.listen(common.PORT); - -var body1 = ''; -var body2 = ''; -var body3 = ''; - -server.on('listening', function() { - var client = http.createClient(common.PORT); - - // - // Client #1 is assigned Parser #1 - // - var req1 = client.request('/1'); - req1.end(); - req1.on('response', function(res1) { - res1.setEncoding('utf8'); - - res1.on('data', function(chunk) { - body1 += chunk; - }); - - res1.on('end', function() { - // - // Delay execution a little to allow the 'close' event to be processed - // (required to trigger this bug!) - // - setTimeout(function() { - // - // The bug would introduce itself here: Client #2 would be allocated the - // parser that previously belonged to Client #1. But we're not finished - // with Client #1 yet! - // - var client2 = http.createClient(common.PORT); - - // - // At this point, the bug would manifest itself and crash because the - // internal state of the parser was no longer valid for use by Client #1 - // - var req2 = client.request('/2'); - req2.end(); - req2.on('response', function(res2) { - res2.setEncoding('utf8'); - res2.on('data', function(chunk) { body2 += chunk; }); - res2.on('end', function() { - - // - // Just to be really sure we've covered all our bases, execute a - // request using client2. - // - var req3 = client2.request('/3'); - req3.end(); - req3.on('response', function(res3) { - res3.setEncoding('utf8'); - res3.on('data', function(chunk) { body3 += chunk }); - res3.on('end', function() { server.close(); }); - }); - }); - }); - }, 500); - }); - }); -}); - -process.on('exit', function() { - assert.equal(body1_s, body1); - assert.equal(body2_s, body2); - assert.equal(body3_s, body3); -}); - diff --git a/test/simple/test-http-client-race.js b/test/simple/test-http-client-race.js deleted file mode 100644 index 0f50c8e84104..000000000000 --- a/test/simple/test-http-client-race.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); - -var body1_s = '1111111111111111'; -var body2_s = '22222'; - -var server = http.createServer(function(req, res) { - var body = url.parse(req.url).pathname === '/1' ? body1_s : body2_s; - res.writeHead(200, - {'Content-Type': 'text/plain', 'Content-Length': body.length}); - res.end(body); -}); -server.listen(common.PORT); - -var body1 = ''; -var body2 = ''; - -server.on('listening', function() { - var req1 = http.request({ port: common.PORT, path: '/1' }); - req1.end(); - req1.on('response', function(res1) { - res1.setEncoding('utf8'); - - res1.on('data', function(chunk) { - body1 += chunk; - }); - - res1.on('end', function() { - var req2 = http.request({ port: common.PORT, path: '/2' }); - req2.end(); - req2.on('response', function(res2) { - res2.setEncoding('utf8'); - res2.on('data', function(chunk) { body2 += chunk; }); - res2.on('end', function() { server.close(); }); - }); - }); - }); -}); - -process.on('exit', function() { - assert.equal(body1_s, body1); - assert.equal(body2_s, body2); -}); diff --git a/test/simple/test-http-client-readable.js b/test/simple/test-http-client-readable.js deleted file mode 100644 index 0b26afbe96d7..000000000000 --- a/test/simple/test-http-client-readable.js +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var util = require('util'); - -var Duplex = require('stream').Duplex; - -function FakeAgent() { - http.Agent.call(this); - - this.createConnection = FakeAgent.prototype.createConnection; -} -util.inherits(FakeAgent, http.Agent); - -FakeAgent.prototype.createConnection = function createConnection() { - var s = new Duplex(); - - function ondata(str) { - var buf = new Buffer(str); - s.ondata(buf, 0, buf.length); - } - - Object.defineProperty(s, 'ondata', { - configurable: true, - set: function(value) { - Object.defineProperty(s, 'ondata', { value: value }); - - process.nextTick(function() { - ondata('HTTP/1.1 200 Ok\r\nTransfer-Encoding: chunked\r\n\r\n'); - - s.readable = false; - ondata('b\r\nhello world\r\n'); - ondata('b\r\n ohai world\r\n'); - ondata('0\r\n\r\n'); - }); - } - }); - - // Blackhole - s._write = function write(data, enc, cb) { - cb(); - }; - - s.destroy = s.destroySoon = function destroy() { - this.writable = false; - }; - - return s; -}; - -var received = ''; -var ended = 0; -var response; - -var req = http.request({ - agent: new FakeAgent() -}, function(res) { - response = res; - - res.on('readable', function() { - var chunk = res.read(); - if (chunk !== null) - received += chunk; - }); - - res.on('end', function() { - ended++; - }); -}); -req.end(); - -process.on('exit', function() { - assert.equal(received, 'hello world ohai world'); - assert.equal(ended, 1); -}); diff --git a/test/simple/test-http-client-response-domain.js b/test/simple/test-http-client-response-domain.js deleted file mode 100644 index e5a39913f410..000000000000 --- a/test/simple/test-http-client-response-domain.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'), - assert = require('assert'), - http = require('http'), - domain = require('domain'); - -var gotDomainError = false; -var d; - -process.on('exit', function() { - assert(gotDomainError); -}); - -// first fire up a simple HTTP server -var server = http.createServer(function(req, res) { - res.writeHead(200); - res.end(); - server.close(); -}); -server.listen(common.PIPE, function() { - // create a domain - d = domain.create(); - d.run(test); -}); - -function test() { - - d.on('error', function(err) { - gotDomainError = true; - assert.equal('should be caught by domain', err.message); - }); - - var req = http.get({ - socketPath: common.PIPE, - headers: {'Content-Length':'1'}, - method: 'POST', - path: '/' - }); - req.on('response', function(res) { - res.on('end', function() { - res.emit('error', new Error('should be caught by domain')); - }); - res.resume(); - }); - req.end(); -} diff --git a/test/simple/test-http-client-timeout-agent.js b/test/simple/test-http-client-timeout-agent.js deleted file mode 100644 index 79d0a2424243..000000000000 --- a/test/simple/test-http-client-timeout-agent.js +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var request_number = 0; -var requests_sent = 0; -var requests_done = 0; -var options = { - method: 'GET', - port: common.PORT, - host: '127.0.0.1', -}; - -//http.globalAgent.maxSockets = 15; - -var server = http.createServer(function(req, res) { - var m = /\/(.*)/.exec(req.url), - reqid = parseInt(m[1], 10); - if ( reqid % 2 ) { - // do not reply the request - } else { - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write(reqid.toString()); - res.end(); - } - request_number+=1; -}); - -server.listen(options.port, options.host, function() { - var req; - - for (requests_sent = 0; requests_sent < 30; requests_sent+=1) { - options.path = '/' + requests_sent; - req = http.request(options); - req.id = requests_sent; - req.on('response', function(res) { - res.on('data', function(data) { - console.log('res#'+this.req.id+' data:'+data); - }); - res.on('end', function(data) { - console.log('res#'+this.req.id+' end'); - requests_done += 1; - }); - }); - req.on('close', function() { - console.log('req#'+this.id+' close'); - }); - req.on('error', function() { - console.log('req#'+this.id+' error'); - this.destroy(); - }); - req.setTimeout(50, function () { - var req = this; - console.log('req#'+this.id + ' timeout'); - req.abort(); - requests_done += 1; - }); - req.end(); - } - - setTimeout(function maybeDone() { - if (requests_done >= requests_sent) { - setTimeout(function() { - server.close(); - }, 100); - } else { - setTimeout(maybeDone, 100); - } - }, 100); -}); - -process.on('exit', function() { - console.error('done=%j sent=%j', requests_done, requests_sent); - assert.ok(requests_done == requests_sent, 'timeout on http request called too much'); -}); diff --git a/test/simple/test-http-client-timeout-event.js b/test/simple/test-http-client-timeout-event.js deleted file mode 100644 index 9e0e8bd8e5ef..000000000000 --- a/test/simple/test-http-client-timeout-event.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var options = { - method: 'GET', - port: common.PORT, - host: '127.0.0.1', - path: '/' -}; - -var server = http.createServer(function(req, res) { - // this space intentionally left blank -}); - -server.listen(options.port, options.host, function() { - var req = http.request(options, function(res) { - // this space intentionally left blank - }); - req.on('error', function() { - // this space is intentially left blank - }); - req.on('close', function() { - server.close(); - }); - - var timeout_events = 0; - req.setTimeout(1); - req.on('timeout', function () { - timeout_events += 1; - }); - setTimeout(function () { - req.destroy(); - assert.equal(timeout_events, 1); - }, 10); - req.end(); -}); diff --git a/test/simple/test-http-client-timeout-with-data.js b/test/simple/test-http-client-timeout-with-data.js deleted file mode 100644 index 4e1aae6ff86a..000000000000 --- a/test/simple/test-http-client-timeout-with-data.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var ntimeouts = 0; -var nchunks = 0; - -process.on('exit', function() { - assert.equal(ntimeouts, 1); - assert.equal(nchunks, 2); -}); - -var options = { - method: 'GET', - port: common.PORT, - host: '127.0.0.1', - path: '/' -}; - -var server = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Length':'2'}); - res.write('*'); - setTimeout(function() { res.end('*') }, 100); -}); - -server.listen(options.port, options.host, function() { - var req = http.request(options, onresponse); - req.end(); - - function onresponse(res) { - req.setTimeout(50, function() { - assert.equal(nchunks, 1); // should have received the first chunk by now - ntimeouts++; - }); - - res.on('data', function(data) { - assert.equal('' + data, '*'); - nchunks++; - }); - - res.on('end', function() { - assert.equal(nchunks, 2); - server.close(); - }); - } -}); diff --git a/test/simple/test-http-client-timeout.js b/test/simple/test-http-client-timeout.js deleted file mode 100644 index 98eb5539ebf2..000000000000 --- a/test/simple/test-http-client-timeout.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var options = { - method: 'GET', - port: common.PORT, - host: '127.0.0.1', - path: '/' -}; - -var server = http.createServer(function(req, res) { - // this space intentionally left blank -}); - -server.listen(options.port, options.host, function() { - var req = http.request(options, function(res) { - // this space intentionally left blank - }); - req.on('close', function() { - server.close(); - }); - function destroy() { - req.destroy(); - } - req.setTimeout(1, destroy); - req.on('error', destroy); - req.end(); -}); diff --git a/test/simple/test-http-client-upload-buf.js b/test/simple/test-http-client-upload-buf.js deleted file mode 100644 index d607ea88bb69..000000000000 --- a/test/simple/test-http-client-upload-buf.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var N = 1024; -var bytesReceived = 0; -var server_req_complete = false; -var client_res_complete = false; - -var server = http.createServer(function(req, res) { - assert.equal('POST', req.method); - - req.on('data', function(chunk) { - bytesReceived += chunk.length; - }); - - req.on('end', function() { - server_req_complete = true; - console.log('request complete from server'); - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('hello\n'); - res.end(); - }); -}); -server.listen(common.PORT); - -server.on('listening', function() { - var req = http.request({ - port: common.PORT, - method: 'POST', - path: '/' - }, function(res) { - res.setEncoding('utf8'); - res.on('data', function(chunk) { - console.log(chunk); - }); - res.on('end', function() { - client_res_complete = true; - server.close(); - }); - }); - - req.write(new Buffer(N)); - req.end(); - - common.error('client finished sending request'); -}); - -process.on('exit', function() { - assert.equal(N, bytesReceived); - assert.equal(true, server_req_complete); - assert.equal(true, client_res_complete); -}); diff --git a/test/simple/test-http-client-upload.js b/test/simple/test-http-client-upload.js deleted file mode 100644 index 912ca96084c6..000000000000 --- a/test/simple/test-http-client-upload.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var sent_body = ''; -var server_req_complete = false; -var client_res_complete = false; - -var server = http.createServer(function(req, res) { - assert.equal('POST', req.method); - req.setEncoding('utf8'); - - req.on('data', function(chunk) { - console.log('server got: ' + JSON.stringify(chunk)); - sent_body += chunk; - }); - - req.on('end', function() { - server_req_complete = true; - console.log('request complete from server'); - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('hello\n'); - res.end(); - }); -}); -server.listen(common.PORT); - -server.on('listening', function() { - var req = http.request({ - port: common.PORT, - method: 'POST', - path: '/' - }, function(res) { - res.setEncoding('utf8'); - res.on('data', function(chunk) { - console.log(chunk); - }); - res.on('end', function() { - client_res_complete = true; - server.close(); - }); - }); - - req.write('1\n'); - req.write('2\n'); - req.write('3\n'); - req.end(); - - common.error('client finished sending request'); -}); - -process.on('exit', function() { - assert.equal('1\n2\n3\n', sent_body); - assert.equal(true, server_req_complete); - assert.equal(true, client_res_complete); -}); diff --git a/test/simple/test-http-conn-reset.js b/test/simple/test-http-conn-reset.js deleted file mode 100644 index 9c293721cf96..000000000000 --- a/test/simple/test-http-conn-reset.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -var caughtError = false; - -var options = { - host: '127.0.0.1', - port: common.PORT -}; - -// start a tcp server that closes incoming connections immediately -var server = net.createServer(function(client) { - client.destroy(); - server.close(); -}); -server.listen(options.port, options.host, onListen); - -// do a GET request, expect it to fail -function onListen() { - var req = http.request(options, function(res) { - assert.ok(false, 'this should never run'); - }); - req.on('error', function(err) { - assert.equal(err.code, 'ECONNRESET'); - caughtError = true; - }); - req.end(); -} - -process.on('exit', function() { - assert.equal(caughtError, true); -}); - diff --git a/test/simple/test-http-connect.js b/test/simple/test-http-connect.js deleted file mode 100644 index 3643cec18e98..000000000000 --- a/test/simple/test-http-connect.js +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var serverGotConnect = false; -var clientGotConnect = false; - -var server = http.createServer(function(req, res) { - assert(false); -}); -server.on('connect', function(req, socket, firstBodyChunk) { - assert.equal(req.method, 'CONNECT'); - assert.equal(req.url, 'google.com:443'); - common.debug('Server got CONNECT request'); - serverGotConnect = true; - - socket.write('HTTP/1.1 200 Connection established\r\n\r\n'); - - var data = firstBodyChunk.toString(); - socket.on('data', function(buf) { - data += buf.toString(); - }); - socket.on('end', function() { - socket.end(data); - }); -}); -server.listen(common.PORT, function() { - var req = http.request({ - port: common.PORT, - method: 'CONNECT', - path: 'google.com:443' - }, function(res) { - assert(false); - }); - - var clientRequestClosed = false; - req.on('close', function() { - clientRequestClosed = true; - }); - - req.on('connect', function(res, socket, firstBodyChunk) { - common.debug('Client got CONNECT request'); - clientGotConnect = true; - - // Make sure this request got removed from the pool. - var name = 'localhost:' + common.PORT; - assert(!http.globalAgent.sockets.hasOwnProperty(name)); - assert(!http.globalAgent.requests.hasOwnProperty(name)); - - // Make sure this socket has detached. - assert(!socket.ondata); - assert(!socket.onend); - assert.equal(socket.listeners('connect').length, 0); - assert.equal(socket.listeners('data').length, 0); - - // the stream.Duplex onend listener - // allow 0 here, so that i can run the same test on streams1 impl - assert(socket.listeners('end').length <= 1); - - assert.equal(socket.listeners('free').length, 0); - assert.equal(socket.listeners('close').length, 0); - assert.equal(socket.listeners('error').length, 0); - assert.equal(socket.listeners('agentRemove').length, 0); - - var data = firstBodyChunk.toString(); - socket.on('data', function(buf) { - data += buf.toString(); - }); - socket.on('end', function() { - assert.equal(data, 'HeadBody'); - assert(clientRequestClosed); - server.close(); - }); - socket.write('Body'); - socket.end(); - }); - - // It is legal for the client to send some data intended for the server - // before the "200 Connection established" (or any other success or - // error code) is received. - req.write('Head'); - req.end(); -}); - -process.on('exit', function() { - assert.ok(serverGotConnect); - assert.ok(clientGotConnect); -}); diff --git a/test/simple/test-http-contentLength0.js b/test/simple/test-http-contentLength0.js deleted file mode 100644 index c7f7b6b669ea..000000000000 --- a/test/simple/test-http-contentLength0.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var http = require('http'); - -// Simple test of Node's HTTP Client choking on a response -// with a 'Content-Length: 0 ' response header. -// I.E. a space character after the 'Content-Length' throws an `error` event. - - -var s = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Length': '0 '}); - res.end(); -}); -s.listen(common.PORT, function() { - - var request = http.request({ port: common.PORT }, function(response) { - console.log('STATUS: ' + response.statusCode); - s.close(); - response.resume(); - }); - - request.end(); -}); diff --git a/test/simple/test-http-createConnection.js b/test/simple/test-http-createConnection.js deleted file mode 100644 index bc29d9aee486..000000000000 --- a/test/simple/test-http-createConnection.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -var create = 0; -var response = 0; -process.on('exit', function() { - assert.equal(1, create, 'createConnection() http option was not called'); - assert.equal(1, response, 'http server "request" callback was not called'); -}); - -var server = http.createServer(function(req, res) { - res.end(); - response++; -}).listen(common.PORT, '127.0.0.1', function() { - http.get({ createConnection: createConnection }, function (res) { - res.resume(); - server.close(); - }); -}); - -function createConnection() { - create++; - return net.createConnection(common.PORT, '127.0.0.1'); -} diff --git a/test/simple/test-http-curl-chunk-problem.js b/test/simple/test-http-curl-chunk-problem.js deleted file mode 100644 index 5b1cb0beb275..000000000000 --- a/test/simple/test-http-curl-chunk-problem.js +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -// http://groups.google.com/group/nodejs/browse_thread/thread/f66cd3c960406919 -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var cp = require('child_process'); -var fs = require('fs'); - -var filename = require('path').join(common.tmpDir, 'big'); - -var count = 0; -function maybeMakeRequest() { - if (++count < 2) return; - console.log('making curl request'); - var cmd = 'curl http://127.0.0.1:' + common.PORT + '/ | openssl sha1'; - cp.exec(cmd, function(err, stdout, stderr) { - if (err) throw err; - var hex = stdout.match(/([A-Fa-f0-9]{40})/)[0]; - assert.equal('8c206a1a87599f532ce68675536f0b1546900d7a', hex); - console.log('got the correct response'); - fs.unlink(filename); - server.close(); - }); -} - - -var ddcmd = common.ddCommand(filename, 10240); -console.log('dd command: ', ddcmd); - -cp.exec(ddcmd, function(err, stdout, stderr) { - if (err) throw err; - maybeMakeRequest(); -}); - - -var server = http.createServer(function(req, res) { - res.writeHead(200); - - // Create the subprocess - var cat = cp.spawn('cat', [filename]); - - // Stream the data through to the response as binary chunks - cat.stdout.on('data', function(data) { - res.write(data); - }); - - // End the response on exit (and log errors) - cat.on('exit', function(code) { - if (code !== 0) { - console.error('subprocess exited with code ' + code); - exit(1); - } - res.end(); - }); - -}); - -server.listen(common.PORT, maybeMakeRequest); - -console.log('Server running at http://localhost:8080'); diff --git a/test/simple/test-http-date-header.js b/test/simple/test-http-date-header.js deleted file mode 100644 index b11507c0174f..000000000000 --- a/test/simple/test-http-date-header.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var testResBody = 'other stuff!\n'; - -var server = http.createServer(function(req, res) { - assert.ok(! ('date' in req.headers), - 'Request headers contained a Date.'); - res.writeHead(200, { - 'Content-Type': 'text/plain' - }); - res.end(testResBody); -}); -server.listen(common.PORT); - - -server.addListener('listening', function() { - var options = { - port: common.PORT, - path: '/', - method: 'GET' - }; - var req = http.request(options, function(res) { - assert.ok('date' in res.headers, - 'Response headers didn\'t contain a Date.'); - res.addListener('end', function() { - server.close(); - process.exit(); - }); - res.resume(); - }); - req.end(); -}); diff --git a/test/simple/test-http-default-encoding.js b/test/simple/test-http-default-encoding.js deleted file mode 100644 index b06f7c83a204..000000000000 --- a/test/simple/test-http-default-encoding.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var expected = 'This is a unicode text: سلام'; -var result = ''; - -var server = http.Server(function(req, res) { - req.setEncoding('utf8'); - req.on('data', function(chunk) { - result += chunk; - }).on('end', function() { - clearTimeout(timeout); - server.close(); - }); - - var timeout = setTimeout(function() { - process.exit(1); - }, 100); - - res.writeHead(200); - res.end('hello world\n'); -}); - -server.listen(common.PORT, function() { - http.request({ - port: common.PORT, - path: '/', - method: 'POST' - }, function(res) { - console.log(res.statusCode); - res.resume(); - }).on('error', function(e) { - console.log(e.message); - process.exit(1); - }).end(expected); -}); - -process.on('exit', function() { - assert.equal(expected, result); -}); diff --git a/test/simple/test-http-destroyed-socket-write.js b/test/simple/test-http-destroyed-socket-write.js deleted file mode 100644 index b2498fd8aaf3..000000000000 --- a/test/simple/test-http-destroyed-socket-write.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// Fix the memory explosion that happens when writing to a http request -// where the server has destroyed the socket on us between a successful -// first request, and a subsequent request that reuses the socket. -// -// This test should not be ported to v0.10 and higher, because the -// problem is fixed by not ignoring ECONNRESET in the first place. - -var http = require('http'); -var net = require('net'); -var server = http.createServer(function(req, res) { - // simulate a server that is in the process of crashing or something - // it only crashes after the first request, but before the second, - // which reuses the connection. - res.end('hallo wereld\n', function() { - setTimeout(function() { - req.connection.destroy(); - }, 100); - }); -}); - -var gotFirstResponse = false; -var gotFirstData = false; -var gotFirstEnd = false; -server.listen(common.PORT, function() { - - var gotFirstResponse = false; - var first = http.request({ - port: common.PORT, - path: '/' - }); - first.on('response', function(res) { - gotFirstResponse = true; - res.on('data', function(chunk) { - gotFirstData = true; - }); - res.on('end', function() { - gotFirstEnd = true; - }) - }); - first.end(); - second(); - - function second() { - var sec = http.request({ - port: common.PORT, - path: '/', - method: 'POST' - }); - - var timer = setTimeout(write, 200); - var writes = 0; - var sawFalseWrite; - - function write() { - if (++writes === 64) { - clearTimeout(timer); - sec.end(); - test(); - } else { - timer = setTimeout(write); - var writeRet = sec.write(new Buffer('hello')); - - // Once we find out that the connection is destroyed, every - // write() returns false - if (sawFalseWrite) - assert.equal(writeRet, false); - else - sawFalseWrite = writeRet === false; - } - } - - assert.equal(first.connection, sec.connection, - 'should reuse connection'); - - sec.on('response', function(res) { - res.on('data', function(chunk) { - console.error('second saw data: ' + chunk); - }); - res.on('end', function() { - console.error('second saw end'); - }); - }); - - function test() { - server.close(); - assert(sec.connection.destroyed); - if (sec.output.length || sec.outputEncodings.length) - console.error('bad happened', sec.output, sec.outputEncodings); - assert.equal(sec.output.length, 0); - assert.equal(sec.outputEncodings, 0); - assert(sawFalseWrite); - assert(gotFirstResponse); - assert(gotFirstData); - assert(gotFirstEnd); - console.log('ok'); - } - } -}); diff --git a/test/simple/test-http-dns-error.js b/test/simple/test-http-dns-error.js deleted file mode 100644 index fc6d6b89e117..000000000000 --- a/test/simple/test-http-dns-error.js +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); -var https = require('https'); - -var expected_bad_requests = 0; -var actual_bad_requests = 0; - -var host = '********'; -host += host; -host += host; -host += host; -host += host; -host += host; - -function do_not_call() { - throw new Error('This function should not have been called.'); -} - -function test(mod) { - expected_bad_requests += 2; - - // Bad host name should not throw an uncatchable exception. - // Ensure that there is time to attach an error listener. - var req = mod.get({host: host, port: 42}, do_not_call); - req.on('error', function(err) { - assert.equal(err.code, 'ENOTFOUND'); - actual_bad_requests++; - }); - // http.get() called req.end() for us - - var req = mod.request({method: 'GET', host: host, port: 42}, do_not_call); - req.on('error', function(err) { - assert.equal(err.code, 'ENOTFOUND'); - actual_bad_requests++; - }); - req.end(); -} - -test(https); -test(http); - -process.on('exit', function() { - assert.equal(actual_bad_requests, expected_bad_requests); -}); - diff --git a/test/simple/test-http-end-throw-socket-handling.js b/test/simple/test-http-end-throw-socket-handling.js deleted file mode 100644 index 50aa97ff18e2..000000000000 --- a/test/simple/test-http-end-throw-socket-handling.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// Make sure that throwing in 'end' handler doesn't lock -// up the socket forever. -// -// This is NOT a good way to handle errors in general, but all -// the same, we should not be so brittle and easily broken. - -var http = require('http'); - -var n = 0; -var server = http.createServer(function(req, res) { - if (++n === 10) server.close(); - res.end('ok'); -}); - -server.listen(common.PORT, function() { - for (var i = 0; i < 10; i++) { - var options = { port: common.PORT }; - - var req = http.request(options, function (res) { - res.resume() - res.on('end', function() { - throw new Error('gleep glorp'); - }); - }); - req.end(); - } -}); - -setTimeout(function() { - process.removeListener('uncaughtException', catcher); - throw new Error('Taking too long!'); -}, 1000).unref(); - -process.on('uncaughtException', catcher); -var errors = 0; -function catcher() { - errors++; -} - -process.on('exit', function() { - assert.equal(errors, 10); - console.log('ok'); -}); diff --git a/test/simple/test-http-eof-on-connect.js b/test/simple/test-http-eof-on-connect.js deleted file mode 100644 index 95d6fdc950dd..000000000000 --- a/test/simple/test-http-eof-on-connect.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); - -// This is a regression test for https://github.com/joyent/node/issues/44 -// It is separate from test-http-malformed-request.js because it is only -// reproduceable on the first packet on the first connection to a server. - -var server = http.createServer(function(req, res) {}); -server.listen(common.PORT); - -server.on('listening', function() { - net.createConnection(common.PORT).on('connect', function() { - this.destroy(); - }).on('close', function() { - server.close(); - }); -}); diff --git a/test/simple/test-http-exceptions.js b/test/simple/test-http-exceptions.js deleted file mode 100644 index 1501d944ae48..000000000000 --- a/test/simple/test-http-exceptions.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var server = http.createServer(function(req, res) { - intentionally_not_defined(); - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('Thank you, come again.'); - res.end(); -}); - -server.listen(common.PORT, function() { - var req; - for (var i = 0; i < 4; i += 1) { - req = http.get({ port: common.PORT, path: '/busy/' + i }); - } -}); - -var exception_count = 0; - -process.on('uncaughtException', function(err) { - console.log('Caught an exception: ' + err); - if (err.name === 'AssertionError') throw err; - if (++exception_count == 4) process.exit(0); -}); - diff --git a/test/simple/test-http-exit-delay.js b/test/simple/test-http-exit-delay.js deleted file mode 100644 index 3643492735a1..000000000000 --- a/test/simple/test-http-exit-delay.js +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var common = require('../common.js'); -var http = require('http'); - -var start; -var server = http.createServer(function(req, res) { - req.resume(); - req.on('end', function() { - res.end('Success'); - }); - - server.close(function() { - start = process.hrtime(); - }); -}); - -server.listen(common.PORT, 'localhost', function() { - var interval_id = setInterval(function() { - if (new Date().getMilliseconds() > 100) - return; - - var req = http.request({ - 'host': 'localhost', - 'port': common.PORT, - 'agent': false, - 'method': 'PUT' - }); - - req.end('Test'); - clearInterval(interval_id); - }, 10); -}); - -process.on('exit', function() { - var d = process.hrtime(start); - assert.equal(d[0], 0); - assert(d[1] / 1e9 < 0.03); - console.log('ok'); -}); diff --git a/test/simple/test-http-expect-continue.js b/test/simple/test-http-expect-continue.js deleted file mode 100644 index 54c04cce0ee1..000000000000 --- a/test/simple/test-http-expect-continue.js +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var outstanding_reqs = 0; -var test_req_body = 'some stuff...\n'; -var test_res_body = 'other stuff!\n'; -var sent_continue = false; -var got_continue = false; - -function handler(req, res) { - assert.equal(sent_continue, true, 'Full response sent before 100 Continue'); - common.debug('Server sending full response...'); - res.writeHead(200, { - 'Content-Type' : 'text/plain', - 'ABCD' : '1' - }); - res.end(test_res_body); -} - -var server = http.createServer(handler); -server.on('checkContinue', function(req, res) { - common.debug('Server got Expect: 100-continue...'); - res.writeContinue(); - sent_continue = true; - setTimeout(function() { - handler(req, res); - }, 100); -}); -server.listen(common.PORT); - - - -server.on('listening', function() { - var req = http.request({ - port: common.PORT, - method: 'POST', - path: '/world', - headers: { 'Expect': '100-continue' } - }); - common.debug('Client sending request...'); - outstanding_reqs++; - var body = ''; - req.on('continue', function() { - common.debug('Client got 100 Continue...'); - got_continue = true; - req.end(test_req_body); - }); - req.on('response', function(res) { - assert.equal(got_continue, true, - 'Full response received before 100 Continue'); - assert.equal(200, res.statusCode, - 'Final status code was ' + res.statusCode + ', not 200.'); - res.setEncoding('utf8'); - res.on('data', function(chunk) { body += chunk; }); - res.on('end', function() { - common.debug('Got full response.'); - assert.equal(body, test_res_body, 'Response body doesn\'t match.'); - assert.ok('abcd' in res.headers, 'Response headers missing.'); - outstanding_reqs--; - if (outstanding_reqs == 0) { - server.close(); - process.exit(); - } - }); - }); -}); diff --git a/test/simple/test-http-extra-response.js b/test/simple/test-http-extra-response.js deleted file mode 100644 index 1649a6a92928..000000000000 --- a/test/simple/test-http-extra-response.js +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -// If an HTTP server is broken and sends data after the end of the response, -// node should ignore it and drop the connection. -// Demos this bug: https://github.com/joyent/node/issues/680 - -var body = 'hello world\r\n'; -var fullResponse = - 'HTTP/1.1 500 Internal Server Error\r\n' + - 'Content-Length: ' + body.length + '\r\n' + - 'Content-Type: text/plain\r\n' + - 'Date: Fri + 18 Feb 2011 06:22:45 GMT\r\n' + - 'Host: 10.20.149.2\r\n' + - 'Access-Control-Allow-Credentials: true\r\n' + - 'Server: badly broken/0.1 (OS NAME)\r\n' + - '\r\n' + - body; - -var gotResponse = false; - - -var server = net.createServer(function(socket) { - var postBody = ''; - - socket.setEncoding('utf8'); - - socket.on('data', function(chunk) { - postBody += chunk; - - if (postBody.indexOf('\r\n') > -1) { - socket.write(fullResponse); - // omg, I wrote the response twice, what a terrible HTTP server I am. - socket.end(fullResponse); - } - }); -}); - - -server.listen(common.PORT, function() { - http.get({ port: common.PORT }, function(res) { - var buffer = ''; - console.log('Got res code: ' + res.statusCode); - - res.setEncoding('utf8'); - res.on('data', function(chunk) { - buffer += chunk; - }); - - res.on('end', function() { - console.log('Response ended, read ' + buffer.length + ' bytes'); - assert.equal(body, buffer); - server.close(); - gotResponse = true; - }); - }); -}); - - -process.on('exit', function() { - assert.ok(gotResponse); -}); - diff --git a/test/simple/test-http-full-response.js b/test/simple/test-http-full-response.js deleted file mode 100644 index d33df8b883c6..000000000000 --- a/test/simple/test-http-full-response.js +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -// This test requires the program 'ab' -var http = require('http'); -var exec = require('child_process').exec; - -var bodyLength = 12345; - -var body = ''; -for (var i = 0; i < bodyLength; i++) { - body += 'c'; -} - -var server = http.createServer(function(req, res) { - res.writeHead(200, { - 'Content-Length': bodyLength, - 'Content-Type': 'text/plain' - }); - res.end(body); -}); - -var runs = 0; - -function runAb(opts, callback) { - var command = 'ab ' + opts + ' http://127.0.0.1:' + common.PORT + '/'; - exec(command, function(err, stdout, stderr) { - if (err) { - if (/ab|apr/mi.test(stderr)) { - console.log('problem spawning ab - skipping test.\n' + stderr); - process.reallyExit(0); - } - process.exit(); - return; - } - - var m = /Document Length:\s*(\d+) bytes/mi.exec(stdout); - var documentLength = parseInt(m[1]); - - var m = /Complete requests:\s*(\d+)/mi.exec(stdout); - var completeRequests = parseInt(m[1]); - - var m = /HTML transferred:\s*(\d+) bytes/mi.exec(stdout); - var htmlTransfered = parseInt(m[1]); - - assert.equal(bodyLength, documentLength); - assert.equal(completeRequests * documentLength, htmlTransfered); - - runs++; - - if (callback) callback(); - }); -} - -server.listen(common.PORT, function() { - runAb('-c 1 -n 10', function() { - console.log('-c 1 -n 10 okay'); - - runAb('-c 1 -n 100', function() { - console.log('-c 1 -n 100 okay'); - - runAb('-c 1 -n 1000', function() { - console.log('-c 1 -n 1000 okay'); - server.close(); - }); - }); - }); - -}); - -process.on('exit', function() { - assert.equal(3, runs); -}); diff --git a/test/simple/test-http-get-pipeline-problem.js b/test/simple/test-http-get-pipeline-problem.js deleted file mode 100644 index 720ce4b89c85..000000000000 --- a/test/simple/test-http-get-pipeline-problem.js +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -// We are demonstrating a problem with http.get when queueing up many -// transfers. The server simply introduces some delay and sends a file. -// Note this is demonstrated with connection: close. -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var fs = require('fs'); - -var image = fs.readFileSync(common.fixturesDir + '/person.jpg'); - -console.log('image.length = ' + image.length); - -var total = 100; -var requests = 0, responses = 0; - -var server = http.Server(function(req, res) { - if (++requests == total) { - server.close(); - } - - setTimeout(function() { - res.writeHead(200, { - 'content-type': 'image/jpeg', - 'connection': 'close', - 'content-length': image.length - }); - res.end(image); - }, 1); -}); - - -server.listen(common.PORT, function() { - for (var i = 0; i < total; i++) { - (function() { - var x = i; - - var opts = { - port: common.PORT, - headers: { connection: 'close' } - }; - - http.get(opts, function(res) { - console.error('recv ' + x); - var s = fs.createWriteStream(common.tmpDir + '/' + x + '.jpg'); - res.pipe(s); - - // TODO there should be a callback to pipe() that will allow - // us to get a callback when the pipe is finished. - res.on('end', function() { - console.error('done ' + x); - if (++responses == total) { - s.on('close', checkFiles); - } - }); - }).on('error', function(e) { - console.error('error! ', e.message); - throw e; - }); - })(); - } -}); - - -var checkedFiles = false; -function checkFiles() { - // Should see 1.jpg, 2.jpg, ..., 100.jpg in tmpDir - var files = fs.readdirSync(common.tmpDir); - assert(total <= files.length); - - for (var i = 0; i < total; i++) { - var fn = i + '.jpg'; - assert.ok(files.indexOf(fn) >= 0, "couldn't find '" + fn + "'"); - var stat = fs.statSync(common.tmpDir + '/' + fn); - assert.equal(image.length, stat.size, - "size doesn't match on '" + fn + - "'. Got " + stat.size + ' bytes'); - } - - checkedFiles = true; -} - - -process.on('exit', function() { - assert.equal(total, requests); - assert.equal(total, responses); - assert.ok(checkedFiles); -}); diff --git a/test/simple/test-http-head-request.js b/test/simple/test-http-head-request.js deleted file mode 100644 index ca0f13a1a288..000000000000 --- a/test/simple/test-http-head-request.js +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var util = require('util'); - - -var body = 'hello world\n'; -var id = 0; - -function test(headers) { - var port = common.PORT + id++; - - var server = http.createServer(function(req, res) { - console.error('req: %s headers: %j', req.method, headers); - res.writeHead(200, headers); - res.end(); - server.close(); - }); - - var gotEnd = false; - - server.listen(port, function() { - var request = http.request({ - port: port, - method: 'HEAD', - path: '/' - }, function(response) { - console.error('response start'); - response.on('end', function() { - console.error('response end'); - gotEnd = true; - }); - response.resume(); - }); - request.end(); - }); - - process.on('exit', function() { - assert.ok(gotEnd); - }); -} - -test({ - 'Transfer-Encoding': 'chunked' -}); -test({ - 'Content-Length': body.length -}); diff --git a/test/simple/test-http-head-response-has-no-body-end.js b/test/simple/test-http-head-response-has-no-body-end.js deleted file mode 100644 index cde777a58d91..000000000000 --- a/test/simple/test-http-head-response-has-no-body-end.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); - -// This test is to make sure that when the HTTP server -// responds to a HEAD request with data to res.end, -// it does not send any body. - -var server = http.createServer(function(req, res) { - res.writeHead(200); - res.end('FAIL'); // broken: sends FAIL from hot path. -}); -server.listen(common.PORT); - -var responseComplete = false; - -server.on('listening', function() { - var req = http.request({ - port: common.PORT, - method: 'HEAD', - path: '/' - }, function(res) { - common.error('response'); - res.on('end', function() { - common.error('response end'); - server.close(); - responseComplete = true; - }); - res.resume(); - }); - common.error('req'); - req.end(); -}); - -process.on('exit', function() { - assert.ok(responseComplete); -}); diff --git a/test/simple/test-http-head-response-has-no-body.js b/test/simple/test-http-head-response-has-no-body.js deleted file mode 100644 index ab6bd5b51fc9..000000000000 --- a/test/simple/test-http-head-response-has-no-body.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); - -// This test is to make sure that when the HTTP server -// responds to a HEAD request, it does not send any body. -// In this case it was sending '0\r\n\r\n' - -var server = http.createServer(function(req, res) { - res.writeHead(200); // broken: defaults to TE chunked - res.end(); -}); -server.listen(common.PORT); - -var responseComplete = false; - -server.on('listening', function() { - var req = http.request({ - port: common.PORT, - method: 'HEAD', - path: '/' - }, function(res) { - common.error('response'); - res.on('end', function() { - common.error('response end'); - server.close(); - responseComplete = true; - }); - res.resume(); - }); - common.error('req'); - req.end(); -}); - -process.on('exit', function() { - assert.ok(responseComplete); -}); diff --git a/test/simple/test-http-header-read.js b/test/simple/test-http-header-read.js deleted file mode 100644 index 338377592244..000000000000 --- a/test/simple/test-http-header-read.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -// Verify that ServerResponse.getHeader() works correctly even after -// the response header has been sent. Issue 752 on github. - -var s = http.createServer(function(req, res) { - var contentType = 'Content-Type'; - var plain = 'text/plain'; - res.setHeader(contentType, plain); - assert.ok(!res.headersSent); - res.writeHead(200); - assert.ok(res.headersSent); - res.end('hello world\n'); - // This checks that after the headers have been sent, getHeader works - // and does not throw an exception (Issue 752) - assert.doesNotThrow( - function() { - assert.equal(plain, res.getHeader(contentType)); - } - ); -}); - -s.listen(common.PORT, runTest); - -function runTest() { - http.get({ port: common.PORT }, function(response) { - response.on('end', function() { - s.close(); - }); - response.resume(); - }); -} diff --git a/test/simple/test-http-header-response-splitting.js b/test/simple/test-http-header-response-splitting.js deleted file mode 100644 index 1d3a85ce8b56..000000000000 --- a/test/simple/test-http-header-response-splitting.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'), - assert = require('assert'), - http = require('http'); - -var testIndex = 0, - responses = 0; - -var server = http.createServer(function(req, res) { - switch (testIndex++) { - case 0: - res.writeHead(200, { test: 'foo \r\ninvalid: bar' }); - break; - case 1: - res.writeHead(200, { test: 'foo \ninvalid: bar' }); - break; - case 2: - res.writeHead(200, { test: 'foo \rinvalid: bar' }); - break; - case 3: - res.writeHead(200, { test: 'foo \n\n\ninvalid: bar' }); - break; - case 4: - res.writeHead(200, { test: 'foo \r\n \r\n \r\ninvalid: bar' }); - server.close(); - break; - default: - assert(false); - } - res.end('Hi mars!'); -}); - -server.listen(common.PORT, function() { - for (var i = 0; i < 5; i++) { - var req = http.get({ port: common.PORT, path: '/' }, function(res) { - assert.strictEqual(res.headers.test, 'foo invalid: bar'); - assert.strictEqual(res.headers.invalid, undefined); - responses++; - res.resume(); - }); - } -}); - -process.on('exit', function() { - assert.strictEqual(responses, 5); -}); diff --git a/test/simple/test-http-hex-write.js b/test/simple/test-http-hex-write.js deleted file mode 100644 index 21a93df53e2e..000000000000 --- a/test/simple/test-http-hex-write.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); - -var expect = 'hex\nutf8\n'; -var data = ''; -var ended = false; - -process.on('exit', function() { - assert(ended); - assert.equal(data, expect); - console.log('ok'); -}); - -http.createServer(function(q, s) { - s.setHeader('content-length', expect.length); - s.write('6865780a', 'hex'); - s.write('utf8\n'); - s.end(); - this.close(); -}).listen(common.PORT, function() { - http.request({ port: common.PORT }).on('response', function(res) { - res.setEncoding('ascii'); - res.on('data', function(c) { - data += c; - }); - res.on('end', function() { - ended = true; - }); - }).end(); -}); diff --git a/test/simple/test-http-host-headers.js b/test/simple/test-http-host-headers.js deleted file mode 100644 index ca7f70947f8c..000000000000 --- a/test/simple/test-http-host-headers.js +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var http = require('http'), - https = require('https'), - fs = require('fs'), - common = require('../common'), - assert = require('assert'), - options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') - }, - httpServer = http.createServer(reqHandler), - httpsServer = https.createServer(options, reqHandler); - -function reqHandler(req, res) { - console.log('Got request: ' + req.headers.host + ' ' + req.url); - if (req.url === '/setHostFalse5') { - assert.equal(req.headers.host, undefined); - } else { - assert.equal(req.headers.host, 'localhost:' + common.PORT, - 'Wrong host header for req[' + req.url + ']: ' + - req.headers.host); - } - res.writeHead(200, {}); - //process.nextTick(function() { res.end('ok'); }); - res.end('ok'); -} - -function thrower(er) { - throw er; -} - -testHttp(); - -function testHttp() { - - console.log('testing http on port ' + common.PORT); - - var counter = 0; - - function cb(res) { - counter--; - console.log('back from http request. counter = ' + counter); - if (counter === 0) { - httpServer.close(); - testHttps(); - } - res.resume(); - } - - httpServer.listen(common.PORT, function(er) { - console.error('listening on ' + common.PORT); - - if (er) throw er; - - http.get({ - method: 'GET', - path: '/' + (counter++), - host: 'localhost', - //agent: false, - port: common.PORT, - rejectUnauthorized: false - }, cb).on('error', thrower); - - http.request({ - method: 'GET', - path: '/' + (counter++), - host: 'localhost', - //agent: false, - port: common.PORT, - rejectUnauthorized: false - }, cb).on('error', thrower).end(); - - http.request({ - method: 'POST', - path: '/' + (counter++), - host: 'localhost', - //agent: false, - port: common.PORT, - rejectUnauthorized: false - }, cb).on('error', thrower).end(); - - http.request({ - method: 'PUT', - path: '/' + (counter++), - host: 'localhost', - //agent: false, - port: common.PORT, - rejectUnauthorized: false - }, cb).on('error', thrower).end(); - - http.request({ - method: 'DELETE', - path: '/' + (counter++), - host: 'localhost', - //agent: false, - port: common.PORT, - rejectUnauthorized: false - }, cb).on('error', thrower).end(); - }); -} - -function testHttps() { - - console.log('testing https on port ' + common.PORT); - - var counter = 0; - - function cb(res) { - counter--; - console.log('back from https request. counter = ' + counter); - if (counter === 0) { - httpsServer.close(); - console.log('ok'); - } - res.resume(); - } - - httpsServer.listen(common.PORT, function(er) { - if (er) throw er; - - https.get({ - method: 'GET', - path: '/' + (counter++), - host: 'localhost', - //agent: false, - port: common.PORT, - rejectUnauthorized: false - }, cb).on('error', thrower); - - https.request({ - method: 'GET', - path: '/' + (counter++), - host: 'localhost', - //agent: false, - port: common.PORT, - rejectUnauthorized: false - }, cb).on('error', thrower).end(); - - https.request({ - method: 'POST', - path: '/' + (counter++), - host: 'localhost', - //agent: false, - port: common.PORT, - rejectUnauthorized: false - }, cb).on('error', thrower).end(); - - https.request({ - method: 'PUT', - path: '/' + (counter++), - host: 'localhost', - //agent: false, - port: common.PORT, - rejectUnauthorized: false - }, cb).on('error', thrower).end(); - - https.request({ - method: 'DELETE', - path: '/' + (counter++), - host: 'localhost', - //agent: false, - port: common.PORT, - rejectUnauthorized: false - }, cb).on('error', thrower).end(); - - https.get({ - method: 'GET', - path: '/setHostFalse' + (counter++), - host: 'localhost', - setHost: false, - port: common.PORT, - rejectUnauthorized: false - }, cb).on('error', thrower).end(); - }); -} diff --git a/test/simple/test-http-incoming-pipelined-socket-destroy.js b/test/simple/test-http-incoming-pipelined-socket-destroy.js deleted file mode 100644 index 3a2f531a75c6..000000000000 --- a/test/simple/test-http-incoming-pipelined-socket-destroy.js +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); -var net = require('net'); - - -// Set up some timing issues where sockets can be destroyed -// via either the req or res. -var server = http.createServer(function(req, res) { - switch (req.url) { - case '/1': - return setTimeout(function() { - req.socket.destroy(); - server.emit('requestDone'); - }); - - case '/2': - return process.nextTick(function() { - res.destroy(); - server.emit('requestDone'); - }); - - // in one case, actually send a response in 2 chunks - case '/3': - res.write('hello '); - return setTimeout(function() { - res.end('world!'); - server.emit('requestDone'); - }); - - default: - res.destroy(); - server.emit('requestDone'); - } -}); - - -// Make a bunch of requests pipelined on the same socket -function generator(seeds) { - return seeds.map(function(r) { - return 'GET /' + r + ' HTTP/1.1\r\n' + - 'Host: localhost:' + common.PORT + '\r\n' + - '\r\n' + - '\r\n' - }).join(''); -} - - -server.listen(common.PORT, function() { - var seeds = [ 3, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 ]; - var client = net.connect({ port: common.PORT }); - var done = 0; - server.on('requestDone', function() { - if (++done == seeds.length) { - server.close(); - } - }); - - // immediately write the pipelined requests. - // Some of these will not have a socket to destroy! - client.write(generator(seeds)); -}); - -process.on('exit', function(c) { - if (!c) - console.log('ok'); -}); diff --git a/test/simple/test-http-keep-alive-close-on-header.js b/test/simple/test-http-keep-alive-close-on-header.js deleted file mode 100644 index 53c73ae461d6..000000000000 --- a/test/simple/test-http-keep-alive-close-on-header.js +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var util = require('util'); - -var body = 'hello world\n'; -var headers = {'connection': 'keep-alive'}; - -var server = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Length': body.length, 'Connection': 'close'}); - res.write(body); - res.end(); -}); - -var connectCount = 0; - - -server.listen(common.PORT, function() { - var agent = new http.Agent({ maxSockets: 1 }); - var request = http.request({ - method: 'GET', - path: '/', - headers: headers, - port: common.PORT, - agent: agent - }, function(res) { - assert.equal(1, agent.sockets['localhost:' + common.PORT].length); - res.resume(); - }); - request.on('socket', function(s) { - s.on('connect', function() { - connectCount++; - }); - }); - request.end(); - - request = http.request({ - method: 'GET', - path: '/', - headers: headers, - port: common.PORT, - agent: agent - }, function(res) { - assert.equal(1, agent.sockets['localhost:' + common.PORT].length); - res.resume(); - }); - request.on('socket', function(s) { - s.on('connect', function() { - connectCount++; - }); - }); - request.end(); - request = http.request({ - method: 'GET', - path: '/', - headers: headers, - port: common.PORT, - agent: agent - }, function(response) { - response.on('end', function() { - assert.equal(1, agent.sockets['localhost:' + common.PORT].length); - server.close(); - }); - response.resume(); - }); - request.on('socket', function(s) { - s.on('connect', function() { - connectCount++; - }); - }); - request.end(); -}); - -process.on('exit', function() { - assert.equal(3, connectCount); -}); diff --git a/test/simple/test-http-keep-alive.js b/test/simple/test-http-keep-alive.js deleted file mode 100644 index 4e8a6e816fea..000000000000 --- a/test/simple/test-http-keep-alive.js +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var body = 'hello world\n'; - -var server = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Length': body.length}); - res.write(body); - res.end(); -}); - -var connectCount = 0; -var name = 'localhost:' + common.PORT; -var agent = new http.Agent({maxSockets: 1}); -var headers = {'connection': 'keep-alive'}; - -server.listen(common.PORT, function() { - http.get({ - path: '/', headers: headers, port: common.PORT, agent: agent - }, function(response) { - assert.equal(agent.sockets[name].length, 1); - assert.equal(agent.requests[name].length, 2); - response.resume(); - }); - - http.get({ - path: '/', headers: headers, port: common.PORT, agent: agent - }, function(response) { - assert.equal(agent.sockets[name].length, 1); - assert.equal(agent.requests[name].length, 1); - response.resume(); - }); - - http.get({ - path: '/', headers: headers, port: common.PORT, agent: agent - }, function(response) { - response.on('end', function() { - assert.equal(agent.sockets[name].length, 1); - assert(!agent.requests.hasOwnProperty(name)); - server.close(); - }); - response.resume(); - }); -}); - -process.on('exit', function() { - assert(!agent.sockets.hasOwnProperty(name)); - assert(!agent.requests.hasOwnProperty(name)); -}); diff --git a/test/simple/test-http-legacy.js b/test/simple/test-http-legacy.js deleted file mode 100644 index c6605b0e4e2f..000000000000 --- a/test/simple/test-http-legacy.js +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); - -function p(x) { - common.error(common.inspect(x)); -} - -var responses_sent = 0; -var responses_recvd = 0; -var body0 = ''; -var body1 = ''; - -var server = http.createServer(function(req, res) { - if (responses_sent == 0) { - assert.equal('GET', req.method); - assert.equal('/hello', url.parse(req.url).pathname); - - console.dir(req.headers); - assert.equal(true, 'accept' in req.headers); - assert.equal('*/*', req.headers['accept']); - - assert.equal(true, 'foo' in req.headers); - assert.equal('bar', req.headers['foo']); - } - - if (responses_sent == 1) { - assert.equal('POST', req.method); - assert.equal('/world', url.parse(req.url).pathname); - this.close(); - } - - req.on('end', function() { - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('The path was ' + url.parse(req.url).pathname); - res.end(); - responses_sent += 1; - }); - req.resume(); - - //assert.equal('127.0.0.1', res.connection.remoteAddress); -}); - -server.listen(common.PORT, function() { - var client = http.createClient(common.PORT); - var req = client.request('/hello', {'Accept': '*/*', 'Foo': 'bar'}); - setTimeout(function() { - req.end(); - }, 100); - req.on('response', function(res) { - assert.equal(200, res.statusCode); - responses_recvd += 1; - res.setEncoding('utf8'); - res.on('data', function(chunk) { body0 += chunk; }); - common.debug('Got /hello response'); - }); - - setTimeout(function() { - var req = client.request('POST', '/world'); - req.end(); - req.on('response', function(res) { - assert.equal(200, res.statusCode); - responses_recvd += 1; - res.setEncoding('utf8'); - res.on('data', function(chunk) { body1 += chunk; }); - common.debug('Got /world response'); - }); - }, 1); -}); - -process.on('exit', function() { - common.debug('responses_recvd: ' + responses_recvd); - assert.equal(2, responses_recvd); - - common.debug('responses_sent: ' + responses_sent); - assert.equal(2, responses_sent); - - assert.equal('The path was /hello', body0); - assert.equal('The path was /world', body1); -}); diff --git a/test/simple/test-http-localaddress-bind-error.js b/test/simple/test-http-localaddress-bind-error.js deleted file mode 100644 index 719525cc6122..000000000000 --- a/test/simple/test-http-localaddress-bind-error.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var invalidLocalAddress = '1.2.3.4'; -var gotError = false; - -var server = http.createServer(function(req, res) { - console.log("Connect from: " + req.connection.remoteAddress); - - req.on('end', function() { - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.end('You are from: ' + req.connection.remoteAddress); - }); - req.resume(); -}); - -server.listen(common.PORT, "127.0.0.1", function() { - var req = http.request({ - host: 'localhost', - port: common.PORT, - path: '/', - method: 'GET', - localAddress: invalidLocalAddress - }, function(res) { - assert.fail('unexpectedly got response from server'); - }).on('error', function(e) { - console.log('client got error: ' + e.message); - gotError = true; - server.close(); - }).end(); -}); - -process.on('exit', function() { - assert.ok(gotError); -}); diff --git a/test/simple/test-http-localaddress.js b/test/simple/test-http-localaddress.js deleted file mode 100644 index 27172e33a95d..000000000000 --- a/test/simple/test-http-localaddress.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var http = require('http'), - assert = require('assert'); - -if (!common.hasMultiLocalhost()) { - console.log('Skipping platform-specific test.'); - process.exit(); -} - -var server = http.createServer(function (req, res) { - console.log("Connect from: " + req.connection.remoteAddress); - assert.equal('127.0.0.2', req.connection.remoteAddress); - - req.on('end', function() { - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.end('You are from: ' + req.connection.remoteAddress); - }); - req.resume(); -}); - -server.listen(common.PORT, "127.0.0.1", function() { - var options = { host: 'localhost', - port: common.PORT, - path: '/', - method: 'GET', - localAddress: '127.0.0.2' }; - - var req = http.request(options, function(res) { - res.on('end', function() { - server.close(); - process.exit(); - }); - res.resume(); - }); - req.end(); -}); diff --git a/test/simple/test-http-malformed-request.js b/test/simple/test-http-malformed-request.js deleted file mode 100644 index 52165a21d607..000000000000 --- a/test/simple/test-http-malformed-request.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); -var url = require('url'); - -// Make sure no exceptions are thrown when receiving malformed HTTP -// requests. - -var nrequests_completed = 0; -var nrequests_expected = 1; - -var server = http.createServer(function(req, res) { - console.log('req: ' + JSON.stringify(url.parse(req.url))); - - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('Hello World'); - res.end(); - - if (++nrequests_completed == nrequests_expected) server.close(); -}); -server.listen(common.PORT); - -server.on('listening', function() { - var c = net.createConnection(common.PORT); - c.on('connect', function() { - c.write('GET /hello?foo=%99bar HTTP/1.1\r\n\r\n'); - c.end(); - }); - - // TODO add more! -}); - -process.on('exit', function() { - assert.equal(nrequests_expected, nrequests_completed); -}); diff --git a/test/simple/test-http-many-ended-pipelines.js b/test/simple/test-http-many-ended-pipelines.js deleted file mode 100644 index dffde722f2ac..000000000000 --- a/test/simple/test-http-many-ended-pipelines.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// no warnings should happen! -var trace = console.trace; -console.trace = function() { - trace.apply(console, arguments); - throw new Error('no tracing should happen here'); -}; - -var http = require('http'); -var net = require('net'); - -var numRequests = 20; -var done = 0; - -var server = http.createServer(function(req, res) { - res.end('ok'); - - // Oh no! The connection died! - req.socket.destroy(); - if (++done == numRequests) - server.close(); -}); - -server.listen(common.PORT); - -var client = net.connect({ port: common.PORT, allowHalfOpen: true }); -for (var i = 0; i < numRequests; i++) { - client.write('GET / HTTP/1.1\r\n' + - 'Host: some.host.name\r\n'+ - '\r\n\r\n'); -} -client.end(); -client.pipe(process.stdout); diff --git a/test/simple/test-http-many-keep-alive-connections.js b/test/simple/test-http-many-keep-alive-connections.js deleted file mode 100644 index adbebbdcc433..000000000000 --- a/test/simple/test-http-many-keep-alive-connections.js +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var expected = 10000; -var responses = 0; -var requests = 0; -var connection; - -var server = http.Server(function(req, res) { - requests++; - assert.equal(req.connection, connection); - res.writeHead(200); - res.end('hello world\n'); -}); - -server.once('connection', function(c) { - connection = c; -}); - -server.listen(common.PORT, function() { - var callee = arguments.callee; - var request = http.get({ - port: common.PORT, - path: '/', - headers: { - 'Connection': 'Keep-alive' - } - }, function(res) { - res.on('end', function() { - if (++responses < expected) { - callee(); - } else { - server.close(); - } - }); - res.resume(); - }).on('error', function(e) { - console.log(e.message); - process.exit(1); - }); - request.agent.maxSockets = 1; -}); - -process.on('exit', function() { - assert.equal(expected, responses); - assert.equal(expected, requests); -}); diff --git a/test/simple/test-http-max-headers-count.js b/test/simple/test-http-max-headers-count.js deleted file mode 100644 index 4595b11e7c80..000000000000 --- a/test/simple/test-http-max-headers-count.js +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var requests = 0; -var responses = 0; - -var headers = {}; -var N = 2000; -for (var i = 0; i < N; ++i) { - headers['key' + i] = i; -} - -var maxAndExpected = [ // for server - [50, 50], - [1500, 1500], - [0, N + 2] // Host and Connection -]; -var max = maxAndExpected[requests][0]; -var expected = maxAndExpected[requests][1]; - -var server = http.createServer(function(req, res) { - assert.equal(Object.keys(req.headers).length, expected); - if (++requests < maxAndExpected.length) { - max = maxAndExpected[requests][0]; - expected = maxAndExpected[requests][1]; - server.maxHeadersCount = max; - } - res.writeHead(200, headers); - res.end(); -}); -server.maxHeadersCount = max; - -server.listen(common.PORT, function() { - var maxAndExpected = [ // for client - [20, 20], - [1200, 1200], - [0, N + 3] // Connection, Date and Transfer-Encoding - ]; - doRequest(); - - function doRequest() { - var max = maxAndExpected[responses][0]; - var expected = maxAndExpected[responses][1]; - var req = http.request({ - port: common.PORT, - headers: headers - }, function(res) { - assert.equal(Object.keys(res.headers).length, expected); - res.on('end', function() { - if (++responses < maxAndExpected.length) { - doRequest(); - } else { - server.close(); - } - }); - res.resume(); - }); - req.maxHeadersCount = max; - req.end(); - } -}); - -process.on('exit', function() { - assert.equal(requests, maxAndExpected.length); - assert.equal(responses, maxAndExpected.length); -}); diff --git a/test/simple/test-http-multi-line-headers.js b/test/simple/test-http-multi-line-headers.js deleted file mode 100644 index 92bf9ecc82d0..000000000000 --- a/test/simple/test-http-multi-line-headers.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); -var net = require('net'); - -var gotResponse = false; - -var server = net.createServer(function(conn) { - var body = 'Yet another node.js server.'; - - var response = - 'HTTP/1.1 200 OK\r\n' + - 'Connection: close\r\n' + - 'Content-Length: ' + body.length + '\r\n' + - 'Content-Type: text/plain;\r\n' + - ' x-unix-mode=0600;\r\n' + - ' name=\"hello.txt\"\r\n' + - '\r\n' + - body; - - conn.end(response); - server.close(); -}); - -server.listen(common.PORT, function() { - http.get({host: '127.0.0.1', port: common.PORT}, function(res) { - assert.equal(res.headers['content-type'], - 'text/plain;x-unix-mode=0600;name="hello.txt"'); - gotResponse = true; - res.destroy(); - }); -}); - -process.on('exit', function() { - assert.ok(gotResponse); -}); diff --git a/test/simple/test-http-mutable-headers.js b/test/simple/test-http-mutable-headers.js deleted file mode 100644 index 6106ac6ee004..000000000000 --- a/test/simple/test-http-mutable-headers.js +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -// Simple test of Node's HTTP Client mutable headers -// OutgoingMessage.prototype.setHeader(name, value) -// OutgoingMessage.prototype.getHeader(name) -// OutgoingMessage.prototype.removeHeader(name, value) -// ServerResponse.prototype.statusCode -// .method -// .path - -var testsComplete = 0; -var test = 'headers'; -var content = 'hello world\n'; -var cookies = [ - 'session_token=; path=/; expires=Sun, 15-Sep-2030 13:48:52 GMT', - 'prefers_open_id=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT' -]; - -var s = http.createServer(function(req, res) { - switch (test) { - case 'headers': - assert.throws(function() { res.setHeader() }); - assert.throws(function() { res.setHeader('someHeader') }); - assert.throws(function() { res.getHeader() }); - assert.throws(function() { res.removeHeader() }); - - res.setHeader('x-test-header', 'testing'); - res.setHeader('X-TEST-HEADER2', 'testing'); - res.setHeader('set-cookie', cookies); - res.setHeader('x-test-array-header', [1, 2, 3]); - - var val1 = res.getHeader('x-test-header'); - var val2 = res.getHeader('x-test-header2'); - assert.equal(val1, 'testing'); - assert.equal(val2, 'testing'); - - res.removeHeader('x-test-header2'); - break; - - case 'contentLength': - res.setHeader('content-length', content.length); - assert.equal(content.length, res.getHeader('Content-Length')); - break; - - case 'transferEncoding': - res.setHeader('transfer-encoding', 'chunked'); - assert.equal(res.getHeader('Transfer-Encoding'), 'chunked'); - break; - - case 'writeHead': - res.statusCode = 404; - res.setHeader('x-foo', 'keyboard cat'); - res.writeHead(200, { 'x-foo': 'bar', 'x-bar': 'baz' }); - break; - } - - res.statusCode = 201; - res.end(content); -}); - -s.listen(common.PORT, nextTest); - - -function nextTest() { - if (test === 'end') { - return s.close(); - } - - var bufferedResponse = ''; - - http.get({ port: common.PORT }, function(response) { - console.log('TEST: ' + test); - console.log('STATUS: ' + response.statusCode); - console.log('HEADERS: '); - console.dir(response.headers); - - switch (test) { - case 'headers': - assert.equal(response.statusCode, 201); - assert.equal(response.headers['x-test-header'], - 'testing'); - assert.equal(response.headers['x-test-array-header'], - [1, 2, 3].join(', ')); - assert.deepEqual(cookies, - response.headers['set-cookie']); - assert.equal(response.headers['x-test-header2'] !== undefined, false); - // Make the next request - test = 'contentLength'; - console.log('foobar'); - break; - - case 'contentLength': - assert.equal(response.headers['content-length'], content.length); - test = 'transferEncoding'; - break; - - case 'transferEncoding': - assert.equal(response.headers['transfer-encoding'], 'chunked'); - test = 'writeHead'; - break; - - case 'writeHead': - assert.equal(response.headers['x-foo'], 'bar'); - assert.equal(response.headers['x-bar'], 'baz'); - assert.equal(200, response.statusCode); - test = 'end'; - break; - - default: - throw Error('?'); - } - - response.setEncoding('utf8'); - response.on('data', function(s) { - bufferedResponse += s; - }); - - response.on('end', function() { - assert.equal(content, bufferedResponse); - testsComplete++; - nextTest(); - }); - }); -} - - -process.on('exit', function() { - assert.equal(4, testsComplete); -}); - diff --git a/test/simple/test-http-no-content-length.js b/test/simple/test-http-no-content-length.js deleted file mode 100644 index 8c565aedc7ca..000000000000 --- a/test/simple/test-http-no-content-length.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); - -var body = ''; - -var server = net.createServer(function(socket) { - // Neither Content-Length nor Connection - socket.end('HTTP/1.1 200 ok\r\n\r\nHello'); -}).listen(common.PORT, function() { - var req = http.get({port: common.PORT}, function(res) { - res.setEncoding('utf8'); - res.on('data', function(chunk) { - body += chunk; - }); - res.on('end', function() { - server.close(); - }); - }); -}); - -process.on('exit', function() { - assert.equal(body, 'Hello'); -}); diff --git a/test/simple/test-http-parser-bad-ref.js b/test/simple/test-http-parser-bad-ref.js deleted file mode 100644 index 4a9c70515bb3..000000000000 --- a/test/simple/test-http-parser-bad-ref.js +++ /dev/null @@ -1,81 +0,0 @@ -// Run this program with valgrind or efence with --expose_gc to expose the -// problem. - -// Flags: --expose_gc - -var common = require('../common'); -var assert = require('assert'); -var HTTPParser = process.binding('http_parser').HTTPParser; - -var headersComplete = 0; -var messagesComplete = 0; - -function flushPool() { - new Buffer(Buffer.poolSize - 1); - gc(); -} - -function demoBug(part1, part2) { - flushPool(); - - var parser = new HTTPParser('REQUEST'); - - parser.headers = []; - parser.url = ''; - - parser.onHeaders = function(headers, url) { - parser.headers = parser.headers.concat(headers); - parser.url += url; - }; - - parser.onHeadersComplete = function(info) { - headersComplete++; - console.log('url', info.url); - }; - - parser.onBody = function(b, start, len) { }; - - parser.onMessageComplete = function() { - messagesComplete++; - }; - - - // We use a function to eliminate references to the Buffer b - // We want b to be GCed. The parser will hold a bad reference to it. - (function() { - var b = Buffer(part1); - flushPool(); - - console.log('parse the first part of the message'); - parser.execute(b, 0, b.length); - })(); - - flushPool(); - - (function() { - var b = Buffer(part2); - - console.log('parse the second part of the message'); - parser.execute(b, 0, b.length); - parser.finish(); - })(); - - flushPool(); -} - - -demoBug('POST /1', '/22 HTTP/1.1\r\n' + - 'Content-Type: text/plain\r\n' + - 'Content-Length: 4\r\n\r\n' + - 'pong'); - -demoBug('POST /1/22 HTTP/1.1\r\n' + - 'Content-Type: tex', 't/plain\r\n' + - 'Content-Length: 4\r\n\r\n' + - 'pong'); - -process.on('exit', function() { - assert.equal(2, headersComplete); - assert.equal(2, messagesComplete); - console.log('done!'); -}); diff --git a/test/simple/test-http-parser-free.js b/test/simple/test-http-parser-free.js deleted file mode 100644 index 7b35781f4d3e..000000000000 --- a/test/simple/test-http-parser-free.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var N = 100; -var responses = 0; - -var server = http.createServer(function(req, res) { - res.end('Hello'); -}); - -server.listen(common.PORT, function() { - http.globalAgent.maxSockets = 1; - var parser; - for (var i = 0; i < N; ++i) { - (function makeRequest(i) { - var req = http.get({port: common.PORT}, function(res) { - if (!parser) { - parser = req.parser; - } else { - assert.strictEqual(req.parser, parser); - } - - if (++responses === N) { - server.close(); - } - res.resume(); - }); - })(i); - } -}); - -process.on('exit', function() { - assert.equal(responses, N); -}); diff --git a/test/simple/test-http-parser.js b/test/simple/test-http-parser.js deleted file mode 100644 index e8c809513114..000000000000 --- a/test/simple/test-http-parser.js +++ /dev/null @@ -1,549 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var HTTPParser = process.binding('http_parser').HTTPParser; - -var CRLF = '\r\n'; -var REQUEST = HTTPParser.REQUEST; -var RESPONSE = HTTPParser.RESPONSE; - -// The purpose of this test is not to check HTTP compliance but to test the -// binding. Tests for pathological http messages should be submitted -// upstream to https://github.com/joyent/http-parser for inclusion into -// deps/http-parser/test.c - - -function newParser(type) { - var parser = new HTTPParser(type); - - parser.headers = []; - parser.url = ''; - - parser.onHeaders = function(headers, url) { - parser.headers = parser.headers.concat(headers); - parser.url += url; - }; - - parser.onHeadersComplete = function(info) { - }; - - parser.onBody = function(b, start, len) { - assert.ok(false, 'Function should not be called.'); - }; - - parser.onMessageComplete = function() { - }; - - return parser; -} - - -function mustCall(f, times) { - var actual = 0; - - process.setMaxListeners(256); - process.on('exit', function() { - assert.equal(actual, times || 1); - }); - - return function() { - actual++; - return f.apply(this, Array.prototype.slice.call(arguments)); - }; -} - - -function expectBody(expected) { - return mustCall(function(buf, start, len) { - var body = '' + buf.slice(start, start + len); - assert.equal(body, expected); - }); -} - - -// -// Simple request test. -// -(function() { - var request = Buffer( - 'GET /hello HTTP/1.1' + CRLF + - CRLF); - - var parser = newParser(REQUEST); - - parser.onHeadersComplete = mustCall(function(info) { - assert.equal(info.method, 'GET'); - assert.equal(info.url || parser.url, '/hello'); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 1); - }); - - parser.execute(request, 0, request.length); - - // - // Check that if we throw an error in the callbacks that error will be - // thrown from parser.execute() - // - - parser.onHeadersComplete = function(info) { - throw new Error('hello world'); - }; - - parser.reinitialize(HTTPParser.REQUEST); - - assert.throws(function() { - parser.execute(request, 0, request.length); - }, Error, 'hello world'); -})(); - - -// -// Simple response test. -// -(function() { - var request = Buffer( - 'HTTP/1.1 200 OK' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Content-Length: 4' + CRLF + - CRLF + - 'pong'); - - var parser = newParser(RESPONSE); - - parser.onHeadersComplete = mustCall(function(info) { - assert.equal(info.method, undefined); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 1); - assert.equal(info.statusCode, 200); - }); - - parser.onBody = mustCall(function(buf, start, len) { - var body = '' + buf.slice(start, start + len); - assert.equal(body, 'pong'); - }); - - parser.execute(request, 0, request.length); -})(); - - -// -// Response with no headers. -// -(function() { - var request = Buffer( - 'HTTP/1.0 200 Connection established' + CRLF + - CRLF); - - var parser = newParser(RESPONSE); - - parser.onHeadersComplete = mustCall(function(info) { - assert.equal(info.method, undefined); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 0); - assert.equal(info.statusCode, 200); - assert.deepEqual(info.headers || parser.headers, []); - }); - - parser.execute(request, 0, request.length); -})(); - - -// -// Trailing headers. -// -(function() { - var request = Buffer( - 'POST /it HTTP/1.1' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '4' + CRLF + - 'ping' + CRLF + - '0' + CRLF + - 'Vary: *' + CRLF + - 'Content-Type: text/plain' + CRLF + - CRLF); - - var seen_body = false; - - function onHeaders(headers, url) { - assert.ok(seen_body); // trailers should come after the body - assert.deepEqual(headers, - ['Vary', '*', 'Content-Type', 'text/plain']); - } - - var parser = newParser(REQUEST); - - parser.onHeadersComplete = mustCall(function(info) { - assert.equal(info.method, 'POST'); - assert.equal(info.url || parser.url, '/it'); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 1); - // expect to see trailing headers now - parser.onHeaders = mustCall(onHeaders); - }); - - parser.onBody = mustCall(function(buf, start, len) { - var body = '' + buf.slice(start, start + len); - assert.equal(body, 'ping'); - seen_body = true; - }); - - parser.execute(request, 0, request.length); -})(); - - -// -// Test header ordering. -// -(function() { - var request = Buffer( - 'GET / HTTP/1.0' + CRLF + - 'X-Filler: 1337' + CRLF + - 'X-Filler: 42' + CRLF + - 'X-Filler2: 42' + CRLF + - CRLF); - - var parser = newParser(REQUEST); - - parser.onHeadersComplete = mustCall(function(info) { - assert.equal(info.method, 'GET'); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 0); - assert.deepEqual(info.headers || parser.headers, - ['X-Filler', '1337', - 'X-Filler', '42', - 'X-Filler2', '42']); - }); - - parser.execute(request, 0, request.length); -})(); - - -// -// Test large number of headers -// -(function() { - // 256 X-Filler headers - var lots_of_headers = 'X-Filler: 42' + CRLF; - for (var i = 0; i < 8; ++i) lots_of_headers += lots_of_headers; - - var request = Buffer( - 'GET /foo/bar/baz?quux=42#1337 HTTP/1.0' + CRLF + - lots_of_headers + - CRLF); - - var parser = newParser(REQUEST); - - parser.onHeadersComplete = mustCall(function(info) { - assert.equal(info.method, 'GET'); - assert.equal(info.url || parser.url, '/foo/bar/baz?quux=42#1337'); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 0); - - var headers = info.headers || parser.headers; - - assert.equal(headers.length, 2 * 256); // 256 key/value pairs - for (var i = 0; i < headers.length; i += 2) { - assert.equal(headers[i], 'X-Filler'); - assert.equal(headers[i + 1], '42'); - } - }); - - parser.execute(request, 0, request.length); -})(); - - -// -// Test request body -// -(function() { - var request = Buffer( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: application/x-www-form-urlencoded' + CRLF + - 'Content-Length: 15' + CRLF + - CRLF + - 'foo=42&bar=1337'); - - var parser = newParser(REQUEST); - - parser.onHeadersComplete = mustCall(function(info) { - assert.equal(info.method, 'POST'); - assert.equal(info.url || parser.url, '/it'); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 1); - }); - - parser.onBody = mustCall(function(buf, start, len) { - var body = '' + buf.slice(start, start + len); - assert.equal(body, 'foo=42&bar=1337'); - }); - - parser.execute(request, 0, request.length); -})(); - - -// -// Test chunked request body -// -(function() { - var request = Buffer( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF + - 'A' + CRLF + - '1234567890' + CRLF + - '0' + CRLF); - - var parser = newParser(REQUEST); - - parser.onHeadersComplete = mustCall(function(info) { - assert.equal(info.method, 'POST'); - assert.equal(info.url || parser.url, '/it'); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 1); - }); - - var body_part = 0, - body_parts = ['123', '123456', '1234567890']; - - function onBody(buf, start, len) { - var body = '' + buf.slice(start, start + len); - assert.equal(body, body_parts[body_part++]); - } - - parser.onBody = mustCall(onBody, body_parts.length); - parser.execute(request, 0, request.length); -})(); - - -// -// Test chunked request body spread over multiple buffers (packets) -// -(function() { - var request = Buffer( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF); - - var parser = newParser(REQUEST); - - parser.onHeadersComplete = mustCall(function(info) { - assert.equal(info.method, 'POST'); - assert.equal(info.url || parser.url, '/it'); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 1); - }); - - var body_part = 0, - body_parts = [ - '123', '123456', '123456789', - '123456789ABC', '123456789ABCDEF']; - - function onBody(buf, start, len) { - var body = '' + buf.slice(start, start + len); - assert.equal(body, body_parts[body_part++]); - } - - parser.onBody = mustCall(onBody, body_parts.length); - parser.execute(request, 0, request.length); - - request = Buffer( - '9' + CRLF + - '123456789' + CRLF + - 'C' + CRLF + - '123456789ABC' + CRLF + - 'F' + CRLF + - '123456789ABCDEF' + CRLF + - '0' + CRLF); - - parser.execute(request, 0, request.length); -})(); - - -// -// Stress test. -// -(function() { - var request = Buffer( - 'POST /helpme HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF + - '9' + CRLF + - '123456789' + CRLF + - 'C' + CRLF + - '123456789ABC' + CRLF + - 'F' + CRLF + - '123456789ABCDEF' + CRLF + - '0' + CRLF); - - function test(a, b) { - var parser = newParser(REQUEST); - - parser.onHeadersComplete = mustCall(function(info) { - assert.equal(info.method, 'POST'); - assert.equal(info.url || parser.url, '/helpme'); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 1); - }); - - var expected_body = '123123456123456789123456789ABC123456789ABCDEF'; - - parser.onBody = function(buf, start, len) { - var chunk = '' + buf.slice(start, start + len); - assert.equal(expected_body.indexOf(chunk), 0); - expected_body = expected_body.slice(chunk.length); - }; - - parser.execute(a, 0, a.length); - parser.execute(b, 0, b.length); - - assert.equal(expected_body, ''); - } - - for (var i = 1; i < request.length - 1; ++i) { - var a = request.slice(0, i); - console.error('request.slice(0, ' + i + ') = ', - JSON.stringify(a.toString())); - var b = request.slice(i); - console.error('request.slice(' + i + ') = ', - JSON.stringify(b.toString())); - test(a, b); - } -})(); - - -// -// Byte by byte test. -// -(function() { - var request = Buffer( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF + - '9' + CRLF + - '123456789' + CRLF + - 'C' + CRLF + - '123456789ABC' + CRLF + - 'F' + CRLF + - '123456789ABCDEF' + CRLF + - '0' + CRLF); - - var parser = newParser(REQUEST); - - parser.onHeadersComplete = mustCall(function(info) { - assert.equal(info.method, 'POST'); - assert.equal(info.url || parser.url, '/it'); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 1); - assert.deepEqual(info.headers || parser.headers, - ['Content-Type', 'text/plain', - 'Transfer-Encoding', 'chunked']); - }); - - var expected_body = '123123456123456789123456789ABC123456789ABCDEF'; - - parser.onBody = function(buf, start, len) { - var chunk = '' + buf.slice(start, start + len); - assert.equal(expected_body.indexOf(chunk), 0); - expected_body = expected_body.slice(chunk.length); - }; - - for (var i = 0; i < request.length; ++i) { - parser.execute(request, i, 1); - } - - assert.equal(expected_body, ''); -})(); - - -// -// Test parser reinit sequence. -// -(function() { - var req1 = Buffer( - 'PUT /this HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '4' + CRLF + - 'ping' + CRLF + - '0' + CRLF); - - var req2 = Buffer( - 'POST /that HTTP/1.0' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Content-Length: 4' + CRLF + - CRLF + - 'pong'); - - function onHeadersComplete1(info) { - assert.equal(info.method, 'PUT'); - assert.equal(info.url, '/this'); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 1); - assert.deepEqual(info.headers, - ['Content-Type', 'text/plain', - 'Transfer-Encoding', 'chunked']); - }; - - function onHeadersComplete2(info) { - assert.equal(info.method, 'POST'); - assert.equal(info.url, '/that'); - assert.equal(info.versionMajor, 1); - assert.equal(info.versionMinor, 0); - assert.deepEqual(info.headers, - ['Content-Type', 'text/plain', - 'Content-Length', '4']); - }; - - var parser = newParser(REQUEST); - parser.onHeadersComplete = onHeadersComplete1; - parser.onBody = expectBody('ping'); - parser.execute(req1, 0, req1.length); - - parser.reinitialize(REQUEST); - parser.onBody = expectBody('pong'); - parser.onHeadersComplete = onHeadersComplete2; - parser.execute(req2, 0, req2.length); -})(); diff --git a/test/simple/test-http-pause-resume-one-end.js b/test/simple/test-http-pause-resume-one-end.js deleted file mode 100644 index d5a4cb983e29..000000000000 --- a/test/simple/test-http-pause-resume-one-end.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var server = http.Server(function(req, res) { - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end('Hello World\n'); - server.close(); -}); - - -var dataCount = 0, endCount = 0; - -server.listen(common.PORT, function() { - var opts = { - port: common.PORT, - headers: { connection: 'close' } - }; - - http.get(opts, function(res) { - res.on('data', function(chunk) { - dataCount++; - res.pause(); - }); - - res.on('end', function() { - endCount++; - res.resume(); - }); - }); -}); - - -process.on('exit', function() { - assert.equal(1, dataCount); - assert.equal(1, endCount); -}); diff --git a/test/simple/test-http-pause.js b/test/simple/test-http-pause.js deleted file mode 100644 index 0edf6d62215f..000000000000 --- a/test/simple/test-http-pause.js +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var expectedServer = 'Request Body from Client'; -var resultServer = ''; -var expectedClient = 'Response Body from Server'; -var resultClient = ''; - -var server = http.createServer(function(req, res) { - common.debug('pause server request'); - req.pause(); - setTimeout(function() { - common.debug('resume server request'); - req.resume(); - req.setEncoding('utf8'); - req.on('data', function(chunk) { - resultServer += chunk; - }); - req.on('end', function() { - common.debug(resultServer); - res.writeHead(200); - res.end(expectedClient); - }); - }, 100); -}); - -server.listen(common.PORT, function() { - var req = http.request({ - port: common.PORT, - path: '/', - method: 'POST' - }, function(res) { - common.debug('pause client response'); - res.pause(); - setTimeout(function() { - common.debug('resume client response'); - res.resume(); - res.on('data', function(chunk) { - resultClient += chunk; - }); - res.on('end', function() { - common.debug(resultClient); - server.close(); - }); - }, 100); - }); - req.end(expectedServer); -}); - -process.on('exit', function() { - assert.equal(expectedServer, resultServer); - assert.equal(expectedClient, resultClient); -}); diff --git a/test/simple/test-http-pipe-fs.js b/test/simple/test-http-pipe-fs.js deleted file mode 100644 index 57ebb11dca5b..000000000000 --- a/test/simple/test-http-pipe-fs.js +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var fs = require('fs'); -var path = require('path'); - -var file = path.join(common.tmpDir, 'http-pipe-fs-test.txt'); -var requests = 0; - -var server = http.createServer(function(req, res) { - ++requests; - var stream = fs.createWriteStream(file); - req.pipe(stream); - stream.on('close', function() { - res.writeHead(200); - res.end(); - }); -}).listen(common.PORT, function() { - http.globalAgent.maxSockets = 1; - - for (var i = 0; i < 2; ++i) { - (function(i) { - var req = http.request({ - port: common.PORT, - method: 'POST', - headers: { - 'Content-Length': 5 - } - }, function(res) { - res.on('end', function() { - common.debug('res' + i + ' end'); - if (i === 2) { - server.close(); - } - }); - res.resume(); - }); - req.on('socket', function(s) { - common.debug('req' + i + ' start'); - }); - req.end('12345'); - }(i + 1)); - } -}); - -process.on('exit', function() { - assert.equal(requests, 2); -}); diff --git a/test/simple/test-http-pipeline-flood.js b/test/simple/test-http-pipeline-flood.js deleted file mode 100644 index 30925eef383b..000000000000 --- a/test/simple/test-http-pipeline-flood.js +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -switch (process.argv[2]) { - case undefined: - return parent(); - case 'child': - return child(); - default: - throw new Error('wtf'); -} - -function parent() { - var http = require('http'); - var bigResponse = new Buffer(10240) - bigResponse.fill('x'); - var gotTimeout = false; - var childClosed = false; - var requests = 0; - var connections = 0; - - var server = http.createServer(function(req, res) { - requests++; - res.setHeader('content-length', bigResponse.length); - res.end(bigResponse); - }); - - server.on('connection', function(conn) { - connections++; - }); - - // kill the connection after a bit, verifying that the - // flood of requests was eventually halted. - server.setTimeout(200, function(conn) { - gotTimeout = true; - conn.destroy(); - }); - - server.listen(common.PORT, function() { - var spawn = require('child_process').spawn; - var args = [__filename, 'child']; - var child = spawn(process.execPath, args, { stdio: 'inherit' }); - child.on('close', function(code) { - assert(!code); - childClosed = true; - server.close(); - }); - }); - - process.on('exit', function() { - assert(gotTimeout); - assert(childClosed); - assert.equal(connections, 1); - // 1213 works out to be the number of requests we end up processing - // before the outgoing connection backs up and requires a drain. - // however, to avoid being unnecessarily tied to a specific magic number, - // and making the test brittle, just assert that it's "a lot", which we - // can safely assume is more than 500. - assert(requests >= 500); - console.log('ok'); - }); -} - -function child() { - var net = require('net'); - - var gotEpipe = false; - var conn = net.connect({ port: common.PORT }); - - var req = 'GET / HTTP/1.1\r\nHost: localhost:' + - common.PORT + '\r\nAccept: */*\r\n\r\n'; - - req = new Array(10241).join(req); - - conn.on('connect', function() { - write(); - }); - - conn.on('drain', write); - - conn.on('error', function(er) { - gotEpipe = true; - }); - - process.on('exit', function() { - assert(gotEpipe); - console.log('ok - child'); - }); - - function write() { - while (false !== conn.write(req, 'ascii')); - } -} diff --git a/test/simple/test-http-proxy.js b/test/simple/test-http-proxy.js deleted file mode 100644 index 099afb9d0a3c..000000000000 --- a/test/simple/test-http-proxy.js +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); - -var PROXY_PORT = common.PORT; -var BACKEND_PORT = common.PORT + 1; - -var cookies = [ - 'session_token=; path=/; expires=Sun, 15-Sep-2030 13:48:52 GMT', - 'prefers_open_id=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT' -]; - -var headers = {'content-type': 'text/plain', - 'set-cookie': cookies, - 'hello': 'world' }; - -var backend = http.createServer(function(req, res) { - common.debug('backend request'); - res.writeHead(200, headers); - res.write('hello world\n'); - res.end(); -}); - -var proxy = http.createServer(function(req, res) { - common.debug('proxy req headers: ' + JSON.stringify(req.headers)); - var proxy_req = http.get({ - port: BACKEND_PORT, - path: url.parse(req.url).pathname - }, function(proxy_res) { - - common.debug('proxy res headers: ' + JSON.stringify(proxy_res.headers)); - - assert.equal('world', proxy_res.headers['hello']); - assert.equal('text/plain', proxy_res.headers['content-type']); - assert.deepEqual(cookies, proxy_res.headers['set-cookie']); - - res.writeHead(proxy_res.statusCode, proxy_res.headers); - - proxy_res.on('data', function(chunk) { - res.write(chunk); - }); - - proxy_res.on('end', function() { - res.end(); - common.debug('proxy res'); - }); - }); -}); - -var body = ''; - -var nlistening = 0; -function startReq() { - nlistening++; - if (nlistening < 2) return; - - var client = http.get({ - port: PROXY_PORT, - path: '/test' - }, function(res) { - common.debug('got res'); - assert.equal(200, res.statusCode); - - assert.equal('world', res.headers['hello']); - assert.equal('text/plain', res.headers['content-type']); - assert.deepEqual(cookies, res.headers['set-cookie']); - - res.setEncoding('utf8'); - res.on('data', function(chunk) { body += chunk; }); - res.on('end', function() { - proxy.close(); - backend.close(); - common.debug('closed both'); - }); - }); - common.debug('client req'); -} - -common.debug('listen proxy'); -proxy.listen(PROXY_PORT, startReq); - -common.debug('listen backend'); -backend.listen(BACKEND_PORT, startReq); - -process.on('exit', function() { - assert.equal(body, 'hello world\n'); -}); diff --git a/test/simple/test-http-request-end-twice.js b/test/simple/test-http-request-end-twice.js deleted file mode 100644 index aa5877222644..000000000000 --- a/test/simple/test-http-request-end-twice.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var server = http.Server(function(req, res) { - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end('hello world\n'); -}); -server.listen(common.PORT, function() { - var req = http.get({port: common.PORT}, function(res) { - res.on('end', function() { - assert.ok(!req.end()); - server.close(); - }); - res.resume(); - }); -}); - diff --git a/test/simple/test-http-request-end.js b/test/simple/test-http-request-end.js deleted file mode 100644 index f64dcc305ada..000000000000 --- a/test/simple/test-http-request-end.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var expected = 'Post Body For Test'; -var result = ''; - -var server = http.Server(function(req, res) { - req.setEncoding('utf8'); - req.on('data', function(chunk) { - result += chunk; - }); - - req.on('end', function() { - server.close(); - }); - - res.writeHead(200); - res.end('hello world\n'); -}); - -server.listen(common.PORT, function() { - http.request({ - port: common.PORT, - path: '/', - method: 'POST' - }, function(res) { - console.log(res.statusCode); - res.resume(); - }).on('error', function(e) { - console.log(e.message); - process.exit(1); - }).end(expected); -}); - -process.on('exit', function() { - assert.equal(expected, result); -}); diff --git a/test/simple/test-http-request-methods.js b/test/simple/test-http-request-methods.js deleted file mode 100644 index f0be3a046e53..000000000000 --- a/test/simple/test-http-request-methods.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); - -// Test that the PATCH and PURGE verbs get passed through correctly - -['PATCH', 'PURGE'].forEach(function(method, index) { - var port = common.PORT + index; - - var server_response = ''; - var received_method = null; - - var server = http.createServer(function(req, res) { - received_method = req.method; - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('hello '); - res.write('world\n'); - res.end(); - }); - server.listen(port); - - server.on('listening', function() { - var c = net.createConnection(port); - - c.setEncoding('utf8'); - - c.on('connect', function() { - c.write(method + ' / HTTP/1.0\r\n\r\n'); - }); - - c.on('data', function(chunk) { - console.log(chunk); - server_response += chunk; - }); - - c.on('end', function() { - c.end(); - }); - - c.on('close', function() { - server.close(); - }); - }); - - process.on('exit', function() { - var m = server_response.split('\r\n\r\n'); - assert.equal(m[1], 'hello world\n'); - assert.equal(received_method, method); - }); -}); diff --git a/test/simple/test-http-res-write-end-dont-take-array.js b/test/simple/test-http-res-write-end-dont-take-array.js deleted file mode 100644 index 0d68afc3f800..000000000000 --- a/test/simple/test-http-res-write-end-dont-take-array.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var test = 1; - -var server = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Type': 'text/plain'}); - if (test === 1) { - // write should accept string - res.write('string'); - // write should accept buffer - res.write(new Buffer('asdf')); - - // write should not accept an Array - assert.throws(function() { - res.write(['array']); - }, TypeError, 'first argument must be a string or Buffer'); - - // end should not accept an Array - assert.throws(function() { - res.end(['moo']); - }, TypeError, 'first argument must be a string or Buffer'); - - // end should accept string - res.end('string'); - } else if (test === 2) { - // end should accept Buffer - res.end(new Buffer('asdf')); - } -}); - -server.listen(common.PORT, function() { - // just make a request, other tests handle responses - http.get({port: common.PORT}, function(res) { - res.resume(); - // lazy serial test, becuase we can only call end once per request - test += 1; - // do it again to test .end(Buffer); - http.get({port: common.PORT}, function(res) { - res.resume(); - server.close(); - }); - }); -}); diff --git a/test/simple/test-http-response-close.js b/test/simple/test-http-response-close.js deleted file mode 100644 index be89682a6893..000000000000 --- a/test/simple/test-http-response-close.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var requestGotEnd = false; -var responseGotEnd = false; - -var server = http.createServer(function(req, res) { - res.writeHead(200); - res.write('a'); - - req.on('close', function() { - console.error('request aborted'); - requestGotEnd = true; - }); - res.on('close', function() { - console.error('response aborted'); - responseGotEnd = true; - }); -}); -server.listen(common.PORT); - -server.on('listening', function() { - console.error('make req'); - http.get({ - port: common.PORT - }, function(res) { - console.error('got res'); - res.on('data', function(data) { - console.error('destroy res'); - res.destroy(); - server.close(); - }); - }); -}); - -process.on('exit', function() { - assert.ok(requestGotEnd); - assert.ok(responseGotEnd); -}); diff --git a/test/simple/test-http-response-no-headers.js b/test/simple/test-http-response-no-headers.js deleted file mode 100644 index d16d8a4ce92f..000000000000 --- a/test/simple/test-http-response-no-headers.js +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -var expected = { - '0.9': 'I AM THE WALRUS', - '1.0': 'I AM THE WALRUS', - '1.1': '' -}; - -var gotExpected = false; - -function test(httpVersion, callback) { - process.on('exit', function() { - assert(gotExpected); - }); - - var server = net.createServer(function(conn) { - var reply = 'HTTP/' + httpVersion + ' 200 OK\r\n\r\n' + - expected[httpVersion]; - - conn.end(reply); - }); - - server.listen(common.PORT, '127.0.0.1', function() { - var options = { - host: '127.0.0.1', - port: common.PORT - }; - - var req = http.get(options, function(res) { - var body = ''; - - res.on('data', function(data) { - body += data; - }); - - res.on('end', function() { - assert.equal(body, expected[httpVersion]); - gotExpected = true; - server.close(); - if (callback) process.nextTick(callback); - }); - }); - - req.on('error', function(err) { - throw err; - }); - }); -} - -test('0.9', function() { - test('1.0', function() { - test('1.1'); - }); -}); diff --git a/test/simple/test-http-response-readable.js b/test/simple/test-http-response-readable.js deleted file mode 100644 index b48c06fb4094..000000000000 --- a/test/simple/test-http-response-readable.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var testServer = new http.Server(function(req, res) { - res.writeHead(200); - res.end('Hello world'); -}); - -testServer.listen(common.PORT, function() { - http.get({ port: common.PORT }, function(res) { - assert.equal(res.readable, true, 'res.readable initially true'); - res.on('end', function() { - assert.equal(res.readable, false, 'res.readable set to false after end'); - testServer.close(); - }); - res.resume(); - }); -}); - diff --git a/test/simple/test-http-server-multiheaders.js b/test/simple/test-http-server-multiheaders.js deleted file mode 100644 index b287169bdab9..000000000000 --- a/test/simple/test-http-server-multiheaders.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Verify that the HTTP server implementation handles multiple instances -// of the same header as per RFC2616: joining the handful of fields by ', ' -// that support it, and dropping duplicates for other fields. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var srv = http.createServer(function(req, res) { - assert.equal(req.headers.accept, 'abc, def, ghijklmnopqrst'); - assert.equal(req.headers.host, 'foo'); - assert.equal(req.headers['www-authenticate'], 'foo, bar, baz'); - assert.equal(req.headers['proxy-authenticate'], 'foo, bar, baz'); - assert.equal(req.headers['x-foo'], 'bingo'); - assert.equal(req.headers['x-bar'], 'banjo, bango'); - assert.equal(req.headers['sec-websocket-protocol'], 'chat, share'); - assert.equal(req.headers['sec-websocket-extensions'], 'foo; 1, bar; 2, baz'); - - res.writeHead(200, {'Content-Type' : 'text/plain'}); - res.end('EOF'); - - srv.close(); -}); - -srv.listen(common.PORT, function() { - http.get({ - host: 'localhost', - port: common.PORT, - path: '/', - headers: [ - ['accept', 'abc'], - ['accept', 'def'], - ['Accept', 'ghijklmnopqrst'], - ['host', 'foo'], - ['Host', 'bar'], - ['hOst', 'baz'], - ['www-authenticate', 'foo'], - ['WWW-Authenticate', 'bar'], - ['WWW-AUTHENTICATE', 'baz'], - ['proxy-authenticate','foo'], - ['Proxy-Authenticate','bar'], - ['PROXY-AUTHENTICATE','baz'], - ['x-foo', 'bingo'], - ['x-bar', 'banjo'], - ['x-bar', 'bango'], - ['sec-websocket-protocol', 'chat'], - ['sec-websocket-protocol', 'share'], - ['sec-websocket-extensions', 'foo; 1'], - ['sec-websocket-extensions', 'bar; 2'], - ['sec-websocket-extensions', 'baz'] - ] - }); -}); diff --git a/test/simple/test-http-server-stale-close.js b/test/simple/test-http-server-stale-close.js deleted file mode 100644 index aa42a049bb85..000000000000 --- a/test/simple/test-http-server-stale-close.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var util = require('util'); -var fork = require('child_process').fork; - -if (process.env.NODE_TEST_FORK) { - var req = http.request({ - headers: {'Content-Length': '42'}, - method: 'POST', - host: '127.0.0.1', - port: common.PORT, - }, process.exit); - req.write('BAM'); - req.end(); -} -else { - var server = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Length': '42'}); - req.pipe(res); - req.on('close', function() { - server.close(); - res.end(); - }); - }); - server.listen(common.PORT, function() { - fork(__filename, { - env: util._extend(process.env, {NODE_TEST_FORK: '1'}) - }); - }); -} diff --git a/test/simple/test-http-server.js b/test/simple/test-http-server.js deleted file mode 100644 index 7d97382d3e49..000000000000 --- a/test/simple/test-http-server.js +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); -var url = require('url'); -var qs = require('querystring'); - -var request_number = 0; -var requests_sent = 0; -var server_response = ''; -var client_got_eof = false; - -var server = http.createServer(function(req, res) { - res.id = request_number; - req.id = request_number++; - - if (req.id == 0) { - assert.equal('GET', req.method); - assert.equal('/hello', url.parse(req.url).pathname); - assert.equal('world', qs.parse(url.parse(req.url).query).hello); - assert.equal('b==ar', qs.parse(url.parse(req.url).query).foo); - } - - if (req.id == 1) { - common.error('req 1'); - assert.equal('POST', req.method); - assert.equal('/quit', url.parse(req.url).pathname); - } - - if (req.id == 2) { - common.error('req 2'); - assert.equal('foo', req.headers['x-x']); - } - - if (req.id == 3) { - common.error('req 3'); - assert.equal('bar', req.headers['x-x']); - this.close(); - common.error('server closed'); - } - - setTimeout(function() { - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write(url.parse(req.url).pathname); - res.end(); - }, 1); - -}); -server.listen(common.PORT); - -server.httpAllowHalfOpen = true; - -server.on('listening', function() { - var c = net.createConnection(common.PORT); - - c.setEncoding('utf8'); - - c.on('connect', function() { - c.write('GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n'); - requests_sent += 1; - }); - - c.on('data', function(chunk) { - server_response += chunk; - - if (requests_sent == 1) { - c.write('POST /quit HTTP/1.1\r\n\r\n'); - requests_sent += 1; - } - - if (requests_sent == 2) { - c.write('GET / HTTP/1.1\r\nX-X: foo\r\n\r\n' + - 'GET / HTTP/1.1\r\nX-X: bar\r\n\r\n'); - // Note: we are making the connection half-closed here - // before we've gotten the response from the server. This - // is a pretty bad thing to do and not really supported - // by many http servers. Node supports it optionally if - // you set server.httpAllowHalfOpen=true, which we've done - // above. - c.end(); - assert.equal(c.readyState, 'readOnly'); - requests_sent += 2; - } - - }); - - c.on('end', function() { - client_got_eof = true; - }); - - c.on('close', function() { - assert.equal(c.readyState, 'closed'); - }); -}); - -process.on('exit', function() { - assert.equal(4, request_number); - assert.equal(4, requests_sent); - - var hello = new RegExp('/hello'); - assert.equal(true, hello.exec(server_response) != null); - - var quit = new RegExp('/quit'); - assert.equal(true, quit.exec(server_response) != null); - - assert.equal(true, client_got_eof); -}); diff --git a/test/simple/test-http-set-cookies.js b/test/simple/test-http-set-cookies.js deleted file mode 100644 index bff34d82982c..000000000000 --- a/test/simple/test-http-set-cookies.js +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var nresponses = 0; - -var server = http.createServer(function(req, res) { - if (req.url == '/one') { - res.writeHead(200, [['set-cookie', 'A'], - ['content-type', 'text/plain']]); - res.end('one\n'); - } else { - res.writeHead(200, [['set-cookie', 'A'], - ['set-cookie', 'B'], - ['content-type', 'text/plain']]); - res.end('two\n'); - } -}); -server.listen(common.PORT); - -server.on('listening', function() { - // - // one set-cookie header - // - http.get({ port: common.PORT, path: '/one' }, function(res) { - // set-cookie headers are always return in an array. - // even if there is only one. - assert.deepEqual(['A'], res.headers['set-cookie']); - assert.equal('text/plain', res.headers['content-type']); - - res.on('data', function(chunk) { - console.log(chunk.toString()); - }); - - res.on('end', function() { - if (++nresponses == 2) { - server.close(); - } - }); - }); - - // two set-cookie headers - - http.get({ port: common.PORT, path: '/two' }, function(res) { - assert.deepEqual(['A', 'B'], res.headers['set-cookie']); - assert.equal('text/plain', res.headers['content-type']); - - res.on('data', function(chunk) { - console.log(chunk.toString()); - }); - - res.on('end', function() { - if (++nresponses == 2) { - server.close(); - } - }); - }); - -}); - -process.on('exit', function() { - assert.equal(2, nresponses); -}); diff --git a/test/simple/test-http-set-timeout-server.js b/test/simple/test-http-set-timeout-server.js deleted file mode 100644 index ff4144963afc..000000000000 --- a/test/simple/test-http-set-timeout-server.js +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -var tests = []; - -function test(fn) { - if (!tests.length) - process.nextTick(run); - tests.push(fn); -} - -function run() { - var fn = tests.shift(); - if (fn) { - console.log('# %s', fn.name); - fn(run); - } else - console.log('ok'); -} - -test(function serverTimeout(cb) { - var caughtTimeout = false; - process.on('exit', function() { - assert(caughtTimeout); - }); - var server = http.createServer(function(req, res) { - // just do nothing, we should get a timeout event. - }); - server.listen(common.PORT); - server.setTimeout(50, function(socket) { - caughtTimeout = true; - socket.destroy(); - server.close(); - cb(); - }); - http.get({ port: common.PORT }).on('error', function() {}); -}); - -test(function serverRequestTimeout(cb) { - var caughtTimeout = false; - process.on('exit', function() { - assert(caughtTimeout); - }); - var server = http.createServer(function(req, res) { - // just do nothing, we should get a timeout event. - req.setTimeout(50, function() { - caughtTimeout = true; - req.socket.destroy(); - server.close(); - cb(); - }); - }); - server.listen(common.PORT); - var req = http.request({ port: common.PORT, method: 'POST' }); - req.on('error', function() {}); - req.write('Hello'); - // req is in progress -}); - -test(function serverResponseTimeout(cb) { - var caughtTimeout = false; - process.on('exit', function() { - assert(caughtTimeout); - }); - var server = http.createServer(function(req, res) { - // just do nothing, we should get a timeout event. - res.setTimeout(50, function() { - caughtTimeout = true; - res.socket.destroy(); - server.close(); - cb(); - }); - }); - server.listen(common.PORT); - http.get({ port: common.PORT }).on('error', function() {}); -}); - -test(function serverRequestNotTimeoutAfterEnd(cb) { - var caughtTimeoutOnRequest = false; - var caughtTimeoutOnResponse = false; - process.on('exit', function() { - assert(!caughtTimeoutOnRequest); - assert(caughtTimeoutOnResponse); - }); - var server = http.createServer(function(req, res) { - // just do nothing, we should get a timeout event. - req.setTimeout(50, function(socket) { - caughtTimeoutOnRequest = true; - }); - res.on('timeout', function(socket) { - caughtTimeoutOnResponse = true; - }); - }); - server.on('timeout', function(socket) { - socket.destroy(); - server.close(); - cb(); - }); - server.listen(common.PORT); - http.get({ port: common.PORT }).on('error', function() {}); -}); - -test(function serverResponseTimeoutWithPipeline(cb) { - var caughtTimeout = ''; - process.on('exit', function() { - assert.equal(caughtTimeout, '/2'); - }); - var server = http.createServer(function(req, res) { - res.setTimeout(50, function() { - caughtTimeout += req.url; - }); - if (req.url === '/1') res.end(); - }); - server.on('timeout', function(socket) { - socket.destroy(); - server.close(); - cb(); - }); - server.listen(common.PORT); - var c = net.connect({ port: common.PORT, allowHalfOpen: true }, function() { - c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); - c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); - c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); - }); -}); - -test(function idleTimeout(cb) { - var caughtTimeoutOnRequest = false; - var caughtTimeoutOnResponse = false; - var caughtTimeoutOnServer = false; - process.on('exit', function() { - assert(!caughtTimeoutOnRequest); - assert(!caughtTimeoutOnResponse); - assert(caughtTimeoutOnServer); - }); - var server = http.createServer(function(req, res) { - req.on('timeout', function(socket) { - caughtTimeoutOnRequest = true; - }); - res.on('timeout', function(socket) { - caughtTimeoutOnResponse = true; - }); - res.end(); - }); - server.setTimeout(50, function(socket) { - caughtTimeoutOnServer = true; - socket.destroy(); - server.close(); - cb(); - }); - server.listen(common.PORT); - var c = net.connect({ port: common.PORT, allowHalfOpen: true }, function() { - c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); - // Keep-Alive - }); -}); diff --git a/test/simple/test-http-set-timeout.js b/test/simple/test-http-set-timeout.js deleted file mode 100644 index 01d182b34c50..000000000000 --- a/test/simple/test-http-set-timeout.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var server = http.createServer(function(req, res) { - console.log('got request. setting 1 second timeout'); - req.connection.setTimeout(500); - - req.connection.on('timeout', function() { - req.connection.destroy(); - common.debug('TIMEOUT'); - server.close(); - }); -}); - -server.listen(common.PORT, function() { - console.log('Server running at http://127.0.0.1:' + common.PORT + '/'); - - var errorTimer = setTimeout(function() { - throw new Error('Timeout was not successful'); - }, 2000); - - var x = http.get({port: common.PORT, path: '/'}); - x.on('error', function() { - clearTimeout(errorTimer); - console.log('HTTP REQUEST COMPLETE (this is good)'); - }); - x.end(); - -}); diff --git a/test/simple/test-http-set-trailers.js b/test/simple/test-http-set-trailers.js deleted file mode 100644 index 445a3eeaacc9..000000000000 --- a/test/simple/test-http-set-trailers.js +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -var outstanding_reqs = 0; - -var server = http.createServer(function(req, res) { - res.writeHead(200, [['content-type', 'text/plain']]); - res.addTrailers({'x-foo': 'bar'}); - res.end('stuff' + '\n'); -}); -server.listen(common.PORT); - - -// first, we test an HTTP/1.0 request. -server.on('listening', function() { - var c = net.createConnection(common.PORT); - var res_buffer = ''; - - c.setEncoding('utf8'); - - c.on('connect', function() { - outstanding_reqs++; - c.write('GET / HTTP/1.0\r\n\r\n'); - }); - - c.on('data', function(chunk) { - //console.log(chunk); - res_buffer += chunk; - }); - - c.on('end', function() { - c.end(); - assert.ok(! /x-foo/.test(res_buffer), 'Trailer in HTTP/1.0 response.'); - outstanding_reqs--; - if (outstanding_reqs == 0) { - server.close(); - process.exit(); - } - }); -}); - -// now, we test an HTTP/1.1 request. -server.on('listening', function() { - var c = net.createConnection(common.PORT); - var res_buffer = ''; - var tid; - - c.setEncoding('utf8'); - - c.on('connect', function() { - outstanding_reqs++; - c.write('GET / HTTP/1.1\r\n\r\n'); - tid = setTimeout(assert.fail, 2000, 'Couldn\'t find last chunk.'); - }); - - c.on('data', function(chunk) { - //console.log(chunk); - res_buffer += chunk; - if (/0\r\n/.test(res_buffer)) { // got the end. - outstanding_reqs--; - clearTimeout(tid); - assert.ok( - /0\r\nx-foo: bar\r\n\r\n$/.test(res_buffer), - 'No trailer in HTTP/1.1 response.' - ); - if (outstanding_reqs == 0) { - server.close(); - process.exit(); - } - } - }); -}); - -// now, see if the client sees the trailers. -server.on('listening', function() { - http.get({ port: common.PORT, path: '/hello', headers: {} }, function(res) { - res.on('end', function() { - //console.log(res.trailers); - assert.ok('x-foo' in res.trailers, 'Client doesn\'t see trailers.'); - outstanding_reqs--; - if (outstanding_reqs == 0) { - server.close(); - process.exit(); - } - }); - res.resume(); - }); - outstanding_reqs++; -}); diff --git a/test/simple/test-http-should-keep-alive.js b/test/simple/test-http-should-keep-alive.js deleted file mode 100644 index e2303be7bf60..000000000000 --- a/test/simple/test-http-should-keep-alive.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -var SERVER_RESPONSES = [ - 'HTTP/1.0 200 ok\r\nContent-Length: 0\r\n\r\n', - 'HTTP/1.0 200 ok\r\nContent-Length: 0\r\nConnection: keep-alive\r\n\r\n', - 'HTTP/1.0 200 ok\r\nContent-Length: 0\r\nConnection: close\r\n\r\n', - 'HTTP/1.1 200 ok\r\nContent-Length: 0\r\n\r\n', - 'HTTP/1.1 200 ok\r\nContent-Length: 0\r\nConnection: keep-alive\r\n\r\n', - 'HTTP/1.1 200 ok\r\nContent-Length: 0\r\nConnection: close\r\n\r\n' -]; -var SHOULD_KEEP_ALIVE = [ - false, // HTTP/1.0, default - true, // HTTP/1.0, Connection: keep-alive - false, // HTTP/1.0, Connection: close - true, // HTTP/1.1, default - true, // HTTP/1.1, Connection: keep-alive - false // HTTP/1.1, Connection: close -]; -var requests = 0; -var responses = 0; - -var server = net.createServer(function(socket) { - socket.write(SERVER_RESPONSES[requests]); - ++requests; -}).listen(common.PORT, function() { - function makeRequest() { - var req = http.get({port: common.PORT}, function(res) { - assert.equal(req.shouldKeepAlive, SHOULD_KEEP_ALIVE[responses], - SERVER_RESPONSES[responses] + ' should ' + - (SHOULD_KEEP_ALIVE[responses] ? '' : 'not ') + - 'Keep-Alive'); - ++responses; - if (responses < SHOULD_KEEP_ALIVE.length) { - makeRequest(); - } else { - server.close(); - } - res.resume(); - }); - } - - makeRequest(); -}); - -process.on('exit', function() { - assert.equal(requests, SERVER_RESPONSES.length); - assert.equal(responses, SHOULD_KEEP_ALIVE.length); -}); diff --git a/test/simple/test-http-status-code.js b/test/simple/test-http-status-code.js deleted file mode 100644 index ca56230d264f..000000000000 --- a/test/simple/test-http-status-code.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -// Simple test of Node's HTTP ServerResponse.statusCode -// ServerResponse.prototype.statusCode - -var testsComplete = 0; -var tests = [200, 202, 300, 404, 500]; -var testIdx = 0; - -var s = http.createServer(function(req, res) { - var t = tests[testIdx]; - res.writeHead(t, {'Content-Type': 'text/plain'}); - console.log('--\nserver: statusCode after writeHead: ' + res.statusCode); - assert.equal(res.statusCode, t); - res.end('hello world\n'); -}); - -s.listen(common.PORT, nextTest); - - -function nextTest() { - if (testIdx + 1 === tests.length) { - return s.close(); - } - var test = tests[testIdx]; - - http.get({ port: common.PORT }, function(response) { - console.log('client: expected status: ' + test); - console.log('client: statusCode: ' + response.statusCode); - assert.equal(response.statusCode, test); - response.on('end', function() { - testsComplete++; - testIdx += 1; - nextTest(); - }); - response.resume(); - }); -} - - -process.on('exit', function() { - assert.equal(4, testsComplete); -}); - diff --git a/test/simple/test-http-timeout-overflow.js b/test/simple/test-http-timeout-overflow.js deleted file mode 100644 index 3e62612b38ec..000000000000 --- a/test/simple/test-http-timeout-overflow.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); - -var port = common.PORT; -var serverRequests = 0; -var clientRequests = 0; - -var server = http.createServer(function(req, res) { - serverRequests++; - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end('OK'); -}); - -server.listen(port, function() { - function callback(){} - - var req = http.request({ - port: port, - path: '/', - agent: false - }, function(res) { - req.clearTimeout(callback); - - res.on('end', function() { - clientRequests++; - server.close(); - }) - - res.resume(); - }); - - // Overflow signed int32 - req.setTimeout(0xffffffff, callback); - req.end(); -}); - -process.once('exit', function() { - assert.equal(clientRequests, 1); - assert.equal(serverRequests, 1); -}); diff --git a/test/simple/test-http-timeout.js b/test/simple/test-http-timeout.js deleted file mode 100644 index ddd01c8a8f58..000000000000 --- a/test/simple/test-http-timeout.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); - -var port = common.PORT; - -var server = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end('OK'); -}); - -var agent = new http.Agent({maxSockets: 1}); - -server.listen(port, function() { - - for (var i = 0; i < 11; ++i) { - createRequest().end(); - } - - function callback(){} - - var count = 0; - - function createRequest() { - var req = http.request({port: port, path: '/', agent: agent}, function(res) { - - req.clearTimeout(callback); - - res.on('end', function() { - count++; - - if (count == 11) { - server.close(); - } - }) - - res.resume(); - }); - - req.setTimeout(1000, callback); - return req; - } -}); diff --git a/test/simple/test-http-unix-socket.js b/test/simple/test-http-unix-socket.js deleted file mode 100644 index 01c29c113b52..000000000000 --- a/test/simple/test-http-unix-socket.js +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var http = require('http'); - -var status_ok = false; // status code == 200? -var headers_ok = false; -var body_ok = false; - -var server = http.createServer(function(req, res) { - res.writeHead(200, { - 'Content-Type': 'text/plain', - 'Connection': 'close' - }); - res.write('hello '); - res.write('world\n'); - res.end(); -}); - -server.listen(common.PIPE, function() { - - var options = { - socketPath: common.PIPE, - path: '/' - }; - - var req = http.get(options, function(res) { - assert.equal(res.statusCode, 200); - status_ok = true; - - assert.equal(res.headers['content-type'], 'text/plain'); - headers_ok = true; - - res.body = ''; - res.setEncoding('utf8'); - - res.on('data', function(chunk) { - res.body += chunk; - }); - - res.on('end', function() { - assert.equal(res.body, 'hello world\n'); - body_ok = true; - server.close(); - }); - }); - - req.on('error', function(e) { - console.log(e.stack); - process.exit(1); - }); - - req.end(); - -}); - -process.on('exit', function() { - assert.ok(status_ok); - assert.ok(headers_ok); - assert.ok(body_ok); - - // Double close should throw. Follows net_legacy behaviour. - assert.throws(function() { - server.close(); - }); -}); diff --git a/test/simple/test-http-upgrade-agent.js b/test/simple/test-http-upgrade-agent.js deleted file mode 100644 index 1077a983dcbc..000000000000 --- a/test/simple/test-http-upgrade-agent.js +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Verify that the 'upgrade' header causes an 'upgrade' event to be emitted to -// the HTTP client. This test uses a raw TCP server to better control server -// behavior. - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); -var net = require('net'); - -// Create a TCP server -var srv = net.createServer(function(c) { - var data = ''; - c.on('data', function(d) { - data += d.toString('utf8'); - - c.write('HTTP/1.1 101\r\n'); - c.write('hello: world\r\n'); - c.write('connection: upgrade\r\n'); - c.write('upgrade: websocket\r\n'); - c.write('\r\n'); - c.write('nurtzo'); - }); - - c.on('end', function() { - c.end(); - }); -}); - -var gotUpgrade = false; - -srv.listen(common.PORT, '127.0.0.1', function() { - - var options = { - port: common.PORT, - host: '127.0.0.1', - headers: { - 'upgrade': 'websocket' - } - }; - var name = options.host + ':' + options.port; - - var req = http.request(options); - req.end(); - - req.on('upgrade', function(res, socket, upgradeHead) { - // XXX: This test isn't fantastic, as it assumes that the entire response - // from the server will arrive in a single data callback - assert.equal(upgradeHead, 'nurtzo'); - - console.log(res.headers); - var expectedHeaders = { 'hello': 'world', - 'connection': 'upgrade', - 'upgrade': 'websocket' }; - assert.deepEqual(expectedHeaders, res.headers); - - // Make sure this request got removed from the pool. - assert(!http.globalAgent.sockets.hasOwnProperty(name)); - - req.on('close', function() { - socket.end(); - srv.close(); - - gotUpgrade = true; - }); - }); - -}); - -process.on('exit', function() { - assert.ok(gotUpgrade); -}); diff --git a/test/simple/test-http-upgrade-client.js b/test/simple/test-http-upgrade-client.js deleted file mode 100644 index 3bf5beccf5bd..000000000000 --- a/test/simple/test-http-upgrade-client.js +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Verify that the 'upgrade' header causes an 'upgrade' event to be emitted to -// the HTTP client. This test uses a raw TCP server to better control server -// behavior. - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); -var net = require('net'); - -// Create a TCP server -var srv = net.createServer(function(c) { - var data = ''; - c.on('data', function(d) { - data += d.toString('utf8'); - - c.write('HTTP/1.1 101\r\n'); - c.write('hello: world\r\n'); - c.write('connection: upgrade\r\n'); - c.write('upgrade: websocket\r\n'); - c.write('\r\n'); - c.write('nurtzo'); - }); - - c.on('end', function() { - c.end(); - }); -}); - -var gotUpgrade = false; - -srv.listen(common.PORT, '127.0.0.1', function() { - - var req = http.get({ port: common.PORT }); - req.on('upgrade', function(res, socket, upgradeHead) { - // XXX: This test isn't fantastic, as it assumes that the entire response - // from the server will arrive in a single data callback - assert.equal(upgradeHead, 'nurtzo'); - - console.log(res.headers); - var expectedHeaders = {'hello': 'world', - 'connection': 'upgrade', - 'upgrade': 'websocket' }; - assert.deepEqual(expectedHeaders, res.headers); - - socket.end(); - srv.close(); - - gotUpgrade = true; - }); -}); - -process.on('exit', function() { - assert.ok(gotUpgrade); -}); diff --git a/test/simple/test-http-upgrade-client2.js b/test/simple/test-http-upgrade-client2.js deleted file mode 100644 index fa39f2a572c4..000000000000 --- a/test/simple/test-http-upgrade-client2.js +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var CRLF = '\r\n'; - -var server = http.createServer(); -server.on('upgrade', function(req, socket, head) { - socket.write('HTTP/1.1 101 Ok' + CRLF + - 'Connection: Upgrade' + CRLF + - 'Upgrade: Test' + CRLF + CRLF + 'head'); - socket.on('end', function() { - socket.end(); - }); -}); - -var successCount = 0; - -server.listen(common.PORT, function() { - - function upgradeRequest(fn) { - console.log('req'); - var header = { 'Connection': 'Upgrade', 'Upgrade': 'Test' }; - var request = http.request({ port: common.PORT, headers: header }); - var wasUpgrade = false; - - function onUpgrade(res, socket, head) { - console.log('client upgraded'); - wasUpgrade = true; - - request.removeListener('upgrade', onUpgrade); - socket.end(); - } - request.on('upgrade', onUpgrade); - - function onEnd() { - console.log('client end'); - request.removeListener('end', onEnd); - if (!wasUpgrade) { - throw new Error('hasn\'t received upgrade event'); - } else { - fn && process.nextTick(fn); - } - } - request.on('close', onEnd); - - request.write('head'); - - } - - upgradeRequest(function() { - successCount++; - upgradeRequest(function() { - successCount++; - // Test pass - console.log('Pass!'); - server.close(); - }); - }); - -}); - -process.on('exit', function() { - assert.equal(2, successCount); -}); diff --git a/test/simple/test-http-upgrade-server.js b/test/simple/test-http-upgrade-server.js deleted file mode 100644 index 6a14d39aa5bc..000000000000 --- a/test/simple/test-http-upgrade-server.js +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var util = require('util'); -var net = require('net'); -var http = require('http'); - - -var requests_recv = 0; -var requests_sent = 0; -var request_upgradeHead = null; - -function createTestServer() { - return new testServer(); -} - -function testServer() { - var server = this; - http.Server.call(server, function() {}); - - server.on('connection', function() { - requests_recv++; - }); - - server.on('request', function(req, res) { - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('okay'); - res.end(); - }); - - server.on('upgrade', function(req, socket, upgradeHead) { - socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' + - 'Upgrade: WebSocket\r\n' + - 'Connection: Upgrade\r\n' + - '\r\n\r\n'); - - request_upgradeHead = upgradeHead; - - socket.ondata = function(d, start, end) { - var data = d.toString('utf8', start, end); - if (data == 'kill') { - socket.end(); - } else { - socket.write(data, 'utf8'); - } - }; - }); -} - -util.inherits(testServer, http.Server); - - -function writeReq(socket, data, encoding) { - requests_sent++; - socket.write(data); -} - - -/*----------------------------------------------- - connection: Upgrade with listener ------------------------------------------------*/ -function test_upgrade_with_listener(_server) { - var conn = net.createConnection(common.PORT); - conn.setEncoding('utf8'); - var state = 0; - - conn.on('connect', function() { - writeReq(conn, - 'GET / HTTP/1.1\r\n' + - 'Upgrade: WebSocket\r\n' + - 'Connection: Upgrade\r\n' + - '\r\n' + - 'WjN}|M(6'); - }); - - conn.on('data', function(data) { - state++; - - assert.equal('string', typeof data); - - if (state == 1) { - assert.equal('HTTP/1.1 101', data.substr(0, 12)); - assert.equal('WjN}|M(6', request_upgradeHead.toString('utf8')); - conn.write('test', 'utf8'); - } else if (state == 2) { - assert.equal('test', data); - conn.write('kill', 'utf8'); - } - }); - - conn.on('end', function() { - assert.equal(2, state); - conn.end(); - _server.removeAllListeners('upgrade'); - test_upgrade_no_listener(); - }); -} - -/*----------------------------------------------- - connection: Upgrade, no listener ------------------------------------------------*/ -var test_upgrade_no_listener_ended = false; - -function test_upgrade_no_listener() { - var conn = net.createConnection(common.PORT); - conn.setEncoding('utf8'); - - conn.on('connect', function() { - writeReq(conn, - 'GET / HTTP/1.1\r\n' + - 'Upgrade: WebSocket\r\n' + - 'Connection: Upgrade\r\n' + - '\r\n'); - }); - - conn.on('end', function() { - test_upgrade_no_listener_ended = true; - conn.end(); - }); - - conn.on('close', function() { - test_standard_http(); - }); -} - -/*----------------------------------------------- - connection: normal ------------------------------------------------*/ -function test_standard_http() { - var conn = net.createConnection(common.PORT); - conn.setEncoding('utf8'); - - conn.on('connect', function() { - writeReq(conn, 'GET / HTTP/1.1\r\n\r\n'); - }); - - conn.on('data', function(data) { - assert.equal('string', typeof data); - assert.equal('HTTP/1.1 200', data.substr(0, 12)); - conn.end(); - }); - - conn.on('close', function() { - server.close(); - }); -} - - -var server = createTestServer(); - -server.listen(common.PORT, function() { - // All tests get chained after this: - test_upgrade_with_listener(server); -}); - - -/*----------------------------------------------- - Fin. ------------------------------------------------*/ -process.on('exit', function() { - assert.equal(3, requests_recv); - assert.equal(3, requests_sent); - assert.ok(test_upgrade_no_listener_ended); -}); diff --git a/test/simple/test-http-upgrade-server2.js b/test/simple/test-http-upgrade-server2.js deleted file mode 100644 index e617d3b1c55f..000000000000 --- a/test/simple/test-http-upgrade-server2.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -var server = http.createServer(function(req, res) { - common.error('got req'); - throw new Error('This shouldn\'t happen.'); -}); - -server.on('upgrade', function(req, socket, upgradeHead) { - common.error('got upgrade event'); - // test that throwing an error from upgrade gets - // is uncaught - throw new Error('upgrade error'); -}); - -var gotError = false; - -process.on('uncaughtException', function(e) { - common.error('got \'clientError\' event'); - assert.equal('upgrade error', e.message); - gotError = true; - process.exit(0); -}); - - -server.listen(common.PORT, function() { - var c = net.createConnection(common.PORT); - - c.on('connect', function() { - common.error('client wrote message'); - c.write('GET /blah HTTP/1.1\r\n' + - 'Upgrade: WebSocket\r\n' + - 'Connection: Upgrade\r\n' + - '\r\n\r\nhello world'); - }); - - c.on('end', function() { - c.end(); - }); - - c.on('close', function() { - common.error('client close'); - server.close(); - }); -}); - -process.on('exit', function() { - assert.ok(gotError); -}); diff --git a/test/simple/test-http-url.parse-auth-with-header-in-request.js b/test/simple/test-http-url.parse-auth-with-header-in-request.js deleted file mode 100644 index 5ac789068e68..000000000000 --- a/test/simple/test-http-url.parse-auth-with-header-in-request.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); - -var testURL = url.parse('http://asdf:qwer@localhost:' + common.PORT); -// the test here is if you set a specific authorization header in the -// request we should not override that with basic auth -testURL.headers = { - Authorization: 'NoAuthForYOU' -}; - -function check(request) { - // the correct authorization header is be passed - assert.strictEqual(request.headers.authorization, 'NoAuthForYOU'); -} - -var server = http.createServer(function(request, response) { - // run the check function - check.call(this, request, response); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(common.PORT, function() { - // make the request - http.request(testURL).end(); -}); diff --git a/test/simple/test-http-url.parse-auth.js b/test/simple/test-http-url.parse-auth.js deleted file mode 100644 index 4c07d5ffccf5..000000000000 --- a/test/simple/test-http-url.parse-auth.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); - -// username = "user", password = "pass:" -var testURL = url.parse('http://user:pass%3A@localhost:' + common.PORT); - -function check(request) { - // the correct authorization header is be passed - assert.strictEqual(request.headers.authorization, 'Basic dXNlcjpwYXNzOg=='); -} - -var server = http.createServer(function(request, response) { - // run the check function - check.call(this, request, response); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(common.PORT, function() { - // make the request - http.request(testURL).end(); -}); diff --git a/test/simple/test-http-url.parse-basic.js b/test/simple/test-http-url.parse-basic.js deleted file mode 100644 index 8bf12b1c2dfa..000000000000 --- a/test/simple/test-http-url.parse-basic.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); - -var testURL = url.parse('http://localhost:' + common.PORT); - -// make sure the basics work -function check(request) { - // default method should still be get - assert.strictEqual(request.method, 'GET'); - // there are no URL params, so you should not see any - assert.strictEqual(request.url, '/'); - // the host header should use the url.parse.hostname - assert.strictEqual(request.headers.host, - testURL.hostname + ':' + testURL.port); -} - -var server = http.createServer(function(request, response) { - // run the check function - check.call(this, request, response); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(common.PORT, function() { - // make the request - var clientRequest = http.request(testURL); - // since there is a little magic with the agent - // make sure that an http request uses the http.Agent - assert.ok(clientRequest.agent instanceof http.Agent); - clientRequest.end(); -}); diff --git a/test/simple/test-http-url.parse-https.request.js b/test/simple/test-http-url.parse-https.request.js deleted file mode 100644 index bcf37526a85e..000000000000 --- a/test/simple/test-http-url.parse-https.request.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var url = require('url'); -var fs = require('fs'); -var clientRequest; - -// https options -var httpsOptions = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var testURL = url.parse('https://localhost:' + common.PORT); -testURL.rejectUnauthorized = false; - -function check(request) { - // assert that I'm https - assert.ok(request.socket.encrypted); -} - -var server = https.createServer(httpsOptions, function(request, response) { - // run the check function - check.call(this, request, response); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(common.PORT, function() { - // make the request - var clientRequest = https.request(testURL); - // since there is a little magic with the agent - // make sure that the request uses the https.Agent - assert.ok(clientRequest.agent instanceof https.Agent); - clientRequest.end(); -}); diff --git a/test/simple/test-http-url.parse-only-support-http-https-protocol.js b/test/simple/test-http-url.parse-only-support-http-https-protocol.js deleted file mode 100644 index c77df5e20b0e..000000000000 --- a/test/simple/test-http-url.parse-only-support-http-https-protocol.js +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); - - -assert.throws(function() { - http.request(url.parse('file:///whatever')); -}, function(err) { - if (err instanceof Error) { - assert.strictEqual(err.message, 'Protocol:file: not supported.'); - return true; - } -}); - -assert.throws(function() { - http.request(url.parse('mailto:asdf@asdf.com')); -}, function(err) { - if (err instanceof Error) { - assert.strictEqual(err.message, 'Protocol:mailto: not supported.'); - return true; - } -}); - -assert.throws(function() { - http.request(url.parse('ftp://www.example.com')); -}, function(err) { - if (err instanceof Error) { - assert.strictEqual(err.message, 'Protocol:ftp: not supported.'); - return true; - } -}); - -assert.throws(function() { - http.request(url.parse('javascript:alert(\'hello\');')); -}, function(err) { - if (err instanceof Error) { - assert.strictEqual(err.message, 'Protocol:javascript: not supported.'); - return true; - } -}); - -assert.throws(function() { - http.request(url.parse('xmpp:isaacschlueter@jabber.org')); -}, function(err) { - if (err instanceof Error) { - assert.strictEqual(err.message, 'Protocol:xmpp: not supported.'); - return true; - } -}); - -assert.throws(function() { - http.request(url.parse('f://some.host/path')); -}, function(err) { - if (err instanceof Error) { - assert.strictEqual(err.message, 'Protocol:f: not supported.'); - return true; - } -}); - -//TODO do I need to test url.parse(notPrococol.example.com)? diff --git a/test/simple/test-http-url.parse-path.js b/test/simple/test-http-url.parse-path.js deleted file mode 100644 index 8ef09520c6e4..000000000000 --- a/test/simple/test-http-url.parse-path.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); - -var testURL = url.parse('http://localhost:' + common.PORT + '/asdf'); - -function check(request) { - // a path should come over - assert.strictEqual(request.url, '/asdf'); -} - -var server = http.createServer(function(request, response) { - // run the check function - check.call(this, request, response); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(common.PORT, function() { - // make the request - http.request(testURL).end(); -}); diff --git a/test/simple/test-http-url.parse-post.js b/test/simple/test-http-url.parse-post.js deleted file mode 100644 index be93166d532c..000000000000 --- a/test/simple/test-http-url.parse-post.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var https = require('https'); -var url = require('url'); - -var testURL = url.parse('http://localhost:' + common.PORT + '/asdf?qwer=zxcv'); -testURL.method = 'POST'; - -function check(request) { - //url.parse should not mess with the method - assert.strictEqual(request.method, 'POST'); - //everything else should be right - assert.strictEqual(request.url, '/asdf?qwer=zxcv'); - //the host header should use the url.parse.hostname - assert.strictEqual(request.headers.host, - testURL.hostname + ':' + testURL.port); -} - -var server = http.createServer(function(request, response) { - // run the check function - check.call(this, request, response); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(common.PORT, function() { - // make the request - http.request(testURL).end(); -}); diff --git a/test/simple/test-http-url.parse-search.js b/test/simple/test-http-url.parse-search.js deleted file mode 100644 index 3b6727d0bf63..000000000000 --- a/test/simple/test-http-url.parse-search.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var https = require('https'); -var url = require('url'); - -var testURL = url.parse('http://localhost:' + common.PORT + '/asdf?qwer=zxcv'); - -function check(request) { - // a path should come over with params - assert.strictEqual(request.url, '/asdf?qwer=zxcv'); -} - -var server = http.createServer(function(request, response) { - // run the check function - check.call(this, request, response); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(common.PORT, function() { - // make the request - http.request(testURL).end(); -}); diff --git a/test/simple/test-http-wget.js b/test/simple/test-http-wget.js deleted file mode 100644 index b6cf7d8be4f6..000000000000 --- a/test/simple/test-http-wget.js +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var http = require('http'); - -// wget sends an HTTP/1.0 request with Connection: Keep-Alive -// -// Sending back a chunked response to an HTTP/1.0 client would be wrong, -// so what has to happen in this case is that the connection is closed -// by the server after the entity body if the Content-Length was not -// sent. -// -// If the Content-Length was sent, we can probably safely honor the -// keep-alive request, even though HTTP 1.0 doesn't say that the -// connection can be kept open. Presumably any client sending this -// header knows that it is extending HTTP/1.0 and can handle the -// response. We don't test that here however, just that if the -// content-length is not provided, that the connection is in fact -// closed. - -var server_response = ''; -var client_got_eof = false; -var connection_was_closed = false; - -var server = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('hello '); - res.write('world\n'); - res.end(); -}); -server.listen(common.PORT); - -server.on('listening', function() { - var c = net.createConnection(common.PORT); - - c.setEncoding('utf8'); - - c.on('connect', function() { - c.write('GET / HTTP/1.0\r\n' + - 'Connection: Keep-Alive\r\n\r\n'); - }); - - c.on('data', function(chunk) { - console.log(chunk); - server_response += chunk; - }); - - c.on('end', function() { - client_got_eof = true; - console.log('got end'); - c.end(); - }); - - c.on('close', function() { - connection_was_closed = true; - console.log('got close'); - server.close(); - }); -}); - -process.on('exit', function() { - var m = server_response.split('\r\n\r\n'); - assert.equal(m[1], 'hello world\n'); - assert.ok(client_got_eof); - assert.ok(connection_was_closed); -}); diff --git a/test/simple/test-http-write-empty-string.js b/test/simple/test-http-write-empty-string.js deleted file mode 100644 index baf9c27f4b33..000000000000 --- a/test/simple/test-http-write-empty-string.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); - -var server = http.createServer(function(request, response) { - console.log('responding to ' + request.url); - - response.writeHead(200, {'Content-Type': 'text/plain'}); - response.write('1\n'); - response.write(''); - response.write('2\n'); - response.write(''); - response.end('3\n'); - - this.close(); -}); - -var response = ''; - -process.on('exit', function() { - assert.equal('1\n2\n3\n', response); -}); - - -server.listen(common.PORT, function() { - http.get({ port: common.PORT }, function(res) { - assert.equal(200, res.statusCode); - res.setEncoding('ascii'); - res.on('data', function(chunk) { - response += chunk; - }); - common.error('Got /hello response'); - }); -}); - diff --git a/test/simple/test-http-zero-length-write.js b/test/simple/test-http-zero-length-write.js deleted file mode 100644 index e68f947c32cc..000000000000 --- a/test/simple/test-http-zero-length-write.js +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var http = require('http'); - -var Stream = require('stream'); - -function getSrc() { - // An old-style readable stream. - // The Readable class prevents this behavior. - var src = new Stream(); - - // start out paused, just so we don't miss anything yet. - var paused = false; - src.pause = function() { - paused = true; - }; - src.resume = function() { - paused = false; - }; - - var chunks = [ '', 'asdf', '', 'foo', '', 'bar', '' ]; - var interval = setInterval(function() { - if (paused) - return - - var chunk = chunks.shift(); - if (chunk !== undefined) { - src.emit('data', chunk); - } else { - src.emit('end'); - clearInterval(interval); - } - }, 1); - - return src; -} - - -var expect = 'asdffoobar'; - -var server = http.createServer(function(req, res) { - var actual = ''; - req.setEncoding('utf8'); - req.on('data', function(c) { - actual += c; - }); - req.on('end', function() { - assert.equal(actual, expect); - getSrc().pipe(res); - }); - server.close(); -}); - -server.listen(common.PORT, function() { - var req = http.request({ port: common.PORT, method: 'POST' }); - var actual = ''; - req.on('response', function(res) { - res.setEncoding('utf8'); - res.on('data', function(c) { - actual += c; - }); - res.on('end', function() { - assert.equal(actual, expect); - }); - }); - getSrc().pipe(req); -}); - -process.on('exit', function(c) { - if (!c) console.log('ok'); -}); diff --git a/test/simple/test-http.js b/test/simple/test-http.js deleted file mode 100644 index fa388356d839..000000000000 --- a/test/simple/test-http.js +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var url = require('url'); - -function p(x) { - common.error(common.inspect(x)); -} - -var responses_sent = 0; -var responses_recvd = 0; -var body0 = ''; -var body1 = ''; - -var server = http.Server(function(req, res) { - if (responses_sent == 0) { - assert.equal('GET', req.method); - assert.equal('/hello', url.parse(req.url).pathname); - - console.dir(req.headers); - assert.equal(true, 'accept' in req.headers); - assert.equal('*/*', req.headers['accept']); - - assert.equal(true, 'foo' in req.headers); - assert.equal('bar', req.headers['foo']); - } - - if (responses_sent == 1) { - assert.equal('POST', req.method); - assert.equal('/world', url.parse(req.url).pathname); - this.close(); - } - - req.on('end', function() { - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('The path was ' + url.parse(req.url).pathname); - res.end(); - responses_sent += 1; - }); - req.resume(); - - //assert.equal('127.0.0.1', res.connection.remoteAddress); -}); -server.listen(common.PORT); - -server.on('listening', function() { - var agent = new http.Agent({ port: common.PORT, maxSockets: 1 }); - http.get({ - port: common.PORT, - path: '/hello', - headers: {'Accept': '*/*', 'Foo': 'bar'}, - agent: agent - }, function(res) { - assert.equal(200, res.statusCode); - responses_recvd += 1; - res.setEncoding('utf8'); - res.on('data', function(chunk) { body0 += chunk; }); - common.debug('Got /hello response'); - }); - - setTimeout(function() { - var req = http.request({ - port: common.PORT, - method: 'POST', - path: '/world', - agent: agent - }, function(res) { - assert.equal(200, res.statusCode); - responses_recvd += 1; - res.setEncoding('utf8'); - res.on('data', function(chunk) { body1 += chunk; }); - common.debug('Got /world response'); - }); - req.end(); - }, 1); -}); - -process.on('exit', function() { - common.debug('responses_recvd: ' + responses_recvd); - assert.equal(2, responses_recvd); - - common.debug('responses_sent: ' + responses_sent); - assert.equal(2, responses_sent); - - assert.equal('The path was /hello', body0); - assert.equal('The path was /world', body1); -}); - diff --git a/test/simple/test-https-agent.js b/test/simple/test-https-agent.js deleted file mode 100644 index 34fa15c737a1..000000000000 --- a/test/simple/test-https-agent.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var fs = require('fs'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - - -var server = https.Server(options, function(req, res) { - res.writeHead(200); - res.end('hello world\n'); -}); - - -var responses = 0; -var N = 10; -var M = 10; - -server.listen(common.PORT, function() { - for (var i = 0; i < N; i++) { - setTimeout(function() { - for (var j = 0; j < M; j++) { - https.get({ - path: '/', - port: common.PORT, - rejectUnauthorized: false - }, function(res) { - res.resume(); - console.log(res.statusCode); - if (++responses == N * M) server.close(); - }).on('error', function(e) { - console.log(e.message); - process.exit(1); - }); - } - }, i); - } -}); - - -process.on('exit', function() { - assert.equal(N * M, responses); -}); diff --git a/test/simple/test-https-byteswritten.js b/test/simple/test-https-byteswritten.js deleted file mode 100644 index 21c300efa703..000000000000 --- a/test/simple/test-https-byteswritten.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var http = require('http'); -var https = require('https'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var body = 'hello world\n'; - -var httpsServer = https.createServer(options, function(req, res) { - res.on('finish', function() { - assert(typeof(req.connection.bytesWritten) === 'number'); - assert(req.connection.bytesWritten > 0); - httpsServer.close(); - console.log('ok'); - }); - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.end(body); -}); - -httpsServer.listen(common.PORT, function() { - https.get({ - port: common.PORT, - rejectUnauthorized: false - }); -}); diff --git a/test/simple/test-https-client-get-url.js b/test/simple/test-https-client-get-url.js deleted file mode 100644 index ae5613c1434b..000000000000 --- a/test/simple/test-https-client-get-url.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -// disable strict server certificate validation by the client -process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var fs = require('fs'); - -var seen_req = false; - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var server = https.createServer(options, function(req, res) { - assert.equal('GET', req.method); - assert.equal('/foo?bar', req.url); - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('hello\n'); - res.end(); - server.close(); - seen_req = true; -}); - -server.listen(common.PORT, function() { - https.get('https://127.0.0.1:' + common.PORT + '/foo?bar'); -}); - -process.on('exit', function() { - assert(seen_req); -}); diff --git a/test/simple/test-https-client-reject.js b/test/simple/test-https-client-reject.js deleted file mode 100644 index bf191da1d999..000000000000 --- a/test/simple/test-https-client-reject.js +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var fs = require('fs'); -var path = require('path'); - -var options = { - key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), - cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) -}; - -var reqCount = 0; - -var server = https.createServer(options, function(req, res) { - ++reqCount; - res.writeHead(200); - res.end(); - req.resume(); -}).listen(common.PORT, function() { - unauthorized(); -}); - -function unauthorized() { - var req = https.request({ - port: common.PORT, - rejectUnauthorized: false - }, function(res) { - assert(!req.socket.authorized); - res.resume(); - rejectUnauthorized(); - }); - req.on('error', function(err) { - throw err; - }); - req.end(); -} - -function rejectUnauthorized() { - var options = { - port: common.PORT - }; - options.agent = new https.Agent(options); - var req = https.request(options, function(res) { - assert(false); - }); - req.on('error', function(err) { - authorized(); - }); - req.end(); -} - -function authorized() { - var options = { - port: common.PORT, - ca: [fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))] - }; - options.agent = new https.Agent(options); - var req = https.request(options, function(res) { - res.resume(); - assert(req.socket.authorized); - server.close(); - }); - req.on('error', function(err) { - assert(false); - }); - req.end(); -} - -process.on('exit', function() { - assert.equal(reqCount, 2); -}); diff --git a/test/simple/test-https-client-resume.js b/test/simple/test-https-client-resume.js deleted file mode 100644 index 0433afdd99b0..000000000000 --- a/test/simple/test-https-client-resume.js +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Create an ssl server. First connection, validate that not resume. -// Cache session and close connection. Use session on second connection. -// ASSERT resumption. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var tls = require('tls'); -var fs = require('fs'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') -}; - -var connections = 0; - -// create server -var server = https.createServer(options, function(res, res) { - res.end('Goodbye'); - connections++; -}); - -// start listening -server.listen(common.PORT, function() { - - var session1 = null; - var client1 = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - console.log('connect1'); - assert.ok(!client1.isSessionReused(), 'Session *should not* be reused.'); - session1 = client1.getSession(); - client1.write('GET / HTTP/1.0\r\n' + - 'Server: 127.0.0.1\r\n' + - '\r\n'); - }); - - client1.on('close', function() { - console.log('close1'); - - var opts = { - port: common.PORT, - rejectUnauthorized: false, - session: session1 - }; - - var client2 = tls.connect(opts, function() { - console.log('connect2'); - assert.ok(client2.isSessionReused(), 'Session *should* be reused.'); - client2.write('GET / HTTP/1.0\r\n' + - 'Server: 127.0.0.1\r\n' + - '\r\n'); - }); - - client2.on('close', function() { - console.log('close2'); - server.close(); - }); - }); -}); - -process.on('exit', function() { - assert.equal(2, connections); -}); diff --git a/test/simple/test-https-connecting-to-http.js b/test/simple/test-https-connecting-to-http.js deleted file mode 100644 index 50bb2a8a3e25..000000000000 --- a/test/simple/test-https-connecting-to-http.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -// This tests the situation where you try to connect a https client -// to an http server. You should get an error and exit. -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var http = require('http'); - - -var reqCount = 0; -var resCount = 0; -var reqErrorCount = 0; -var body = 'hello world\n'; - - -var server = http.createServer(function(req, res) { - reqCount++; - console.log('got request'); - res.writeHead(200, { 'content-type': 'text/plain' }); - res.end(body); -}); - - -server.listen(common.PORT, function() { - var req = https.get({ port: common.PORT }, function(res) { - resCount++; - }); - - req.on('error', function(e) { - console.log('Got expected error: ', e.message); - server.close(); - reqErrorCount++; - }); -}); - - -process.on('exit', function() { - assert.equal(0, reqCount); - assert.equal(0, resCount); - assert.equal(1, reqErrorCount); -}); diff --git a/test/simple/test-https-drain.js b/test/simple/test-https-drain.js deleted file mode 100644 index 5509a2474498..000000000000 --- a/test/simple/test-https-drain.js +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var fs = require('fs'); -var path = require('path'); - -var options = { - key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), - cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) -}; - -var bufSize = 1024 * 1024; -var sent = 0; -var received = 0; - -var server = https.createServer(options, function(req, res) { - res.writeHead(200); - req.pipe(res); -}); - -server.listen(common.PORT, function() { - var resumed = false; - var req = https.request({ - method: 'POST', - port: common.PORT, - rejectUnauthorized: false - }, function(res) { - var timer; - res.pause(); - common.debug('paused'); - send(); - function send() { - if (req.write(new Buffer(bufSize))) { - sent += bufSize; - assert.ok(sent < 100 * 1024 * 1024); // max 100MB - return process.nextTick(send); - } - sent += bufSize; - common.debug('sent: ' + sent); - resumed = true; - res.resume(); - common.debug('resumed'); - timer = setTimeout(function() { - process.exit(1); - }, 1000); - } - - res.on('data', function(data) { - assert.ok(resumed); - if (timer) { - clearTimeout(timer); - timer = null; - } - received += data.length; - if (received >= sent) { - common.debug('received: ' + received); - req.end(); - server.close(); - } - }); - }); - req.write('a'); - ++sent; -}); - -process.on('exit', function() { - assert.equal(sent, received); -}); diff --git a/test/simple/test-https-eof-for-eom.js b/test/simple/test-https-eof-for-eom.js deleted file mode 100644 index 2b35835e9018..000000000000 --- a/test/simple/test-https-eof-for-eom.js +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// I hate HTTP. One way of terminating an HTTP response is to not send -// a content-length header, not send a transfer-encoding: chunked header, -// and simply terminate the TCP connection. That is identity -// transfer-encoding. -// -// This test is to be sure that the https client is handling this case -// correctly. -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var https = require('https'); -var fs = require('fs'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - - -var server = tls.Server(options, function(socket) { - console.log('2) Server got request'); - socket.write('HTTP/1.1 200 OK\r\n' + - 'Date: Tue, 15 Feb 2011 22:14:54 GMT\r\n' + - 'Expires: -1\r\n' + - 'Cache-Control: private, max-age=0\r\n' + - 'Set-Cookie: xyz\r\n' + - 'Set-Cookie: abc\r\n' + - 'Server: gws\r\n' + - 'X-XSS-Protection: 1; mode=block\r\n' + - 'Connection: close\r\n' + - '\r\n'); - - socket.write('hello world\n'); - - setTimeout(function() { - socket.end('hello world\n'); - console.log('4) Server finished response'); - }, 100); -}); - - -var gotHeaders = false; -var gotEnd = false; -var bodyBuffer = ''; - -server.listen(common.PORT, function() { - console.log('1) Making Request'); - var req = https.get({ - port: common.PORT, - rejectUnauthorized: false - }, function(res) { - server.close(); - console.log('3) Client got response headers.'); - - assert.equal('gws', res.headers.server); - gotHeaders = true; - - res.setEncoding('utf8'); - res.on('data', function(s) { - bodyBuffer += s; - }); - - res.on('close', function() { - console.log('5) Client got "end" event.'); - gotEnd = true; - }); - }); -}); - -process.on('exit', function() { - assert.ok(gotHeaders); - assert.ok(gotEnd); - assert.equal('hello world\nhello world\n', bodyBuffer); -}); - diff --git a/test/simple/test-https-foafssl.js b/test/simple/test-https-foafssl.js deleted file mode 100644 index d896d19cc72e..000000000000 --- a/test/simple/test-https-foafssl.js +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); - -if (!common.opensslCli) { - console.error('Skipping because node compiled without OpenSSL CLI.'); - process.exit(0); -} - -var assert = require('assert'); -var join = require('path').join; - -var fs = require('fs'); -var spawn = require('child_process').spawn; - -var https = require('https'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/agent.key'), - cert: fs.readFileSync(common.fixturesDir + '/agent.crt'), - requestCert: true -}; - -var reqCount = 0; -var CRLF = '\r\n'; -var body = 'hello world\n'; -var cert; -var subjectaltname; -var modulus; -var exponent; - -var server = https.createServer(options, function(req, res) { - reqCount++; - console.log('got request'); - - cert = req.connection.getPeerCertificate(); - - subjectaltname = cert.subjectaltname; - modulus = cert.modulus; - exponent = cert.exponent; - - res.writeHead(200, { 'content-type': 'text/plain' }); - res.end(body); -}); - - -server.listen(common.PORT, function() { - var args = ['s_client', - '-quiet', - '-connect', '127.0.0.1:' + common.PORT, - '-cert', join(common.fixturesDir, 'foafssl.crt'), - '-key', join(common.fixturesDir, 'foafssl.key')]; - - var client = spawn(common.opensslCli, args); - - client.stdout.on('data', function(data) { - var message = data.toString(); - var contents = message.split(CRLF + CRLF).pop(); - assert.equal(body, contents); - server.close(); - }); - - client.stdin.write('GET /\n\n'); - - client.on('error', function(error) { - throw error; - }); -}); - -process.on('exit', function() { - assert.equal(subjectaltname, 'URI:http://example.com/#me'); - assert.equal(modulus, 'A6F44A9C25791431214F5C87AF9E040177A8BB89AC803F7E09' + - 'BBC3A5519F349CD9B9C40BE436D0AA823A94147E26C89248ADA2BE3DD4D34E8C2896' + - '4694B2047D217B4F1299371EA93A83C89AB9440724131E65F2B0161DE9560CDE9C13' + - '455552B2F49CF0FB00D8D77532324913F6F80FF29D0A131D29DB06AFF8BE191B7920' + - 'DC2DAE1C26EA82A47847A10391EF3BF6AABB3CC40FF82100B03A4F0FF1809278E4DD' + - 'FDA7DE954ED56DC7AD9A47EEBC37D771A366FC60A5BCB72373BEC180649B3EFA0E90' + - '92707210B41B90032BB18BC91F2046EBDAF1191F4A4E26D71879C4C7867B62FCD508' + - 'E8CE66E82D128A71E915809FCF44E8DE774067F1DE5D70B9C03687'); - assert.equal(exponent, '10001'); -}); diff --git a/test/simple/test-https-invalid-key.js b/test/simple/test-https-invalid-key.js deleted file mode 100644 index 82e05a2af9e3..000000000000 --- a/test/simple/test-https-invalid-key.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var fs = require('fs'); -var path = require('path'); - -var options = { - key: fs.readFileSync(path.join(common.fixturesDir, 'keys/agent1-key.pem')), - cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) -}; -var serverErrorHappened = false; -var clientErrorHappened = false; - -var server = https.Server(options, function(req, res) { - assert(false); -}); -server.on('clientError', function(err) { - serverErrorHappened = true; - common.debug('Server: ' + err); - server.close(); -}); - -server.listen(common.PORT, function() { - var req = https.get({port: common.PORT}, function(res) { - assert(false); - }); - req.on('error', function(err) { - clientErrorHappened = true; - common.debug('Client: ' + err); - }); -}); - -process.on('exit', function() { - assert(serverErrorHappened); - assert(clientErrorHappened); -}); diff --git a/test/simple/test-https-localaddress-bind-error.js b/test/simple/test-https-localaddress-bind-error.js deleted file mode 100644 index 0c4f8da4c4da..000000000000 --- a/test/simple/test-https-localaddress-bind-error.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var fs = require('fs'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var invalidLocalAddress = '1.2.3.4'; -var gotError = false; - -var server = https.createServer(options, function(req, res) { - console.log("Connect from: " + req.connection.remoteAddress); - - req.on('end', function() { - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.end('You are from: ' + req.connection.remoteAddress); - }); - req.resume(); -}); - -server.listen(common.PORT, "127.0.0.1", function() { - var req = https.request({ - host: 'localhost', - port: common.PORT, - path: '/', - method: 'GET', - localAddress: invalidLocalAddress - }, function(res) { - assert.fail('unexpectedly got response from server'); - }).on('error', function(e) { - console.log('client got error: ' + e.message); - gotError = true; - server.close(); - }).end(); -}); - -process.on('exit', function() { - assert.ok(gotError); -}); diff --git a/test/simple/test-https-localaddress.js b/test/simple/test-https-localaddress.js deleted file mode 100644 index 6388c5baa296..000000000000 --- a/test/simple/test-https-localaddress.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var https = require('https'), - fs = require('fs'), - assert = require('assert'); - -if (!common.hasMultiLocalhost()) { - console.log('Skipping platform-specific test.'); - process.exit(); -} - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var server = https.createServer(options, function (req, res) { - console.log("Connect from: " + req.connection.socket.remoteAddress); - assert.equal('127.0.0.2', req.connection.socket.remoteAddress); - - req.on('end', function() { - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.end('You are from: ' + req.connection.remoteAddress); - }); - req.resume(); -}); - -server.listen(common.PORT, "127.0.0.1", function() { - var options = { - host: 'localhost', - port: common.PORT, - path: '/', - method: 'GET', - localAddress: '127.0.0.2', - rejectUnauthorized: false - }; - - var req = https.request(options, function(res) { - res.on('end', function() { - server.close(); - process.exit(); - }); - res.resume(); - }); - req.end(); -}); diff --git a/test/simple/test-https-no-reader.js b/test/simple/test-https-no-reader.js deleted file mode 100644 index 5e63e1407105..000000000000 --- a/test/simple/test-https-no-reader.js +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var Buffer = require('buffer').Buffer; -var fs = require('fs'); -var path = require('path'); - -var options = { - key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), - cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) -}; - -var buf = new Buffer(1024 * 1024); -var sent = 0; -var received = 0; - -var server = https.createServer(options, function(req, res) { - res.writeHead(200); - for (var i = 0; i < 50; i++) { - res.write(buf); - } - res.end(); -}); - -server.listen(common.PORT, function() { - var resumed = false; - var req = https.request({ - method: 'POST', - port: common.PORT, - rejectUnauthorized: false - }, function(res) { - res.read(0); - - setTimeout(function() { - // Read buffer should be somewhere near high watermark - // (i.e. should not leak) - assert(res._readableState.length < 100 * 1024); - process.exit(0); - }, 5000); - }); - req.end(); -}); diff --git a/test/simple/test-https-pfx.js b/test/simple/test-https-pfx.js deleted file mode 100644 index 9da1ff8ee987..000000000000 --- a/test/simple/test-https-pfx.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var fs = require('fs'); - -var pfx = fs.readFileSync(common.fixturesDir + '/test_cert.pfx'); - -var options = { - host: '127.0.0.1', - port: common.PORT, - path: '/', - pfx: pfx, - passphrase: 'sample', - requestCert: true, - rejectUnauthorized: false -}; - -var server = https.createServer(options, function(req, res) { - assert.equal(req.socket.authorized, false); // not a client cert - assert.equal(req.socket.authorizationError, 'DEPTH_ZERO_SELF_SIGNED_CERT'); - res.writeHead(200); - res.end('OK'); -}); - -server.listen(options.port, options.host, function() { - var data = ''; - - https.get(options, function(res) { - res.on('data', function(data_) { data += data_ }); - res.on('end', function() { server.close() }); - }); - - process.on('exit', function() { - assert.equal(data, 'OK'); - }); -}); diff --git a/test/simple/test-https-req-split.js b/test/simple/test-https-req-split.js deleted file mode 100644 index db54d7237727..000000000000 --- a/test/simple/test-https-req-split.js +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -// disable strict server certificate validation by the client -process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var tls = require('tls'); -var fs = require('fs'); - -var seen_req = false; - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -// Force splitting incoming data -tls.SLAB_BUFFER_SIZE = 1; - -var server = https.createServer(options); -server.on('upgrade', function(req, socket, upgrade) { - socket.on('data', function(data) { - throw new Error('Unexpected data: ' + data); - }); - socket.end('HTTP/1.1 200 Ok\r\n\r\n'); - seen_req = true; -}); - -server.listen(common.PORT, function() { - var req = https.request({ - host: '127.0.0.1', - port: common.PORT, - agent: false, - headers: { - Connection: 'Upgrade', - Upgrade: 'Websocket' - } - }, function() { - req.socket.destroy(); - server.close(); - }); - - req.end(); -}); - -process.on('exit', function() { - assert(seen_req); - console.log('ok'); -}); diff --git a/test/simple/test-https-simple.js b/test/simple/test-https-simple.js deleted file mode 100644 index 552450c3010e..000000000000 --- a/test/simple/test-https-simple.js +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); - -var fs = require('fs'); -var exec = require('child_process').exec; - -var https = require('https'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var reqCount = 0; -var body = 'hello world\n'; - -var server = https.createServer(options, function(req, res) { - reqCount++; - console.log('got request'); - res.writeHead(200, { 'content-type': 'text/plain' }); - res.end(body); -}); - - -server.listen(common.PORT, function() { - var cmd = 'curl --insecure https://127.0.0.1:' + common.PORT + '/'; - console.error('executing %j', cmd); - exec(cmd, function(err, stdout, stderr) { - if (err) throw err; - common.error(common.inspect(stdout)); - assert.equal(body, stdout); - - // Do the same thing now without --insecure - // The connection should not be accepted. - var cmd = 'curl https://127.0.0.1:' + common.PORT + '/'; - console.error('executing %j', cmd); - exec(cmd, function(err, stdout, stderr) { - assert.ok(err); - server.close(); - }); - }); -}); - -process.on('exit', function() { - assert.equal(1, reqCount); -}); diff --git a/test/simple/test-https-socket-options.js b/test/simple/test-https-socket-options.js deleted file mode 100644 index 21b1118f7d4c..000000000000 --- a/test/simple/test-https-socket-options.js +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); - -var fs = require('fs'); -var exec = require('child_process').exec; - -var http = require('http'); -var https = require('https'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var body = 'hello world\n'; - -// Try first with http server - -var server_http = http.createServer(function(req, res) { - console.log('got HTTP request'); - res.writeHead(200, { 'content-type': 'text/plain' }); - res.end(body); -}); - - -server_http.listen(common.PORT, function() { - var req = http.request({ - port: common.PORT, - rejectUnauthorized: false - }, function(res) { - server_http.close(); - res.resume(); - }); - // These methods should exist on the request and get passed down to the socket - req.setNoDelay(true); - req.setTimeout(1000, function() { }); - req.setSocketKeepAlive(true, 1000); - req.end(); -}); - -// Then try https server (requires functions to be mirroed in tls.js's CryptoStream) - -var server_https = https.createServer(options, function(req, res) { - console.log('got HTTPS request'); - res.writeHead(200, { 'content-type': 'text/plain' }); - res.end(body); -}); - -server_https.listen(common.PORT+1, function() { - var req = https.request({ - port: common.PORT + 1, - rejectUnauthorized: false - }, function(res) { - server_https.close(); - res.resume(); - }); - // These methods should exist on the request and get passed down to the socket - req.setNoDelay(true); - req.setTimeout(1000, function() { }); - req.setSocketKeepAlive(true, 1000); - req.end(); -}); diff --git a/test/simple/test-https-strict.js b/test/simple/test-https-strict.js deleted file mode 100644 index 720b0a6db746..000000000000 --- a/test/simple/test-https-strict.js +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -// disable strict server certificate validation by the client -process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; - -var common = require('../common'); -var assert = require('assert'); - -var fs = require('fs'); -var path = require('path'); -var https = require('https'); - -function file(fname) { - return path.resolve(common.fixturesDir, 'keys', fname); -} - -function read(fname) { - return fs.readFileSync(file(fname)); -} - -// key1 is signed by ca1. -var key1 = read('agent1-key.pem'); -var cert1 = read('agent1-cert.pem'); - -// key2 has a self signed cert -var key2 = read('agent2-key.pem'); -var cert2 = read('agent2-cert.pem'); - -// key3 is signed by ca2. -var key3 = read('agent3-key.pem'); -var cert3 = read('agent3-cert.pem'); - -var ca1 = read('ca1-cert.pem'); -var ca2 = read('ca2-cert.pem'); - -// different agents to use different CA lists. -// this api is beyond bad. -var agent0 = new https.Agent(); -var agent1 = new https.Agent({ ca: [ca1] }); -var agent2 = new https.Agent({ ca: [ca2] }); -var agent3 = new https.Agent({ ca: [ca1, ca2] }); - -var options1 = { - key: key1, - cert: cert1 -}; - -var options2 = { - key: key2, - cert: cert2 -}; - -var options3 = { - key: key3, - cert: cert3 -}; - -var server1 = server(options1); -var server2 = server(options2); -var server3 = server(options3); - -var listenWait = 0; - -var port = common.PORT; -var port1 = port++; -var port2 = port++; -var port3 = port++; -server1.listen(port1, listening()); -server2.listen(port2, listening()); -server3.listen(port3, listening()); - -var responseErrors = {}; -var expectResponseCount = 0; -var responseCount = 0; -var pending = 0; - - - -function server(options, port) { - var s = https.createServer(options, handler); - s.requests = []; - s.expectCount = 0; - return s; -} - -function handler(req, res) { - this.requests.push(req.url); - res.statusCode = 200; - res.setHeader('foo', 'bar'); - res.end('hello, world\n'); -} - -function listening() { - listenWait++; - return function() { - listenWait--; - if (listenWait === 0) { - allListening(); - } - } -} - -function makeReq(path, port, error, host, ca) { - pending++; - var options = { - port: port, - path: path, - ca: ca - }; - var whichCa = 0; - if (!ca) { - options.agent = agent0; - } else { - if (!Array.isArray(ca)) ca = [ca]; - if (-1 !== ca.indexOf(ca1) && -1 !== ca.indexOf(ca2)) { - options.agent = agent3; - } else if (-1 !== ca.indexOf(ca1)) { - options.agent = agent1; - } else if (-1 !== ca.indexOf(ca2)) { - options.agent = agent2; - } else { - options.agent = agent0; - } - } - - if (host) { - options.headers = { host: host } - } - var req = https.get(options); - expectResponseCount++; - var server = port === port1 ? server1 - : port === port2 ? server2 - : port === port3 ? server3 - : null; - - if (!server) throw new Error('invalid port: '+port); - server.expectCount++; - - req.on('response', function(res) { - responseCount++; - assert.equal(res.connection.authorizationError, error); - responseErrors[path] = res.connection.authorizationError; - pending--; - if (pending === 0) { - server1.close(); - server2.close(); - server3.close(); - } - res.resume(); - }) -} - -function allListening() { - // ok, ready to start the tests! - - // server1: host 'agent1', signed by ca1 - makeReq('/inv1', port1, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'); - makeReq('/inv1-ca1', port1, - 'Hostname/IP doesn\'t match certificate\'s altnames', - null, ca1); - makeReq('/inv1-ca1ca2', port1, - 'Hostname/IP doesn\'t match certificate\'s altnames', - null, [ca1, ca2]); - makeReq('/val1-ca1', port1, null, 'agent1', ca1); - makeReq('/val1-ca1ca2', port1, null, 'agent1', [ca1, ca2]); - makeReq('/inv1-ca2', port1, - 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', 'agent1', ca2); - - // server2: self-signed, host = 'agent2' - // doesn't matter that thename matches, all of these will error. - makeReq('/inv2', port2, 'DEPTH_ZERO_SELF_SIGNED_CERT'); - makeReq('/inv2-ca1', port2, 'DEPTH_ZERO_SELF_SIGNED_CERT', - 'agent2', ca1); - makeReq('/inv2-ca1ca2', port2, 'DEPTH_ZERO_SELF_SIGNED_CERT', - 'agent2', [ca1, ca2]); - - // server3: host 'agent3', signed by ca2 - makeReq('/inv3', port3, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'); - makeReq('/inv3-ca2', port3, - 'Hostname/IP doesn\'t match certificate\'s altnames', - null, ca2); - makeReq('/inv3-ca1ca2', port3, - 'Hostname/IP doesn\'t match certificate\'s altnames', - null, [ca1, ca2]); - makeReq('/val3-ca2', port3, null, 'agent3', ca2); - makeReq('/val3-ca1ca2', port3, null, 'agent3', [ca1, ca2]); - makeReq('/inv3-ca1', port3, - 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', 'agent1', ca1); - -} - -process.on('exit', function() { - console.error(responseErrors); - assert.equal(server1.requests.length, server1.expectCount); - assert.equal(server2.requests.length, server2.expectCount); - assert.equal(server3.requests.length, server3.expectCount); - assert.equal(responseCount, expectResponseCount); -}); diff --git a/test/simple/test-https-timeout-server-2.js b/test/simple/test-https-timeout-server-2.js deleted file mode 100644 index 076a0ec26f31..000000000000 --- a/test/simple/test-https-timeout-server-2.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) process.exit(); - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var net = require('net'); -var tls = require('tls'); -var fs = require('fs'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var server = https.createServer(options, assert.fail); - -server.on('secureConnection', function(cleartext) { - cleartext.setTimeout(50, function() { - cleartext.destroy(); - server.close(); - }); -}); - -server.listen(common.PORT, function() { - tls.connect({ - host: '127.0.0.1', - port: common.PORT, - rejectUnauthorized: false - }); -}); diff --git a/test/simple/test-https-timeout-server.js b/test/simple/test-https-timeout-server.js deleted file mode 100644 index 18dc4b8fbe09..000000000000 --- a/test/simple/test-https-timeout-server.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) process.exit(); - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var net = require('net'); -var tls = require('tls'); -var fs = require('fs'); - -var clientErrors = 0; - -process.on('exit', function() { - assert.equal(clientErrors, 1); -}); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), - handshakeTimeout: 50 -}; - -var server = https.createServer(options, assert.fail); - -server.on('clientError', function(err, conn) { - // Don't hesitate to update the asserts if the internal structure of - // the cleartext object ever changes. We're checking that the https.Server - // has closed the client connection. - assert.equal(conn._secureEstablished, false); - assert.equal(conn._doneFlag, true); - assert.equal(conn.ssl, null); - server.close(); - clientErrors++; -}); - -server.listen(common.PORT, function() { - net.connect({ host: '127.0.0.1', port: common.PORT }); -}); diff --git a/test/simple/test-https-timeout.js b/test/simple/test-https-timeout.js deleted file mode 100644 index 8b79204d461c..000000000000 --- a/test/simple/test-https-timeout.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var exec = require('child_process').exec; -var https = require('https'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -// a server that never replies -var server = https.createServer(options, function() { - console.log('Got request. Doing nothing.'); -}).listen(common.PORT, function() { - var req = https.request({ - host: 'localhost', - port: common.PORT, - path: '/', - method: 'GET', - rejectUnauthorized: false - }); - req.setTimeout(10); - req.end(); - - req.on('response', function(res) { - console.log('got response'); - }); - - req.on('socket', function() { - console.log('got a socket'); - - req.socket.on('connect', function() { - console.log('socket connected'); - }); - - setTimeout(function() { - throw new Error('Did not get timeout event'); - }, 200); - }); - - req.on('timeout', function() { - console.log('timeout occurred outside'); - req.destroy(); - server.close(); - process.exit(0); - }); -}); diff --git a/test/simple/test-init.js b/test/simple/test-init.js deleted file mode 100644 index 139df7f58b3e..000000000000 --- a/test/simple/test-init.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -(function() { - var assert = require('assert'), - child = require('child_process'), - util = require('util'), - common = require('../common'); - if (process.env['TEST_INIT']) { - util.print('Loaded successfully!'); - } else { - // change CWD as we do this test so its not dependant on current CWD - // being in the test folder - process.chdir(__dirname); - - // slow but simple - var envCopy = JSON.parse(JSON.stringify(process.env)); - envCopy.TEST_INIT = 1; - - child.exec(process.execPath + ' test-init', {env: envCopy}, - function(err, stdout, stderr) { - assert.equal(stdout, 'Loaded successfully!', - '`node test-init` failed!'); - }); - child.exec(process.execPath + ' test-init.js', {env: envCopy}, - function(err, stdout, stderr) { - assert.equal(stdout, 'Loaded successfully!', - '`node test-init.js` failed!'); - }); - - // test-init-index is in fixtures dir as requested by ry, so go there - process.chdir(common.fixturesDir); - - child.exec(process.execPath + ' test-init-index', {env: envCopy}, - function(err, stdout, stderr) { - assert.equal(stdout, 'Loaded successfully!', - '`node test-init-index failed!'); - }); - - // ensures that `node fs` does not mistakenly load the native 'fs' module - // instead of the desired file and that the fs module loads as - // expected in node - process.chdir(common.fixturesDir + '/test-init-native/'); - - child.exec(process.execPath + ' fs', {env: envCopy}, - function(err, stdout, stderr) { - assert.equal(stdout, 'fs loaded successfully', - '`node fs` failed!'); - }); - } -})(); diff --git a/test/simple/test-listen-fd-cluster.js b/test/simple/test-listen-fd-cluster.js deleted file mode 100644 index 0d6d7748aa1c..000000000000 --- a/test/simple/test-listen-fd-cluster.js +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); -var PORT = common.PORT; -var spawn = require('child_process').spawn; -var cluster = require('cluster'); - -console.error('Cluster listen fd test', process.argv.slice(2)); - -if (process.platform === 'win32') { - console.error('This test is disabled on windows.'); - return; -} - -switch (process.argv[2]) { - case 'master': return master(); - case 'worker': return worker(); - case 'parent': return parent(); - default: return test(); -} - -// spawn the parent, and listen for it to tell us the pid of the cluster. -// WARNING: This is an example of listening on some arbitrary FD number -// that has already been bound elsewhere in advance. However, binding -// server handles to stdio fd's is NOT a good or reliable way to do -// concurrency in HTTP servers! Use the cluster module, or if you want -// a more low-level approach, use child process IPC manually. -function test() { - var parent = spawn(process.execPath, [__filename, 'parent'], { - stdio: [ 0, 'pipe', 2 ] - }); - var json = ''; - parent.stdout.on('data', function(c) { - json += c.toString(); - if (json.indexOf('\n') !== -1) next(); - }); - function next() { - console.error('output from parent = %s', json); - var cluster = JSON.parse(json); - // now make sure that we can request to the worker, then kill it. - http.get({ - server: 'localhost', - port: PORT, - path: '/', - }).on('response', function (res) { - var s = ''; - res.on('data', function(c) { - s += c.toString(); - }); - res.on('end', function() { - // kill the worker before we start doing asserts. - // it's really annoying when tests leave orphans! - parent.kill(); - process.kill(cluster.master, 'SIGKILL'); - - assert.equal(s, 'hello from worker\n'); - assert.equal(res.statusCode, 200); - console.log('ok'); - }); - }) - } -} - -function parent() { - console.error('about to listen in parent'); - var server = net.createServer(function(conn) { - console.error('connection on parent'); - conn.end('hello from parent\n'); - }).listen(PORT, function() { - console.error('server listening on %d', PORT); - - var spawn = require('child_process').spawn; - var master = spawn(process.execPath, [__filename, 'master'], { - stdio: [ 0, 1, 2, server._handle ], - detached: true - }); - - // Now close the parent, so that the master is the only thing - // referencing that handle. Note that connections will still - // be accepted, because the master has the fd open. - server.close(); - - master.on('exit', function(code) { - console.error('master exited', code); - }); - - master.on('close', function() { - console.error('master closed'); - }); - console.error('master spawned'); - }); -} - -function master() { - console.error('in master, spawning worker'); - cluster.setupMaster({ - args: [ 'worker' ] - }); - var worker = cluster.fork(); - console.log('%j\n', { master: process.pid, worker: worker.pid }); -} - - -function worker() { - console.error('worker, about to create server and listen on fd=3'); - // start a server on fd=3 - http.createServer(function(req, res) { - console.error('request on worker'); - console.error('%s %s', req.method, req.url, req.headers); - res.end('hello from worker\n'); - }).listen({ fd: 3 }, function() { - console.error('worker listening on fd=3'); - }); -} diff --git a/test/simple/test-listen-fd-detached-inherit.js b/test/simple/test-listen-fd-detached-inherit.js deleted file mode 100644 index dabc46cd313c..000000000000 --- a/test/simple/test-listen-fd-detached-inherit.js +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); -var PORT = common.PORT; -var spawn = require('child_process').spawn; - -if (process.platform === 'win32') { - console.error('This test is disabled on windows.'); - return; -} - -switch (process.argv[2]) { - case 'child': return child(); - case 'parent': return parent(); - default: return test(); -} - -// spawn the parent, and listen for it to tell us the pid of the child. -// WARNING: This is an example of listening on some arbitrary FD number -// that has already been bound elsewhere in advance. However, binding -// server handles to stdio fd's is NOT a good or reliable way to do -// concurrency in HTTP servers! Use the cluster module, or if you want -// a more low-level approach, use child process IPC manually. -function test() { - var parent = spawn(process.execPath, [__filename, 'parent'], { - stdio: [ 0, 'pipe', 2 ] - }); - var json = ''; - parent.stdout.on('data', function(c) { - json += c.toString(); - if (json.indexOf('\n') !== -1) next(); - }); - function next() { - console.error('output from parent = %s', json); - var child = JSON.parse(json); - // now make sure that we can request to the child, then kill it. - http.get({ - server: 'localhost', - port: PORT, - path: '/', - }).on('response', function (res) { - var s = ''; - res.on('data', function(c) { - s += c.toString(); - }); - res.on('end', function() { - // kill the child before we start doing asserts. - // it's really annoying when tests leave orphans! - process.kill(child.pid, 'SIGKILL'); - try { - parent.kill(); - } catch (e) {} - - assert.equal(s, 'hello from child\n'); - assert.equal(res.statusCode, 200); - }); - }) - } -} - -// Listen on PORT, and then pass the handle to the detached child. -// Then output the child's pid, and immediately exit. -function parent() { - var server = net.createServer(function(conn) { - throw new Error('Should not see connections on parent'); - conn.end('HTTP/1.1 403 Forbidden\r\n\r\nI got problems.\r\n'); - }).listen(PORT, function() { - console.error('server listening on %d', PORT); - - var child = spawn(process.execPath, [__filename, 'child'], { - stdio: [ 0, 1, 2, server._handle ], - detached: true - }); - - console.log('%j\n', { pid: child.pid }); - - // Now close the parent, so that the child is the only thing - // referencing that handle. Note that connections will still - // be accepted, because the child has the fd open, but the parent - // will exit gracefully. - server.close(); - child.unref(); - }); -} - -// Run as a child of the parent() mode. -function child() { - // start a server on fd=3 - http.createServer(function(req, res) { - console.error('request on child'); - console.error('%s %s', req.method, req.url, req.headers); - res.end('hello from child\n'); - }).listen({ fd: 3 }, function() { - console.error('child listening on fd=3'); - }); -} - diff --git a/test/simple/test-listen-fd-detached.js b/test/simple/test-listen-fd-detached.js deleted file mode 100644 index 3d98abeacda6..000000000000 --- a/test/simple/test-listen-fd-detached.js +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); -var PORT = common.PORT; -var spawn = require('child_process').spawn; - -if (process.platform === 'win32') { - console.error('This test is disabled on windows.'); - return; -} - -switch (process.argv[2]) { - case 'child': return child(); - case 'parent': return parent(); - default: return test(); -} - -// spawn the parent, and listen for it to tell us the pid of the child. -// WARNING: This is an example of listening on some arbitrary FD number -// that has already been bound elsewhere in advance. However, binding -// server handles to stdio fd's is NOT a good or reliable way to do -// concurrency in HTTP servers! Use the cluster module, or if you want -// a more low-level approach, use child process IPC manually. -function test() { - var parent = spawn(process.execPath, [__filename, 'parent'], { - stdio: [ 0, 'pipe', 2 ] - }); - var json = ''; - parent.stdout.on('data', function(c) { - json += c.toString(); - if (json.indexOf('\n') !== -1) next(); - }); - function next() { - console.error('output from parent = %s', json); - var child = JSON.parse(json); - // now make sure that we can request to the child, then kill it. - http.get({ - server: 'localhost', - port: PORT, - path: '/', - }).on('response', function (res) { - var s = ''; - res.on('data', function(c) { - s += c.toString(); - }); - res.on('end', function() { - // kill the child before we start doing asserts. - // it's really annoying when tests leave orphans! - process.kill(child.pid, 'SIGKILL'); - try { - parent.kill(); - } catch (e) {} - - assert.equal(s, 'hello from child\n'); - assert.equal(res.statusCode, 200); - }); - }) - } -} - -function parent() { - var server = net.createServer(function(conn) { - console.error('connection on parent'); - conn.end('hello from parent\n'); - }).listen(PORT, function() { - console.error('server listening on %d', PORT); - - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child'], { - stdio: [ 'ignore', 'ignore', 'ignore', server._handle ], - detached: true - }); - - console.log('%j\n', { pid: child.pid }); - - // Now close the parent, so that the child is the only thing - // referencing that handle. Note that connections will still - // be accepted, because the child has the fd open, but the parent - // will exit gracefully. - server.close(); - child.unref(); - }); -} - -function child() { - // start a server on fd=3 - http.createServer(function(req, res) { - console.error('request on child'); - console.error('%s %s', req.method, req.url, req.headers); - res.end('hello from child\n'); - }).listen({ fd: 3 }, function() { - console.error('child listening on fd=3'); - }); -} - diff --git a/test/simple/test-listen-fd-ebadf.js b/test/simple/test-listen-fd-ebadf.js deleted file mode 100644 index 6c0f20ae4364..000000000000 --- a/test/simple/test-listen-fd-ebadf.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var gotError = 0; - -process.on('exit', function() { - assert.equal(gotError, 2); -}); - -net.createServer(assert.fail).listen({fd:2}).on('error', onError); -net.createServer(assert.fail).listen({fd:42}).on('error', onError); - -function onError(ex) { - assert.equal(ex.code, 'EINVAL'); - gotError++; -} diff --git a/test/simple/test-listen-fd-server.js b/test/simple/test-listen-fd-server.js deleted file mode 100644 index 8f3454fbbd63..000000000000 --- a/test/simple/test-listen-fd-server.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); -var PORT = common.PORT; -var spawn = require('child_process').spawn; - -if (process.platform === 'win32') { - console.error('This test is disabled on windows.'); - return; -} - -switch (process.argv[2]) { - case 'child': return child(); - case 'parent': return parent(); - default: return test(); -} - -// spawn the parent, and listen for it to tell us the pid of the child. -// WARNING: This is an example of listening on some arbitrary FD number -// that has already been bound elsewhere in advance. However, binding -// server handles to stdio fd's is NOT a good or reliable way to do -// concurrency in HTTP servers! Use the cluster module, or if you want -// a more low-level approach, use child process IPC manually. -function test() { - var parent = spawn(process.execPath, [__filename, 'parent'], { - stdio: [ 0, 'pipe', 2 ] - }); - var json = ''; - parent.stdout.on('data', function(c) { - json += c.toString(); - if (json.indexOf('\n') !== -1) next(); - }); - function next() { - console.error('output from parent = %s', json); - var child = JSON.parse(json); - // now make sure that we can request to the child, then kill it. - http.get({ - server: 'localhost', - port: PORT, - path: '/', - }).on('response', function (res) { - var s = ''; - res.on('data', function(c) { - s += c.toString(); - }); - res.on('end', function() { - // kill the child before we start doing asserts. - // it's really annoying when tests leave orphans! - process.kill(child.pid, 'SIGKILL'); - try { - parent.kill(); - } catch (e) {} - - assert.equal(s, 'hello from child\n'); - assert.equal(res.statusCode, 200); - }); - }) - } -} - -function child() { - // start a server on fd=3 - http.createServer(function(req, res) { - console.error('request on child'); - console.error('%s %s', req.method, req.url, req.headers); - res.end('hello from child\n'); - }).listen({ fd: 3 }, function() { - console.error('child listening on fd=3'); - }); -} - -function parent() { - var server = net.createServer(function(conn) { - console.error('connection on parent'); - conn.end('hello from parent\n'); - }).listen(PORT, function() { - console.error('server listening on %d', PORT); - - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child'], { - stdio: [ 0, 1, 2, server._handle ] - }); - - console.log('%j\n', { pid: child.pid }); - - // Now close the parent, so that the child is the only thing - // referencing that handle. Note that connections will still - // be accepted, because the child has the fd open. - server.close(); - - child.on('exit', function(code) { - console.error('child exited', code); - }); - - child.on('close', function() { - console.error('child closed'); - }); - console.error('child spawned'); - }); -} diff --git a/test/simple/test-memory-usage-emfile.js b/test/simple/test-memory-usage-emfile.js deleted file mode 100644 index aaed8995309f..000000000000 --- a/test/simple/test-memory-usage-emfile.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -var fs = require('fs'); - -var files = []; - -while (files.length < 256) - files.push(fs.openSync(__filename, 'r')); - -var r = process.memoryUsage(); -console.log(common.inspect(r)); -assert.equal(true, r['rss'] > 0); diff --git a/test/simple/test-memory-usage.js b/test/simple/test-memory-usage.js deleted file mode 100644 index 0df17420c97d..000000000000 --- a/test/simple/test-memory-usage.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -var r = process.memoryUsage(); -console.log(common.inspect(r)); -assert.equal(true, r['rss'] > 0); diff --git a/test/simple/test-mkdir-rmdir.js b/test/simple/test-mkdir-rmdir.js deleted file mode 100644 index 73534555c8c1..000000000000 --- a/test/simple/test-mkdir-rmdir.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); - -var dirname = path.dirname(__filename); -var d = path.join(common.tmpDir, 'dir'); - -var mkdir_error = false; -var rmdir_error = false; - -fs.mkdir(d, 0666, function(err) { - if (err) { - console.log('mkdir error: ' + err.message); - mkdir_error = true; - } else { - fs.mkdir(d, 0666, function(err) { - console.log('expect EEXIST error: ', err); - assert.ok(err.message.match(/^EEXIST/), 'got EEXIST message'); - assert.equal(err.code, 'EEXIST', 'got EEXIST code'); - assert.equal(err.path, d, 'got proper path for EEXIST'); - - console.log('mkdir okay!'); - fs.rmdir(d, function(err) { - if (err) { - console.log('rmdir error: ' + err.message); - rmdir_error = true; - } else { - console.log('rmdir okay!'); - } - }); - }); - } -}); - -process.on('exit', function() { - assert.equal(false, mkdir_error); - assert.equal(false, rmdir_error); - console.log('exit'); -}); diff --git a/test/simple/test-module-loading-error.js b/test/simple/test-module-loading-error.js deleted file mode 100644 index c1afd58e0770..000000000000 --- a/test/simple/test-module-loading-error.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -common.debug('load test-module-loading-error.js'); - -var error_desc = { - win32: '%1 is not a valid Win32 application', - linux: 'file too short', - sunos: 'unknown file type' -}; - -var dlerror_msg = error_desc[process.platform]; - -if (!dlerror_msg) { - console.error('Skipping test, platform not supported.'); - process.exit(); -} - -try { - require('../fixtures/module-loading-error.node'); -} catch (e) { - assert.notEqual(e.toString().indexOf(dlerror_msg), -1); -} diff --git a/test/simple/test-module-loading.js b/test/simple/test-module-loading.js deleted file mode 100644 index 8687c3b98647..000000000000 --- a/test/simple/test-module-loading.js +++ /dev/null @@ -1,308 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); - -common.debug('load test-module-loading.js'); - -// assert that this is the main module. -assert.equal(require.main.id, '.', 'main module should have id of \'.\''); -assert.equal(require.main, module, 'require.main should === module'); -assert.equal(process.mainModule, module, - 'process.mainModule should === module'); -// assert that it's *not* the main module in the required module. -require('../fixtures/not-main-module.js'); - -// require a file with a request that includes the extension -var a_js = require('../fixtures/a.js'); -assert.equal(42, a_js.number); - -// require a file without any extensions -var foo_no_ext = require('../fixtures/foo'); -assert.equal('ok', foo_no_ext.foo); - -var a = require('../fixtures/a'); -var c = require('../fixtures/b/c'); -var d = require('../fixtures/b/d'); -var d2 = require('../fixtures/b/d'); -// Absolute -var d3 = require(path.join(__dirname, '../fixtures/b/d')); -// Relative -var d4 = require('../fixtures/b/d'); - -assert.equal(false, false, 'testing the test program.'); - -assert.equal(true, common.indirectInstanceOf(a.A, Function)); -assert.equal('A', a.A()); - -assert.equal(true, common.indirectInstanceOf(a.C, Function)); -assert.equal('C', a.C()); - -assert.equal(true, common.indirectInstanceOf(a.D, Function)); -assert.equal('D', a.D()); - -assert.equal(true, common.indirectInstanceOf(d.D, Function)); -assert.equal('D', d.D()); - -assert.equal(true, common.indirectInstanceOf(d2.D, Function)); -assert.equal('D', d2.D()); - -assert.equal(true, common.indirectInstanceOf(d3.D, Function)); -assert.equal('D', d3.D()); - -assert.equal(true, common.indirectInstanceOf(d4.D, Function)); -assert.equal('D', d4.D()); - -assert.ok((new a.SomeClass) instanceof c.SomeClass); - -common.debug('test index.js modules ids and relative loading'); -var one = require('../fixtures/nested-index/one'), - two = require('../fixtures/nested-index/two'); -assert.notEqual(one.hello, two.hello); - -common.debug('test index.js in a folder with a trailing slash'); -var three = require('../fixtures/nested-index/three'), - threeFolder = require('../fixtures/nested-index/three/'), - threeIndex = require('../fixtures/nested-index/three/index.js'); -assert.equal(threeFolder, threeIndex); -assert.notEqual(threeFolder, three); - -common.debug('test package.json require() loading'); -assert.equal(require('../fixtures/packages/main').ok, 'ok', - 'Failed loading package'); -assert.equal(require('../fixtures/packages/main-index').ok, 'ok', - 'Failed loading package with index.js in main subdir'); - -common.debug('test cycles containing a .. path'); -var root = require('../fixtures/cycles/root'), - foo = require('../fixtures/cycles/folder/foo'); -assert.equal(root.foo, foo); -assert.equal(root.sayHello(), root.hello); - -common.debug('test node_modules folders'); -// asserts are in the fixtures files themselves, -// since they depend on the folder structure. -require('../fixtures/node_modules/foo'); - -common.debug('test name clashes'); -// this one exists and should import the local module -var my_path = require('./path'); -assert.ok(common.indirectInstanceOf(my_path.path_func, Function)); -// this one does not exist and should throw -assert.throws(function() { require('./utils')}); - -var errorThrown = false; -try { - require('../fixtures/throws_error'); -} catch (e) { - errorThrown = true; - assert.equal('blah', e.message); -} - -assert.equal(require('path').dirname(__filename), __dirname); - -common.debug('load custom file types with extensions'); -require.extensions['.test'] = function(module, filename) { - var content = fs.readFileSync(filename).toString(); - assert.equal('this is custom source\n', content); - content = content.replace('this is custom source', - 'exports.test = \'passed\''); - module._compile(content, filename); -}; - -assert.equal(require('../fixtures/registerExt').test, 'passed'); -// unknown extension, load as .js -assert.equal(require('../fixtures/registerExt.hello.world').test, 'passed'); - -common.debug('load custom file types that return non-strings'); -require.extensions['.test'] = function(module, filename) { - module.exports = { - custom: 'passed' - }; -}; - -assert.equal(require('../fixtures/registerExt2').custom, 'passed'); - -assert.equal(require('../fixtures/foo').foo, 'ok', - 'require module with no extension'); - -assert.throws(function() { - require.paths; -}, /removed/, 'Accessing require.paths should throw.'); - -// Should not attempt to load a directory -try { - require('../fixtures/empty'); -} catch (err) { - assert.equal(err.message, 'Cannot find module \'../fixtures/empty\''); -} - -// Check load order is as expected -common.debug('load order'); - -var loadOrder = '../fixtures/module-load-order/', - msg = 'Load order incorrect.'; - -require.extensions['.reg'] = require.extensions['.js']; -require.extensions['.reg2'] = require.extensions['.js']; - -assert.equal(require(loadOrder + 'file1').file1, 'file1', msg); -assert.equal(require(loadOrder + 'file2').file2, 'file2.js', msg); -try { - require(loadOrder + 'file3'); -} catch (e) { - // Not a real .node module, but we know we require'd the right thing. - assert.ok(e.message.replace(/\\/g, '/').match(/file3\.node/)); -} -assert.equal(require(loadOrder + 'file4').file4, 'file4.reg', msg); -assert.equal(require(loadOrder + 'file5').file5, 'file5.reg2', msg); -assert.equal(require(loadOrder + 'file6').file6, 'file6/index.js', msg); -try { - require(loadOrder + 'file7'); -} catch (e) { - assert.ok(e.message.replace(/\\/g, '/').match(/file7\/index\.node/)); -} -assert.equal(require(loadOrder + 'file8').file8, 'file8/index.reg', msg); -assert.equal(require(loadOrder + 'file9').file9, 'file9/index.reg2', msg); - - -// make sure that module.require() is the same as -// doing require() inside of that module. -var parent = require('../fixtures/module-require/parent/'); -var child = require('../fixtures/module-require/child/'); -assert.equal(child.loaded, parent.loaded); - - -// #1357 Loading JSON files with require() -var json = require('../fixtures/packages/main/package.json'); -assert.deepEqual(json, { - name: 'package-name', - version: '1.2.3', - main: 'package-main-module' -}); - - -// now verify that module.children contains all the different -// modules that we've required, and that all of them contain -// the appropriate children, and so on. - -var children = module.children.reduce(function red(set, child) { - var id = path.relative(path.dirname(__dirname), child.id) - id = id.replace(/\\/g, '/'); - set[id] = child.children.reduce(red, {}); - return set; -}, {}); - -assert.deepEqual(children, { - 'common.js': {}, - 'fixtures/not-main-module.js': {}, - 'fixtures/a.js': { - 'fixtures/b/c.js': { - 'fixtures/b/d.js': {}, - 'fixtures/b/package/index.js': {} - } - }, - 'fixtures/foo': {}, - 'fixtures/nested-index/one/index.js': { - 'fixtures/nested-index/one/hello.js': {} - }, - 'fixtures/nested-index/two/index.js': { - 'fixtures/nested-index/two/hello.js': {} - }, - 'fixtures/nested-index/three.js': {}, - 'fixtures/nested-index/three/index.js': {}, - 'fixtures/packages/main/package-main-module.js': {}, - 'fixtures/packages/main-index/package-main-module/index.js': {}, - 'fixtures/cycles/root.js': { - 'fixtures/cycles/folder/foo.js': {} - }, - 'fixtures/node_modules/foo.js': { - 'fixtures/node_modules/baz/index.js': { - 'fixtures/node_modules/bar.js': {}, - 'fixtures/node_modules/baz/node_modules/asdf.js': {} - } - }, - 'simple/path.js': {}, - 'fixtures/throws_error.js': {}, - 'fixtures/registerExt.test': {}, - 'fixtures/registerExt.hello.world': {}, - 'fixtures/registerExt2.test': {}, - 'fixtures/empty.js': {}, - 'fixtures/module-load-order/file1': {}, - 'fixtures/module-load-order/file2.js': {}, - 'fixtures/module-load-order/file3.node': {}, - 'fixtures/module-load-order/file4.reg': {}, - 'fixtures/module-load-order/file5.reg2': {}, - 'fixtures/module-load-order/file6/index.js': {}, - 'fixtures/module-load-order/file7/index.node': {}, - 'fixtures/module-load-order/file8/index.reg': {}, - 'fixtures/module-load-order/file9/index.reg2': {}, - 'fixtures/module-require/parent/index.js': { - 'fixtures/module-require/child/index.js': { - 'fixtures/module-require/child/node_modules/target.js': {} - } - }, - 'fixtures/packages/main/package.json': {} -}); - - -// require() must take string, and must be truthy -assert.throws(function() { - console.error('require non-string'); - require({ foo: 'bar' }); -}, 'path must be a string'); - -assert.throws(function() { - console.error('require empty string'); - require(''); -}, 'missing path'); - -process.on('exit', function() { - assert.ok(common.indirectInstanceOf(a.A, Function)); - assert.equal('A done', a.A()); - - assert.ok(common.indirectInstanceOf(a.C, Function)); - assert.equal('C done', a.C()); - - assert.ok(common.indirectInstanceOf(a.D, Function)); - assert.equal('D done', a.D()); - - assert.ok(common.indirectInstanceOf(d.D, Function)); - assert.equal('D done', d.D()); - - assert.ok(common.indirectInstanceOf(d2.D, Function)); - assert.equal('D done', d2.D()); - - assert.equal(true, errorThrown); - - console.log('exit'); -}); - - -// #1440 Loading files with a byte order marker. -assert.equal(42, require('../fixtures/utf8-bom.js')); -assert.equal(42, require('../fixtures/utf8-bom.json')); diff --git a/test/simple/test-net-GH-5504.js b/test/simple/test-net-GH-5504.js deleted file mode 100644 index d5059f028640..000000000000 --- a/test/simple/test-net-GH-5504.js +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// this test only fails with CentOS 6.3 using kernel version 2.6.32 -// On other linuxes and darwin, the `read` call gets an ECONNRESET in -// that case. On sunos, the `write` call fails with EPIPE. -// -// However, old CentOS will occasionally send an EOF instead of a -// ECONNRESET or EPIPE when the client has been destroyed abruptly. -// -// Make sure we don't keep trying to write or read more in that case. - -switch (process.argv[2]) { - case 'server': return server(); - case 'client': return client(); - case undefined: return parent(); - default: throw new Error('wtf'); -} - -function server() { - var net = require('net'); - var content = new Buffer(64 * 1024 * 1024); - content.fill('#'); - net.createServer(function(socket) { - this.close(); - socket.on('end', function() { - console.error('end'); - }); - socket.on('_socketEnd', function() { - console.error('_socketEnd'); - }); - socket.write(content); - }).listen(3000, function() { - console.log('listening'); - }); -} - -function client() { - var net = require('net'); - var client = net.connect({ - host: 'localhost', - port: 3000 - }, function() { - client.destroy(); - }); -} - -function parent() { - var spawn = require('child_process').spawn; - var node = process.execPath; - var assert = require('assert'); - var serverExited = false; - var clientExited = false; - var serverListened = false; - var opt = { env: { NODE_DEBUG: 'net' } }; - - process.on('exit', function() { - assert(serverExited); - assert(clientExited); - assert(serverListened); - console.log('ok'); - }); - - setTimeout(function() { - if (s) s.kill(); - if (c) c.kill(); - setTimeout(function() { - throw new Error('hang'); - }); - }, 1000).unref(); - - var s = spawn(node, [__filename, 'server'], opt); - var c; - - wrap(s.stderr, process.stderr, 'SERVER 2>'); - wrap(s.stdout, process.stdout, 'SERVER 1>'); - s.on('exit', function(c) { - console.error('server exited', c); - serverExited = true; - }); - - s.stdout.once('data', function() { - serverListened = true; - c = spawn(node, [__filename, 'client']); - wrap(c.stderr, process.stderr, 'CLIENT 2>'); - wrap(c.stdout, process.stdout, 'CLIENT 1>'); - c.on('exit', function(c) { - console.error('client exited', c); - clientExited = true; - }); - }); - - function wrap(inp, out, w) { - inp.setEncoding('utf8'); - inp.on('data', function(c) { - c = c.trim(); - if (!c) return; - out.write(w + c.split('\n').join('\n' + w) + '\n'); - }); - } -} - diff --git a/test/simple/test-net-after-close.js b/test/simple/test-net-after-close.js deleted file mode 100644 index 2f3d4c37976a..000000000000 --- a/test/simple/test-net-after-close.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var closed = false; - -var server = net.createServer(function(s) { - console.error('SERVER: got connection'); - s.end(); -}); - -server.listen(common.PORT, function() { - var c = net.createConnection(common.PORT); - c.on('close', function() { - console.error('connection closed'); - assert.strictEqual(c._handle, null); - closed = true; - assert.doesNotThrow(function() { - c.setNoDelay(); - c.setKeepAlive(); - c.bufferSize; - c.pause(); - c.resume(); - c.address(); - c.remoteAddress; - c.remotePort; - }); - server.close(); - }); -}); - -process.on('exit', function() { - assert(closed); -}); diff --git a/test/simple/test-net-binary.js b/test/simple/test-net-binary.js deleted file mode 100644 index 310046584641..000000000000 --- a/test/simple/test-net-binary.js +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var binaryString = ''; -for (var i = 255; i >= 0; i--) { - var s = '\'\\' + i.toString(8) + '\''; - var S = eval(s); - common.error(s + - ' ' + - JSON.stringify(S) + - ' ' + - JSON.stringify(String.fromCharCode(i)) + - ' ' + - S.charCodeAt(0)); - assert.ok(S.charCodeAt(0) == i); - assert.ok(S == String.fromCharCode(i)); - binaryString += S; -} - -// safe constructor -var echoServer = net.Server(function(connection) { - console.error('SERVER got connection'); - connection.setEncoding('binary'); - connection.on('data', function(chunk) { - common.error('SERVER recved: ' + JSON.stringify(chunk)); - connection.write(chunk, 'binary'); - }); - connection.on('end', function() { - console.error('SERVER ending'); - connection.end(); - }); -}); -echoServer.listen(common.PORT); - -var recv = ''; - -echoServer.on('listening', function() { - console.error('SERVER listening'); - var j = 0; - var c = net.createConnection({ - port: common.PORT - }); - - c.setEncoding('binary'); - c.on('data', function(chunk) { - console.error('CLIENT data %j', chunk); - var n = j + chunk.length; - while (j < n && j < 256) { - common.error('CLIENT write ' + j); - c.write(String.fromCharCode(j), 'binary'); - j++; - } - if (j === 256) { - console.error('CLIENT ending'); - c.end(); - } - recv += chunk; - }); - - c.on('connect', function() { - console.error('CLIENT connected, writing'); - c.write(binaryString, 'binary'); - }); - - c.on('close', function() { - console.error('CLIENT closed'); - console.dir(recv); - echoServer.close(); - }); - - c.on('finish', function() { - console.error('CLIENT finished'); - }); -}); - -process.on('exit', function() { - console.log('recv: ' + JSON.stringify(recv)); - - assert.equal(2 * 256, recv.length); - - var a = recv.split(''); - - var first = a.slice(0, 256).reverse().join(''); - console.log('first: ' + JSON.stringify(first)); - - var second = a.slice(256, 2 * 256).join(''); - console.log('second: ' + JSON.stringify(second)); - - assert.equal(first, second); -}); diff --git a/test/simple/test-net-bind-twice.js b/test/simple/test-net-bind-twice.js deleted file mode 100644 index 58086cc9669f..000000000000 --- a/test/simple/test-net-bind-twice.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var gotError = false; - -process.on('exit', function() { - assert(gotError); -}); - -function dontCall() { - assert(false); -} - -var server1 = net.createServer(dontCall); -server1.listen(common.PORT, '127.0.0.1', function() {}); - -var server2 = net.createServer(dontCall); -server2.listen(common.PORT, '127.0.0.1', dontCall); - -server2.on('error', function(e) { - assert.equal(e.code, 'EADDRINUSE'); - server1.close(); - gotError = true; -}); diff --git a/test/simple/test-net-buffersize.js b/test/simple/test-net-buffersize.js deleted file mode 100644 index 5759503a134e..000000000000 --- a/test/simple/test-net-buffersize.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var iter = 10; - -var server = net.createServer(function(socket) { - socket.on('readable', function() { - socket.read(); - }); - - socket.on('end', function() { - server.close(); - }); -}); - -server.listen(common.PORT, function() { - var client = net.connect(common.PORT); - - client.on('finish', function() { - assert.strictEqual(client.bufferSize, 0); - }); - - for (var i = 1; i < iter; i++) { - client.write('a'); - assert.strictEqual(client.bufferSize, i); - } - - client.end(); -}); diff --git a/test/simple/test-net-bytes-stats.js b/test/simple/test-net-bytes-stats.js deleted file mode 100644 index 0cb08009ee4e..000000000000 --- a/test/simple/test-net-bytes-stats.js +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var tcpPort = common.PORT; -var bytesRead = 0; -var bytesWritten = 0; -var count = 0; - -var tcp = net.Server(function(s) { - console.log('tcp server connection'); - - // trigger old mode. - s.resume(); - - s.on('end', function() { - bytesRead += s.bytesRead; - console.log('tcp socket disconnect #' + count); - }); -}); - -tcp.listen(common.PORT, function doTest() { - console.error('listening'); - var socket = net.createConnection(tcpPort); - - socket.on('connect', function() { - count++; - console.error('CLIENT connect #%d', count); - - socket.write('foo', function() { - console.error('CLIENT: write cb'); - socket.end('bar'); - }); - }); - - socket.on('finish', function() { - bytesWritten += socket.bytesWritten; - console.error('CLIENT end event #%d', count); - }); - - socket.on('close', function() { - console.error('CLIENT close event #%d', count); - console.log('Bytes read: ' + bytesRead); - console.log('Bytes written: ' + bytesWritten); - if (count < 2) { - console.error('RECONNECTING'); - socket.connect(tcpPort); - } else { - tcp.close(); - } - }); -}); - -process.on('exit', function() { - assert.equal(bytesRead, 12); - assert.equal(bytesWritten, 12); -}); diff --git a/test/simple/test-net-can-reset-timeout.js b/test/simple/test-net-can-reset-timeout.js deleted file mode 100644 index b9ea97efe80b..000000000000 --- a/test/simple/test-net-can-reset-timeout.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var net = require('net'); -var common = require('../common'); -var assert = require('assert'); - -var timeoutCount = 0; - -var server = net.createServer(function(stream) { - stream.setTimeout(100); - - stream.resume(); - - stream.on('timeout', function() { - console.log('timeout'); - // try to reset the timeout. - stream.write('WHAT.'); - // don't worry, the socket didn't *really* time out, we're just thinking - // it did. - timeoutCount += 1; - }); - - stream.on('end', function() { - console.log('server side end'); - stream.end(); - }); -}); - -server.listen(common.PORT, function() { - var c = net.createConnection(common.PORT); - - c.on('data', function() { - c.end(); - }); - - c.on('end', function() { - console.log('client side end'); - server.close(); - }); -}); - - -process.on('exit', function() { - assert.equal(1, timeoutCount); -}); diff --git a/test/simple/test-net-connect-buffer.js b/test/simple/test-net-connect-buffer.js deleted file mode 100644 index 679e18e90720..000000000000 --- a/test/simple/test-net-connect-buffer.js +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var tcpPort = common.PORT; -var dataWritten = false; -var connectHappened = false; - -var tcp = net.Server(function(s) { - tcp.close(); - - console.log('tcp server connection'); - - var buf = ''; - s.on('data', function(d) { - buf += d; - }); - - s.on('end', function() { - console.error('SERVER: end', buf.toString()); - assert.equal(buf, "L'État, c'est moi"); - console.log('tcp socket disconnect'); - s.end(); - }); - - s.on('error', function(e) { - console.log('tcp server-side error: ' + e.message); - process.exit(1); - }); -}); - -tcp.listen(common.PORT, function() { - var socket = net.Stream({ highWaterMark: 0 }); - - console.log('Connecting to socket '); - - socket.connect(tcpPort, function() { - console.log('socket connected'); - connectHappened = true; - }); - - console.log('_connecting = ' + socket._connecting); - - assert.equal('opening', socket.readyState); - - // Make sure that anything besides a buffer or a string throws. - [null, - true, - false, - undefined, - 1, - 1.0, - 1 / 0, - +Infinity, - -Infinity, - [], - {} - ].forEach(function(v) { - function f() { - console.error('write', v); - socket.write(v); - } - assert.throws(f, TypeError); - }); - - // Write a string that contains a multi-byte character sequence to test that - // `bytesWritten` is incremented with the # of bytes, not # of characters. - var a = "L'État, c'est "; - var b = 'moi'; - - // We're still connecting at this point so the datagram is first pushed onto - // the connect queue. Make sure that it's not added to `bytesWritten` again - // when the actual write happens. - var r = socket.write(a, function(er) { - console.error('write cb'); - dataWritten = true; - assert.ok(connectHappened); - console.error('socket.bytesWritten', socket.bytesWritten); - //assert.equal(socket.bytesWritten, Buffer(a + b).length); - console.error('data written'); - }); - console.error('socket.bytesWritten', socket.bytesWritten); - console.error('write returned', r); - - assert.equal(socket.bytesWritten, Buffer(a).length); - - assert.equal(false, r); - socket.end(b); - - assert.equal('opening', socket.readyState); -}); - -process.on('exit', function() { - assert.ok(connectHappened); - assert.ok(dataWritten); -}); diff --git a/test/simple/test-net-connect-handle-econnrefused.js b/test/simple/test-net-connect-handle-econnrefused.js deleted file mode 100644 index e890b6a8d49e..000000000000 --- a/test/simple/test-net-connect-handle-econnrefused.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var net = require('net'); -var assert = require('assert'); - - -// Hopefully nothing is running on common.PORT -var c = net.createConnection(common.PORT); - -c.on('connect', function() { - console.error('connected?!'); - assert.ok(false); -}); - -var gotError = false; -c.on('error', function(e) { - console.error('couldn\'t connect.'); - gotError = true; - assert.equal('ECONNREFUSED', e.code); -}); - - -process.on('exit', function() { - assert.ok(gotError); -}); diff --git a/test/simple/test-net-connect-immediate-finish.js b/test/simple/test-net-connect-immediate-finish.js deleted file mode 100644 index ac2a61331d19..000000000000 --- a/test/simple/test-net-connect-immediate-finish.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var gotError = false; - -var client = net.connect({ - host: 'no.way.you.will.resolve.this', - port: common.PORT -}); - -client.once('error', function(err) { - gotError = true; -}); - -client.end(); - -process.on('exit', function() { - assert(gotError); -}); diff --git a/test/simple/test-net-connect-options.js b/test/simple/test-net-connect-options.js deleted file mode 100644 index 6be3696dae72..000000000000 --- a/test/simple/test-net-connect-options.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var serverGotEnd = false; -var clientGotEnd = false; - -var server = net.createServer({allowHalfOpen: true}, function(socket) { - socket.resume(); - socket.on('end', function() { - serverGotEnd = true; - }); - socket.end(); -}); - -server.listen(common.PORT, function() { - var client = net.connect({ - host: '127.0.0.1', - port: common.PORT, - allowHalfOpen: true - }, function() { - console.error('client connect cb'); - client.resume(); - client.on('end', function() { - clientGotEnd = true; - setTimeout(function() { - assert(client.writable); - client.end(); - }, 10); - }); - client.on('close', function() { - server.close(); - }); - }); -}); - -process.on('exit', function() { - console.error('exit', serverGotEnd, clientGotEnd); - assert(serverGotEnd); - assert(clientGotEnd); -}); diff --git a/test/simple/test-net-create-connection.js b/test/simple/test-net-create-connection.js deleted file mode 100644 index c21be152c0c5..000000000000 --- a/test/simple/test-net-create-connection.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var tcpPort = common.PORT; -var clientConnected = 0; -var serverConnected = 0; - -var server = net.createServer(function(socket) { - socket.end(); - if (++serverConnected === 4) { - server.close(); - } -}); -server.listen(tcpPort, 'localhost', function() { - function cb() { - ++clientConnected; - } - - net.createConnection(tcpPort).on('connect', cb); - net.createConnection(tcpPort, 'localhost').on('connect', cb); - net.createConnection(tcpPort, cb); - net.createConnection(tcpPort, 'localhost', cb); -}); - -process.on('exit', function() { - assert.equal(clientConnected, 4); -}); - diff --git a/test/simple/test-net-dns-error.js b/test/simple/test-net-dns-error.js deleted file mode 100644 index 10857a9af037..000000000000 --- a/test/simple/test-net-dns-error.js +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var net = require('net'); - -var expected_bad_connections = 1; -var actual_bad_connections = 0; - -var host = '********'; -host += host; -host += host; -host += host; -host += host; -host += host; - -function do_not_call() { - throw new Error('This function should not have been called.'); -} - -var socket = net.connect(42, host, do_not_call); -socket.on('error', function(err) { - assert.equal(err.code, 'ENOTFOUND'); - actual_bad_connections++; -}); - -process.on('exit', function() { - assert.equal(actual_bad_connections, expected_bad_connections); -}); diff --git a/test/simple/test-net-during-close.js b/test/simple/test-net-during-close.js deleted file mode 100644 index 0bcdd4d3a0be..000000000000 --- a/test/simple/test-net-during-close.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var accessedProperties = false; - -var server = net.createServer(function(socket) { - socket.end(); -}); - -server.listen(common.PORT, function() { - var client = net.createConnection(common.PORT); - server.close(); - // server connection event has not yet fired - // client is still attempting to connect - assert.doesNotThrow(function() { - client.remoteAddress; - client.remotePort; - }); - accessedProperties = true; - // exit now, do not wait for the client error event - process.exit(0); -}); - -process.on('exit', function() { - assert(accessedProperties); -}); diff --git a/test/simple/test-net-eaddrinuse.js b/test/simple/test-net-eaddrinuse.js deleted file mode 100644 index 2192ea22420e..000000000000 --- a/test/simple/test-net-eaddrinuse.js +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var server1 = net.createServer(function(socket) { -}); -var server2 = net.createServer(function(socket) { -}); -server1.listen(common.PORT); -server2.on('error', function(error) { - assert.equal(true, error.message.indexOf('EADDRINUSE') >= 0); - server1.close(); -}); -server2.listen(common.PORT); diff --git a/test/simple/test-net-end-without-connect.js b/test/simple/test-net-end-without-connect.js deleted file mode 100644 index 156071a0d124..000000000000 --- a/test/simple/test-net-end-without-connect.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var net = require('net'); - -var sock = new net.Socket; -sock.end(); // Should not throw. diff --git a/test/simple/test-net-error-twice.js b/test/simple/test-net-error-twice.js deleted file mode 100644 index 5ab370eb33b3..000000000000 --- a/test/simple/test-net-error-twice.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var buf = new Buffer(2 * 1024 * 1024); - -buf.fill(0x62); - -var errs = []; - -var srv = net.createServer(function onConnection(conn) { - conn.write(buf); - conn.on('error', function (err) { - errs.push(err); - if (errs.length > 1 && errs[0] === errs[1]) - assert(false, "We should not be emitting the same error twice"); - }); - conn.on('close', function() { - srv.unref(); - }); -}).listen(common.PORT, function () { - var client = net.connect({ port: common.PORT }); - - client.on('connect', function () { - client.destroy(); - }); -}); - -process.on('exit', function() { - console.log(errs); - assert.equal(errs.length, 1); -}); diff --git a/test/simple/test-net-isip.js b/test/simple/test-net-isip.js deleted file mode 100644 index 0d324007f221..000000000000 --- a/test/simple/test-net-isip.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -assert.equal(net.isIP('127.0.0.1'), 4); -assert.equal(net.isIP('x127.0.0.1'), 0); -assert.equal(net.isIP('example.com'), 0); -assert.equal(net.isIP('0000:0000:0000:0000:0000:0000:0000:0000'), 6); -assert.equal(net.isIP('0000:0000:0000:0000:0000:0000:0000:0000::0000'), 0); -assert.equal(net.isIP('1050:0:0:0:5:600:300c:326b'), 6); -assert.equal(net.isIP('2001:252:0:1::2008:6'), 6); -assert.equal(net.isIP('2001:dead:beef:1::2008:6'), 6); -assert.equal(net.isIP('2001::'), 6); -assert.equal(net.isIP('2001:dead::'), 6); -assert.equal(net.isIP('2001:dead:beef::'), 6); -assert.equal(net.isIP('2001:dead:beef:1::'), 6); -assert.equal(net.isIP('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'), 6); -assert.equal(net.isIP(':2001:252:0:1::2008:6:'), 0); -assert.equal(net.isIP(':2001:252:0:1::2008:6'), 0); -assert.equal(net.isIP('2001:252:0:1::2008:6:'), 0); -assert.equal(net.isIP('2001:252::1::2008:6'), 0); -assert.equal(net.isIP('::2001:252:1:2008:6'), 6); -assert.equal(net.isIP('::2001:252:1:1.1.1.1'), 6); -assert.equal(net.isIP('::2001:252:1:255.255.255.255'), 6); -assert.equal(net.isIP('::2001:252:1:255.255.255.255.76'), 0); -assert.equal(net.isIP('::anything'), 0); -assert.equal(net.isIP('::1'), 6); -assert.equal(net.isIP('::'), 6); -assert.equal(net.isIP('0000:0000:0000:0000:0000:0000:12345:0000'), 0); -assert.equal(net.isIP('0'), 0); -assert.equal(net.isIP(), 0); -assert.equal(net.isIP(""), 0); - -assert.equal(net.isIPv4('127.0.0.1'), true); -assert.equal(net.isIPv4('example.com'), false); -assert.equal(net.isIPv4('2001:252:0:1::2008:6'), false); - -assert.equal(net.isIPv6('127.0.0.1'), false); -assert.equal(net.isIPv6('example.com'), false); -assert.equal(net.isIPv6('2001:252:0:1::2008:6'), true); diff --git a/test/simple/test-net-keepalive.js b/test/simple/test-net-keepalive.js deleted file mode 100644 index b09d9d5d68f9..000000000000 --- a/test/simple/test-net-keepalive.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var serverConnection; -var echoServer = net.createServer(function(connection) { - serverConnection = connection; - connection.setTimeout(0); - assert.notEqual(connection.setKeepAlive, undefined); - // send a keepalive packet after 1000 ms - connection.setKeepAlive(true, 1000); - connection.on('end', function() { - connection.end(); - }); -}); -echoServer.listen(common.PORT); - -echoServer.on('listening', function() { - var clientConnection = net.createConnection(common.PORT); - clientConnection.setTimeout(0); - - setTimeout(function() { - // make sure both connections are still open - assert.equal(serverConnection.readyState, 'open'); - assert.equal(clientConnection.readyState, 'open'); - serverConnection.end(); - clientConnection.end(); - echoServer.close(); - }, 1200); -}); diff --git a/test/simple/test-net-large-string.js b/test/simple/test-net-large-string.js deleted file mode 100644 index 877dc7c780e3..000000000000 --- a/test/simple/test-net-large-string.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var kPoolSize = 40 * 1024; -var data = ''; -for (var i = 0; i < kPoolSize; ++i) { - data += 'あ'; // 3bytes -} -var receivedSize = 0; -var encoding = 'UTF-8'; - -var server = net.createServer(function(socket) { - socket.setEncoding(encoding); - socket.on('data', function(data) { - receivedSize += data.length; - }); - socket.on('end', function() { - socket.end(); - }); -}); - -server.listen(common.PORT, function() { - var client = net.createConnection(common.PORT); - client.on('end', function() { - server.close(); - }); - client.write(data, encoding); - client.end(); -}); - -process.on('exit', function() { - assert.equal(receivedSize, kPoolSize); -}); diff --git a/test/simple/test-net-listen-error.js b/test/simple/test-net-listen-error.js deleted file mode 100644 index 17ec762cafe1..000000000000 --- a/test/simple/test-net-listen-error.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var gotError = false; - -var server = net.createServer(function(socket) { -}); -server.listen(1, '1.1.1.1', function() { // EACCESS or EADDRNOTAVAIL - assert(false); -}); -server.on('error', function(error) { - common.debug(error); - gotError = true; -}); - -process.on('exit', function() { - assert(gotError); -}); diff --git a/test/simple/test-net-listen-fd0.js b/test/simple/test-net-listen-fd0.js deleted file mode 100644 index ac5896ee8f99..000000000000 --- a/test/simple/test-net-listen-fd0.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var gotError = false; - -process.on('exit', function() { - assert(gotError instanceof Error); -}); - -// this should fail with an async EINVAL error, not throw an exception -net.createServer(assert.fail).listen({fd:0}).on('error', function(e) { - switch(e.code) { - case 'EINVAL': - case 'ENOTSOCK': - gotError = e; - break - } -}); diff --git a/test/simple/test-net-local-address-port.js b/test/simple/test-net-local-address-port.js deleted file mode 100644 index 0f59cec9b6fa..000000000000 --- a/test/simple/test-net-local-address-port.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var conns = 0, conns_closed = 0; - -var server = net.createServer(function(socket) { - conns++; - assert.equal('127.0.0.1', socket.localAddress); - assert.equal(socket.localPort, common.PORT); - socket.on('end', function() { - server.close(); - }); - socket.resume(); -}); - -server.listen(common.PORT, '127.0.0.1', function() { - var client = net.createConnection(common.PORT, '127.0.0.1'); - client.on('connect', function() { - client.end(); - }); -}); - -process.on('exit', function() { - assert.equal(1, conns); -}); diff --git a/test/simple/test-net-pause-resume-connecting.js b/test/simple/test-net-pause-resume-connecting.js deleted file mode 100644 index 264dc96801b6..000000000000 --- a/test/simple/test-net-pause-resume-connecting.js +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'), - assert = require('assert'), - net = require('net'); - -var connections = 0, - dataEvents = 0, - conn; - - -// Server -var server = net.createServer(function(conn) { - connections++; - conn.end('This was the year he fell to pieces.'); - - if (connections === 5) - server.close(); -}); - -server.listen(common.PORT); - - -// Client 1 -conn = require('net').createConnection(common.PORT, 'localhost'); -conn.resume(); -conn.on('data', onDataOk); - - -// Client 2 -conn = require('net').createConnection(common.PORT, 'localhost'); -conn.pause(); -conn.resume(); -conn.on('data', onDataOk); - - -// Client 3 -conn = require('net').createConnection(common.PORT, 'localhost'); -conn.pause(); -conn.on('data', onDataError); -scheduleTearDown(conn); - - -// Client 4 -conn = require('net').createConnection(common.PORT, 'localhost'); -conn.resume(); -conn.pause(); -conn.resume(); -conn.on('data', onDataOk); - - -// Client 5 -conn = require('net').createConnection(common.PORT, 'localhost'); -conn.resume(); -conn.resume(); -conn.pause(); -conn.on('data', onDataError); -scheduleTearDown(conn); - - -// Client helper functions -function onDataError() { - assert(false); -} - -function onDataOk() { - dataEvents++; -} - -function scheduleTearDown(conn) { - setTimeout(function() { - conn.removeAllListeners('data'); - conn.resume(); - }, 100); -} - - -// Exit sanity checks -process.on('exit', function() { - assert.strictEqual(connections, 5); - assert.strictEqual(dataEvents, 3); -}); diff --git a/test/simple/test-net-pingpong.js b/test/simple/test-net-pingpong.js deleted file mode 100644 index 1e7b6681ab26..000000000000 --- a/test/simple/test-net-pingpong.js +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var net = require('net'); - -var tests_run = 0; - -function pingPongTest(port, host) { - var N = 1000; - var count = 0; - var sentPongs = 0; - var sent_final_ping = false; - - var server = net.createServer({ allowHalfOpen: true }, function(socket) { - console.log('connection: ' + socket.remoteAddress); - assert.equal(server, socket.server); - assert.equal(1, server.connections); - - socket.setNoDelay(); - socket.timeout = 0; - - socket.setEncoding('utf8'); - socket.on('data', function(data) { - // Since we never queue data (we're always waiting for the PING - // before sending a pong) the writeQueueSize should always be less - // than one message. - assert.ok(0 <= socket.bufferSize && socket.bufferSize <= 4); - - console.log('server got: ' + data); - assert.equal(true, socket.writable); - assert.equal(true, socket.readable); - assert.equal(true, count <= N); - if (/PING/.exec(data)) { - socket.write('PONG', function() { - sentPongs++; - console.error('sent PONG'); - }); - } - }); - - socket.on('end', function() { - console.error(socket); - assert.equal(true, socket.allowHalfOpen); - assert.equal(true, socket.writable); // because allowHalfOpen - assert.equal(false, socket.readable); - socket.end(); - }); - - socket.on('error', function(e) { - throw e; - }); - - socket.on('close', function() { - console.log('server socket.endd'); - assert.equal(false, socket.writable); - assert.equal(false, socket.readable); - socket.server.close(); - }); - }); - - - server.listen(port, host, function() { - console.log('server listening on ' + port + ' ' + host); - - var client = net.createConnection(port, host); - - client.setEncoding('ascii'); - client.on('connect', function() { - assert.equal(true, client.readable); - assert.equal(true, client.writable); - client.write('PING'); - }); - - client.on('data', function(data) { - console.log('client got: ' + data); - - assert.equal('PONG', data); - count += 1; - - if (sent_final_ping) { - assert.equal(false, client.writable); - assert.equal(true, client.readable); - return; - } else { - assert.equal(true, client.writable); - assert.equal(true, client.readable); - } - - if (count < N) { - client.write('PING'); - } else { - sent_final_ping = true; - client.write('PING'); - client.end(); - } - }); - - client.on('close', function() { - console.log('client.end'); - assert.equal(N + 1, count); - assert.equal(N + 1, sentPongs); - assert.equal(true, sent_final_ping); - tests_run += 1; - }); - - client.on('error', function(e) { - throw e; - }); - }); -} - -/* All are run at once, so run on different ports */ -console.log(common.PIPE); -pingPongTest(common.PIPE); -pingPongTest(common.PORT); -pingPongTest(common.PORT + 1, 'localhost'); -pingPongTest(common.PORT + 2, '::1'); - -process.on('exit', function() { - assert.equal(4, tests_run); - console.log('done'); -}); diff --git a/test/simple/test-net-pipe-connect-errors.js b/test/simple/test-net-pipe-connect-errors.js deleted file mode 100644 index 8200a16cf0ba..000000000000 --- a/test/simple/test-net-pipe-connect-errors.js +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var fs = require('fs'); -var net = require('net'); -var path = require('path'); -var assert = require('assert'); -var common = require('../common'); - -var notSocketErrorFired = false; -var noEntErrorFired = false; -var accessErrorFired = false; - -// Test if ENOTSOCK is fired when trying to connect to a file which is not -// a socket. -var emptyTxt = path.join(common.fixturesDir, 'empty.txt'); -var notSocketClient = net.createConnection(emptyTxt, function() { - assert.ok(false); -}); - -notSocketClient.on('error', function(err) { - assert(err.code === 'ENOTSOCK' || err.code === 'ECONNREFUSED'); - notSocketErrorFired = true; -}); - - -// Trying to connect to not-existing socket should result in ENOENT error -var noEntSocketClient = net.createConnection('no-ent-file', function() { - assert.ok(false); -}); - -noEntSocketClient.on('error', function(err) { - assert.equal(err.code, 'ENOENT'); - noEntErrorFired = true; -}); - - -// On Windows or when running as root, a chmod has no effect on named pipes -if (process.platform !== 'win32' && process.getuid() !== 0) { - // Trying to connect to a socket one has no access to should result in EACCES - var accessServer = net.createServer(function() { - assert.ok(false); - }); - accessServer.listen(common.PIPE, function() { - fs.chmodSync(common.PIPE, 0); - - var accessClient = net.createConnection(common.PIPE, function() { - assert.ok(false); - }); - - accessClient.on('error', function(err) { - assert.equal(err.code, 'EACCES'); - accessErrorFired = true; - accessServer.close(); - }); - }); -} - - -// Assert that all error events were fired -process.on('exit', function() { - assert.ok(notSocketErrorFired); - assert.ok(noEntErrorFired); - if (process.platform !== 'win32' && process.getuid() !== 0) { - assert.ok(accessErrorFired); - } -}); - diff --git a/test/simple/test-net-reconnect.js b/test/simple/test-net-reconnect.js deleted file mode 100644 index ffc2a73c6313..000000000000 --- a/test/simple/test-net-reconnect.js +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var net = require('net'); - -var N = 50; -var c = 0; -var client_recv_count = 0; -var client_end_count = 0; -var disconnect_count = 0; - -var server = net.createServer(function(socket) { - console.error('SERVER: got socket connection'); - socket.resume(); - - console.error('SERVER connect, writing'); - socket.write('hello\r\n'); - - socket.on('end', function() { - console.error('SERVER socket end, calling end()'); - socket.end(); - }); - - socket.on('close', function(had_error) { - console.log('SERVER had_error: ' + JSON.stringify(had_error)); - assert.equal(false, had_error); - }); -}); - -server.listen(common.PORT, function() { - console.log('SERVER listening'); - var client = net.createConnection(common.PORT); - - client.setEncoding('UTF8'); - - client.on('connect', function() { - console.error('CLIENT connected', client._writableState); - }); - - client.on('data', function(chunk) { - client_recv_count += 1; - console.log('client_recv_count ' + client_recv_count); - assert.equal('hello\r\n', chunk); - console.error('CLIENT: calling end', client._writableState); - client.end(); - }); - - client.on('end', function() { - console.error('CLIENT end'); - client_end_count++; - }); - - client.on('close', function(had_error) { - console.log('CLIENT disconnect'); - assert.equal(false, had_error); - if (disconnect_count++ < N) - client.connect(common.PORT); // reconnect - else - server.close(); - }); -}); - -process.on('exit', function() { - assert.equal(N + 1, disconnect_count); - assert.equal(N + 1, client_recv_count); - assert.equal(N + 1, client_end_count); -}); - diff --git a/test/simple/test-net-remote-address-port.js b/test/simple/test-net-remote-address-port.js deleted file mode 100644 index 5d1ae3c8eb63..000000000000 --- a/test/simple/test-net-remote-address-port.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var net = require('net'); - -var conns = 0, conns_closed = 0; - -var server = net.createServer(function(socket) { - conns++; - assert.equal('127.0.0.1', socket.remoteAddress); - assert.ok(socket.remotePort); - assert.notEqual(socket.remotePort, common.PORT); - socket.on('end', function() { - if (++conns_closed == 2) server.close(); - }); - socket.resume(); -}); - -server.listen(common.PORT, 'localhost', function() { - var client = net.createConnection(common.PORT, 'localhost'); - var client2 = net.createConnection(common.PORT); - client.on('connect', function() { - assert.equal('127.0.0.1', client.remoteAddress); - assert.equal(common.PORT, client.remotePort); - client.end(); - }); - client2.on('connect', function() { - assert.equal('127.0.0.1', client2.remoteAddress); - assert.equal(common.PORT, client2.remotePort); - client2.end(); - }); -}); - -process.on('exit', function() { - assert.equal(2, conns); -}); diff --git a/test/simple/test-net-server-address.js b/test/simple/test-net-server-address.js deleted file mode 100644 index a9f92c448be2..000000000000 --- a/test/simple/test-net-server-address.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -// Test on IPv4 Server -var localhost_ipv4 = '127.0.0.1'; -var family_ipv4 = 'IPv4'; -var server_ipv4 = net.createServer(); - -server_ipv4.on('error', function(e) { - console.log('Error on ipv4 socket: ' + e.toString()); -}); - -server_ipv4.listen(common.PORT, localhost_ipv4, function() { - var address_ipv4 = server_ipv4.address(); - assert.strictEqual(address_ipv4.address, localhost_ipv4); - assert.strictEqual(address_ipv4.port, common.PORT); - assert.strictEqual(address_ipv4.family, family_ipv4); - server_ipv4.close(); -}); - -// Test on IPv6 Server -var localhost_ipv6 = '::1'; -var family_ipv6 = 'IPv6'; -var server_ipv6 = net.createServer(); - -server_ipv6.on('error', function(e) { - console.log('Error on ipv6 socket: ' + e.toString()); -}); - -server_ipv6.listen(common.PORT, localhost_ipv6, function() { - var address_ipv6 = server_ipv6.address(); - assert.strictEqual(address_ipv6.address, localhost_ipv6); - assert.strictEqual(address_ipv6.port, common.PORT); - assert.strictEqual(address_ipv6.family, family_ipv6); - server_ipv6.close(); -}); diff --git a/test/simple/test-net-server-bind.js b/test/simple/test-net-server-bind.js deleted file mode 100644 index 0951aa246209..000000000000 --- a/test/simple/test-net-server-bind.js +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - - -// With only a callback, server should get a port assigned by the OS - -var address0; -var server0 = net.createServer(function(socket) { }); - -server0.listen(function() { - address0 = server0.address(); - console.log('address0 %j', address0); - server0.close(); -}); - - -// No callback to listen(), assume we can bind in 100 ms - -var address1; -var server1 = net.createServer(function(socket) { }); - -server1.listen(common.PORT); - -setTimeout(function() { - address1 = server1.address(); - console.log('address1 %j', address1); - server1.close(); -}, 100); - - -// Callback to listen() - -var address2; -var server2 = net.createServer(function(socket) { }); - -server2.listen(common.PORT + 1, function() { - address2 = server2.address(); - console.log('address2 %j', address2); - server2.close(); -}); - - -// Backlog argument - -var address3; -var server3 = net.createServer(function(socket) { }); - -server3.listen(common.PORT + 2, '0.0.0.0', 127, function() { - address3 = server3.address(); - console.log('address3 %j', address3); - server3.close(); -}); - - -// Backlog argument without host argument - -var address4; -var server4 = net.createServer(function(socket) { }); - -server4.listen(common.PORT + 3, 127, function() { - address4 = server4.address(); - console.log('address4 %j', address4); - server4.close(); -}); - - -process.on('exit', function() { - assert.ok(address0.port > 100); - assert.equal(common.PORT, address1.port); - assert.equal(common.PORT + 1, address2.port); - assert.equal(common.PORT + 2, address3.port); - assert.equal(common.PORT + 3, address4.port); -}); diff --git a/test/simple/test-net-server-close.js b/test/simple/test-net-server-close.js deleted file mode 100644 index afa83f10d6aa..000000000000 --- a/test/simple/test-net-server-close.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var events = []; -var sockets = []; - -process.on('exit', function() { - assert.equal(server.connections, 0); - assert.equal(events.length, 3); - // Expect to see one server event and two client events. The order of the - // events is undefined because they arrive on the same event loop tick. - assert.equal(events.join(' ').match(/server/g).length, 1); - assert.equal(events.join(' ').match(/client/g).length, 2); -}); - -var server = net.createServer(function(c) { - c.on('close', function() { - events.push('client'); - }); - - sockets.push(c); - - if (sockets.length === 2) { - server.close(); - sockets.forEach(function(c) { c.destroy() }); - } -}); - -server.on('close', function() { - events.push('server'); -}); - -server.listen(common.PORT, function() { - net.createConnection(common.PORT); - net.createConnection(common.PORT); -}); diff --git a/test/simple/test-net-server-listen-remove-callback.js b/test/simple/test-net-server-listen-remove-callback.js deleted file mode 100644 index e10231de8cde..000000000000 --- a/test/simple/test-net-server-listen-remove-callback.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -// Server should only fire listen callback once -var server = net.createServer(); - -server.on('close', function() { - var listeners = server.listeners('listening'); - console.log('Closed, listeners:', listeners.length); - assert.equal(0, listeners.length); -}); - -server.listen(common.PORT, function() { - server.close(); -}); - -server.once('close', function() { - server.listen(common.PORT + 1, function() { - server.close(); - }); -}); diff --git a/test/simple/test-net-server-max-connections.js b/test/simple/test-net-server-max-connections.js deleted file mode 100644 index 43bc2fee17ec..000000000000 --- a/test/simple/test-net-server-max-connections.js +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var net = require('net'); - -// This test creates 200 connections to a server and sets the server's -// maxConnections property to 100. The first 100 connections make it through -// and the last 100 connections are rejected. -// TODO: test that the server can accept more connections after it reaches -// its maximum and some are closed. - -var N = 200; -var count = 0; -var closes = 0; -var waits = []; - -var server = net.createServer(function(connection) { - console.error('connect %d', count++); - connection.write('hello'); - waits.push(function() { connection.end(); }); -}); - -server.listen(common.PORT, function() { - makeConnection(0); -}); - -server.maxConnections = N / 2; - -console.error('server.maxConnections = %d', server.maxConnections); - - -function makeConnection(index) { - var c = net.createConnection(common.PORT); - var gotData = false; - - c.on('connect', function() { - if (index + 1 < N) { - makeConnection(index + 1); - } - }); - - c.on('end', function() { c.end(); }); - - c.on('data', function(b) { - gotData = true; - assert.ok(0 < b.length); - }); - - c.on('error', function(e) { - console.error('error %d: %s', index, e); - }); - - c.on('close', function() { - console.error('closed %d', index); - closes++; - - if (closes < N / 2) { - assert.ok(server.maxConnections <= index, - index + - ' was one of the first closed connections ' + - 'but shouldnt have been'); - } - - if (closes === N / 2) { - var cb; - console.error('calling wait callback.'); - while (cb = waits.shift()) { - cb(); - } - server.close(); - } - - if (index < server.maxConnections) { - assert.equal(true, gotData, - index + ' didn\'t get data, but should have'); - } else { - assert.equal(false, gotData, - index + ' got data, but shouldn\'t have'); - } - }); -} - - -process.on('exit', function() { - assert.equal(N, closes); -}); diff --git a/test/simple/test-net-server-try-ports.js b/test/simple/test-net-server-try-ports.js deleted file mode 100644 index 5eca9d0957d5..000000000000 --- a/test/simple/test-net-server-try-ports.js +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// This tests binds to one port, then attempts to start a server on that -// port. It should be EADDRINUSE but be able to then bind to another port. -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var connections = 0; - -var server1listening = false; -var server2listening = false; - -var server1 = net.Server(function(socket) { - connections++; - socket.destroy(); -}); - -var server2 = net.Server(function(socket) { - connections++; - socket.destroy(); -}); - -var server2errors = 0; -server2.on('error', function() { - server2errors++; - console.error('server2 error'); -}); - - -server1.listen(common.PORT, function() { - console.error('server1 listening'); - server1listening = true; - // This should make server2 emit EADDRINUSE - server2.listen(common.PORT); - - // Wait a bit, now try again. - // TODO, the listen callback should report if there was an error. - // Then we could avoid this very unlikely but potential race condition - // here. - setTimeout(function() { - server2.listen(common.PORT + 1, function() { - console.error('server2 listening'); - server2listening = true; - - server1.close(); - server2.close(); - }); - }, 100); -}); - - -process.on('exit', function() { - assert.equal(1, server2errors); - assert.ok(server2listening); - assert.ok(server1listening); -}); diff --git a/test/simple/test-net-server-unref.js b/test/simple/test-net-server-unref.js deleted file mode 100644 index d20cbe5068d8..000000000000 --- a/test/simple/test-net-server-unref.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var net = require('net'); -var closed = false; - -var s = net.createServer(); -s.listen(); -s.unref(); - -setTimeout(function() { - closed = true; - s.close(); -}, 1000).unref(); - -process.on('exit', function() { - assert.strictEqual(closed, false, 'Unrefd socket should not hold loop open'); -}); diff --git a/test/simple/test-net-settimeout.js b/test/simple/test-net-settimeout.js deleted file mode 100644 index da13385b94e3..000000000000 --- a/test/simple/test-net-settimeout.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// This example sets a timeout then immediately attempts to disable the timeout -// https://github.com/joyent/node/pull/2245 - -var common = require('../common'); -var net = require('net'); -var assert = require('assert'); - -var T = 100; - -var server = net.createServer(function(c) { - c.write('hello'); -}); -server.listen(common.PORT); - -var killers = [0, Infinity, NaN]; - -var left = killers.length; -killers.forEach(function(killer) { - var socket = net.createConnection(common.PORT, 'localhost'); - - socket.setTimeout(T, function() { - socket.destroy(); - if (--left === 0) server.close(); - assert.ok(killer !== 0); - clearTimeout(timeout); - }); - - socket.setTimeout(killer); - - var timeout = setTimeout(function() { - socket.destroy(); - if (--left === 0) server.close(); - assert.ok(killer === 0); - }, T * 2); -}); diff --git a/test/simple/test-net-socket-destroy-twice.js b/test/simple/test-net-socket-destroy-twice.js deleted file mode 100644 index 882e3a14ce9a..000000000000 --- a/test/simple/test-net-socket-destroy-twice.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var nerrors = 0; -var ncloses = 0; - -process.on('exit', function() { - assert.equal(nerrors, 1); - assert.equal(ncloses, 1); -}); - -var conn = net.createConnection(common.PORT); - -conn.on('error', function() { - nerrors++; - conn.destroy(); -}); - -conn.on('close', function() { - ncloses++; -}); diff --git a/test/simple/test-net-socket-timeout-unref.js b/test/simple/test-net-socket-timeout-unref.js deleted file mode 100644 index 32aef444a9b0..000000000000 --- a/test/simple/test-net-socket-timeout-unref.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var server = net.createServer(function (c) { - c.write('hello'); - c.unref(); -}); -server.listen(common.PORT); -server.unref(); - -var timedout = false; - -[8, 5, 3, 6, 2, 4].forEach(function (T) { - var socket = net.createConnection(common.PORT, 'localhost'); - socket.setTimeout(T * 1000, function () { - console.log(process._getActiveHandles()); - timedout = true; - socket.destroy(); - }); - socket.unref(); -}); - -process.on('exit', function () { - assert.strictEqual(timedout, false, 'Socket timeout should not hold loop open'); -}); diff --git a/test/simple/test-net-socket-timeout.js b/test/simple/test-net-socket-timeout.js deleted file mode 100644 index 2256d6813aab..000000000000 --- a/test/simple/test-net-socket-timeout.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var net = require('net'); -var assert = require('assert'); - -var timedout = false; - -var server = net.Server(); -server.listen(common.PORT, function() { - var socket = net.createConnection(common.PORT); - socket.setTimeout(100, function() { - timedout = true; - socket.destroy(); - server.close(); - clearTimeout(timer); - }); - var timer = setTimeout(function() { - process.exit(1); - }, 200); -}); - -process.on('exit', function() { - assert.ok(timedout); -}); diff --git a/test/simple/test-net-stream.js b/test/simple/test-net-stream.js deleted file mode 100644 index 9f2db51be82b..000000000000 --- a/test/simple/test-net-stream.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var net = require('net'); - -var s = new net.Stream(); - -// test that destroy called on a stream with a server only ever decrements the -// server connection count once - -s.server = new net.Server(); -s.server.connections = 10; - -assert.equal(10, s.server.connections); -s.destroy(); -assert.equal(9, s.server.connections); -s.destroy(); -assert.equal(9, s.server.connections); - -var SIZE = 2E6; -var N = 10; -var buf = new Buffer(SIZE); -buf.fill(0x61); // 'a' - -var server = net.createServer(function(socket) { - socket.setNoDelay(); - - socket.on('error', function(err) { - socket.destroy(); - }).on('close', function() { - server.close(); - }) - - for (var i = 0; i < N; ++i) { - socket.write(buf, function() { }); - } - socket.end(); - -}).listen(common.PORT, function() { - var conn = net.connect(common.PORT); - conn.on('data', function(buf) { - conn.pause(); - setTimeout(function() { - conn.destroy(); - }, 20); - }); - }); - -process.on('exit', function() { - assert.equal(server.connections, 0); -}); diff --git a/test/simple/test-net-write-after-close.js b/test/simple/test-net-write-after-close.js deleted file mode 100644 index 3b98bbc42eac..000000000000 --- a/test/simple/test-net-write-after-close.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var gotError = false; -var gotWriteCB = false; - -process.on('exit', function() { - assert(gotError); - assert(gotWriteCB); -}); - -var server = net.createServer(function(socket) { - socket.resume(); - - socket.on('error', function(error) { - console.error('got error, closing server', error); - server.close(); - gotError = true; - }); - - setTimeout(function() { - console.error('about to try to write'); - socket.write('test', function(e) { - gotWriteCB = true; - }); - }, 250); -}); - -server.listen(common.PORT, function() { - var client = net.connect(common.PORT, function() { - client.end(); - }); -}); diff --git a/test/simple/test-net-write-connect-write.js b/test/simple/test-net-write-connect-write.js deleted file mode 100644 index cb65af8a8086..000000000000 --- a/test/simple/test-net-write-connect-write.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var received = ''; - -var server = net.createServer(function(socket) { - socket.pipe(socket); -}).listen(common.PORT, function() { - var conn = net.connect(common.PORT); - conn.setEncoding('utf8'); - conn.write('before'); - conn.on('connect', function() { - conn.write('after'); - }); - conn.on('data', function(buf) { - received += buf; - conn.end(); - }); - conn.on('end', function() { - server.close(); - }); -}); - -process.on('exit', function() { - assert.equal(received, 'before' + 'after'); -}); diff --git a/test/simple/test-net-write-slow.js b/test/simple/test-net-write-slow.js deleted file mode 100644 index 468c311c5c84..000000000000 --- a/test/simple/test-net-write-slow.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var SIZE = 2E5; -var N = 10; -var flushed = 0; -var received = 0; -var buf = new Buffer(SIZE); -buf.fill(0x61); // 'a' - -var server = net.createServer(function(socket) { - socket.setNoDelay(); - socket.setTimeout(1000); - socket.on('timeout', function() { - assert.fail('flushed: ' + flushed + - ', received: ' + received + '/' + SIZE * N); - }); - - for (var i = 0; i < N; ++i) { - socket.write(buf, function() { - ++flushed; - if (flushed === N) { - socket.setTimeout(0); - } - }); - } - socket.end(); - -}).listen(common.PORT, function() { - var conn = net.connect(common.PORT); - conn.on('data', function(buf) { - received += buf.length; - conn.pause(); - setTimeout(function() { - conn.resume(); - }, 20); - }); - conn.on('end', function() { - server.close(); - }); -}); - -process.on('exit', function() { - assert.equal(received, SIZE * N); -}); diff --git a/test/simple/test-next-tick-doesnt-hang.js b/test/simple/test-next-tick-doesnt-hang.js deleted file mode 100644 index 3d26bd3c6b0d..000000000000 --- a/test/simple/test-next-tick-doesnt-hang.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -/* - * This test verifies that having a single nextTick statement and nothing else - * does not hang the event loop. If this test times out it has failed. - */ - -process.nextTick(function() { - // Nothing -}); diff --git a/test/simple/test-next-tick-domain.js b/test/simple/test-next-tick-domain.js deleted file mode 100644 index 16f77ed94d53..000000000000 --- a/test/simple/test-next-tick-domain.js +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var origNextTick = process.nextTick; - -require('domain'); - -assert.strictEqual(origNextTick, process.nextTick, 'Requiring domain should not change nextTick'); diff --git a/test/simple/test-next-tick-error-spin.js b/test/simple/test-next-tick-error-spin.js deleted file mode 100644 index 4ed31511beb1..000000000000 --- a/test/simple/test-next-tick-error-spin.js +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -if (process.argv[2] !== 'child') { - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child'], { - stdio: 'pipe'//'inherit' - }); - var timer = setTimeout(function() { - throw new Error('child is hung'); - }, 500); - child.on('exit', function(code) { - console.error('ok'); - assert(!code); - clearTimeout(timer); - }); -} else { - - var domain = require('domain'); - var d = domain.create(); - process.maxTickDepth = 10; - - // in the error handler, we trigger several MakeCallback events - d.on('error', function(e) { - console.log('a') - console.log('b') - console.log('c') - console.log('d') - console.log('e') - f(); - }); - - function f() { - process.nextTick(function() { - d.run(function() { - throw(new Error('x')); - }); - }); - } - - f(); - setTimeout(function () { - console.error('broke in!'); - //process.stdout.close(); - //process.stderr.close(); - process.exit(0); - }); -} diff --git a/test/simple/test-next-tick-errors.js b/test/simple/test-next-tick-errors.js deleted file mode 100644 index bf3c2e3065fa..000000000000 --- a/test/simple/test-next-tick-errors.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var order = [], - exceptionHandled = false; - -// This nextTick function will throw an error. It should only be called once. -// When it throws an error, it should still get removed from the queue. -process.nextTick(function() { - order.push('A'); - // cause an error - what(); -}); - -// This nextTick function should remain in the queue when the first one -// is removed. It should be called if the error in the first one is -// caught (which we do in this test). -process.nextTick(function() { - order.push('C'); -}); - -process.on('uncaughtException', function() { - if (!exceptionHandled) { - exceptionHandled = true; - order.push('B'); - } - else { - // If we get here then the first process.nextTick got called twice - order.push('OOPS!'); - } -}); - -process.on('exit', function() { - assert.deepEqual(['A', 'B', 'C'], order); -}); - diff --git a/test/simple/test-next-tick-intentional-starvation.js b/test/simple/test-next-tick-intentional-starvation.js deleted file mode 100644 index 1a76b27e44e4..000000000000 --- a/test/simple/test-next-tick-intentional-starvation.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// this is the inverse of test-next-tick-starvation. -// it verifies that process.nextTick will *always* come before other -// events, up to the limit of the process.maxTickDepth value. - -// WARNING: unsafe! -process.maxTickDepth = Infinity; - -var ran = false; -var starved = false; -var start = +new Date(); -var timerRan = false; - -function spin() { - ran = true; - var now = +new Date(); - if (now - start > 100) { - console.log('The timer is starving, just as we planned.'); - starved = true; - - // now let it out. - return; - } - - process.nextTick(spin); -} - -function onTimeout() { - if (!starved) throw new Error('The timer escaped!'); - console.log('The timer ran once the ban was lifted'); - timerRan = true; -} - -spin(); -setTimeout(onTimeout, 50); - -process.on('exit', function() { - assert.ok(ran); - assert.ok(starved); - assert.ok(timerRan); -}); diff --git a/test/simple/test-next-tick-ordering.js b/test/simple/test-next-tick-ordering.js deleted file mode 100644 index 5dc1dfbe1691..000000000000 --- a/test/simple/test-next-tick-ordering.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var i; - -var N = 30; -var done = []; - -function get_printer(timeout) { - return function() { - console.log('Running from setTimeout ' + timeout); - done.push(timeout); - }; -} - -process.nextTick(function() { - console.log('Running from nextTick'); - done.push('nextTick'); -}); - -for (i = 0; i < N; i += 1) { - setTimeout(get_printer(i), i); -} - -console.log('Running from main.'); - - -process.on('exit', function() { - assert.equal('nextTick', done[0]); - /* Disabling this test. I don't think we can ensure the order - for (i = 0; i < N; i += 1) { - assert.equal(i, done[i + 1]); - } - */ -}); diff --git a/test/simple/test-next-tick-ordering2.js b/test/simple/test-next-tick-ordering2.js deleted file mode 100644 index 94fd20fbb5a0..000000000000 --- a/test/simple/test-next-tick-ordering2.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var order = []; -process.nextTick(function() { - setTimeout(function() { - order.push('setTimeout'); - }, 0); - - process.nextTick(function() { - order.push('nextTick'); - }); -}); - -process.on('exit', function() { - assert.deepEqual(order, ['nextTick', 'setTimeout']); -}); diff --git a/test/simple/test-next-tick-starvation.js b/test/simple/test-next-tick-starvation.js deleted file mode 100644 index bf678a064631..000000000000 --- a/test/simple/test-next-tick-starvation.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - - -var ran = false; -var stop = false; -var start = +new Date(); - -function spin() { - var now = +new Date(); - if (now - start > 100) { - throw new Error('The timer is starving'); - } - - if (!stop) { - ran = true; - process.nextTick(spin); - } -} - -function onTimeout() { - stop = true; -} - -spin(); -setTimeout(onTimeout, 50); - -process.on('exit', function() { - assert.ok(ran); - assert.ok(stop); -}); diff --git a/test/simple/test-next-tick.js b/test/simple/test-next-tick.js deleted file mode 100644 index 2e40658c923c..000000000000 --- a/test/simple/test-next-tick.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var complete = 0; - -process.nextTick(function() { - complete++; - process.nextTick(function() { - complete++; - process.nextTick(function() { - complete++; - }); - }); -}); - -setTimeout(function() { - process.nextTick(function() { - complete++; - }); -}, 50); - -process.nextTick(function() { - complete++; -}); - -process.on('exit', function() { - assert.equal(5, complete); - process.nextTick(function() { - throw new Error('this should not occur'); - }); -}); diff --git a/test/simple/test-os.js b/test/simple/test-os.js deleted file mode 100644 index 79de1b14a40b..000000000000 --- a/test/simple/test-os.js +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var os = require('os'); - - -process.env.TMPDIR = '/tmpdir'; -process.env.TMP = '/tmp'; -process.env.TEMP = '/temp'; -var t = ( process.platform === 'win32' ? 'c:\\windows\\temp' : '/tmp' ); -assert.equal(os.tmpdir(), '/tmpdir'); -process.env.TMPDIR = ''; -assert.equal(os.tmpdir(), '/tmp'); -process.env.TMP = ''; -assert.equal(os.tmpdir(), '/temp'); -process.env.TEMP = ''; -assert.equal(os.tmpdir(), t); - -var endianness = os.endianness(); -console.log('endianness = %s', endianness); -assert.ok(/[BL]E/.test(endianness)); - -var hostname = os.hostname(); -console.log('hostname = %s', hostname); -assert.ok(hostname.length > 0); - -var uptime = os.uptime(); -console.log('uptime = %d', uptime); -assert.ok(uptime > 0); - -var cpus = os.cpus(); -console.log('cpus = ', cpus); -assert.ok(cpus.length > 0); - -var type = os.type(); -console.log('type = ', type); -assert.ok(type.length > 0); - -var release = os.release(); -console.log('release = ', release); -assert.ok(release.length > 0); - -var platform = os.platform(); -console.log('platform = ', platform); -assert.ok(platform.length > 0); - -var arch = os.arch(); -console.log('arch = ', arch); -assert.ok(arch.length > 0); - -if (process.platform != 'sunos') { - // not implemeneted yet - assert.ok(os.loadavg().length > 0); - assert.ok(os.freemem() > 0); - assert.ok(os.totalmem() > 0); -} - - -var interfaces = os.networkInterfaces(); -console.error(interfaces); -switch (platform) { - case 'linux': - var filter = function(e) { return e.address == '127.0.0.1'; }; - var actual = interfaces.lo.filter(filter); - var expected = [{ address: '127.0.0.1', family: 'IPv4', internal: true }]; - assert.deepEqual(actual, expected); - break; - case 'win32': - var filter = function(e) { return e.address == '127.0.0.1'; }; - var actual = interfaces['Loopback Pseudo-Interface 1'].filter(filter); - var expected = [{ address: '127.0.0.1', family: 'IPv4', internal: true }]; - assert.deepEqual(actual, expected); - break; -} - -var EOL = os.EOL; -assert.ok(EOL.length > 0); diff --git a/test/simple/test-path-makelong.js b/test/simple/test-path-makelong.js deleted file mode 100644 index d9d8efd4052a..000000000000 --- a/test/simple/test-path-makelong.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var path = require('path'); -var common = require('../common'); - -if (process.platform === 'win32') { - var file = path.join(common.fixturesDir, 'a.js'); - var resolvedFile = path.resolve(file); - - assert.equal('\\\\?\\' + resolvedFile, path._makeLong(file)); - assert.equal('\\\\?\\' + resolvedFile, path._makeLong('\\\\?\\' + file)); - assert.equal('\\\\?\\UNC\\someserver\\someshare\\somefile', - path._makeLong('\\\\someserver\\someshare\\somefile')); - assert.equal('\\\\?\\UNC\\someserver\\someshare\\somefile', - path._makeLong('\\\\?\\UNC\\someserver\\someshare\\somefile')); - assert.equal('\\\\.\\pipe\\somepipe', - path._makeLong('\\\\.\\pipe\\somepipe')); -} - -assert.equal(path._makeLong(null), null); -assert.equal(path._makeLong(100), 100); -assert.equal(path._makeLong(path), path); -assert.equal(path._makeLong(false), false); -assert.equal(path._makeLong(true), true); diff --git a/test/simple/test-path.js b/test/simple/test-path.js deleted file mode 100644 index da076d494dd6..000000000000 --- a/test/simple/test-path.js +++ /dev/null @@ -1,407 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var path = require('path'); - -var isWindows = process.platform === 'win32'; - -var f = __filename; - -assert.equal(path.basename(f), 'test-path.js'); -assert.equal(path.basename(f, '.js'), 'test-path'); -assert.equal(path.basename(''), ''); -assert.equal(path.basename('/dir/basename.ext'), 'basename.ext'); -assert.equal(path.basename('/basename.ext'), 'basename.ext'); -assert.equal(path.basename('basename.ext'), 'basename.ext'); -assert.equal(path.basename('basename.ext/'), 'basename.ext'); -assert.equal(path.basename('basename.ext//'), 'basename.ext'); - -if (isWindows) { - // On Windows a backslash acts as a path separator. - assert.equal(path.basename('\\dir\\basename.ext'), 'basename.ext'); - assert.equal(path.basename('\\basename.ext'), 'basename.ext'); - assert.equal(path.basename('basename.ext'), 'basename.ext'); - assert.equal(path.basename('basename.ext\\'), 'basename.ext'); - assert.equal(path.basename('basename.ext\\\\'), 'basename.ext'); - -} else { - // On unix a backslash is just treated as any other character. - assert.equal(path.basename('\\dir\\basename.ext'), '\\dir\\basename.ext'); - assert.equal(path.basename('\\basename.ext'), '\\basename.ext'); - assert.equal(path.basename('basename.ext'), 'basename.ext'); - assert.equal(path.basename('basename.ext\\'), 'basename.ext\\'); - assert.equal(path.basename('basename.ext\\\\'), 'basename.ext\\\\'); -} - -// POSIX filenames may include control characters -// c.f. http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html -if (!isWindows) { - var controlCharFilename = 'Icon' + String.fromCharCode(13); - assert.equal(path.basename('/a/b/' + controlCharFilename), - controlCharFilename); -} - -assert.equal(path.extname(f), '.js'); - -assert.equal(path.dirname(f).substr(-11), - isWindows ? 'test\\simple' : 'test/simple'); -assert.equal(path.dirname('/a/b/'), '/a'); -assert.equal(path.dirname('/a/b'), '/a'); -assert.equal(path.dirname('/a'), '/'); -assert.equal(path.dirname(''), '.'); -assert.equal(path.dirname('/'), '/'); -assert.equal(path.dirname('////'), '/'); - -if (isWindows) { - assert.equal(path.dirname('c:\\'), 'c:\\'); - assert.equal(path.dirname('c:\\foo'), 'c:\\'); - assert.equal(path.dirname('c:\\foo\\'), 'c:\\'); - assert.equal(path.dirname('c:\\foo\\bar'), 'c:\\foo'); - assert.equal(path.dirname('c:\\foo\\bar\\'), 'c:\\foo'); - assert.equal(path.dirname('c:\\foo\\bar\\baz'), 'c:\\foo\\bar'); - assert.equal(path.dirname('\\'), '\\'); - assert.equal(path.dirname('\\foo'), '\\'); - assert.equal(path.dirname('\\foo\\'), '\\'); - assert.equal(path.dirname('\\foo\\bar'), '\\foo'); - assert.equal(path.dirname('\\foo\\bar\\'), '\\foo'); - assert.equal(path.dirname('\\foo\\bar\\baz'), '\\foo\\bar'); - assert.equal(path.dirname('c:'), 'c:'); - assert.equal(path.dirname('c:foo'), 'c:'); - assert.equal(path.dirname('c:foo\\'), 'c:'); - assert.equal(path.dirname('c:foo\\bar'), 'c:foo'); - assert.equal(path.dirname('c:foo\\bar\\'), 'c:foo'); - assert.equal(path.dirname('c:foo\\bar\\baz'), 'c:foo\\bar'); - assert.equal(path.dirname('\\\\unc\\share'), '\\\\unc\\share'); - assert.equal(path.dirname('\\\\unc\\share\\foo'), '\\\\unc\\share\\'); - assert.equal(path.dirname('\\\\unc\\share\\foo\\'), '\\\\unc\\share\\'); - assert.equal(path.dirname('\\\\unc\\share\\foo\\bar'), - '\\\\unc\\share\\foo'); - assert.equal(path.dirname('\\\\unc\\share\\foo\\bar\\'), - '\\\\unc\\share\\foo'); - assert.equal(path.dirname('\\\\unc\\share\\foo\\bar\\baz'), - '\\\\unc\\share\\foo\\bar'); -} - - -assert.equal(path.extname(''), ''); -assert.equal(path.extname('/path/to/file'), ''); -assert.equal(path.extname('/path/to/file.ext'), '.ext'); -assert.equal(path.extname('/path.to/file.ext'), '.ext'); -assert.equal(path.extname('/path.to/file'), ''); -assert.equal(path.extname('/path.to/.file'), ''); -assert.equal(path.extname('/path.to/.file.ext'), '.ext'); -assert.equal(path.extname('/path/to/f.ext'), '.ext'); -assert.equal(path.extname('/path/to/..ext'), '.ext'); -assert.equal(path.extname('file'), ''); -assert.equal(path.extname('file.ext'), '.ext'); -assert.equal(path.extname('.file'), ''); -assert.equal(path.extname('.file.ext'), '.ext'); -assert.equal(path.extname('/file'), ''); -assert.equal(path.extname('/file.ext'), '.ext'); -assert.equal(path.extname('/.file'), ''); -assert.equal(path.extname('/.file.ext'), '.ext'); -assert.equal(path.extname('.path/file.ext'), '.ext'); -assert.equal(path.extname('file.ext.ext'), '.ext'); -assert.equal(path.extname('file.'), '.'); -assert.equal(path.extname('.'), ''); -assert.equal(path.extname('./'), ''); -assert.equal(path.extname('.file.ext'), '.ext'); -assert.equal(path.extname('.file'), ''); -assert.equal(path.extname('.file.'), '.'); -assert.equal(path.extname('.file..'), '.'); -assert.equal(path.extname('..'), ''); -assert.equal(path.extname('../'), ''); -assert.equal(path.extname('..file.ext'), '.ext'); -assert.equal(path.extname('..file'), '.file'); -assert.equal(path.extname('..file.'), '.'); -assert.equal(path.extname('..file..'), '.'); -assert.equal(path.extname('...'), '.'); -assert.equal(path.extname('...ext'), '.ext'); -assert.equal(path.extname('....'), '.'); -assert.equal(path.extname('file.ext/'), '.ext'); -assert.equal(path.extname('file.ext//'), '.ext'); -assert.equal(path.extname('file/'), ''); -assert.equal(path.extname('file//'), ''); -assert.equal(path.extname('file./'), '.'); -assert.equal(path.extname('file.//'), '.'); - -if (isWindows) { - // On windows, backspace is a path separator. - assert.equal(path.extname('.\\'), ''); - assert.equal(path.extname('..\\'), ''); - assert.equal(path.extname('file.ext\\'), '.ext'); - assert.equal(path.extname('file.ext\\\\'), '.ext'); - assert.equal(path.extname('file\\'), ''); - assert.equal(path.extname('file\\\\'), ''); - assert.equal(path.extname('file.\\'), '.'); - assert.equal(path.extname('file.\\\\'), '.'); - -} else { - // On unix, backspace is a valid name component like any other character. - assert.equal(path.extname('.\\'), ''); - assert.equal(path.extname('..\\'), '.\\'); - assert.equal(path.extname('file.ext\\'), '.ext\\'); - assert.equal(path.extname('file.ext\\\\'), '.ext\\\\'); - assert.equal(path.extname('file\\'), ''); - assert.equal(path.extname('file\\\\'), ''); - assert.equal(path.extname('file.\\'), '.\\'); - assert.equal(path.extname('file.\\\\'), '.\\\\'); -} - -// path.join tests -var failures = []; -var joinTests = - // arguments result - [[['.', 'x/b', '..', '/b/c.js'], 'x/b/c.js'], - [['/.', 'x/b', '..', '/b/c.js'], '/x/b/c.js'], - [['/foo', '../../../bar'], '/bar'], - [['foo', '../../../bar'], '../../bar'], - [['foo/', '../../../bar'], '../../bar'], - [['foo/x', '../../../bar'], '../bar'], - [['foo/x', './bar'], 'foo/x/bar'], - [['foo/x/', './bar'], 'foo/x/bar'], - [['foo/x/', '.', 'bar'], 'foo/x/bar'], - [['./'], './'], - [['.', './'], './'], - [['.', '.', '.'], '.'], - [['.', './', '.'], '.'], - [['.', '/./', '.'], '.'], - [['.', '/////./', '.'], '.'], - [['.'], '.'], - [['', '.'], '.'], - [['', 'foo'], 'foo'], - [['foo', '/bar'], 'foo/bar'], - [['', '/foo'], '/foo'], - [['', '', '/foo'], '/foo'], - [['', '', 'foo'], 'foo'], - [['foo', ''], 'foo'], - [['foo/', ''], 'foo/'], - [['foo', '', '/bar'], 'foo/bar'], - [['./', '..', '/foo'], '../foo'], - [['./', '..', '..', '/foo'], '../../foo'], - [['.', '..', '..', '/foo'], '../../foo'], - [['', '..', '..', '/foo'], '../../foo'], - [['/'], '/'], - [['/', '.'], '/'], - [['/', '..'], '/'], - [['/', '..', '..'], '/'], - [[''], '.'], - [['', ''], '.'], - [[' /foo'], ' /foo'], - [[' ', 'foo'], ' /foo'], - [[' ', '.'], ' '], - [[' ', '/'], ' /'], - [[' ', ''], ' '], - [['/', 'foo'], '/foo'], - [['/', '/foo'], '/foo'], - [['/', '//foo'], '/foo'], - [['/', '', '/foo'], '/foo'], - [['', '/', 'foo'], '/foo'], - [['', '/', '/foo'], '/foo'] - ]; - -// Windows-specific join tests -if (isWindows) { - joinTests = joinTests.concat( - [// UNC path expected - [['//foo/bar'], '//foo/bar/'], - [['\\/foo/bar'], '//foo/bar/'], - [['\\\\foo/bar'], '//foo/bar/'], - // UNC path expected - server and share separate - [['//foo', 'bar'], '//foo/bar/'], - [['//foo/', 'bar'], '//foo/bar/'], - [['//foo', '/bar'], '//foo/bar/'], - // UNC path expected - questionable - [['//foo', '', 'bar'], '//foo/bar/'], - [['//foo/', '', 'bar'], '//foo/bar/'], - [['//foo/', '', '/bar'], '//foo/bar/'], - // UNC path expected - even more questionable - [['', '//foo', 'bar'], '//foo/bar/'], - [['', '//foo/', 'bar'], '//foo/bar/'], - [['', '//foo/', '/bar'], '//foo/bar/'], - // No UNC path expected (no double slash in first component) - [['\\', 'foo/bar'], '/foo/bar'], - [['\\', '/foo/bar'], '/foo/bar'], - [['', '/', '/foo/bar'], '/foo/bar'], - // No UNC path expected (no non-slashes in first component - questionable) - [['//', 'foo/bar'], '/foo/bar'], - [['//', '/foo/bar'], '/foo/bar'], - [['\\\\', '/', '/foo/bar'], '/foo/bar'], - [['//'], '/'], - // No UNC path expected (share name missing - questionable). - [['//foo'], '/foo'], - [['//foo/'], '/foo/'], - [['//foo', '/'], '/foo/'], - [['//foo', '', '/'], '/foo/'], - // No UNC path expected (too many leading slashes - questionable) - [['///foo/bar'], '/foo/bar'], - [['////foo', 'bar'], '/foo/bar'], - [['\\\\\\/foo/bar'], '/foo/bar'], - // Drive-relative vs drive-absolute paths. This merely describes the - // status quo, rather than being obviously right - [['c:'], 'c:.'], - [['c:.'], 'c:.'], - [['c:', ''], 'c:.'], - [['', 'c:'], 'c:.'], - [['c:.', '/'], 'c:./'], - [['c:.', 'file'], 'c:file'], - [['c:', '/'], 'c:/'], - [['c:', 'file'], 'c:/file'] - ]); -} - -// Run the join tests. -joinTests.forEach(function(test) { - var actual = path.join.apply(path, test[0]); - var expected = isWindows ? test[1].replace(/\//g, '\\') : test[1]; - var message = 'path.join(' + test[0].map(JSON.stringify).join(',') + ')' + - '\n expect=' + JSON.stringify(expected) + - '\n actual=' + JSON.stringify(actual); - if (actual !== expected) failures.push('\n' + message); - // assert.equal(actual, expected, message); -}); -assert.equal(failures.length, 0, failures.join('')); -var joinThrowTests = [true, false, 7, null, {}, undefined, [], NaN]; -joinThrowTests.forEach(function(test) { - assert.throws(function() { - path.join(test); - }, TypeError); - assert.throws(function() { - path.resolve(test); - }, TypeError); -}); - - -// path normalize tests -if (isWindows) { - assert.equal(path.normalize('./fixtures///b/../b/c.js'), - 'fixtures\\b\\c.js'); - assert.equal(path.normalize('/foo/../../../bar'), '\\bar'); - assert.equal(path.normalize('a//b//../b'), 'a\\b'); - assert.equal(path.normalize('a//b//./c'), 'a\\b\\c'); - assert.equal(path.normalize('a//b//.'), 'a\\b'); - assert.equal(path.normalize('//server/share/dir/file.ext'), - '\\\\server\\share\\dir\\file.ext'); -} else { - assert.equal(path.normalize('./fixtures///b/../b/c.js'), - 'fixtures/b/c.js'); - assert.equal(path.normalize('/foo/../../../bar'), '/bar'); - assert.equal(path.normalize('a//b//../b'), 'a/b'); - assert.equal(path.normalize('a//b//./c'), 'a/b/c'); - assert.equal(path.normalize('a//b//.'), 'a/b'); -} - -// path.resolve tests -if (isWindows) { - // windows - var resolveTests = - // arguments result - [[['c:/blah\\blah', 'd:/games', 'c:../a'], 'c:\\blah\\a'], - [['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'], 'd:\\e.exe'], - [['c:/ignore', 'c:/some/file'], 'c:\\some\\file'], - [['d:/ignore', 'd:some/dir//'], 'd:\\ignore\\some\\dir'], - [['.'], process.cwd()], - [['//server/share', '..', 'relative\\'], '\\\\server\\share\\relative'], - [['c:/', '//'], 'c:\\'], - [['c:/', '//dir'], 'c:\\dir'], - [['c:/', '//server/share'], '\\\\server\\share\\'], - [['c:/', '//server//share'], '\\\\server\\share\\'], - [['c:/', '///some//dir'], 'c:\\some\\dir'] - ]; -} else { - // Posix - var resolveTests = - // arguments result - [[['/var/lib', '../', 'file/'], '/var/file'], - [['/var/lib', '/../', 'file/'], '/file'], - [['a/b/c/', '../../..'], process.cwd()], - [['.'], process.cwd()], - [['/some/dir', '.', '/absolute/'], '/absolute']]; -} -var failures = []; -resolveTests.forEach(function(test) { - var actual = path.resolve.apply(path, test[0]); - var expected = test[1]; - var message = 'path.resolve(' + test[0].map(JSON.stringify).join(',') + ')' + - '\n expect=' + JSON.stringify(expected) + - '\n actual=' + JSON.stringify(actual); - if (actual !== expected) failures.push('\n' + message); - // assert.equal(actual, expected, message); -}); -assert.equal(failures.length, 0, failures.join('')); - -// path.relative tests -if (isWindows) { - // windows - var relativeTests = - // arguments result - [['c:/blah\\blah', 'd:/games', 'd:\\games'], - ['c:/aaaa/bbbb', 'c:/aaaa', '..'], - ['c:/aaaa/bbbb', 'c:/cccc', '..\\..\\cccc'], - ['c:/aaaa/bbbb', 'c:/aaaa/bbbb', ''], - ['c:/aaaa/bbbb', 'c:/aaaa/cccc', '..\\cccc'], - ['c:/aaaa/', 'c:/aaaa/cccc', 'cccc'], - ['c:/', 'c:\\aaaa\\bbbb', 'aaaa\\bbbb'], - ['c:/aaaa/bbbb', 'd:\\', 'd:\\']]; -} else { - // posix - var relativeTests = - // arguments result - [['/var/lib', '/var', '..'], - ['/var/lib', '/bin', '../../bin'], - ['/var/lib', '/var/lib', ''], - ['/var/lib', '/var/apache', '../apache'], - ['/var/', '/var/lib', 'lib'], - ['/', '/var/lib', 'var/lib']]; -} -var failures = []; -relativeTests.forEach(function(test) { - var actual = path.relative(test[0], test[1]); - var expected = test[2]; - var message = 'path.relative(' + - test.slice(0, 2).map(JSON.stringify).join(',') + - ')' + - '\n expect=' + JSON.stringify(expected) + - '\n actual=' + JSON.stringify(actual); - if (actual !== expected) failures.push('\n' + message); -}); -assert.equal(failures.length, 0, failures.join('')); - -// path.sep tests -if (isWindows) { - // windows - assert.equal(path.sep, '\\'); -} else { - // posix - assert.equal(path.sep, '/'); -} - -// path.delimiter tests -if (isWindows) { - // windows - assert.equal(path.delimiter, ';'); -} else { - // posix - assert.equal(path.delimiter, ':'); -} diff --git a/test/simple/test-pipe-address.js b/test/simple/test-pipe-address.js deleted file mode 100644 index 6b29d2a2c484..000000000000 --- a/test/simple/test-pipe-address.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var address = null; - -var server = net.createServer(function() { - assert(false); // should not be called -}); - -server.listen(common.PIPE, function() { - address = server.address(); - server.close(); -}); - -process.on('exit', function() { - assert.equal(address, common.PIPE); -}); diff --git a/test/simple/test-pipe-file-to-http.js b/test/simple/test-pipe-file-to-http.js deleted file mode 100644 index 1b3ba7089b48..000000000000 --- a/test/simple/test-pipe-file-to-http.js +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var http = require('http'); -var path = require('path'); -var cp = require('child_process'); - -var filename = path.join(common.tmpDir || '/tmp', 'big'); -var clientReqComplete = false; -var count = 0; - -var server = http.createServer(function(req, res) { - console.error('SERVER request'); - var timeoutId; - assert.equal('POST', req.method); - req.pause(); - common.error('request paused'); - - setTimeout(function() { - req.resume(); - common.error('request resumed'); - }, 1000); - - req.on('data', function(chunk) { - common.error('recv data! nchars = ' + chunk.length); - count += chunk.length; - }); - - req.on('end', function() { - if (timeoutId) { - clearTimeout(timeoutId); - } - console.log('request complete from server'); - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end(); - }); -}); -server.listen(common.PORT); - -server.on('listening', function() { - var cmd = common.ddCommand(filename, 10240); - console.log('dd command: ', cmd); - - cp.exec(cmd, function(err, stdout, stderr) { - if (err) throw err; - console.error('EXEC returned successfully stdout=%d stderr=%d', - stdout.length, stderr.length); - makeRequest(); - }); -}); - -function makeRequest() { - var req = http.request({ - port: common.PORT, - path: '/', - method: 'POST' - }); - - common.error('pipe!'); - - var s = fs.ReadStream(filename); - s.pipe(req); - s.on('data', function(chunk) { - console.error('FS data chunk=%d', chunk.length); - }); - s.on('end', function() { - console.error('FS end'); - }); - s.on('close', function(err) { - if (err) throw err; - clientReqComplete = true; - common.error('client finished sending request'); - }); - - req.on('response', function(res) { - console.error('RESPONSE', res.statusCode, res.headers); - res.resume(); - res.on('end', function() { - console.error('RESPONSE end'); - server.close(); - }); - }); -} - -process.on('exit', function() { - assert.equal(1024 * 10240, count); - assert.ok(clientReqComplete); -}); diff --git a/test/simple/test-pipe-head.js b/test/simple/test-pipe-head.js deleted file mode 100644 index a049be6c295e..000000000000 --- a/test/simple/test-pipe-head.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -var exec = require('child_process').exec; -var join = require('path').join; - -var nodePath = process.argv[0]; -var script = join(common.fixturesDir, 'print-10-lines.js'); - -var cmd = '"' + nodePath + '" "' + script + '" | head -2'; - -var finished = false; - -exec(cmd, function(err, stdout, stderr) { - if (err) throw err; - var lines = stdout.split('\n'); - assert.equal(3, lines.length); - finished = true; -}); - - -process.on('exit', function() { - assert.ok(finished); -}); diff --git a/test/simple/test-pipe-return-val.js b/test/simple/test-pipe-return-val.js deleted file mode 100644 index 274e9f5bc61d..000000000000 --- a/test/simple/test-pipe-return-val.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -// This test ensures SourceStream.pipe(DestStream) returns DestStream - -var common = require('../common'); -var Stream = require('stream').Stream; -var assert = require('assert'); -var util = require('util'); - -var sourceStream = new Stream(); -var destStream = new Stream(); -var result = sourceStream.pipe(destStream); - -assert.strictEqual(result, destStream); - diff --git a/test/simple/test-pipe-stream.js b/test/simple/test-pipe-stream.js deleted file mode 100644 index b2b2a551847a..000000000000 --- a/test/simple/test-pipe-stream.js +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -function test(clazz, cb) { - var have_ping = false; - var have_pong = false; - - function check() { - assert.ok(have_ping); - assert.ok(have_pong); - } - - function ping() { - var conn = new clazz(); - - conn.on('error', function(err) { - throw err; - }); - - conn.connect(common.PIPE, function() { - conn.write('PING', 'utf-8'); - }); - - conn.on('data', function(data) { - assert.equal(data.toString(), 'PONG'); - have_pong = true; - conn.destroy(); - }); - } - - function pong(conn) { - conn.on('error', function(err) { - throw err; - }); - - conn.on('data', function(data) { - assert.equal(data.toString(), 'PING'); - have_ping = true; - conn.write('PONG', 'utf-8'); - }); - - conn.on('close', function() { - server.close(); - }); - } - - var timeout = setTimeout(function() { - server.close(); - }, 2000); - - var server = net.Server(); - server.listen(common.PIPE, ping); - server.on('connection', pong); - server.on('close', function() { - clearTimeout(timeout); - check(); - cb && cb(); - }); -} - -test(net.Stream, function() { - test(net.Socket); -}); - diff --git a/test/simple/test-pipe-unref.js b/test/simple/test-pipe-unref.js deleted file mode 100644 index 9f715a9d172d..000000000000 --- a/test/simple/test-pipe-unref.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var net = require('net'); -var closed = false; - -var s = net.Server(); -s.listen(common.PIPE); -s.unref(); - -setTimeout(function() { - closed = true; - s.close(); -}, 1000).unref(); - -process.on('exit', function() { - assert.strictEqual(closed, false, 'Unrefd socket should not hold loop open'); -}); diff --git a/test/simple/test-pipe.js b/test/simple/test-pipe.js deleted file mode 100644 index 9f1dae885b03..000000000000 --- a/test/simple/test-pipe.js +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); -var net = require('net'); - -var webPort = common.PORT; -var tcpPort = webPort + 1; - -var listenCount = 0; -var gotThanks = false; -var tcpLengthSeen = 0; -var bufferSize = 5 * 1024 * 1024; - - -/* - * 5MB of random buffer. - */ -var buffer = Buffer(bufferSize); -for (var i = 0; i < buffer.length; i++) { - buffer[i] = parseInt(Math.random() * 10000) % 256; -} - - -var web = http.Server(function(req, res) { - web.close(); - - console.log(req.headers); - - var socket = net.Stream(); - socket.connect(tcpPort); - - socket.on('connect', function() { - console.log('socket connected'); - }); - - req.pipe(socket); - - req.on('end', function() { - res.writeHead(200); - res.write('thanks'); - res.end(); - console.log('response with \'thanks\''); - }); - - req.connection.on('error', function(e) { - console.log('http server-side error: ' + e.message); - process.exit(1); - }); -}); -web.listen(webPort, startClient); - - - -var tcp = net.Server(function(s) { - tcp.close(); - - console.log('tcp server connection'); - - var i = 0; - - s.on('data', function(d) { - process.stdout.write('.'); - tcpLengthSeen += d.length; - for (var j = 0; j < d.length; j++) { - assert.equal(buffer[i], d[j]); - i++; - } - }); - - s.on('end', function() { - console.log('tcp socket disconnect'); - s.end(); - }); - - s.on('error', function(e) { - console.log('tcp server-side error: ' + e.message); - process.exit(1); - }); -}); -tcp.listen(tcpPort, startClient); - - -function startClient() { - listenCount++; - if (listenCount < 2) return; - - console.log('Making request'); - - var req = http.request({ - port: common.PORT, - method: 'GET', - path: '/', - headers: { 'content-length': buffer.length } - }, function(res) { - console.log('Got response'); - res.setEncoding('utf8'); - res.on('data', function(string) { - assert.equal('thanks', string); - gotThanks = true; - }); - }); - req.write(buffer); - req.end(); - console.error('ended request', req); -} - -process.on('exit', function() { - assert.ok(gotThanks); - assert.equal(bufferSize, tcpLengthSeen); -}); - diff --git a/test/simple/test-process-active-wraps.js b/test/simple/test-process-active-wraps.js deleted file mode 100644 index 63fc218debc4..000000000000 --- a/test/simple/test-process-active-wraps.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; -var net = require('net'); - -function expect(activeHandles, activeRequests) { - assert.equal(process._getActiveHandles().length, activeHandles); - assert.equal(process._getActiveRequests().length, activeRequests); -} - -var handles = []; - -(function() { - expect(0, 0); - var server = net.createServer().listen(common.PORT); - expect(1, 0); - server.close(); - expect(1, 0); // server handle doesn't shut down until next tick - handles.push(server); -})(); - -(function() { - expect(1, 0); - var conn = net.createConnection(common.PORT); - conn.on('error', function() { /* ignore */ }); - expect(2, 1); - conn.destroy(); - expect(2, 1); // client handle doesn't shut down until next tick - handles.push(conn); -})(); - -(function() { - var n = 0; - handles.forEach(function(handle) { - handle.once('close', onclose); - }); - function onclose() { - if (++n === handles.length) setImmediate(expect, 0, 0); - } -})(); diff --git a/test/simple/test-process-argv-0.js b/test/simple/test-process-argv-0.js deleted file mode 100644 index 0c38f6ac7bbf..000000000000 --- a/test/simple/test-process-argv-0.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. -var util = require('util'); -var path = require('path'); -var assert = require('assert'); -var spawn = require('child_process').spawn; -var common = require('../common'); - -console.error('argv=%j', process.argv); -console.error('exec=%j', process.execPath); - -if (process.argv[2] !== "child") { - var child = spawn('./node', [__filename, "child"], { - cwd: path.dirname(process.execPath) - }); - - var childArgv0 = ''; - var childErr = ''; - child.stdout.on('data', function(chunk) { - childArgv0 += chunk; - }); - child.stderr.on('data', function(chunk) { - childErr += chunk; - }); - child.on('exit', function () { - console.error('CHILD: %s', childErr.trim().split('\n').join('\nCHILD: ')); - if (process.platform === 'win32') { - // On Windows argv[0] is not expanded into full path - assert.equal(childArgv0, './node'); - } else { - assert.equal(childArgv0, process.execPath); - } - }); -} -else { - process.stdout.write(process.argv[0]); -} diff --git a/test/simple/test-process-config.js b/test/simple/test-process-config.js deleted file mode 100644 index b3236cd5ec31..000000000000 --- a/test/simple/test-process-config.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); - -// check for existence -assert(process.hasOwnProperty('config')); - -// ensure that `process.config` is an Object -assert(Object(process.config) === process.config); - -var configPath = path.resolve(__dirname, '..', '..', 'config.gypi'); -var config = fs.readFileSync(configPath, 'utf8'); - -// clean up comment at the first line -config = config.split('\n').slice(1).join('\n').replace(/'/g, '"'); -config = JSON.parse(config, function(key, value) { - if (value === 'true') return true; - if (value === 'false') return false; - return value; -}); - -assert.deepEqual(config, process.config); diff --git a/test/simple/test-process-env.js b/test/simple/test-process-env.js deleted file mode 100644 index 919d0d54ed47..000000000000 --- a/test/simple/test-process-env.js +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// first things first, set the timezone; see tzset(3) -process.env.TZ = 'Europe/Amsterdam'; - -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; - -/* For the moment we are not going to support setting the timezone via the - * environment variables. The problem is that various V8 platform backends - * deal with timezone in different ways. The windows platform backend caches - * the timezone value while the Linux one hits libc for every query. - -https://github.com/joyent/node/blob/08782931205bc4f6d28102ebc29fd806e8ccdf1f/deps/v8/src/platform-linux.cc#L339-345 -https://github.com/joyent/node/blob/08782931205bc4f6d28102ebc29fd806e8ccdf1f/deps/v8/src/platform-win32.cc#L590-596 - - -// time difference between Greenwich and Amsterdam is +2 hours in the summer -date = new Date('Fri, 10 Sep 1982 03:15:00 GMT'); -assert.equal(3, date.getUTCHours()); -assert.equal(5, date.getHours()); -*/ - - -// changes in environment should be visible to child processes -if (process.argv[2] == 'you-are-the-child') { - // failed assertion results in process exiting with status code 1 - assert.equal(false, 'NODE_PROCESS_ENV_DELETED' in process.env); - assert.equal(42, process.env.NODE_PROCESS_ENV); - assert.equal('asdf', process.env.hasOwnProperty); - var hasOwnProperty = Object.prototype.hasOwnProperty; - var has = hasOwnProperty.call(process.env, 'hasOwnProperty'); - assert.equal(true, has); - process.exit(0); -} else { - assert.equal(Object.prototype.hasOwnProperty, process.env.hasOwnProperty); - var has = process.env.hasOwnProperty('hasOwnProperty'); - assert.equal(false, has); - - process.env.hasOwnProperty = 'asdf'; - - process.env.NODE_PROCESS_ENV = 42; - assert.equal(42, process.env.NODE_PROCESS_ENV); - - process.env.NODE_PROCESS_ENV_DELETED = 42; - assert.equal(true, 'NODE_PROCESS_ENV_DELETED' in process.env); - - delete process.env.NODE_PROCESS_ENV_DELETED; - assert.equal(false, 'NODE_PROCESS_ENV_DELETED' in process.env); - - var child = spawn(process.argv[0], [process.argv[1], 'you-are-the-child']); - child.stdout.on('data', function(data) { console.log(data.toString()); }); - child.stderr.on('data', function(data) { console.log(data.toString()); }); - child.on('exit', function(statusCode) { - if (statusCode != 0) { - process.exit(statusCode); // failed assertion in child process - } - }); -} diff --git a/test/simple/test-process-exec-argv.js b/test/simple/test-process-exec-argv.js deleted file mode 100644 index 96ed8172de7d..000000000000 --- a/test/simple/test-process-exec-argv.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var spawn = require('child_process').spawn; - -if (process.argv[2] === 'child') { - process.stdout.write(JSON.stringify(process.execArgv)); -} else { - var execArgv = ['--harmony_proxies', '--max-stack-size=0']; - var args = [__filename, 'child', 'arg0']; - var child = spawn(process.execPath, execArgv.concat(args)); - var out = ''; - - child.stdout.on('data', function (chunk) { - out += chunk; - }); - - child.on('exit', function () { - assert.deepEqual(JSON.parse(out), execArgv); - }); -} diff --git a/test/simple/test-process-exit-recursive.js b/test/simple/test-process-exit-recursive.js deleted file mode 100644 index 556ab13903de..000000000000 --- a/test/simple/test-process-exit-recursive.js +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); - -// recursively calling .exit() should not overflow the call stack -var nexits = 0; - -process.on('exit', function(code) { - assert.equal(nexits++, 0); - assert.equal(code, 1); - - // now override the exit code of 1 with 0 so that the test passes - process.exit(); -}); - -process.exit(1); diff --git a/test/simple/test-process-exit.js b/test/simple/test-process-exit.js deleted file mode 100644 index 365d5f109366..000000000000 --- a/test/simple/test-process-exit.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// calling .exit() from within "exit" should not overflow the call stack -var nexits = 0; - -process.on('exit', function(code) { - assert.equal(nexits++, 0); - assert.equal(code, 0); - process.exit(); -}); - -// "exit" should be emitted unprovoked diff --git a/test/simple/test-process-getgroups.js b/test/simple/test-process-getgroups.js deleted file mode 100644 index 16d017b3cc7e..000000000000 --- a/test/simple/test-process-getgroups.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; - -if (process.platform === 'darwin') { - console.log('Skipping. Output of `id -G` is unreliable on Darwin.'); - return; -} - -if (typeof process.getgroups === 'function') { - var groups = process.getgroups(); - assert(Array.isArray(groups)); - assert(groups.length > 0); - exec('id -G', function(err, stdout) { - if (err) throw err; - var real_groups = stdout.match(/\d+/g).map(Number); - assert.equal(groups.length, real_groups.length); - check(groups, real_groups); - check(real_groups, groups); - }); -} - -function check(a, b) { - for (var i = 0; i < a.length; ++i) assert(b.indexOf(a[i]) !== -1); -} diff --git a/test/simple/test-process-hrtime.js b/test/simple/test-process-hrtime.js deleted file mode 100644 index d8ffcafa9cc5..000000000000 --- a/test/simple/test-process-hrtime.js +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// the default behavior, return an Array "tuple" of numbers -var tuple = process.hrtime(); - -// validate the default behavior -validateTuple(tuple); - -// validate that passing an existing tuple returns another valid tuple -validateTuple(process.hrtime(tuple)); - -// test that only an Array may be passed to process.hrtime() -assert.throws(function() { - process.hrtime(1); -}); - -function validateTuple(tuple) { - assert(Array.isArray(tuple)); - assert.equal(2, tuple.length); - tuple.forEach(function (v) { - assert.equal('number', typeof v); - assert(isFinite(v)); - }); -} diff --git a/test/simple/test-process-kill-null.js b/test/simple/test-process-kill-null.js deleted file mode 100644 index 520210ef1f8c..000000000000 --- a/test/simple/test-process-kill-null.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; - -var cat = spawn('cat'); -var called; - -assert.ok(process.kill(cat.pid, 0)); - -cat.on('exit', function() { - assert.throws(function() { - process.kill(cat.pid, 0); - }, Error); -}); - -cat.stdout.on('data', function() { - called = true; - process.kill(cat.pid, 'SIGKILL'); -}); - -// EPIPE when null sig fails -cat.stdin.write('test'); - -process.on('exit', function() { - assert.ok(called); -}); diff --git a/test/simple/test-process-next-tick.js b/test/simple/test-process-next-tick.js deleted file mode 100644 index 0322a033e393..000000000000 --- a/test/simple/test-process-next-tick.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var N = 2; -var tickCount = 0; -var exceptionCount = 0; - -function cb() { - ++tickCount; - throw new Error(); -} - -for (var i = 0; i < N; ++i) { - process.nextTick(cb); -} - -process.on('uncaughtException', function() { - ++exceptionCount; -}); - -process.on('exit', function() { - process.removeAllListeners('uncaughtException'); - assert.equal(tickCount, N); - assert.equal(exceptionCount, N); -}); diff --git a/test/simple/test-process-wrap.js b/test/simple/test-process-wrap.js deleted file mode 100644 index 655c8281586d..000000000000 --- a/test/simple/test-process-wrap.js +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var Process = process.binding('process_wrap').Process; -var Pipe = process.binding('pipe_wrap').Pipe; -var pipe = new Pipe(); -var p = new Process(); - -var processExited = false; -var gotPipeEOF = false; -var gotPipeData = false; - -p.onexit = function(exitCode, signal) { - console.log('exit'); - p.close(); - pipe.readStart(); - - assert.equal(0, exitCode); - assert.equal(0, signal); - - processExited = true; -}; - -pipe.onread = function(b, off, len) { - assert.ok(processExited); - if (b) { - gotPipeData = true; - console.log('read %d', len); - } else { - gotPipeEOF = true; - pipe.close(); - } -}; - -p.spawn({ - file: process.execPath, - args: [process.execPath, '-v'], - stdio: [ - { type: 'ignore' }, - { type: 'pipe', handle: pipe }, - { type: 'ignore' } - ] -}); - - -process.on('exit', function() { - assert.ok(processExited); - assert.ok(gotPipeEOF); - assert.ok(gotPipeData); -}); diff --git a/test/simple/test-pump-file2tcp-noexist.js b/test/simple/test-pump-file2tcp-noexist.js deleted file mode 100644 index 8017db73f189..000000000000 --- a/test/simple/test-pump-file2tcp-noexist.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var fs = require('fs'); -var util = require('util'); -var path = require('path'); -var fn = path.join(common.fixturesDir, 'does_not_exist.txt'); - -var got_error = false; -var conn_closed = false; - -var server = net.createServer(function(stream) { - common.error('pump!'); - util.pump(fs.createReadStream(fn), stream, function(err) { - common.error('util.pump\'s callback fired'); - if (err) { - got_error = true; - } else { - common.debug('util.pump\'s callback fired with no error'); - common.debug('this shouldn\'t happen as the file doesn\'t exist...'); - assert.equal(true, false); - } - server.close(); - }); -}); - -server.listen(common.PORT, function() { - var conn = net.createConnection(common.PORT); - conn.setEncoding('utf8'); - conn.on('data', function(chunk) { - common.error('recv data! nchars = ' + chunk.length); - buffer += chunk; - }); - - conn.on('end', function() { - conn.end(); - }); - - conn.on('close', function() { - common.error('client connection close'); - conn_closed = true; - }); -}); - -var buffer = ''; - -process.on('exit', function() { - assert.equal(true, got_error); - assert.equal(true, conn_closed); - console.log('exiting'); -}); diff --git a/test/simple/test-pump-file2tcp.js b/test/simple/test-pump-file2tcp.js deleted file mode 100644 index 60c0fdd7f048..000000000000 --- a/test/simple/test-pump-file2tcp.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var fs = require('fs'); -var util = require('util'); -var path = require('path'); -var fn = path.join(common.fixturesDir, 'elipses.txt'); - -var expected = fs.readFileSync(fn, 'utf8'); - -var server = net.createServer(function(stream) { - common.error('pump!'); - util.pump(fs.createReadStream(fn), stream, function() { - common.error('server stream close'); - common.error('server close'); - server.close(); - }); -}); - -server.listen(common.PORT, function() { - var conn = net.createConnection(common.PORT); - conn.setEncoding('utf8'); - conn.on('data', function(chunk) { - common.error('recv data! nchars = ' + chunk.length); - buffer += chunk; - }); - - conn.on('end', function() { - conn.end(); - }); - conn.on('close', function() { - common.error('client connection close'); - }); -}); - -var buffer = ''; -var count = 0; - -server.on('listening', function() { -}); - -process.on('exit', function() { - assert.equal(expected, buffer); -}); diff --git a/test/simple/test-punycode.js b/test/simple/test-punycode.js deleted file mode 100644 index fa6a9c0ec96b..000000000000 --- a/test/simple/test-punycode.js +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Copyright (C) 2011 by Ben Noordhuis -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -var common = require('../common'); -var punycode = require('punycode'); -var assert = require('assert'); - -assert.equal(punycode.encode('ü'), 'tda'); -assert.equal(punycode.encode('Goethe'), 'Goethe-'); -assert.equal(punycode.encode('Bücher'), 'Bcher-kva'); -assert.equal(punycode.encode( - 'Willst du die Blüthe des frühen, die Früchte des späteren Jahres'), - 'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal'); -assert.equal(punycode.encode('日本語'), 'wgv71a119e'); - -assert.equal(punycode.decode('tda'), 'ü'); -assert.equal(punycode.decode('Goethe-'), 'Goethe'); -assert.equal(punycode.decode('Bcher-kva'), 'Bücher'); -assert.equal(punycode.decode( - 'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal'), - 'Willst du die Blüthe des frühen, die Früchte des späteren Jahres'); -assert.equal(punycode.decode('wgv71a119e'), '日本語'); - -// http://tools.ietf.org/html/rfc3492#section-7.1 -var tests = { - // (A) Arabic (Egyptian) - 'egbpdaj6bu4bxfgehfvwxn': - '\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648' + - '\u0634\u0639\u0631\u0628\u064A\u061F', - - // (B) Chinese (simplified) - 'ihqwcrb4cv8a8dqg056pqjye': - '\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587', - - // (C) Chinese (traditional) - 'ihqwctvzc91f659drss3x8bo0yb': - '\u4ED6\u5011\u7232\u4EC0\u9EBD\u4E0D\u8AAA\u4E2D\u6587', - - // (D) Czech: Proprostnemluvesky - 'Proprostnemluvesky-uyb24dma41a': - '\u0050\u0072\u006F\u010D\u0070\u0072\u006F\u0073\u0074\u011B\u006E' + - '\u0065\u006D\u006C\u0075\u0076\u00ED\u010D\u0065\u0073\u006B\u0079', - - // (E) Hebrew - '4dbcagdahymbxekheh6e0a7fei0b': - '\u05DC\u05DE\u05D4\u05D4\u05DD\u05E4\u05E9\u05D5\u05D8\u05DC\u05D0' + - '\u05DE\u05D3\u05D1\u05E8\u05D9\u05DD\u05E2\u05D1\u05E8\u05D9\u05EA', - - // (F) Hindi (Devanagari) - 'i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd': - '\u092F\u0939\u0932\u094B\u0917\u0939\u093F\u0928\u094D\u0926\u0940' + - '\u0915\u094D\u092F\u094B\u0902\u0928\u0939\u0940\u0902\u092C\u094B' + - '\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902', - - // (G) Japanese (kanji and hiragana) - 'n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa': - '\u306A\u305C\u307F\u3093\u306A\u65E5\u672C\u8A9E\u3092\u8A71\u3057' + - '\u3066\u304F\u308C\u306A\u3044\u306E\u304B', - - // (H) Korean (Hangul syllables) - '989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c': - '\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774\uD55C\uAD6D' + - '\uC5B4\uB97C\uC774\uD574\uD55C\uB2E4\uBA74\uC5BC\uB9C8\uB098\uC88B' + - '\uC744\uAE4C', - - // (I) Russian (Cyrillic) - /* XXX disabled, fails - possibly a bug in the RFC - 'b1abfaaepdrnnbgefbaDotcwatmq2g4l': - '\u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E\u043D\u0438' + - '\u043D\u0435\u0433\u043E\u0432\u043E\u0440\u044F\u0442\u043F\u043E' + - '\u0440\u0443\u0441\u0441\u043A\u0438', - */ - - // (J) Spanish: PorqunopuedensimplementehablarenEspaol - 'PorqunopuedensimplementehablarenEspaol-fmd56a': - '\u0050\u006F\u0072\u0071\u0075\u00E9\u006E\u006F\u0070\u0075\u0065' + - '\u0064\u0065\u006E\u0073\u0069\u006D\u0070\u006C\u0065\u006D\u0065' + - '\u006E\u0074\u0065\u0068\u0061\u0062\u006C\u0061\u0072\u0065\u006E' + - '\u0045\u0073\u0070\u0061\u00F1\u006F\u006C', - - // (K) Vietnamese: Tisaohkhngth - // chnitingVit - 'TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g': - '\u0054\u1EA1\u0069\u0073\u0061\u006F\u0068\u1ECD\u006B\u0068\u00F4' + - '\u006E\u0067\u0074\u0068\u1EC3\u0063\u0068\u1EC9\u006E\u00F3\u0069' + - '\u0074\u0069\u1EBF\u006E\u0067\u0056\u0069\u1EC7\u0074', - - // (L) 3B - '3B-ww4c5e180e575a65lsy2b': - '\u0033\u5E74\u0042\u7D44\u91D1\u516B\u5148\u751F', - - // (M) -with-SUPER-MONKEYS - '-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n': - '\u5B89\u5BA4\u5948\u7F8E\u6075\u002D\u0077\u0069\u0074\u0068\u002D' + - '\u0053\u0055\u0050\u0045\u0052\u002D\u004D\u004F\u004E\u004B\u0045' + - '\u0059\u0053', - - // (N) Hello-Another-Way- - 'Hello-Another-Way--fc4qua05auwb3674vfr0b': - '\u0048\u0065\u006C\u006C\u006F\u002D\u0041\u006E\u006F\u0074\u0068' + - '\u0065\u0072\u002D\u0057\u0061\u0079\u002D\u305D\u308C\u305E\u308C' + - '\u306E\u5834\u6240', - - // (O) 2 - '2-u9tlzr9756bt3uc0v': - '\u3072\u3068\u3064\u5C4B\u6839\u306E\u4E0B\u0032', - - // (P) MajiKoi5 - 'MajiKoi5-783gue6qz075azm5e': - '\u004D\u0061\u006A\u0069\u3067\u004B\u006F\u0069\u3059\u308B\u0035' + - '\u79D2\u524D', - - // (Q) de - 'de-jg4avhby1noc0d': - '\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0', - - // (R) - 'd9juau41awczczp': - '\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067', - - // (S) -> $1.00 <- - '-> $1.00 <--': - '\u002D\u003E\u0020\u0024\u0031\u002E\u0030\u0030\u0020\u003C\u002D' -}; - -var errors = 0; - -for (var encoded in tests) { - var decoded = tests[encoded]; - try { - assert.equal(punycode.encode(decoded), encoded); - } catch (e) { - console.error('FAIL: expected %j, got %j', e.expected, e.actual); - errors++; - } - try { - assert.equal(punycode.decode(encoded), decoded); - } catch (e) { - console.error('FAIL: expected %j, got %j', e.expected, e.actual); - errors++; - } -} - -// BMP code point -assert.equal(punycode.ucs2.encode([0x61]), 'a'); -// supplementary code point (surrogate pair) -assert.equal(punycode.ucs2.encode([0x1D306]), '\uD834\uDF06'); -// high surrogate -assert.equal(punycode.ucs2.encode([0xD800]), '\uD800'); -// high surrogate followed by non-surrogates -assert.equal(punycode.ucs2.encode([0xD800, 0x61, 0x62]), '\uD800ab'); -// low surrogate -assert.equal(punycode.ucs2.encode([0xDC00]), '\uDC00'); -// low surrogate followed by non-surrogates -assert.equal(punycode.ucs2.encode([0xDC00, 0x61, 0x62]), '\uDC00ab'); - -assert.equal(errors, 0); diff --git a/test/simple/test-querystring.js b/test/simple/test-querystring.js deleted file mode 100644 index 545c507fc455..000000000000 --- a/test/simple/test-querystring.js +++ /dev/null @@ -1,239 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// test using assert -var qs = require('querystring'); - -// folding block, commented to pass gjslint -// {{{ -// [ wonkyQS, canonicalQS, obj ] -var qsTestCases = [ - ['foo=918854443121279438895193', - 'foo=918854443121279438895193', - {'foo': '918854443121279438895193'}], - ['foo=bar', 'foo=bar', {'foo': 'bar'}], - ['foo=bar&foo=quux', 'foo=bar&foo=quux', {'foo': ['bar', 'quux']}], - ['foo=1&bar=2', 'foo=1&bar=2', {'foo': '1', 'bar': '2'}], - ['my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F', - 'my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F', - {'my weird field': 'q1!2"\'w$5&7/z8)?' }], - ['foo%3Dbaz=bar', 'foo%3Dbaz=bar', {'foo=baz': 'bar'}], - ['foo=baz=bar', 'foo=baz%3Dbar', {'foo': 'baz=bar'}], - ['str=foo&arr=1&arr=2&arr=3&somenull=&undef=', - 'str=foo&arr=1&arr=2&arr=3&somenull=&undef=', - { 'str': 'foo', - 'arr': ['1', '2', '3'], - 'somenull': '', - 'undef': ''}], - [' foo = bar ', '%20foo%20=%20bar%20', {' foo ': ' bar '}], - ['foo=%zx', 'foo=%25zx', {'foo': '%zx'}], - ['foo=%EF%BF%BD', 'foo=%EF%BF%BD', {'foo': '\ufffd' }], - // See: https://github.com/joyent/node/issues/1707 - ['hasOwnProperty=x&toString=foo&valueOf=bar&__defineGetter__=baz', - 'hasOwnProperty=x&toString=foo&valueOf=bar&__defineGetter__=baz', - { hasOwnProperty: 'x', - toString: 'foo', - valueOf: 'bar', - __defineGetter__: 'baz' }], - // See: https://github.com/joyent/node/issues/3058 - ['foo&bar=baz', 'foo=&bar=baz', { foo: '', bar: 'baz' }] -]; - -// [ wonkyQS, canonicalQS, obj ] -var qsColonTestCases = [ - ['foo:bar', 'foo:bar', {'foo': 'bar'}], - ['foo:bar;foo:quux', 'foo:bar;foo:quux', {'foo': ['bar', 'quux']}], - ['foo:1&bar:2;baz:quux', - 'foo:1%26bar%3A2;baz:quux', - {'foo': '1&bar:2', 'baz': 'quux'}], - ['foo%3Abaz:bar', 'foo%3Abaz:bar', {'foo:baz': 'bar'}], - ['foo:baz:bar', 'foo:baz%3Abar', {'foo': 'baz:bar'}] -]; - -// [wonkyObj, qs, canonicalObj] -var extendedFunction = function() {}; -extendedFunction.prototype = {a: 'b'}; -var qsWeirdObjects = [ - [{regexp: /./g}, 'regexp=', {'regexp': ''}], - [{regexp: new RegExp('.', 'g')}, 'regexp=', {'regexp': ''}], - [{fn: function() {}}, 'fn=', {'fn': ''}], - [{fn: new Function('')}, 'fn=', {'fn': ''}], - [{math: Math}, 'math=', {'math': ''}], - [{e: extendedFunction}, 'e=', {'e': ''}], - [{d: new Date()}, 'd=', {'d': ''}], - [{d: Date}, 'd=', {'d': ''}], - [{f: new Boolean(false), t: new Boolean(true)}, 'f=&t=', {'f': '', 't': ''}], - [{f: false, t: true}, 'f=false&t=true', {'f': 'false', 't': 'true'}], - [{n: null}, 'n=', {'n': ''}], - [{nan: NaN}, 'nan=', {'nan': ''}], - [{inf: Infinity}, 'inf=', {'inf': ''}] -]; -// }}} - -var Script = require('vm').Script; -var foreignObject = Script.runInContext('({"foo": ["bar", "baz"]})', - Script.createContext()); - -var qsNoMungeTestCases = [ - ['', {}], - ['foo=bar&foo=baz', {'foo': ['bar', 'baz']}], - ['foo=bar&foo=baz', foreignObject], - ['blah=burp', {'blah': 'burp'}], - ['gragh=1&gragh=3&goo=2', {'gragh': ['1', '3'], 'goo': '2'}], - ['frappucino=muffin&goat%5B%5D=scone&pond=moose', - {'frappucino': 'muffin', 'goat[]': 'scone', 'pond': 'moose'}], - ['trololol=yes&lololo=no', {'trololol': 'yes', 'lololo': 'no'}] -]; - -assert.strictEqual('918854443121279438895193', - qs.parse('id=918854443121279438895193').id); - -// test that the canonical qs is parsed properly. -qsTestCases.forEach(function(testCase) { - assert.deepEqual(testCase[2], qs.parse(testCase[0])); -}); - -// test that the colon test cases can do the same -qsColonTestCases.forEach(function(testCase) { - assert.deepEqual(testCase[2], qs.parse(testCase[0], ';', ':')); -}); - -// test the weird objects, that they get parsed properly -qsWeirdObjects.forEach(function(testCase) { - assert.deepEqual(testCase[2], qs.parse(testCase[1])); -}); - -qsNoMungeTestCases.forEach(function(testCase) { - assert.deepEqual(testCase[0], qs.stringify(testCase[1], '&', '=', false)); -}); - -// test the nested qs-in-qs case -(function() { - var f = qs.parse('a=b&q=x%3Dy%26y%3Dz'); - f.q = qs.parse(f.q); - assert.deepEqual(f, { a: 'b', q: { x: 'y', y: 'z' } }); -})(); - -// nested in colon -(function() { - var f = qs.parse('a:b;q:x%3Ay%3By%3Az', ';', ':'); - f.q = qs.parse(f.q, ';', ':'); - assert.deepEqual(f, { a: 'b', q: { x: 'y', y: 'z' } }); -})(); - -// now test stringifying - -// basic -qsTestCases.forEach(function(testCase) { - assert.equal(testCase[1], qs.stringify(testCase[2])); -}); - -qsColonTestCases.forEach(function(testCase) { - assert.equal(testCase[1], qs.stringify(testCase[2], ';', ':')); -}); - -qsWeirdObjects.forEach(function(testCase) { - assert.equal(testCase[1], qs.stringify(testCase[0])); -}); - -// nested -var f = qs.stringify({ - a: 'b', - q: qs.stringify({ - x: 'y', - y: 'z' - }) -}); -assert.equal(f, 'a=b&q=x%3Dy%26y%3Dz'); - -assert.doesNotThrow(function() { - qs.parse(undefined); -}); - -// nested in colon -var f = qs.stringify({ - a: 'b', - q: qs.stringify({ - x: 'y', - y: 'z' - }, ';', ':') -}, ';', ':'); -assert.equal(f, 'a:b;q:x%3Ay%3By%3Az'); - - -assert.deepEqual({}, qs.parse()); - - -// Test limiting -assert.equal( - Object.keys(qs.parse('a=1&b=1&c=1', null, null, { maxKeys: 1 })).length, - 1); - -// Test removing limit -function testUnlimitedKeys() { - var query = {}, - url; - - for (var i = 0; i < 2000; i++) query[i] = i; - - url = qs.stringify(query); - - assert.equal( - Object.keys(qs.parse(url, null, null, { maxKeys: 0 })).length, - 2000); -} -testUnlimitedKeys(); - - -var b = qs.unescapeBuffer('%d3%f2Ug%1f6v%24%5e%98%cb' + - '%0d%ac%a2%2f%9d%eb%d8%a2%e6'); -// -assert.equal(0xd3, b[0]); -assert.equal(0xf2, b[1]); -assert.equal(0x55, b[2]); -assert.equal(0x67, b[3]); -assert.equal(0x1f, b[4]); -assert.equal(0x36, b[5]); -assert.equal(0x76, b[6]); -assert.equal(0x24, b[7]); -assert.equal(0x5e, b[8]); -assert.equal(0x98, b[9]); -assert.equal(0xcb, b[10]); -assert.equal(0x0d, b[11]); -assert.equal(0xac, b[12]); -assert.equal(0xa2, b[13]); -assert.equal(0x2f, b[14]); -assert.equal(0x9d, b[15]); -assert.equal(0xeb, b[16]); -assert.equal(0xd8, b[17]); -assert.equal(0xa2, b[18]); -assert.equal(0xe6, b[19]); - -// test overriding .unescape -var prevUnescape = qs.unescape; -qs.unescape = function (str) { - return str.replace(/o/g, '_'); -}; -assert.deepEqual(qs.parse('foo=bor'), {f__: 'b_r'}); -qs.unescape = prevUnescape; diff --git a/test/simple/test-readdir.js b/test/simple/test-readdir.js deleted file mode 100644 index 24997241f9b9..000000000000 --- a/test/simple/test-readdir.js +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); - -var got_error = false, - readdirDir = path.join(common.fixturesDir, 'readdir'); - -var files = ['are', - 'dir', - 'empty', - 'files', - 'for', - 'just', - 'testing.js', - 'these']; - - -console.log('readdirSync ' + readdirDir); -var f = fs.readdirSync(readdirDir); -console.dir(f); -assert.deepEqual(files, f.sort()); - - -console.log('readdir ' + readdirDir); -fs.readdir(readdirDir, function(err, f) { - if (err) { - console.log('error'); - got_error = true; - } else { - console.dir(f); - assert.deepEqual(files, f.sort()); - } -}); - -process.on('exit', function() { - assert.equal(false, got_error); - console.log('exit'); -}); - - -// readdir() on file should throw ENOTDIR -// https://github.com/joyent/node/issues/1869 -(function() { - var has_caught = false; - - try { - fs.readdirSync(__filename); - } - catch (e) { - has_caught = true; - assert.equal(e.code, 'ENOTDIR'); - } - - assert(has_caught); -})(); - - -(function() { - var readdir_cb_called = false; - - fs.readdir(__filename, function(e) { - readdir_cb_called = true; - assert.equal(e.code, 'ENOTDIR'); - }); - - process.on('exit', function() { - assert(readdir_cb_called); - }); -})(); diff --git a/test/simple/test-readdouble.js b/test/simple/test-readdouble.js deleted file mode 100644 index 9fa23e090e4c..000000000000 --- a/test/simple/test-readdouble.js +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * Tests to verify we're reading in doubles correctly - */ -var SlowBuffer = process.binding('buffer').SlowBuffer; -var common = require('../common'); -var ASSERT = require('assert'); - -/* - * Test (64 bit) double - */ -function test(clazz) { - var buffer = new clazz(8); - - buffer[0] = 0x55; - buffer[1] = 0x55; - buffer[2] = 0x55; - buffer[3] = 0x55; - buffer[4] = 0x55; - buffer[5] = 0x55; - buffer[6] = 0xd5; - buffer[7] = 0x3f; - ASSERT.equal(1.1945305291680097e+103, buffer.readDoubleBE(0)); - ASSERT.equal(0.3333333333333333, buffer.readDoubleLE(0)); - - buffer[0] = 1; - buffer[1] = 0; - buffer[2] = 0; - buffer[3] = 0; - buffer[4] = 0; - buffer[5] = 0; - buffer[6] = 0xf0; - buffer[7] = 0x3f; - ASSERT.equal(7.291122019655968e-304, buffer.readDoubleBE(0)); - ASSERT.equal(1.0000000000000002, buffer.readDoubleLE(0)); - - buffer[0] = 2; - ASSERT.equal(4.778309726801735e-299, buffer.readDoubleBE(0)); - ASSERT.equal(1.0000000000000004, buffer.readDoubleLE(0)); - - buffer[0] = 1; - buffer[6] = 0; - buffer[7] = 0; - ASSERT.equal(7.291122019556398e-304, buffer.readDoubleBE(0)); - ASSERT.equal(5e-324, buffer.readDoubleLE(0)); - - buffer[0] = 0xff; - buffer[1] = 0xff; - buffer[2] = 0xff; - buffer[3] = 0xff; - buffer[4] = 0xff; - buffer[5] = 0xff; - buffer[6] = 0x0f; - buffer[7] = 0x00; - ASSERT.ok(isNaN(buffer.readDoubleBE(0))); - ASSERT.equal(2.225073858507201e-308, buffer.readDoubleLE(0)); - - buffer[6] = 0xef; - buffer[7] = 0x7f; - ASSERT.ok(isNaN(buffer.readDoubleBE(0))); - ASSERT.equal(1.7976931348623157e+308, buffer.readDoubleLE(0)); - - buffer[0] = 0; - buffer[1] = 0; - buffer[2] = 0; - buffer[3] = 0; - buffer[4] = 0; - buffer[5] = 0; - buffer[6] = 0xf0; - buffer[7] = 0x3f; - ASSERT.equal(3.03865e-319, buffer.readDoubleBE(0)); - ASSERT.equal(1, buffer.readDoubleLE(0)); - - buffer[6] = 0; - buffer[7] = 0x40; - ASSERT.equal(3.16e-322, buffer.readDoubleBE(0)); - ASSERT.equal(2, buffer.readDoubleLE(0)); - - buffer[7] = 0xc0; - ASSERT.equal(9.5e-322, buffer.readDoubleBE(0)); - ASSERT.equal(-2, buffer.readDoubleLE(0)); - - buffer[6] = 0x10; - buffer[7] = 0; - ASSERT.equal(2.0237e-320, buffer.readDoubleBE(0)); - ASSERT.equal(2.2250738585072014e-308, buffer.readDoubleLE(0)); - - buffer[6] = 0; - ASSERT.equal(0, buffer.readDoubleBE(0)); - ASSERT.equal(0, buffer.readDoubleLE(0)); - ASSERT.equal(false, 1 / buffer.readDoubleLE(0) < 0); - - buffer[7] = 0x80; - ASSERT.equal(6.3e-322, buffer.readDoubleBE(0)); - ASSERT.equal(0, buffer.readDoubleLE(0)); - ASSERT.equal(true, 1 / buffer.readDoubleLE(0) < 0); - - buffer[6] = 0xf0; - buffer[7] = 0x7f; - ASSERT.equal(3.0418e-319, buffer.readDoubleBE(0)); - ASSERT.equal(Infinity, buffer.readDoubleLE(0)); - - buffer[6] = 0xf0; - buffer[7] = 0xff; - ASSERT.equal(3.04814e-319, buffer.readDoubleBE(0)); - ASSERT.equal(-Infinity, buffer.readDoubleLE(0)); -} - - -test(Buffer); -test(SlowBuffer); diff --git a/test/simple/test-readfloat.js b/test/simple/test-readfloat.js deleted file mode 100644 index 373fa209780c..000000000000 --- a/test/simple/test-readfloat.js +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * Tests to verify we're reading in floats correctly - */ -var SlowBuffer = process.binding('buffer').SlowBuffer; -var common = require('../common'); -var ASSERT = require('assert'); - -/* - * Test (32 bit) float - */ -function test(clazz) { - var buffer = new clazz(4); - - buffer[0] = 0; - buffer[1] = 0; - buffer[2] = 0x80; - buffer[3] = 0x3f; - ASSERT.equal(4.600602988224807e-41, buffer.readFloatBE(0)); - ASSERT.equal(1, buffer.readFloatLE(0)); - - buffer[0] = 0; - buffer[1] = 0; - buffer[2] = 0; - buffer[3] = 0xc0; - ASSERT.equal(2.6904930515036488e-43, buffer.readFloatBE(0)); - ASSERT.equal(-2, buffer.readFloatLE(0)); - - buffer[0] = 0xff; - buffer[1] = 0xff; - buffer[2] = 0x7f; - buffer[3] = 0x7f; - ASSERT.ok(isNaN(buffer.readFloatBE(0))); - ASSERT.equal(3.4028234663852886e+38, buffer.readFloatLE(0)); - - buffer[0] = 0xab; - buffer[1] = 0xaa; - buffer[2] = 0xaa; - buffer[3] = 0x3e; - ASSERT.equal(-1.2126478207002966e-12, buffer.readFloatBE(0)); - ASSERT.equal(0.3333333432674408, buffer.readFloatLE(0)); - - buffer[0] = 0; - buffer[1] = 0; - buffer[2] = 0; - buffer[3] = 0; - ASSERT.equal(0, buffer.readFloatBE(0)); - ASSERT.equal(0, buffer.readFloatLE(0)); - ASSERT.equal(false, 1 / buffer.readFloatLE(0) < 0); - - buffer[3] = 0x80; - ASSERT.equal(1.793662034335766e-43, buffer.readFloatBE(0)); - ASSERT.equal(0, buffer.readFloatLE(0)); - ASSERT.equal(true, 1 / buffer.readFloatLE(0) < 0); - - buffer[0] = 0; - buffer[1] = 0; - buffer[2] = 0x80; - buffer[3] = 0x7f; - ASSERT.equal(4.609571298396486e-41, buffer.readFloatBE(0)); - ASSERT.equal(Infinity, buffer.readFloatLE(0)); - - buffer[0] = 0; - buffer[1] = 0; - buffer[2] = 0x80; - buffer[3] = 0xff; - ASSERT.equal(4.627507918739843e-41, buffer.readFloatBE(0)); - ASSERT.equal(-Infinity, buffer.readFloatLE(0)); -} - - -test(Buffer); -test(SlowBuffer); diff --git a/test/simple/test-readint.js b/test/simple/test-readint.js deleted file mode 100644 index f1bae2d130b5..000000000000 --- a/test/simple/test-readint.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * Tests to verify we're reading in signed integers correctly - */ -var SlowBuffer = process.binding('buffer').SlowBuffer; -var common = require('../common'); -var ASSERT = require('assert'); - -/* - * Test 8 bit signed integers - */ -function test8(clazz) { - var data = new clazz(4); - - data[0] = 0x23; - ASSERT.equal(0x23, data.readInt8(0)); - - data[0] = 0xff; - ASSERT.equal(-1, data.readInt8(0)); - - data[0] = 0x87; - data[1] = 0xab; - data[2] = 0x7c; - data[3] = 0xef; - ASSERT.equal(-121, data.readInt8(0)); - ASSERT.equal(-85, data.readInt8(1)); - ASSERT.equal(124, data.readInt8(2)); - ASSERT.equal(-17, data.readInt8(3)); -} - - -function test16(clazz) { - var buffer = new clazz(6); - - buffer[0] = 0x16; - buffer[1] = 0x79; - ASSERT.equal(0x1679, buffer.readInt16BE(0)); - ASSERT.equal(0x7916, buffer.readInt16LE(0)); - - buffer[0] = 0xff; - buffer[1] = 0x80; - ASSERT.equal(-128, buffer.readInt16BE(0)); - ASSERT.equal(-32513, buffer.readInt16LE(0)); - - /* test offset with weenix */ - buffer[0] = 0x77; - buffer[1] = 0x65; - buffer[2] = 0x65; - buffer[3] = 0x6e; - buffer[4] = 0x69; - buffer[5] = 0x78; - ASSERT.equal(0x7765, buffer.readInt16BE(0)); - ASSERT.equal(0x6565, buffer.readInt16BE(1)); - ASSERT.equal(0x656e, buffer.readInt16BE(2)); - ASSERT.equal(0x6e69, buffer.readInt16BE(3)); - ASSERT.equal(0x6978, buffer.readInt16BE(4)); - ASSERT.equal(0x6577, buffer.readInt16LE(0)); - ASSERT.equal(0x6565, buffer.readInt16LE(1)); - ASSERT.equal(0x6e65, buffer.readInt16LE(2)); - ASSERT.equal(0x696e, buffer.readInt16LE(3)); - ASSERT.equal(0x7869, buffer.readInt16LE(4)); -} - - -function test32(clazz) { - var buffer = new clazz(6); - - buffer[0] = 0x43; - buffer[1] = 0x53; - buffer[2] = 0x16; - buffer[3] = 0x79; - ASSERT.equal(0x43531679, buffer.readInt32BE(0)); - ASSERT.equal(0x79165343, buffer.readInt32LE(0)); - - buffer[0] = 0xff; - buffer[1] = 0xfe; - buffer[2] = 0xef; - buffer[3] = 0xfa; - ASSERT.equal(-69638, buffer.readInt32BE(0)); - ASSERT.equal(-84934913, buffer.readInt32LE(0)); - - buffer[0] = 0x42; - buffer[1] = 0xc3; - buffer[2] = 0x95; - buffer[3] = 0xa9; - buffer[4] = 0x36; - buffer[5] = 0x17; - ASSERT.equal(0x42c395a9, buffer.readInt32BE(0)); - ASSERT.equal(-1013601994, buffer.readInt32BE(1)); - ASSERT.equal(-1784072681, buffer.readInt32BE(2)); - ASSERT.equal(-1449802942, buffer.readInt32LE(0)); - ASSERT.equal(917083587, buffer.readInt32LE(1)); - ASSERT.equal(389458325, buffer.readInt32LE(2)); -} - - -test8(Buffer); -test8(SlowBuffer); -test16(Buffer); -test16(SlowBuffer); -test32(Buffer); -test32(SlowBuffer); diff --git a/test/simple/test-readline-interface.js b/test/simple/test-readline-interface.js deleted file mode 100644 index 8976b8eb28e3..000000000000 --- a/test/simple/test-readline-interface.js +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - -var assert = require('assert'); -var readline = require('readline'); -var EventEmitter = require('events').EventEmitter; -var inherits = require('util').inherits; - -function FakeInput() { - EventEmitter.call(this); -} -inherits(FakeInput, EventEmitter); -FakeInput.prototype.resume = function() {}; -FakeInput.prototype.pause = function() {}; -FakeInput.prototype.write = function() {}; -FakeInput.prototype.end = function() {}; - -[ true, false ].forEach(function(terminal) { - var fi; - var rli; - var called; - - // sending a full line - fi = new FakeInput(); - rli = new readline.Interface({ input: fi, output: fi, terminal: terminal }); - called = false; - rli.on('line', function(line) { - called = true; - assert.equal(line, 'asdf'); - }); - fi.emit('data', 'asdf\n'); - assert.ok(called); - - // sending a blank line - fi = new FakeInput(); - rli = new readline.Interface({ input: fi, output: fi, terminal: terminal }); - called = false; - rli.on('line', function(line) { - called = true; - assert.equal(line, ''); - }); - fi.emit('data', '\n'); - assert.ok(called); - - // sending a single character with no newline - fi = new FakeInput(); - rli = new readline.Interface(fi, {}); - called = false; - rli.on('line', function(line) { - called = true; - }); - fi.emit('data', 'a'); - assert.ok(!called); - rli.close(); - - // sending a single character with no newline and then a newline - fi = new FakeInput(); - rli = new readline.Interface({ input: fi, output: fi, terminal: terminal }); - called = false; - rli.on('line', function(line) { - called = true; - assert.equal(line, 'a'); - }); - fi.emit('data', 'a'); - assert.ok(!called); - fi.emit('data', '\n'); - assert.ok(called); - rli.close(); - - // sending multiple newlines at once - fi = new FakeInput(); - rli = new readline.Interface({ input: fi, output: fi, terminal: terminal }); - var expectedLines = ['foo', 'bar', 'baz']; - var callCount = 0; - rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); - callCount++; - }); - fi.emit('data', expectedLines.join('\n') + '\n'); - assert.equal(callCount, expectedLines.length); - rli.close(); - - // sending multiple newlines at once that does not end with a new line - fi = new FakeInput(); - rli = new readline.Interface({ input: fi, output: fi, terminal: terminal }); - expectedLines = ['foo', 'bar', 'baz', 'bat']; - callCount = 0; - rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); - callCount++; - }); - fi.emit('data', expectedLines.join('\n')); - assert.equal(callCount, expectedLines.length - 1); - rli.close(); - - // \r\n should emit one line event, not two - fi = new FakeInput(); - rli = new readline.Interface({ input: fi, output: fi, terminal: terminal }); - expectedLines = ['foo', 'bar', 'baz', 'bat']; - callCount = 0; - rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); - callCount++; - }); - fi.emit('data', expectedLines.join('\r\n')); - assert.equal(callCount, expectedLines.length - 1); - rli.close(); - - // \r\n should emit one line event when split across multiple writes. - fi = new FakeInput(); - rli = new readline.Interface({ input: fi, output: fi, terminal: terminal }); - expectedLines = ['foo', 'bar', 'baz', 'bat']; - callCount = 0; - rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); - callCount++; - }); - expectedLines.forEach(function(line) { - fi.emit('data', line + '\r'); - fi.emit('data', '\n'); - }); - assert.equal(callCount, expectedLines.length); - rli.close(); - - // \r should behave like \n when alone - fi = new FakeInput(); - rli = new readline.Interface({ input: fi, output: fi, terminal: true }); - expectedLines = ['foo', 'bar', 'baz', 'bat']; - callCount = 0; - rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); - callCount++; - }); - fi.emit('data', expectedLines.join('\r')); - assert.equal(callCount, expectedLines.length - 1); - rli.close(); - - // \r at start of input should output blank line - fi = new FakeInput(); - rli = new readline.Interface({ input: fi, output: fi, terminal: true }); - expectedLines = ['', 'foo' ]; - callCount = 0; - rli.on('line', function(line) { - assert.equal(line, expectedLines[callCount]); - callCount++; - }); - fi.emit('data', '\rfoo\r'); - assert.equal(callCount, expectedLines.length); - rli.close(); - - // sending a multi-byte utf8 char over multiple writes - var buf = Buffer('☮', 'utf8'); - fi = new FakeInput(); - rli = new readline.Interface({ input: fi, output: fi, terminal: terminal }); - callCount = 0; - rli.on('line', function(line) { - callCount++; - assert.equal(line, buf.toString('utf8')); - }); - [].forEach.call(buf, function(i) { - fi.emit('data', Buffer([i])); - }); - assert.equal(callCount, 0); - fi.emit('data', '\n'); - assert.equal(callCount, 1); - rli.close(); - - assert.deepEqual(fi.listeners('end'), []); - assert.deepEqual(fi.listeners(terminal ? 'keypress' : 'data'), []); -}); diff --git a/test/simple/test-readline-set-raw-mode.js b/test/simple/test-readline-set-raw-mode.js deleted file mode 100644 index 5bca5272ccc4..000000000000 --- a/test/simple/test-readline-set-raw-mode.js +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - -var assert = require('assert'); -var readline = require('readline'); -var Stream = require('stream'); - -var stream = new Stream(); -var expectedRawMode = true; -var rawModeCalled = false; -var resumeCalled = false; -var pauseCalled = false; - -stream.setRawMode = function(mode) { - rawModeCalled = true; - assert.equal(mode, expectedRawMode); -}; -stream.resume = function() { - resumeCalled = true; -}; -stream.pause = function() { - pauseCalled = true; -}; - -// when the "readline" starts in "terminal" mode, -// then setRawMode(true) should be called -var rli = readline.createInterface({ - input: stream, - output: stream, - terminal: true -}); -assert(rli.terminal) -assert(rawModeCalled); -assert(resumeCalled); -assert(!pauseCalled); - - -// pause() should call *not* call setRawMode() -rawModeCalled = false; -resumeCalled = false; -pauseCalled = false; -rli.pause(); -assert(!rawModeCalled); -assert(!resumeCalled); -assert(pauseCalled); - - -// resume() should *not* call setRawMode() -rawModeCalled = false; -resumeCalled = false; -pauseCalled = false; -rli.resume(); -assert(!rawModeCalled); -assert(resumeCalled); -assert(!pauseCalled); - - -// close() should call setRawMode(false) -expectedRawMode = false; -rawModeCalled = false; -resumeCalled = false; -pauseCalled = false; -rli.close(); -assert(rawModeCalled); -assert(!resumeCalled); -assert(pauseCalled); - -assert.deepEqual(stream.listeners('end'), []); -assert.deepEqual(stream.listeners('keypress'), []); -// one data listener for the keypress events. -assert.equal(stream.listeners('data').length, 1); diff --git a/test/simple/test-readuint.js b/test/simple/test-readuint.js deleted file mode 100644 index e63bba70058c..000000000000 --- a/test/simple/test-readuint.js +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * A battery of tests to help us read a series of uints - */ - -var SlowBuffer = process.binding('buffer').SlowBuffer; -var common = require('../common'); -var ASSERT = require('assert'); - -/* - * We need to check the following things: - * - We are correctly resolving big endian (doesn't mean anything for 8 bit) - * - Correctly resolving little endian (doesn't mean anything for 8 bit) - * - Correctly using the offsets - * - Correctly interpreting values that are beyond the signed range as unsigned - */ -function test8(clazz) { - var data = new clazz(4); - - data[0] = 23; - data[1] = 23; - data[2] = 23; - data[3] = 23; - ASSERT.equal(23, data.readUInt8(0)); - ASSERT.equal(23, data.readUInt8(1)); - ASSERT.equal(23, data.readUInt8(2)); - ASSERT.equal(23, data.readUInt8(3)); - - data[0] = 255; /* If it became a signed int, would be -1 */ - ASSERT.equal(255, data.readUInt8(0)); -} - - -/* - * Test 16 bit unsigned integers. We need to verify the same set as 8 bit, only - * now some of the issues actually matter: - * - We are correctly resolving big endian - * - Correctly resolving little endian - * - Correctly using the offsets - * - Correctly interpreting values that are beyond the signed range as unsigned - */ -function test16(clazz) { - var data = new clazz(4); - - data[0] = 0; - data[1] = 0x23; - data[2] = 0x42; - data[3] = 0x3f; - ASSERT.equal(0x23, data.readUInt16BE(0)); - ASSERT.equal(0x2342, data.readUInt16BE(1)); - ASSERT.equal(0x423f, data.readUInt16BE(2)); - ASSERT.equal(0x2300, data.readUInt16LE(0)); - ASSERT.equal(0x4223, data.readUInt16LE(1)); - ASSERT.equal(0x3f42, data.readUInt16LE(2)); - - data[0] = 0xfe; - data[1] = 0xfe; - ASSERT.equal(0xfefe, data.readUInt16BE(0)); - ASSERT.equal(0xfefe, data.readUInt16LE(0)); -} - - -/* - * Test 32 bit unsigned integers. We need to verify the same set as 8 bit, only - * now some of the issues actually matter: - * - We are correctly resolving big endian - * - Correctly using the offsets - * - Correctly interpreting values that are beyond the signed range as unsigned - */ -function test32(clazz) { - var data = new clazz(8); - - data[0] = 0x32; - data[1] = 0x65; - data[2] = 0x42; - data[3] = 0x56; - data[4] = 0x23; - data[5] = 0xff; - ASSERT.equal(0x32654256, data.readUInt32BE(0)); - ASSERT.equal(0x65425623, data.readUInt32BE(1)); - ASSERT.equal(0x425623ff, data.readUInt32BE(2)); - ASSERT.equal(0x56426532, data.readUInt32LE(0)); - ASSERT.equal(0x23564265, data.readUInt32LE(1)); - ASSERT.equal(0xff235642, data.readUInt32LE(2)); -} - - -test8(Buffer); -test8(SlowBuffer); -test16(Buffer); -test16(SlowBuffer); -test32(Buffer); -test32(SlowBuffer); diff --git a/test/simple/test-regress-GH-1531.js b/test/simple/test-regress-GH-1531.js deleted file mode 100644 index 60cd9498d390..000000000000 --- a/test/simple/test-regress-GH-1531.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var https = require('https'); -var assert = require('assert'); -var fs = require('fs'); -var common = require('../common'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var gotCallback = false; - -var server = https.createServer(options, function(req, res) { - res.writeHead(200); - res.end('hello world\n'); -}); - -server.listen(common.PORT, function() { - https.get({ - agent: false, - path: '/', - port: common.PORT, - rejectUnauthorized: false - }, function(res) { - console.error(res.statusCode); - gotCallback = true; - server.close(); - }).on('error', function(e) { - console.error(e.message); - process.exit(1); - }); -}); - -process.on('exit', function() { - assert.ok(gotCallback); -}); - diff --git a/test/simple/test-regress-GH-1697.js b/test/simple/test-regress-GH-1697.js deleted file mode 100644 index fdf2c42e9e2d..000000000000 --- a/test/simple/test-regress-GH-1697.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var net = require('net'), - cp = require('child_process'), - util = require('util'); - -if (process.argv[2] === 'server') { - // Server - - var server = net.createServer(function(conn) { - conn.on('data', function(data) { - console.log('server received ' + data.length + ' bytes'); - }); - - conn.on('close', function() { - server.close(); - }); - }); - - server.listen(common.PORT, '127.0.0.1', function() { - console.log('Server running.'); - }); - -} else { - // Client - - var serverProcess = cp.spawn(process.execPath, [process.argv[1], 'server']); - serverProcess.stdout.pipe(process.stdout); - serverProcess.stderr.pipe(process.stdout); - - serverProcess.stdout.once('data', function() { - var client = net.createConnection(common.PORT, '127.0.0.1'); - client.on('connect', function() { - var alot = new Buffer(1024), - alittle = new Buffer(1); - - for (var i = 0; i < 100; i++) { - client.write(alot); - } - - // Block the event loop for 1 second - var start = (new Date()).getTime(); - while ((new Date).getTime() < start + 1000) {} - - client.write(alittle); - - client.destroySoon(); - }); - }); -} diff --git a/test/simple/test-regress-GH-1726.js b/test/simple/test-regress-GH-1726.js deleted file mode 100644 index 2ed30045375b..000000000000 --- a/test/simple/test-regress-GH-1726.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// 'Software'), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Open a chain of five Node processes each a child of the next. The final -// process exits immediately. Each process in the chain is instructed to -// exit when its child exits. -// https://github.com/joyent/node/issues/1726 - -var common = require('../common'); -var assert = require('assert'); -var ch = require('child_process'); - -var gen = +(process.argv[2] || 0); -var maxGen = 5; - - -if (gen === maxGen) { - console.error('hit maxGen, exiting', maxGen); - return; -} - -var child = ch.spawn(process.execPath, [__filename, gen + 1], { - customFds: [0, -1, 2] -}); -assert.ok(!child.stdin); -assert.ok(child.stdout); -assert.ok(!child.stderr); - -console.error('gen=%d, pid=%d', gen, process.pid); - -/* -var timer = setTimeout(function () { - throw new Error('timeout! gen='+gen); -}, 1000); -*/ - -child.on('exit', function(code) { - console.error('exit %d from gen %d', code, gen + 1); - //clearTimeout(timer); -}); - -child.stdout.pipe(process.stdout); - -child.stdout.on('close', function() { - console.error('child.stdout close gen=%d', gen); -}); diff --git a/test/simple/test-regress-GH-1899.js b/test/simple/test-regress-GH-1899.js deleted file mode 100644 index 7fc8007a24c2..000000000000 --- a/test/simple/test-regress-GH-1899.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var path = require('path'); -var assert = require('assert'); -var spawn = require('child_process').spawn; -var common = require('../common'); - -var child = spawn(process.argv[0], [ - path.join(common.fixturesDir, 'GH-1899-output.js') -]); -var output = ''; - -child.stdout.on('data', function(data) { - output += data; -}); - -child.on('exit', function(code, signal) { - assert.equal(code, 0); - assert.equal(output, 'hello, world!\n'); -}); - diff --git a/test/simple/test-regress-GH-3542.js b/test/simple/test-regress-GH-3542.js deleted file mode 100644 index 90e0b78501a6..000000000000 --- a/test/simple/test-regress-GH-3542.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// This test is only relevant on Windows. -if (process.platform !== 'win32') { - return process.exit(0); -} - -var common = require('../common.js'), - assert = require('assert'), - fs = require('fs'), - path = require('path'), - succeeded = 0; - -function test(p) { - var result = fs.realpathSync(p); - assert.strictEqual(result, path.resolve(p)); - - fs.realpath(p, function(err, result) { - assert.ok(!err); - assert.strictEqual(result, path.resolve(p)); - succeeded++; - }); -} - -test('//localhost/c$/windows/system32'); -test('//localhost/c$/windows'); -test('//localhost/c$/') -test('\\\\localhost\\c$') -test('c:\\'); -test('c:'); -test(process.env.windir); - -process.on('exit', function() { - assert.strictEqual(succeeded, 7); -}); \ No newline at end of file diff --git a/test/simple/test-regress-GH-3739.js b/test/simple/test-regress-GH-3739.js deleted file mode 100644 index 937068795af8..000000000000 --- a/test/simple/test-regress-GH-3739.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'), - assert = require('assert'), - fs = require('fs'), - path = require('path'); - -var dir = path.resolve(common.fixturesDir), - dirs = []; - -// Make a long path. -for (var i = 0; i < 50; i++) { - dir = dir + '/123456790'; - try { - fs.mkdirSync(dir, '0777'); - } catch (e) { - if (e.code == 'EEXIST') { - // Ignore; - } else { - cleanup(); - throw e; - } - } - dirs.push(dir); -} - -// Test existsSync -var r = fs.existsSync(dir); -if (r !== true) { - cleanup(); - throw new Error('fs.existsSync returned false'); -} - -// Text exists -fs.exists(dir, function(r) { - cleanup(); - if (r !== true) { - throw new Error('fs.exists reported false'); - } -}); - -// Remove all created directories -function cleanup() { - for (var i = dirs.length - 1; i >= 0; i--) { - fs.rmdirSync(dirs[i]); - } -} diff --git a/test/simple/test-regress-GH-4015.js b/test/simple/test-regress-GH-4015.js deleted file mode 100644 index b66584f80488..000000000000 --- a/test/simple/test-regress-GH-4015.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; - -var cmd = process.execPath - + ' ' - + common.fixturesDir - + '/test-regress-GH-4015.js'; - -exec(cmd, function(err, stdout, stderr) { - assert(/RangeError: Maximum call stack size exceeded/.test(stderr)); -}); diff --git a/test/simple/test-regress-GH-4027.js b/test/simple/test-regress-GH-4027.js deleted file mode 100644 index 3dff1684d7ba..000000000000 --- a/test/simple/test-regress-GH-4027.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); - -var filename = path.join(common.tmpDir, 'watched'); -fs.writeFileSync(filename, 'quis custodiet ipsos custodes'); -setTimeout(fs.unlinkSync, 100, filename); - -var seenEvent = 0; -process.on('exit', function() { - assert.equal(seenEvent, 1); -}); - -fs.watchFile(filename, { interval: 50 }, function(curr, prev) { - assert.equal(prev.nlink, 1); - assert.equal(curr.nlink, 0); - fs.unwatchFile(filename); - seenEvent++; -}); diff --git a/test/simple/test-regress-GH-4256.js b/test/simple/test-regress-GH-4256.js deleted file mode 100644 index 9f937cc099a6..000000000000 --- a/test/simple/test-regress-GH-4256.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -process.domain = null; -timer = setTimeout(function() { - console.log("this console.log statement should not make node crash"); -}, 1); diff --git a/test/simple/test-regress-GH-4948.js b/test/simple/test-regress-GH-4948.js deleted file mode 100644 index 5e717fad56fd..000000000000 --- a/test/simple/test-regress-GH-4948.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// https://github.com/joyent/node/issues/4948 - -var common = require('../common'); -var http = require('http'); - -var reqCount = 0; -var server = http.createServer(function(serverReq, serverRes){ - if (reqCount) { - serverRes.end(); - server.close(); - return; - } - reqCount = 1; - - - // normally the use case would be to call an external site - // does not require connecting locally or to itself to fail - var r = http.request({hostname: 'localhost', port: common.PORT}, function(res) { - // required, just needs to be in the client response somewhere - serverRes.end(); - - // required for test to fail - res.on('data', function(data) { }); - - }); - r.on('error', function(e) {}); - r.end(); - - serverRes.write('some data'); -}).listen(common.PORT); - -// simulate a client request that closes early -var net = require('net'); - -var sock = new net.Socket(); -sock.connect(common.PORT, 'localhost'); - -sock.on('connect', function() { - sock.write('GET / HTTP/1.1\r\n\r\n'); - sock.end(); -}); \ No newline at end of file diff --git a/test/simple/test-regress-GH-5927.js b/test/simple/test-regress-GH-5927.js deleted file mode 100644 index 5f8f276616c6..000000000000 --- a/test/simple/test-regress-GH-5927.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var readline = require('readline'); - -var rl = readline.createInterface(process.stdin, process.stdout); -rl.resume(); - -var hasPaused = false; - -var origPause = rl.pause; -rl.pause = function() { - hasPaused = true; - origPause.apply(this, arguments); -} - -var origSetRawMode = rl._setRawMode; -rl._setRawMode = function(mode) { - assert.ok(hasPaused); - origSetRawMode.apply(this, arguments); -} - -rl.close(); diff --git a/test/simple/test-regress-GH-746.js b/test/simple/test-regress-GH-746.js deleted file mode 100644 index 29f1456522ac..000000000000 --- a/test/simple/test-regress-GH-746.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Just test that destroying stdin doesn't mess up listening on a server. -// This is a regression test for GH-746. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -process.stdin.destroy(); - -var accepted = null; -var server = net.createServer(function(socket) { - console.log('accepted'); - accepted = socket; - socket.end(); - server.close(); -}); - - -server.listen(common.PORT, function() { - console.log('listening...'); - - net.createConnection(common.PORT); -}); - - -process.on('exit', function() { - assert.ok(accepted); -}); - diff --git a/test/simple/test-regress-GH-784.js b/test/simple/test-regress-GH-784.js deleted file mode 100644 index c2039a9c6ae6..000000000000 --- a/test/simple/test-regress-GH-784.js +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Regression test for GH-784 -// https://github.com/joyent/node/issues/784 -// -// The test works by making a total of 8 requests to the server. The first -// two are made with the server off - they should come back as ECONNREFUSED. -// The next two are made with server on - they should come back successful. -// The next two are made with the server off - and so on. Without the fix -// we were experiencing parse errors and instead of ECONNREFUSED. -var common = require('../common'); -var http = require('http'); -var assert = require('assert'); - - -var server = http.createServer(function(req, res) { - var body = ''; - - req.setEncoding('utf8'); - req.on('data', function(chunk) { - body += chunk; - }); - - req.on('end', function() { - assert.equal('PING', body); - res.writeHead(200); - res.end('PONG'); - }); -}); - - -server.on('listening', pingping); - - -function serverOn() { - console.error('Server ON'); - server.listen(common.PORT); -} - - -function serverOff() { - console.error('Server OFF'); - server.close(); - pingping(); -} - -var responses = []; - - -function afterPing(result) { - responses.push(result); - console.error('afterPing. responses.length = ' + responses.length); - switch (responses.length) { - case 2: - assert.ok(/ECONNREFUSED/.test(responses[0])); - assert.ok(/ECONNREFUSED/.test(responses[1])); - serverOn(); - break; - - case 4: - assert.ok(/success/.test(responses[2])); - assert.ok(/success/.test(responses[3])); - serverOff(); - break; - - case 6: - assert.ok(/ECONNREFUSED/.test(responses[4])); - assert.ok(/ECONNREFUSED/.test(responses[5])); - serverOn(); - break; - - case 8: - assert.ok(/success/.test(responses[6])); - assert.ok(/success/.test(responses[7])); - server.close(); - // we should go to process.on('exit') from here. - break; - } -} - - -function ping() { - console.error('making req'); - - var opt = { - port: common.PORT, - path: '/ping', - method: 'POST' - }; - - var req = http.request(opt, function(res) { - var body = ''; - - res.setEncoding('utf8'); - res.on('data', function(chunk) { - body += chunk; - }); - - res.on('end', function() { - assert.equal('PONG', body); - assert.ok(!hadError); - gotEnd = true; - afterPing('success'); - }); - }); - - req.end('PING'); - - var gotEnd = false; - var hadError = false; - - req.on('error', function(error) { - console.log('Error making ping req: ' + error); - hadError = true; - assert.ok(!gotEnd); - afterPing(error.message); - }); -} - - - -function pingping() { - ping(); - ping(); -} - - -pingping(); - - - - -process.on('exit', function() { - console.error("process.on('exit')"); - console.error(responses); - - assert.equal(8, responses.length); -}); diff --git a/test/simple/test-regress-GH-819.js b/test/simple/test-regress-GH-819.js deleted file mode 100644 index 874d99e285f0..000000000000 --- a/test/simple/test-regress-GH-819.js +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var net = require('net'); -var assert = require('assert'); - -// Connect to something that we need to DNS resolve -var c = net.createConnection(80, 'google.com'); -c.destroy(); diff --git a/test/simple/test-regress-GH-877.js b/test/simple/test-regress-GH-877.js deleted file mode 100644 index 1cdca9f7db95..000000000000 --- a/test/simple/test-regress-GH-877.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var http = require('http'); -var assert = require('assert'); - -var N = 20; -var responses = 0; -var maxQueued = 0; - -var agent = http.globalAgent; -agent.maxSockets = 10; - -var server = http.createServer(function(req, res) { - res.writeHead(200); - res.end('Hello World\n'); -}); - -var addrString = '127.0.0.1:' + common.PORT; - -server.listen(common.PORT, '127.0.0.1', function() { - for (var i = 0; i < N; i++) { - var options = { - host: '127.0.0.1', - port: common.PORT - }; - - var req = http.get(options, function(res) { - if (++responses == N) { - server.close(); - } - res.resume(); - }); - - assert.equal(req.agent, agent); - - console.log('Socket: ' + agent.sockets[addrString].length + '/' + - agent.maxSockets + ' queued: ' + (agent.requests[addrString] ? - agent.requests['127.0.0.1:' + common.PORT].length : 0)); - - var agentRequests = agent.requests[addrString] ? - agent.requests[addrString].length : 0; - - if (maxQueued < agentRequests) { - maxQueued = agentRequests; - } - } -}); - -process.on('exit', function() { - assert.ok(responses == N); - assert.ok(maxQueued <= 10); -}); diff --git a/test/simple/test-regress-GH-897.js b/test/simple/test-regress-GH-897.js deleted file mode 100644 index dd4399f16f12..000000000000 --- a/test/simple/test-regress-GH-897.js +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var t = Date.now(); -var diff; -setTimeout(function() { - diff = Date.now() - t; - console.error(diff); -}, 0.1); - - -process.on('exit', function() { - assert.ok(diff < 100); -}); diff --git a/test/simple/test-regression-object-prototype.js b/test/simple/test-regression-object-prototype.js deleted file mode 100644 index 158532ad873a..000000000000 --- a/test/simple/test-regression-object-prototype.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -//console.log('puts before'); - -Object.prototype.xadsadsdasasdxx = function() { -}; - -console.log('puts after'); diff --git a/test/simple/test-repl-.save.load.js b/test/simple/test-repl-.save.load.js deleted file mode 100644 index b5749c8c7e43..000000000000 --- a/test/simple/test-repl-.save.load.js +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var util = require('util'); -var join = require('path').join; -var fs = require('fs'); -var common = require('../common'); - -var repl = require('repl'); - -// A stream to push an array into a REPL -function ArrayStream() { - this.run = function(data) { - var self = this; - data.forEach(function(line) { - self.emit('data', line + '\n'); - }); - } -} -util.inherits(ArrayStream, require('stream').Stream); -ArrayStream.prototype.readable = true; -ArrayStream.prototype.writable = true; -ArrayStream.prototype.resume = function() {}; -ArrayStream.prototype.write = function() {}; - -var works = [['inner.one'], 'inner.o']; - -var putIn = new ArrayStream(); -var testMe = repl.start('', putIn); - - -var testFile = [ - 'var top = function () {', - 'var inner = {one:1};' -]; -var saveFileName = join(common.tmpDir, 'test.save.js'); - -// input some data -putIn.run(testFile); - -// save it to a file -putIn.run(['.save ' + saveFileName]); - -// the file should have what I wrote -assert.equal(fs.readFileSync(saveFileName, 'utf8'), testFile.join('\n') + '\n'); - -// make sure that the REPL data is "correct" -// so when I load it back I know I'm good -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, works); -}); - -// clear the REPL -putIn.run(['.clear']); - -// Load the file back in -putIn.run(['.load ' + saveFileName]); - -// make sure that the REPL data is "correct" -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, works); -}); - -// clear the REPL -putIn.run(['.clear']); - -var loadFile = join(common.tmpDir, 'file.does.not.exist'); - -// shold not break -putIn.write = function(data) { - // make sure I get a failed to load message and not some crazy error - assert.equal(data, 'Failed to load:' + loadFile + '\n'); - // eat me to avoid work - putIn.write = function() {}; -}; -putIn.run(['.load ' + loadFile]); - - -//TODO how do I do a failed .save test? diff --git a/test/simple/test-repl-autolibs.js b/test/simple/test-repl-autolibs.js deleted file mode 100644 index b6f9294711da..000000000000 --- a/test/simple/test-repl-autolibs.js +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var util = require('util'); -var repl = require('repl'); - -// A stream to push an array into a REPL -function ArrayStream() { - this.run = function (data) { - var self = this; - data.forEach(function (line) { - self.emit('data', line + '\n'); - }); - } -} -util.inherits(ArrayStream, require('stream').Stream); -ArrayStream.prototype.readable = true; -ArrayStream.prototype.writable = true; -ArrayStream.prototype.resume = function () {}; -ArrayStream.prototype.write = function () {}; - -var putIn = new ArrayStream; -var testMe = repl.start('', putIn, null, true); - -test1(); - -function test1(){ - var gotWrite = false; - putIn.write = function (data) { - gotWrite = true; - if (data.length) { - - // inspect output matches repl output - assert.equal(data, util.inspect(require('fs'), null, 2, false) + '\n'); - // globally added lib matches required lib - assert.equal(global.fs, require('fs')); - test2(); - } - }; - assert(!gotWrite); - putIn.run(['fs']); - assert(gotWrite); -} - -function test2(){ - var gotWrite = false; - putIn.write = function(data) { - gotWrite = true; - if (data.length) { - // repl response error message - assert.equal(data, '{}\n'); - // original value wasn't overwritten - assert.equal(val, global.url); - } - }; - var val = {}; - global.url = val; - assert(!gotWrite); - putIn.run(['url']); - assert(gotWrite); -} diff --git a/test/simple/test-repl-console.js b/test/simple/test-repl-console.js deleted file mode 100644 index 3dca14b7f3f5..000000000000 --- a/test/simple/test-repl-console.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'), - assert = require('assert'), - Stream = require('stream'), - repl = require('repl'); - -// create a dummy stream that does nothing -var stream = new Stream(); -stream.write = stream.pause = stream.resume = function(){}; -stream.readable = stream.writable = true; - -var r = repl.start({ - input: stream, - output: stream, - useGlobal: false -}); - - -// ensure that the repl context gets its own "console" instance -assert(r.context.console); - -// ensure that the repl console instance is not the global one -assert.notStrictEqual(r.context.console, console); diff --git a/test/simple/test-repl-domain.js b/test/simple/test-repl-domain.js deleted file mode 100644 index 347664ac38a7..000000000000 --- a/test/simple/test-repl-domain.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var util = require('util'); -var repl = require('repl'); - -// A stream to push an array into a REPL -function ArrayStream() { - this.run = function(data) { - var self = this; - data.forEach(function(line) { - self.emit('data', line + '\n'); - }); - } -} -util.inherits(ArrayStream, require('stream').Stream); -ArrayStream.prototype.readable = true; -ArrayStream.prototype.writable = true; -ArrayStream.prototype.resume = function() {}; -ArrayStream.prototype.write = function() {}; - -var putIn = new ArrayStream(); -var testMe = repl.start('', putIn); - -putIn.write = function(data) { - // Don't use assert for this because the domain might catch it, and - // give a false negative. Don't throw, just print and exit. - if (data === 'OK\n') { - console.log('ok'); - } - else { - console.error(data); - process.exit(1); - } -}; - -putIn.run([ - 'require("domain").create().on("error", function () { console.log("OK") })' - + '.run(function () { throw new Error("threw") })' -]); diff --git a/test/simple/test-repl-end-emits-exit.js b/test/simple/test-repl-end-emits-exit.js deleted file mode 100644 index 46eca2efbf6a..000000000000 --- a/test/simple/test-repl-end-emits-exit.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'), - assert = require('assert'), - Stream = require('stream'), - repl = require('repl'), - terminalExit = 0, - regularExit = 0; - -// create a dummy stream that does nothing -var stream = new Stream(); -stream.write = stream.pause = stream.resume = function(){}; -stream.readable = stream.writable = true; - -function testTerminalMode() { - var r1 = repl.start({ - input: stream, - output: stream, - terminal: true - }); - - process.nextTick(function() { - // manually fire a ^D keypress - stream.emit('data', '\u0004'); - }); - - r1.on('exit', function() { - // should be fired from the simulated ^D keypress - terminalExit++; - testRegularMode(); - }); -} - -function testRegularMode() { - var r2 = repl.start({ - input: stream, - output: stream, - terminal: false - }); - - process.nextTick(function() { - stream.emit('end'); - }); - - r2.on('exit', function() { - // should be fired from the simulated 'end' event - regularExit++; - }); -} - -process.on('exit', function() { - assert.equal(terminalExit, 1); - assert.equal(regularExit, 1); -}); - - -// start -testTerminalMode(); diff --git a/test/simple/test-repl-options.js b/test/simple/test-repl-options.js deleted file mode 100644 index d3fcd588ee8f..000000000000 --- a/test/simple/test-repl-options.js +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'), - assert = require('assert'), - Stream = require('stream'), - repl = require('repl'); - -common.globalCheck = false; - -// create a dummy stream that does nothing -var stream = new Stream(); -stream.write = stream.pause = stream.resume = function(){}; -stream.readable = stream.writable = true; - -// 1, mostly defaults -var r1 = repl.start({ - input: stream, - output: stream, - terminal: true -}); -assert.equal(r1.rli.input, stream); -assert.equal(r1.rli.output, stream); -assert.equal(r1.rli.input, r1.inputStream); -assert.equal(r1.rli.output, r1.outputStream); -assert.equal(r1.rli.terminal, true); -assert.equal(r1.useColors, r1.rli.terminal); -assert.equal(r1.useGlobal, false); -assert.equal(r1.ignoreUndefined, false); - -// 2 -function writer() {} -function evaler() {} -var r2 = repl.start({ - input: stream, - output: stream, - terminal: false, - useColors: true, - useGlobal: true, - ignoreUndefined: true, - eval: evaler, - writer: writer -}); -assert.equal(r2.rli.input, stream); -assert.equal(r2.rli.output, stream); -assert.equal(r2.rli.input, r2.inputStream); -assert.equal(r2.rli.output, r2.outputStream); -assert.equal(r2.rli.terminal, false); -assert.equal(r2.useColors, true); -assert.equal(r2.useGlobal, true); -assert.equal(r2.ignoreUndefined, true); -assert.equal(r2.eval, evaler); -assert.equal(r2.writer, writer); diff --git a/test/simple/test-repl-require-cache.js b/test/simple/test-repl-require-cache.js deleted file mode 100644 index ea2d6d6bd92f..000000000000 --- a/test/simple/test-repl-require-cache.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'), - assert = require('assert'), - repl = require('repl'); - -// https://github.com/joyent/node/issues/3226 - -require.cache.something = 1; -assert.equal(require.cache.something, 1); - -repl.start({ useGlobal: false }).rli.close(); - -assert.equal(require.cache.something, 1); diff --git a/test/simple/test-repl-tab-complete.js b/test/simple/test-repl-tab-complete.js deleted file mode 100644 index 684063831b5b..000000000000 --- a/test/simple/test-repl-tab-complete.js +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var util = require('util'); - -var repl = require('repl'); - -// A stream to push an array into a REPL -function ArrayStream() { - this.run = function(data) { - var self = this; - data.forEach(function(line) { - self.emit('data', line + '\n'); - }); - } -} -util.inherits(ArrayStream, require('stream').Stream); -ArrayStream.prototype.readable = true; -ArrayStream.prototype.writable = true; -ArrayStream.prototype.resume = function() {}; -ArrayStream.prototype.write = function() {}; - -var works = [['inner.one'], 'inner.o']; -var doesNotBreak = [[], 'inner.o']; - -var putIn = new ArrayStream(); -var testMe = repl.start('', putIn); - -// Tab Complete will not break in an object literal -putIn.run(['.clear']); -putIn.run([ - 'var inner = {', - 'one:1' -]); -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, doesNotBreak); -}); -testMe.complete('console.lo', function(error, data) { - assert.deepEqual(data, [['console.log'], 'console.lo']); -}); - -// Tab Complete will return globaly scoped variables -putIn.run(['};']); -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, works); -}); - -putIn.run(['.clear']); - -// Tab Complete will not break in an ternary operator with () -putIn.run([ - 'var inner = ( true ' , - '?', - '{one: 1} : ' -]); -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, doesNotBreak); -}); - -putIn.run(['.clear']); - -// Tab Complete will return a simple local variable -putIn.run([ - 'var top = function () {', - 'var inner = {one:1};' -]); -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, works); -}); - -// When you close the function scope tab complete will not return the -// locally scoped variable -putIn.run(['};']); -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, doesNotBreak); -}); - -putIn.run(['.clear']); - -// Tab Complete will return a complex local variable -putIn.run([ - 'var top = function () {', - 'var inner = {', - ' one:1', - '};' -]); -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, works); -}); - -putIn.run(['.clear']); - -// Tab Complete will return a complex local variable even if the function -// has parameters -putIn.run([ - 'var top = function (one, two) {', - 'var inner = {', - ' one:1', - '};' -]); -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, works); -}); - -putIn.run(['.clear']); - -// Tab Complete will return a complex local variable even if the -// scope is nested inside an immediately executed function -putIn.run([ - 'var top = function () {', - '(function test () {', - 'var inner = {', - ' one:1', - '};' -]); -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, works); -}); - -putIn.run(['.clear']); - -// currently does not work, but should not break note the inner function -// def has the params and { on a separate line -putIn.run([ - 'var top = function () {', - 'r = function test (', - ' one, two) {', - 'var inner = {', - ' one:1', - '};' -]); -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, doesNotBreak); -}); - -putIn.run(['.clear']); - -// currently does not work, but should not break, not the { -putIn.run([ - 'var top = function () {', - 'r = function test ()', - '{', - 'var inner = {', - ' one:1', - '};' -]); -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, doesNotBreak); -}); - -putIn.run(['.clear']); - -// currently does not work, but should not break -putIn.run([ - 'var top = function () {', - 'r = function test (', - ')', - '{', - 'var inner = {', - ' one:1', - '};' -]); -testMe.complete('inner.o', function(error, data) { - assert.deepEqual(data, doesNotBreak); -}); - -putIn.run(['.clear']); - -// make sure tab completion works on non-Objects -putIn.run([ - 'var str = "test";' -]); -testMe.complete('str.len', function(error, data) { - assert.deepEqual(data, [['str.length'], 'str.len']); -}); - -putIn.run(['.clear']); - -// tab completion should not break on spaces -var spaceTimeout = setTimeout(function() { - throw new Error('timeout'); -}, 1000); - -testMe.complete(' ', function(error, data) { - assert.deepEqual(data, [[],undefined]); - clearTimeout(spaceTimeout); -}); - -// tab completion should pick up the global "toString" object, and -// any other properties up the "global" object's prototype chain -testMe.complete('toSt', function(error, data) { - assert.deepEqual(data, [['toString'], 'toSt']); -}); diff --git a/test/simple/test-repl.js b/test/simple/test-repl.js deleted file mode 100644 index 622ee415d1a5..000000000000 --- a/test/simple/test-repl.js +++ /dev/null @@ -1,338 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -common.globalCheck = false; - -var net = require('net'), - repl = require('repl'), - message = 'Read, Eval, Print Loop', - prompt_unix = 'node via Unix socket> ', - prompt_tcp = 'node via TCP socket> ', - prompt_multiline = '... ', - prompt_npm = 'npm should be run outside of the ' + - 'node repl, in your normal shell.\n' + - '(Press Control-D to exit.)\n', - expect_npm = prompt_npm + prompt_unix, - server_tcp, server_unix, client_tcp, client_unix, timer; - - -// absolute path to test/fixtures/a.js -var moduleFilename = require('path').join(common.fixturesDir, 'a'); - -common.error('repl test'); - -// function for REPL to run -invoke_me = function(arg) { - return 'invoked ' + arg; -}; - -function send_expect(list) { - if (list.length > 0) { - var cur = list.shift(); - - common.error('sending ' + JSON.stringify(cur.send)); - - cur.client.expect = cur.expect; - cur.client.list = list; - if (cur.send.length > 0) { - cur.client.write(cur.send + '\n'); - } - } -} - -function clean_up() { - client_tcp.end(); - client_unix.end(); - clearTimeout(timer); -} - -function error_test() { - // The other stuff is done so reuse unix socket - var read_buffer = ''; - client_unix.removeAllListeners('data'); - - client_unix.on('data', function(data) { - read_buffer += data.toString('ascii', 0, data.length); - common.error('Unix data: ' + JSON.stringify(read_buffer) + ', expecting ' + - (client_unix.expect.exec ? - client_unix.expect : - JSON.stringify(client_unix.expect))); - - if (read_buffer.indexOf(prompt_unix) !== -1) { - // if it's an exact match, then don't do the regexp - if (read_buffer !== client_unix.expect) { - assert.ok(read_buffer.match(client_unix.expect)); - common.error('match'); - } - read_buffer = ''; - if (client_unix.list && client_unix.list.length > 0) { - send_expect(client_unix.list); - } else { - common.error('End of Error test, running TCP test.'); - tcp_test(); - } - - } else if (read_buffer.indexOf(prompt_multiline) !== -1) { - // Check that you meant to send a multiline test - assert.strictEqual(prompt_multiline, client_unix.expect); - read_buffer = ''; - if (client_unix.list && client_unix.list.length > 0) { - send_expect(client_unix.list); - } else { - common.error('End of Error test, running TCP test.\n'); - tcp_test(); - } - - } else { - common.error('didn\'t see prompt yet, buffering.'); - } - }); - - send_expect([ - // Uncaught error throws and prints out - { client: client_unix, send: 'throw new Error(\'test error\');', - expect: /^Error: test error/ }, - // Common syntax error is treated as multiline command - { client: client_unix, send: 'function test_func() {', - expect: prompt_multiline }, - // You can recover with the .break command - { client: client_unix, send: '.break', - expect: prompt_unix }, - // Floating point numbers are not interpreted as REPL commands. - { client: client_unix, send: '.1234', - expect: '0.1234' }, - // Floating point expressions are not interpreted as REPL commands - { client: client_unix, send: '.1+.1', - expect: '0.2' }, - // Can parse valid JSON - { client: client_unix, send: 'JSON.parse(\'{"valid": "json"}\');', - expect: '{ valid: \'json\' }'}, - // invalid input to JSON.parse error is special case of syntax error, - // should throw - { client: client_unix, send: 'JSON.parse(\'{invalid: \\\'json\\\'}\');', - expect: /^SyntaxError: Unexpected token i/ }, - // end of input to JSON.parse error is special case of syntax error, - // should throw - { client: client_unix, send: 'JSON.parse(\'066\');', - expect: /^SyntaxError: Unexpected number/ }, - // should throw - { client: client_unix, send: 'JSON.parse(\'{\');', - expect: /^SyntaxError: Unexpected end of input/ }, - // invalid RegExps are a special case of syntax error, - // should throw - { client: client_unix, send: '/(/;', - expect: /^SyntaxError: Invalid regular expression\:/ }, - // invalid RegExp modifiers are a special case of syntax error, - // should throw (GH-4012) - { client: client_unix, send: 'new RegExp("foo", "wrong modifier");', - expect: /^SyntaxError: Invalid flags supplied to RegExp constructor/ }, - // strict mode syntax errors should be caught (GH-5178) - { client: client_unix, send: '(function() { "use strict"; return 0755; })()', - expect: /^SyntaxError: Octal literals are not allowed in strict mode/ }, - { client: client_unix, send: '(function() { "use strict"; return { p: 1, p: 2 }; })()', - expect: /^SyntaxError: Duplicate data property in object literal not allowed in strict mode/ }, - { client: client_unix, send: '(function(a, a, b) { "use strict"; return a + b + c; })()', - expect: /^SyntaxError: Strict mode function may not have duplicate parameter names/ }, - { client: client_unix, send: '(function() { "use strict"; with (this) {} })()', - expect: /^SyntaxError: Strict mode code may not include a with statement/ }, - { client: client_unix, send: '(function() { "use strict"; var x; delete x; })()', - expect: /^SyntaxError: Delete of an unqualified identifier in strict mode/ }, - { client: client_unix, send: '(function() { "use strict"; eval = 17; })()', - expect: /^SyntaxError: Assignment to eval or arguments is not allowed in strict mode/ }, - { client: client_unix, send: '(function() { "use strict"; if (true){ function f() { } } })()', - expect: /^SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function/ }, - // Named functions can be used: - { client: client_unix, send: 'function blah() { return 1; }', - expect: prompt_unix }, - { client: client_unix, send: 'blah()', - expect: '1\n' + prompt_unix }, - // Functions should not evaluate twice (#2773) - { client: client_unix, send: 'var I = [1,2,3,function() {}]; I.pop()', - expect: '[Function]' }, - // Multiline object - { client: client_unix, send: '{ a: ', - expect: prompt_multiline }, - { client: client_unix, send: '1 }', - expect: '{ a: 1 }' }, - // Multiline anonymous function with comment - { client: client_unix, send: '(function () {', - expect: prompt_multiline }, - { client: client_unix, send: '// blah', - expect: prompt_multiline }, - { client: client_unix, send: 'return 1;', - expect: prompt_multiline }, - { client: client_unix, send: '})()', - expect: '1' }, - // npm prompt error message - { client: client_unix, send: 'npm install foobar', - expect: expect_npm }, - { client: client_unix, send: '(function () {\n\nreturn 1;\n})()', - expect: '1' }, - { client: client_unix, send: '{\n\na: 1\n}', - expect: '{ a: 1 }' }, - { client: client_unix, send: 'url.format("http://google.com")', - expect: 'http://google.com/' }, - { client: client_unix, send: 'var path = 42; path', - expect: '42' } - ]); -} - -function tcp_test() { - server_tcp = net.createServer(function(socket) { - assert.strictEqual(server_tcp, socket.server); - - socket.on('end', function() { - socket.end(); - }); - - repl.start(prompt_tcp, socket); - }); - - server_tcp.listen(common.PORT, function() { - var read_buffer = ''; - - client_tcp = net.createConnection(common.PORT); - - client_tcp.on('connect', function() { - assert.equal(true, client_tcp.readable); - assert.equal(true, client_tcp.writable); - - send_expect([ - { client: client_tcp, send: '', - expect: prompt_tcp }, - { client: client_tcp, send: 'invoke_me(333)', - expect: ('\'' + 'invoked 333' + '\'\n' + prompt_tcp) }, - { client: client_tcp, send: 'a += 1', - expect: ('12346' + '\n' + prompt_tcp) }, - { client: client_tcp, - send: 'require(' + JSON.stringify(moduleFilename) + ').number', - expect: ('42' + '\n' + prompt_tcp) } - ]); - }); - - client_tcp.on('data', function(data) { - read_buffer += data.toString('ascii', 0, data.length); - common.error('TCP data: ' + JSON.stringify(read_buffer) + - ', expecting ' + JSON.stringify(client_tcp.expect)); - if (read_buffer.indexOf(prompt_tcp) !== -1) { - assert.strictEqual(client_tcp.expect, read_buffer); - common.error('match'); - read_buffer = ''; - if (client_tcp.list && client_tcp.list.length > 0) { - send_expect(client_tcp.list); - } else { - common.error('End of TCP test.\n'); - clean_up(); - } - } else { - common.error('didn\'t see prompt yet, buffering'); - } - }); - - client_tcp.on('error', function(e) { - throw e; - }); - - client_tcp.on('close', function() { - server_tcp.close(); - }); - }); - -} - -function unix_test() { - server_unix = net.createServer(function(socket) { - assert.strictEqual(server_unix, socket.server); - - socket.on('end', function() { - socket.end(); - }); - - repl.start({ - prompt: prompt_unix, - input: socket, - output: socket, - useGlobal: true - }).context.message = message; - }); - - server_unix.on('listening', function() { - var read_buffer = ''; - - client_unix = net.createConnection(common.PIPE); - - client_unix.on('connect', function() { - assert.equal(true, client_unix.readable); - assert.equal(true, client_unix.writable); - - send_expect([ - { client: client_unix, send: '', - expect: prompt_unix }, - { client: client_unix, send: 'message', - expect: ('\'' + message + '\'\n' + prompt_unix) }, - { client: client_unix, send: 'invoke_me(987)', - expect: ('\'' + 'invoked 987' + '\'\n' + prompt_unix) }, - { client: client_unix, send: 'a = 12345', - expect: ('12345' + '\n' + prompt_unix) }, - { client: client_unix, send: '{a:1}', - expect: ('{ a: 1 }' + '\n' + prompt_unix) } - ]); - }); - - client_unix.on('data', function(data) { - read_buffer += data.toString('ascii', 0, data.length); - common.error('Unix data: ' + JSON.stringify(read_buffer) + - ', expecting ' + JSON.stringify(client_unix.expect)); - if (read_buffer.indexOf(prompt_unix) !== -1) { - assert.strictEqual(client_unix.expect, read_buffer); - common.error('match'); - read_buffer = ''; - if (client_unix.list && client_unix.list.length > 0) { - send_expect(client_unix.list); - } else { - common.error('End of Unix test, running Error test.\n'); - process.nextTick(error_test); - } - } else { - common.error('didn\'t see prompt yet, buffering.'); - } - }); - - client_unix.on('error', function(e) { - throw e; - }); - - client_unix.on('close', function() { - server_unix.close(); - }); - }); - - server_unix.listen(common.PIPE); -} - -unix_test(); - -timer = setTimeout(function() { - assert.fail('Timeout'); -}, 5000); diff --git a/test/simple/test-require-cache-without-stat.js b/test/simple/test-require-cache-without-stat.js deleted file mode 100644 index c2c6c0655248..000000000000 --- a/test/simple/test-require-cache-without-stat.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// We've experienced a regression where the module loader stats a bunch of -// directories on require() even if it's been called before. The require() -// should caching the request. -var common = require('../common'); -var fs = require('fs'); -var assert = require('assert'); - -var counter = 0; - -// Switch out the two stat implementations so that they increase a counter -// each time they are called. - -var _statSync = fs.statSync; -var _stat = fs.stat; - -fs.statSync = function() { - counter++; - return _statSync.apply(this, arguments); -}; - -fs.stat = function() { - counter++; - return _stat.apply(this, arguments); -}; - -// Load the module 'a' and 'http' once. It should become cached. -require(common.fixturesDir + '/a'); -require('../fixtures/a.js'); -require('./../fixtures/a.js'); -require('http'); - -console.log('counterBefore = %d', counter); -var counterBefore = counter; - -// Now load the module a bunch of times with equivalent paths. -// stat should not be called. -for (var i = 0; i < 100; i++) { - require(common.fixturesDir + '/a'); - require('../fixtures/a.js'); - require('./../fixtures/a.js'); -} - -// Do the same with a built-in module -for (var i = 0; i < 100; i++) { - require('http'); -} - -console.log('counterAfter = %d', counter); -var counterAfter = counter; - -assert.equal(counterBefore, counterAfter); diff --git a/test/simple/test-require-cache.js b/test/simple/test-require-cache.js deleted file mode 100644 index 2f812044a7ff..000000000000 --- a/test/simple/test-require-cache.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -(function testInjectFakeModule() { - var relativePath = '../fixtures/semicolon'; - var absolutePath = require.resolve(relativePath); - var fakeModule = {}; - - require.cache[absolutePath] = {exports: fakeModule}; - - assert.strictEqual(require(relativePath), fakeModule); -})(); - - -(function testInjectFakeNativeModule() { - var relativePath = 'fs'; - var fakeModule = {}; - - require.cache[relativePath] = {exports: fakeModule}; - - assert.strictEqual(require(relativePath), fakeModule); -})(); diff --git a/test/simple/test-require-exceptions.js b/test/simple/test-require-exceptions.js deleted file mode 100644 index 307e3e2f3382..000000000000 --- a/test/simple/test-require-exceptions.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// A module with an error in it should throw -assert.throws(function() { - require(common.fixturesDir + '/throws_error'); -}); - -// Requiring the same module again should throw as well -assert.throws(function() { - require(common.fixturesDir + '/throws_error'); -}); - -// Requiring a module that does not exist should throw an -// error with its `code` set to MODULE_NOT_FOUND -assert.throws(function() { - require(common.fixturesDir + '/DOES_NOT_EXIST'); -}, function(e) { - assert.equal('MODULE_NOT_FOUND', e.code); - return true; -}); diff --git a/test/simple/test-require-json.js b/test/simple/test-require-json.js deleted file mode 100644 index 59b1e3d61f18..000000000000 --- a/test/simple/test-require-json.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); - -try { - require('../fixtures/invalid.json'); -} catch (err) { - var re = /test[\/\\]fixtures[\/\\]invalid.json: Unexpected string/; - var i = err.message.match(re); - assert(null !== i, 'require() json error should include path'); -} diff --git a/test/simple/test-require-resolve.js b/test/simple/test-require-resolve.js deleted file mode 100644 index 1e4ff7f09f31..000000000000 --- a/test/simple/test-require-resolve.js +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var fixturesDir = common.fixturesDir; -var assert = require('assert'); -var path = require('path'); - -assert.equal(path.join(__dirname, '../fixtures/a.js'), - require.resolve('../fixtures/a')); -assert.equal(path.join(fixturesDir, 'a.js'), - require.resolve(path.join(fixturesDir, 'a'))); -assert.equal(path.join(fixturesDir, 'nested-index', 'one', 'index.js'), - require.resolve('../fixtures/nested-index/one')); -assert.equal('path', require.resolve('path')); - -console.log('ok'); diff --git a/test/simple/test-script-context.js b/test/simple/test-script-context.js deleted file mode 100644 index 8095a713e9f3..000000000000 --- a/test/simple/test-script-context.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var vm = require('vm'); -var Script = vm.Script; -var script = new Script('"passed";'); - -common.debug('run in a new empty context'); -var context = script.createContext(); -var result = script.runInContext(context); -assert.equal('passed', result); - -common.debug('create a new pre-populated context'); -context = script.createContext({'foo': 'bar', 'thing': 'lala'}); -assert.equal('bar', context.foo); -assert.equal('lala', context.thing); - -common.debug('test updating context'); -script = new Script('foo = 3;'); -result = script.runInContext(context); -assert.equal(3, context.foo); -assert.equal('lala', context.thing); - -// Issue GH-227: -Script.runInNewContext('', null, 'some.js'); - -// Issue GH-1140: -common.debug('test runInContext signature'); -var gh1140Exception; -try { - Script.runInContext('throw new Error()', context, 'expected-filename.js'); -} -catch (e) { - gh1140Exception = e; - assert.ok(/expected-filename/.test(e.stack), - 'expected appearance of filename in Error stack'); -} -assert.ok(gh1140Exception, - 'expected exception from runInContext signature test'); - -// GH-558, non-context argument segfaults / raises assertion -function isTypeError(o) { - return o instanceof TypeError; -} - -([undefined, null, 0, 0.0, '', {}, []].forEach(function(e) { - assert.throws(function() { script.runInContext(e); }, isTypeError); - assert.throws(function() { vm.runInContext('', e); }, isTypeError); -})); - -// Issue GH-693: -common.debug('test RegExp as argument to assert.throws'); -script = vm.createScript('var assert = require(\'assert\'); assert.throws(' + - 'function() { throw "hello world"; }, /hello/);', - 'some.js'); -script.runInNewContext({ require : require }); diff --git a/test/simple/test-script-new.js b/test/simple/test-script-new.js deleted file mode 100644 index 7894bb9fa966..000000000000 --- a/test/simple/test-script-new.js +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var Script = require('vm').Script; - -common.globalCheck = false; - -common.debug('run a string'); -var script = new Script('\'passed\';'); -common.debug('script created'); -var result1 = script.runInNewContext(); -var result2 = script.runInNewContext(); -assert.equal('passed', result1); -assert.equal('passed', result2); - -common.debug('thrown error'); -script = new Script('throw new Error(\'test\');'); -assert.throws(function() { - script.runInNewContext(); -}); - - - -common.debug('undefined reference'); -var error; -script = new Script('foo.bar = 5;'); -try { - script.runInNewContext(); -} catch (e) { - error = e; -} -assert.ok(error); -assert.ok(error.message.indexOf('not defined') >= 0); - -common.debug('error.message: ' + error.message); - - -hello = 5; -script = new Script('hello = 2'); -script.runInNewContext(); -assert.equal(5, hello); - - -common.debug('pass values in and out'); -code = 'foo = 1;' + - 'bar = 2;' + - 'if (baz !== 3) throw new Error(\'test fail\');'; -foo = 2; -obj = { foo: 0, baz: 3 }; -script = new Script(code); -var baz = script.runInNewContext(obj); -assert.equal(1, obj.foo); -assert.equal(2, obj.bar); -assert.equal(2, foo); - -common.debug('call a function by reference'); -script = new Script('f()'); -function changeFoo() { foo = 100 } -script.runInNewContext({ f: changeFoo }); -assert.equal(foo, 100); - -common.debug('modify an object by reference'); -script = new Script('f.a = 2'); -var f = { a: 1 }; -script.runInNewContext({ f: f }); -assert.equal(f.a, 2); - -common.debug('invalid this'); -assert.throws(function() { - script.runInNewContext.call('\'hello\';'); -}); - - diff --git a/test/simple/test-script-static-context.js b/test/simple/test-script-static-context.js deleted file mode 100644 index d2cb70181656..000000000000 --- a/test/simple/test-script-static-context.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var Script = require('vm').Script; - -common.debug('run in a new empty context'); -var context = Script.createContext(); -var result = Script.runInContext('"passed";', context); -assert.equal('passed', result); - -common.debug('create a new pre-populated context'); -context = Script.createContext({'foo': 'bar', 'thing': 'lala'}); -assert.equal('bar', context.foo); -assert.equal('lala', context.thing); - -common.debug('test updating context'); -result = Script.runInContext('var foo = 3;', context); -assert.equal(3, context.foo); -assert.equal('lala', context.thing); diff --git a/test/simple/test-script-static-new.js b/test/simple/test-script-static-new.js deleted file mode 100644 index eaac2d97c0fe..000000000000 --- a/test/simple/test-script-static-new.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var Script = require('vm').Script; - -common.globalCheck = false; - -common.debug('run a string'); -var result = Script.runInNewContext('\'passed\';'); -assert.equal('passed', result); - -common.debug('thrown error'); -assert.throws(function() { - Script.runInNewContext('throw new Error(\'test\');'); -}); - -hello = 5; -Script.runInNewContext('hello = 2'); -assert.equal(5, hello); - - -common.debug('pass values in and out'); -code = 'foo = 1;' + - 'bar = 2;' + - 'if (baz !== 3) throw new Error(\'test fail\');'; -foo = 2; -obj = { foo: 0, baz: 3 }; -var baz = Script.runInNewContext(code, obj); -assert.equal(1, obj.foo); -assert.equal(2, obj.bar); -assert.equal(2, foo); - -common.debug('call a function by reference'); -function changeFoo() { foo = 100 } -Script.runInNewContext('f()', { f: changeFoo }); -assert.equal(foo, 100); - -common.debug('modify an object by reference'); -var f = { a: 1 }; -Script.runInNewContext('f.a = 2', { f: f }); -assert.equal(f.a, 2); - diff --git a/test/simple/test-script-static-this.js b/test/simple/test-script-static-this.js deleted file mode 100644 index 63c11331e940..000000000000 --- a/test/simple/test-script-static-this.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var Script = require('vm').Script; - -common.globalCheck = false; - -common.debug('run a string'); -var result = Script.runInThisContext('\'passed\';'); -assert.equal('passed', result); - -common.debug('thrown error'); -assert.throws(function() { - Script.runInThisContext('throw new Error(\'test\');'); -}); - -hello = 5; -Script.runInThisContext('hello = 2'); -assert.equal(2, hello); - - -common.debug('pass values'); -code = 'foo = 1;' + - 'bar = 2;' + - 'if (typeof baz !== \'undefined\') throw new Error(\'test fail\');'; -foo = 2; -obj = { foo: 0, baz: 3 }; -var baz = Script.runInThisContext(code); -assert.equal(0, obj.foo); -assert.equal(2, bar); -assert.equal(1, foo); - -common.debug('call a function'); -f = function() { foo = 100 }; -Script.runInThisContext('f()'); -assert.equal(100, foo); diff --git a/test/simple/test-script-this.js b/test/simple/test-script-this.js deleted file mode 100644 index a55a49097384..000000000000 --- a/test/simple/test-script-this.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var Script = require('vm').Script; - -common.globalCheck = false; - -common.debug('run a string'); -var script = new Script('\'passed\';'); -var result = script.runInThisContext(script); -assert.equal('passed', result); - -common.debug('thrown error'); -script = new Script('throw new Error(\'test\');'); -assert.throws(function() { - script.runInThisContext(script); -}); - -hello = 5; -script = new Script('hello = 2'); -script.runInThisContext(script); -assert.equal(2, hello); - - -common.debug('pass values'); -code = 'foo = 1;' + - 'bar = 2;' + - 'if (typeof baz !== \'undefined\') throw new Error(\'test fail\');'; -foo = 2; -obj = { foo: 0, baz: 3 }; -script = new Script(code); -script.runInThisContext(script); -assert.equal(0, obj.foo); -assert.equal(2, bar); -assert.equal(1, foo); - -common.debug('call a function'); -f = function() { foo = 100 }; -script = new Script('f()'); -script.runInThisContext(script); -assert.equal(100, foo); diff --git a/test/simple/test-setproctitle.js b/test/simple/test-setproctitle.js deleted file mode 100644 index 6373af4cd184..000000000000 --- a/test/simple/test-setproctitle.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Original test written by Jakub Lekstan - -// FIXME add sunos support -if ('linux freebsd darwin'.indexOf(process.platform) === -1) { - console.error('Skipping test, platform not supported.'); - process.exit(); -} - -var common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; - -// The title shouldn't be too long; libuv's uv_set_process_title() out of -// security considerations no longer overwrites envp, only argv, so the -// maximum title length is possibly quite short. -var title = 'testme'; - -assert.notEqual(process.title, title); -process.title = title; -assert.equal(process.title, title); - -exec('ps -p ' + process.pid + ' -o args=', function(error, stdout, stderr) { - assert.equal(error, null); - assert.equal(stderr, ''); - - // freebsd always add ' (procname)' to the process title - if (process.platform === 'freebsd') title += ' (node)'; - - // omitting trailing whitespace and \n - assert.equal(stdout.replace(/\s+$/, ''), title); -}); diff --git a/test/simple/test-sigint-infinite-loop.js b/test/simple/test-sigint-infinite-loop.js deleted file mode 100644 index 4ff2745845a4..000000000000 --- a/test/simple/test-sigint-infinite-loop.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -// This test is to assert that we can SIGINT a script which loops forever. -// Ref(http): -// groups.google.com/group/nodejs-dev/browse_thread/thread/e20f2f8df0296d3f -var common = require('../common'); -var assert = require('assert'); -var spawn = require('child_process').spawn; - -console.log('start'); - -var c = spawn(process.execPath, ['-e', 'while(true) { console.log("hi"); }']); - -var sentKill = false; -var gotChildExit = true; - -c.stdout.on('data', function(s) { - // Prevent race condition: - // Wait for the first bit of output from the child process - // so that we're sure that it's in the V8 event loop and not - // just in the startup phase of execution. - if (!sentKill) { - c.kill('SIGINT'); - console.log('SIGINT infinite-loop.js'); - sentKill = true; - } -}); - -c.on('exit', function(code) { - assert.ok(code !== 0); - console.log('killed infinite-loop.js'); - gotChildExit = true; -}); - -process.on('exit', function() { - assert.ok(sentKill); - assert.ok(gotChildExit); -}); - diff --git a/test/simple/test-signal-handler.js b/test/simple/test-signal-handler.js deleted file mode 100644 index 5531e2f556e8..000000000000 --- a/test/simple/test-signal-handler.js +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -// SIGUSR1 and SIGHUP are not supported on Windows -if (process.platform === 'win32') { - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); - -console.log('process.pid: ' + process.pid); - -var first = 0, - second = 0; - -var sighup = false; - -process.on('SIGUSR1', function() { - console.log('Interrupted by SIGUSR1'); - first += 1; -}); - -process.on('SIGUSR1', function() { - second += 1; - setTimeout(function() { - console.log('End.'); - process.exit(0); - }, 5); -}); - -var i = 0; -setInterval(function() { - console.log('running process...' + ++i); - - if (i == 5) { - process.kill(process.pid, 'SIGUSR1'); - } -}, 1); - -// Test on condition where a watcher for SIGNAL -// has been previously registered, and `process.listeners(SIGNAL).length === 1` -process.on('SIGHUP', function() {}); -process.removeAllListeners('SIGHUP'); -process.on('SIGHUP', function() { sighup = true }); -process.kill(process.pid, 'SIGHUP'); - -process.on('exit', function() { - assert.equal(1, first); - assert.equal(1, second); - assert.equal(true, sighup); -}); diff --git a/test/simple/test-signal-unregister.js b/test/simple/test-signal-unregister.js deleted file mode 100644 index d65e0a0d98a7..000000000000 --- a/test/simple/test-signal-unregister.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); - -var childKilled = false, done = false, - spawn = require('child_process').spawn, - util = require('util'), - child; - -var join = require('path').join; - -child = spawn(process.argv[0], [join(common.fixturesDir, 'should_exit.js')]); -child.on('exit', function() { - if (!done) childKilled = true; -}); - -setTimeout(function() { - console.log('Sending SIGINT'); - child.kill('SIGINT'); - setTimeout(function() { - console.log('Chance has been given to die'); - done = true; - if (!childKilled) { - // Cleanup - console.log('Child did not die on SIGINT, sending SIGTERM'); - child.kill('SIGTERM'); - } - }, 200); -}, 200); - -process.on('exit', function() { - assert.ok(childKilled); -}); diff --git a/test/simple/test-socket-write-after-fin-error.js b/test/simple/test-socket-write-after-fin-error.js deleted file mode 100644 index 123557417ccc..000000000000 --- a/test/simple/test-socket-write-after-fin-error.js +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// This is similar to simple/test-socket-write-after-fin, except that -// we don't set allowHalfOpen. Then we write after the client has sent -// a FIN, and this is an error. However, the standard "write after end" -// message is too vague, and doesn't actually tell you what happens. - -var net = require('net'); -var serverData = ''; -var gotServerEnd = false; -var clientData = ''; -var gotClientEnd = false; -var gotServerError = false; - -var server = net.createServer(function(sock) { - sock.setEncoding('utf8'); - sock.on('error', function(er) { - console.error(er.code + ': ' + er.message); - gotServerError = er; - }); - - sock.on('data', function(c) { - serverData += c; - }); - sock.on('end', function() { - gotServerEnd = true - sock.write(serverData); - sock.end(); - }); - server.close(); -}); -server.listen(common.PORT); - -var sock = net.connect(common.PORT); -sock.setEncoding('utf8'); -sock.on('data', function(c) { - clientData += c; -}); - -sock.on('end', function() { - gotClientEnd = true; -}); - -process.on('exit', function() { - assert.equal(clientData, ''); - assert.equal(serverData, 'hello1hello2hello3\nTHUNDERMUSCLE!'); - assert(gotClientEnd); - assert(gotServerEnd); - assert(gotServerError); - assert.equal(gotServerError.code, 'EPIPE'); - assert.notEqual(gotServerError.message, 'write after end'); - console.log('ok'); -}); - -sock.write('hello1'); -sock.write('hello2'); -sock.write('hello3\n'); -sock.end('THUNDERMUSCLE!'); diff --git a/test/simple/test-socket-write-after-fin.js b/test/simple/test-socket-write-after-fin.js deleted file mode 100644 index 88d780b81e87..000000000000 --- a/test/simple/test-socket-write-after-fin.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var serverData = ''; -var gotServerEnd = false; -var clientData = ''; -var gotClientEnd = false; - -var server = net.createServer({ allowHalfOpen: true }, function(sock) { - sock.setEncoding('utf8'); - sock.on('data', function(c) { - serverData += c; - }); - sock.on('end', function() { - gotServerEnd = true - sock.end(serverData); - server.close(); - }); -}); -server.listen(common.PORT); - -var sock = net.connect(common.PORT); -sock.setEncoding('utf8'); -sock.on('data', function(c) { - clientData += c; -}); - -sock.on('end', function() { - gotClientEnd = true; -}); - -process.on('exit', function() { - assert.equal(serverData, clientData); - assert.equal(serverData, 'hello1hello2hello3\nTHUNDERMUSCLE!'); - assert(gotClientEnd); - assert(gotServerEnd); - console.log('ok'); -}); - -sock.write('hello1'); -sock.write('hello2'); -sock.write('hello3\n'); -sock.end('THUNDERMUSCLE!'); diff --git a/test/simple/test-stdin-child-proc.js b/test/simple/test-stdin-child-proc.js deleted file mode 100644 index 6a4ea9473948..000000000000 --- a/test/simple/test-stdin-child-proc.js +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// This tests that pausing and resuming stdin does not hang and timeout -// when done in a child process. See test/simple/test-stdin-pause-resume.js -var common = require('../common'); -var child_process = require('child_process'); -var path = require('path'); -child_process.spawn(process.execPath, - [path.resolve(__dirname, 'test-stdin-pause-resume.js')]); diff --git a/test/simple/test-stdin-from-file.js b/test/simple/test-stdin-from-file.js deleted file mode 100644 index 617b9037d233..000000000000 --- a/test/simple/test-stdin-from-file.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var join = require('path').join; -var childProccess = require('child_process'); -var fs = require('fs'); - -var stdoutScript = join(common.fixturesDir, 'echo-close-check.js'); -var tmpFile = join(common.fixturesDir, 'stdin.txt'); - -var cmd = '"' + process.argv[0] + '" "' + stdoutScript + '" < "' + - tmpFile + '"'; - -var string = 'abc\nümlaut.\nsomething else\n' + - '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,' + - '疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、' + - '云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,' + - '由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,' + - '南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + - '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' + - '历经五代君主。南越国是岭南地区的第一个有记载的政权国家,' + - '采用封建制和郡县制并存的制度,' + - '它的建立保证了秦末乱世岭南地区社会秩序的稳定,' + - '有效的改善了岭南地区落后的政治、##济现状。\n'; - - -console.log(cmd + '\n\n'); - -try { - fs.unlinkSync(tmpFile); -} catch (e) {} - -fs.writeFileSync(tmpFile, string); - -childProccess.exec(cmd, function(err, stdout, stderr) { - fs.unlinkSync(tmpFile); - - if (err) throw err; - console.log(stdout); - assert.equal(stdout, 'hello world\r\n' + string); - assert.equal('', stderr); -}); diff --git a/test/simple/test-stdin-hang.js b/test/simple/test-stdin-hang.js deleted file mode 100644 index 1edbf8c25b7c..000000000000 --- a/test/simple/test-stdin-hang.js +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); - -// This test *only* verifies that invoking the stdin getter does not -// cause node to hang indefinitely. -// If it does, then the test-runner will nuke it. - -// invoke the getter. -process.stdin; - -console.error('Should exit normally now.'); diff --git a/test/simple/test-stdin-pause-resume-sync.js b/test/simple/test-stdin-pause-resume-sync.js deleted file mode 100644 index 0e202a3063f2..000000000000 --- a/test/simple/test-stdin-pause-resume-sync.js +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -console.error('before opening stdin'); -process.stdin.resume(); -console.error('stdin opened'); -console.error('pausing stdin'); -process.stdin.pause(); -console.error('opening again'); -process.stdin.resume(); -console.error('pausing again'); -process.stdin.pause(); -console.error('should exit now'); diff --git a/test/simple/test-stdin-pause-resume.js b/test/simple/test-stdin-pause-resume.js deleted file mode 100644 index fed5d665329c..000000000000 --- a/test/simple/test-stdin-pause-resume.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -console.error('before opening stdin'); -process.stdin.resume(); -console.error('stdin opened'); -setTimeout(function() { - console.error('pausing stdin'); - process.stdin.pause(); - setTimeout(function() { - console.error('opening again'); - process.stdin.resume(); - setTimeout(function() { - console.error('pausing again'); - process.stdin.pause(); - console.error('should exit now'); - }, 1); - }, 1); -}, 1); diff --git a/test/simple/test-stdin-pipe-resume.js b/test/simple/test-stdin-pipe-resume.js deleted file mode 100644 index 163d8369c9e9..000000000000 --- a/test/simple/test-stdin-pipe-resume.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// This tests that piping stdin will cause it to resume() as well. -var common = require('../common'); -var assert = require('assert'); - -if (process.argv[2] === 'child') { - process.stdin.pipe(process.stdout); -} else { - var spawn = require('child_process').spawn; - var buffers = []; - var child = spawn(process.execPath, [__filename, 'child']); - child.stdout.on('data', function(c) { - buffers.push(c); - }); - child.stdout.on('close', function() { - var b = Buffer.concat(buffers).toString(); - assert.equal(b, 'Hello, world\n'); - console.log('ok'); - }); - child.stdin.write('Hel'); - child.stdin.write('lo,'); - child.stdin.write(' wo'); - setTimeout(function() { - child.stdin.write('rld\n'); - child.stdin.end(); - }, 10); -} - diff --git a/test/simple/test-stdin-resume-pause.js b/test/simple/test-stdin-resume-pause.js deleted file mode 100644 index 2d2af2fc66d3..000000000000 --- a/test/simple/test-stdin-resume-pause.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -process.stdin.resume(); -process.stdin.pause(); diff --git a/test/simple/test-stdio-readable-writable.js b/test/simple/test-stdio-readable-writable.js deleted file mode 100644 index 5123f968872f..000000000000 --- a/test/simple/test-stdio-readable-writable.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -assert(process.stdout.writable); -assert(!process.stdout.readable); - -assert(process.stderr.writable); -assert(!process.stderr.readable); - -assert(!process.stdin.writable); -assert(process.stdin.readable); diff --git a/test/simple/test-stdout-cannot-be-closed-child-process-pipe.js b/test/simple/test-stdout-cannot-be-closed-child-process-pipe.js deleted file mode 100644 index 2e79c5af101a..000000000000 --- a/test/simple/test-stdout-cannot-be-closed-child-process-pipe.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -if (process.argv[2] === 'child') - process.stdout.end('foo'); -else - parent(); - -function parent() { - var spawn = require('child_process').spawn; - var child = spawn(process.execPath, [__filename, 'child']); - var out = ''; - var err = ''; - - child.stdout.setEncoding('utf8'); - child.stderr.setEncoding('utf8'); - - child.stdout.on('data', function(c) { - out += c; - }); - child.stderr.on('data', function(c) { - err += c; - }); - - child.on('close', function(code, signal) { - assert(code); - assert.equal(out, 'foo'); - assert(/process\.stdout cannot be closed/.test(err)); - console.log('ok'); - }); -} diff --git a/test/simple/test-stdout-close-catch.js b/test/simple/test-stdout-close-catch.js deleted file mode 100644 index f517a6cbe439..000000000000 --- a/test/simple/test-stdout-close-catch.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var child_process = require('child_process'); -var fs = require('fs'); - -var testScript = path.join(common.fixturesDir, 'catch-stdout-error.js'); - -var cmd = JSON.stringify(process.execPath) + ' ' + - JSON.stringify(testScript) + ' | ' + - JSON.stringify(process.execPath) + ' ' + - '-pe "process.exit(1);"'; - -var child = child_process.exec(cmd); -var output = ''; -var outputExpect = { 'code': 'EPIPE', - 'errno': 'EPIPE', - 'syscall': 'write' }; - -child.stderr.on('data', function(c) { - output += c; -}); - -child.on('close', function(code) { - try { - output = JSON.parse(output); - } catch (er) { - console.error(output); - process.exit(1); - } - - assert.deepEqual(output, outputExpect); - console.log('ok'); -}); diff --git a/test/simple/test-stdout-close-unref.js b/test/simple/test-stdout-close-unref.js deleted file mode 100644 index 42f399772f35..000000000000 --- a/test/simple/test-stdout-close-unref.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -process.stdin.resume(); -process.stdin._handle.close(); -process.stdin._handle.unref(); // Should not segfault. diff --git a/test/simple/test-stdout-stderr-reading.js b/test/simple/test-stdout-stderr-reading.js deleted file mode 100644 index 5b67a0d06185..000000000000 --- a/test/simple/test-stdout-stderr-reading.js +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// verify that stdout is never read from. -var net = require('net'); -var read = net.Socket.prototype.read; - -net.Socket.prototype.read = function() { - if (this.fd === 1) - throw new Error('reading from stdout!'); - if (this.fd === 2) - throw new Error('reading from stderr!'); - return read.apply(this, arguments); -}; - -if (process.argv[2] === 'child') - child(); -else - parent(); - -function parent() { - var spawn = require('child_process').spawn; - var node = process.execPath; - var closes = 0; - - var c1 = spawn(node, [__filename, 'child']); - var c1out = ''; - c1.stdout.setEncoding('utf8'); - c1.stdout.on('data', function(chunk) { - c1out += chunk; - }); - c1.stderr.setEncoding('utf8'); - c1.stderr.on('data', function(chunk) { - console.error('c1err: ' + chunk.split('\n').join('\nc1err: ')); - }); - c1.on('close', function(code, signal) { - closes++; - assert(!code); - assert(!signal); - assert.equal(c1out, 'ok\n'); - console.log('ok'); - }); - - var c2 = spawn(node, ['-e', 'console.log("ok")']); - var c2out = ''; - c2.stdout.setEncoding('utf8'); - c2.stdout.on('data', function(chunk) { - c2out += chunk; - }); - c1.stderr.setEncoding('utf8'); - c1.stderr.on('data', function(chunk) { - console.error('c1err: ' + chunk.split('\n').join('\nc1err: ')); - }); - c2.on('close', function(code, signal) { - closes++; - assert(!code); - assert(!signal); - assert.equal(c2out, 'ok\n'); - console.log('ok'); - }); - - process.on('exit', function() { - assert.equal(closes, 2, 'saw both closes'); - }); -} - -function child() { - // should not be reading *ever* in here. - net.Socket.prototype.read = function() { - throw new Error('no reading allowed in child'); - }; - console.log('ok'); -} diff --git a/test/simple/test-stdout-to-file.js b/test/simple/test-stdout-to-file.js deleted file mode 100644 index 94181ef8174e..000000000000 --- a/test/simple/test-stdout-to-file.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var childProccess = require('child_process'); -var fs = require('fs'); - -var scriptString = path.join(common.fixturesDir, 'print-chars.js'); -var scriptBuffer = path.join(common.fixturesDir, 'print-chars-from-buffer.js'); -var tmpFile = path.join(common.tmpDir, 'stdout.txt'); - -function test(size, useBuffer, cb) { - var cmd = '"' + process.argv[0] + '"' + - ' ' + - '"' + (useBuffer ? scriptBuffer : scriptString) + '"' + - ' ' + - size + - ' > ' + - '"' + tmpFile + '"'; - - try { - fs.unlinkSync(tmpFile); - } catch (e) {} - - common.print(size + ' chars to ' + tmpFile + '...'); - - childProccess.exec(cmd, function(err) { - if (err) throw err; - - console.log('done!'); - - var stat = fs.statSync(tmpFile); - - console.log(tmpFile + ' has ' + stat.size + ' bytes'); - - assert.equal(size, stat.size); - fs.unlinkSync(tmpFile); - - cb(); - }); -} - -var finished = false; -test(1024 * 1024, false, function() { - console.log('Done printing with string'); - test(1024 * 1024, true, function() { - console.log('Done printing with buffer'); - finished = true; - }); -}); - -process.on('exit', function() { - assert.ok(finished); -}); diff --git a/test/simple/test-stream-big-packet.js b/test/simple/test-stream-big-packet.js deleted file mode 100644 index 9ec29ca0dcc6..000000000000 --- a/test/simple/test-stream-big-packet.js +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var util = require('util'); -var stream = require('stream'); - -var passed = false; - -function PassThrough () { - stream.Transform.call(this); -}; -util.inherits(PassThrough, stream.Transform); -PassThrough.prototype._transform = function (chunk, encoding, done) { - this.push(chunk); - done(); -}; - -function TestStream () { - stream.Transform.call(this); -}; -util.inherits(TestStream, stream.Transform); -TestStream.prototype._transform = function (chunk, encoding, done) { - if (!passed) { - // Char 'a' only exists in the last write - passed = chunk.toString().indexOf('a') >= 0; - } - done(); -}; - -var s1 = new PassThrough(); -var s2 = new PassThrough(); -var s3 = new TestStream(); -s1.pipe(s3); -// Don't let s2 auto close which may close s3 -s2.pipe(s3, {end: false}); - -// We must write a buffer larger than highWaterMark -var big = new Buffer(s1._writableState.highWaterMark + 1); -big.fill('x'); - -// Since big is larger than highWaterMark, it will be buffered internally. -assert(!s1.write(big)); -// 'tiny' is small enough to pass through internal buffer. -assert(s2.write('tiny')); - -// Write some small data in next IO loop, which will never be written to s3 -// Because 'drain' event is not emitted from s1 and s1 is still paused -setImmediate(s1.write.bind(s1), 'later'); - -// Assert after two IO loops when all operations have been done. -process.on('exit', function () { - assert(passed, 'Large buffer is not handled properly by Writable Stream'); -}); diff --git a/test/simple/test-stream-big-push.js b/test/simple/test-stream-big-push.js deleted file mode 100644 index e3787e4412f3..000000000000 --- a/test/simple/test-stream-big-push.js +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var stream = require('stream'); -var str = 'asdfasdfasdfasdfasdf'; - -var r = new stream.Readable({ - highWaterMark: 5, - encoding: 'utf8' -}); - -var reads = 0; -var eofed = false; -var ended = false; - -r._read = function(n) { - if (reads === 0) { - setTimeout(function() { - r.push(str); - }); - reads++; - } else if (reads === 1) { - var ret = r.push(str); - assert.equal(ret, false); - reads++; - } else { - assert(!eofed); - eofed = true; - r.push(null); - } -}; - -r.on('end', function() { - ended = true; -}); - -// push some data in to start. -// we've never gotten any read event at this point. -var ret = r.push(str); -// should be false. > hwm -assert(!ret); -var chunk = r.read(); -assert.equal(chunk, str); -chunk = r.read(); -assert.equal(chunk, null); - -r.once('readable', function() { - // this time, we'll get *all* the remaining data, because - // it's been added synchronously, as the read WOULD take - // us below the hwm, and so it triggered a _read() again, - // which synchronously added more, which we then return. - chunk = r.read(); - assert.equal(chunk, str + str); - - chunk = r.read(); - assert.equal(chunk, null); -}); - -process.on('exit', function() { - assert(eofed); - assert(ended); - assert.equal(reads, 2); - console.log('ok'); -}); diff --git a/test/simple/test-stream-pipe-after-end.js b/test/simple/test-stream-pipe-after-end.js deleted file mode 100644 index b46ee90ad73a..000000000000 --- a/test/simple/test-stream-pipe-after-end.js +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var Readable = require('_stream_readable'); -var Writable = require('_stream_writable'); -var util = require('util'); - -util.inherits(TestReadable, Readable); -function TestReadable(opt) { - if (!(this instanceof TestReadable)) - return new TestReadable(opt); - Readable.call(this, opt); - this._ended = false; -} - -TestReadable.prototype._read = function(n) { - if (this._ended) - this.emit('error', new Error('_read called twice')); - this._ended = true; - this.push(null); -}; - -util.inherits(TestWritable, Writable); -function TestWritable(opt) { - if (!(this instanceof TestWritable)) - return new TestWritable(opt); - Writable.call(this, opt); - this._written = []; -} - -TestWritable.prototype._write = function(chunk, encoding, cb) { - this._written.push(chunk); - cb(); -}; - -// this one should not emit 'end' until we read() from it later. -var ender = new TestReadable(); -var enderEnded = false; - -// what happens when you pipe() a Readable that's already ended? -var piper = new TestReadable(); -// pushes EOF null, and length=0, so this will trigger 'end' -piper.read(); - -setTimeout(function() { - ender.on('end', function() { - enderEnded = true; - }); - assert(!enderEnded); - var c = ender.read(); - assert.equal(c, null); - - var w = new TestWritable(); - var writableFinished = false; - w.on('finish', function() { - writableFinished = true; - }); - piper.pipe(w); - - process.on('exit', function() { - assert(enderEnded); - assert(writableFinished); - console.log('ok'); - }); -}); diff --git a/test/simple/test-stream-pipe-cleanup.js b/test/simple/test-stream-pipe-cleanup.js deleted file mode 100644 index f689358524fb..000000000000 --- a/test/simple/test-stream-pipe-cleanup.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// This test asserts that Stream.prototype.pipe does not leave listeners -// hanging on the source or dest. - -var common = require('../common'); -var stream = require('stream'); -var assert = require('assert'); -var util = require('util'); - -function Writable() { - this.writable = true; - this.endCalls = 0; - stream.Stream.call(this); -} -util.inherits(Writable, stream.Stream); -Writable.prototype.end = function() { - this.endCalls++; -}; - -Writable.prototype.destroy = function() { - this.endCalls++; -}; - -function Readable() { - this.readable = true; - stream.Stream.call(this); -} -util.inherits(Readable, stream.Stream); - -function Duplex() { - this.readable = true; - Writable.call(this); -} -util.inherits(Duplex, Writable); - -var i = 0; -var limit = 100; - -var w = new Writable(); - -var r; - -for (i = 0; i < limit; i++) { - r = new Readable(); - r.pipe(w); - r.emit('end'); -} -assert.equal(0, r.listeners('end').length); -assert.equal(limit, w.endCalls); - -w.endCalls = 0; - -for (i = 0; i < limit; i++) { - r = new Readable(); - r.pipe(w); - r.emit('close'); -} -assert.equal(0, r.listeners('close').length); -assert.equal(limit, w.endCalls); - -w.endCalls = 0; - -r = new Readable(); - -for (i = 0; i < limit; i++) { - w = new Writable(); - r.pipe(w); - w.emit('close'); -} -assert.equal(0, w.listeners('close').length); - -r = new Readable(); -w = new Writable(); -var d = new Duplex(); -r.pipe(d); // pipeline A -d.pipe(w); // pipeline B -assert.equal(r.listeners('end').length, 2); // A.onend, A.cleanup -assert.equal(r.listeners('close').length, 2); // A.onclose, A.cleanup -assert.equal(d.listeners('end').length, 2); // B.onend, B.cleanup -assert.equal(d.listeners('close').length, 3); // A.cleanup, B.onclose, B.cleanup -assert.equal(w.listeners('end').length, 0); -assert.equal(w.listeners('close').length, 1); // B.cleanup - -r.emit('end'); -assert.equal(d.endCalls, 1); -assert.equal(w.endCalls, 0); -assert.equal(r.listeners('end').length, 0); -assert.equal(r.listeners('close').length, 0); -assert.equal(d.listeners('end').length, 2); // B.onend, B.cleanup -assert.equal(d.listeners('close').length, 2); // B.onclose, B.cleanup -assert.equal(w.listeners('end').length, 0); -assert.equal(w.listeners('close').length, 1); // B.cleanup - -d.emit('end'); -assert.equal(d.endCalls, 1); -assert.equal(w.endCalls, 1); -assert.equal(r.listeners('end').length, 0); -assert.equal(r.listeners('close').length, 0); -assert.equal(d.listeners('end').length, 0); -assert.equal(d.listeners('close').length, 0); -assert.equal(w.listeners('end').length, 0); -assert.equal(w.listeners('close').length, 0); diff --git a/test/simple/test-stream-pipe-error-handling.js b/test/simple/test-stream-pipe-error-handling.js deleted file mode 100644 index c5d724b782d3..000000000000 --- a/test/simple/test-stream-pipe-error-handling.js +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var Stream = require('stream').Stream; - -(function testErrorListenerCatches() { - var source = new Stream(); - var dest = new Stream(); - - source.pipe(dest); - - var gotErr = null; - source.on('error', function(err) { - gotErr = err; - }); - - var err = new Error('This stream turned into bacon.'); - source.emit('error', err); - assert.strictEqual(gotErr, err); -})(); - -(function testErrorWithoutListenerThrows() { - var source = new Stream(); - var dest = new Stream(); - - source.pipe(dest); - - var err = new Error('This stream turned into bacon.'); - - var gotErr = null; - try { - source.emit('error', err); - } catch (e) { - gotErr = e; - } - - assert.strictEqual(gotErr, err); -})(); - -(function testErrorWithRemovedListenerThrows() { - var EE = require('events').EventEmitter; - var R = Stream.Readable; - var W = Stream.Writable; - - var r = new R; - var w = new W; - var removed = false; - var didTest = false; - - process.on('exit', function() { - assert(didTest); - console.log('ok'); - }); - - r._read = function() { - setTimeout(function() { - assert(removed); - assert.throws(function() { - w.emit('error', new Error('fail')); - }); - didTest = true; - }); - }; - - w.on('error', myOnError); - r.pipe(w); - w.removeListener('error', myOnError); - removed = true; - - function myOnError(er) { - throw new Error('this should not happen'); - } -})(); - -(function testErrorWithRemovedListenerThrows() { - var EE = require('events').EventEmitter; - var R = Stream.Readable; - var W = Stream.Writable; - - var r = new R; - var w = new W; - var removed = false; - var didTest = false; - var caught = false; - - process.on('exit', function() { - assert(didTest); - console.log('ok'); - }); - - r._read = function() { - setTimeout(function() { - assert(removed); - w.emit('error', new Error('fail')); - didTest = true; - }); - }; - - w.on('error', myOnError); - w._write = function() {}; - - r.pipe(w); - // Removing some OTHER random listener should not do anything - w.removeListener('error', function() {}); - removed = true; - - function myOnError(er) { - assert(!caught); - caught = true; - } -})(); diff --git a/test/simple/test-stream-pipe-event.js b/test/simple/test-stream-pipe-event.js deleted file mode 100644 index cb9d5fe8ca6b..000000000000 --- a/test/simple/test-stream-pipe-event.js +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var stream = require('stream'); -var assert = require('assert'); -var util = require('util'); - -function Writable() { - this.writable = true; - stream.Stream.call(this); -} -util.inherits(Writable, stream.Stream); - -function Readable() { - this.readable = true; - stream.Stream.call(this); -} -util.inherits(Readable, stream.Stream); - -var passed = false; - -var w = new Writable(); -w.on('pipe', function(src) { - passed = true; -}); - -var r = new Readable(); -r.pipe(w); - -assert.ok(passed); diff --git a/test/simple/test-stream-pipe-multi.js b/test/simple/test-stream-pipe-multi.js deleted file mode 100644 index 9a8535ffe7d2..000000000000 --- a/test/simple/test-stream-pipe-multi.js +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Test that having a bunch of streams piping in parallel -// doesn't break anything. - -var common = require('../common'); -var assert = require('assert'); -var Stream = require('stream').Stream; -var rr = []; -var ww = []; -var cnt = 100; -var chunks = 1000; -var chunkSize = 250; -var data = new Buffer(chunkSize); -var wclosed = 0; -var rclosed = 0; - -function FakeStream() { - Stream.apply(this); - this.wait = false; - this.writable = true; - this.readable = true; -} - -FakeStream.prototype = Object.create(Stream.prototype); - -FakeStream.prototype.write = function(chunk) { - console.error(this.ID, 'write', this.wait); - if (this.wait) { - process.nextTick(this.emit.bind(this, 'drain')); - } - this.wait = !this.wait; - return this.wait; -}; - -FakeStream.prototype.end = function() { - this.emit('end'); - process.nextTick(this.close.bind(this)); -}; - -// noop - closes happen automatically on end. -FakeStream.prototype.close = function() { - this.emit('close'); -}; - - -// expect all streams to close properly. -process.on('exit', function() { - assert.equal(cnt, wclosed, 'writable streams closed'); - assert.equal(cnt, rclosed, 'readable streams closed'); -}); - -for (var i = 0; i < chunkSize; i++) { - chunkSize[i] = i % 256; -} - -for (var i = 0; i < cnt; i++) { - var r = new FakeStream(); - r.on('close', function() { - console.error(this.ID, 'read close'); - rclosed++; - }); - rr.push(r); - - var w = new FakeStream(); - w.on('close', function() { - console.error(this.ID, 'write close'); - wclosed++; - }); - ww.push(w); - - r.ID = w.ID = i; - r.pipe(w); -} - -// now start passing through data -// simulate a relatively fast async stream. -rr.forEach(function(r) { - var cnt = chunks; - var paused = false; - - r.on('pause', function() { - paused = true; - }); - - r.on('resume', function() { - paused = false; - step(); - }); - - function step() { - r.emit('data', data); - if (--cnt === 0) { - r.end(); - return; - } - if (paused) return; - process.nextTick(step); - } - - process.nextTick(step); -}); diff --git a/test/simple/test-stream-push-order.js b/test/simple/test-stream-push-order.js deleted file mode 100644 index f2e6ec29ce34..000000000000 --- a/test/simple/test-stream-push-order.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var Readable = require('stream').Readable; -var assert = require('assert'); - -var s = new Readable({ - highWaterMark: 20, - encoding: 'ascii' -}); - -var list = ['1', '2', '3', '4', '5', '6']; - -s._read = function (n) { - var one = list.shift(); - if (!one) { - s.push(null); - } else { - var two = list.shift(); - s.push(one); - s.push(two); - } -}; - -var v = s.read(0); - -// ACTUALLY [1, 3, 5, 6, 4, 2] - -process.on("exit", function () { - assert.deepEqual(s._readableState.buffer, - ['1', '2', '3', '4', '5', '6']); - console.log("ok"); -}); diff --git a/test/simple/test-stream-push-strings.js b/test/simple/test-stream-push-strings.js deleted file mode 100644 index 06f43dc1c86e..000000000000 --- a/test/simple/test-stream-push-strings.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var Readable = require('stream').Readable; -var util = require('util'); - -util.inherits(MyStream, Readable); -function MyStream(options) { - Readable.call(this, options); - this._chunks = 3; -} - -MyStream.prototype._read = function(n) { - switch (this._chunks--) { - case 0: - return this.push(null); - case 1: - return setTimeout(function() { - this.push('last chunk'); - }.bind(this), 100); - case 2: - return this.push('second to last chunk'); - case 3: - return process.nextTick(function() { - this.push('first chunk'); - }.bind(this)); - default: - throw new Error('?'); - } -}; - -var ms = new MyStream(); -var results = []; -ms.on('readable', function() { - var chunk; - while (null !== (chunk = ms.read())) - results.push(chunk + ''); -}); - -var expect = [ 'first chunksecond to last chunk', 'last chunk' ]; -process.on('exit', function() { - assert.equal(ms._chunks, -1); - assert.deepEqual(results, expect); - console.log('ok'); -}); diff --git a/test/simple/test-stream-readable-event.js b/test/simple/test-stream-readable-event.js deleted file mode 100644 index ba6a57724d23..000000000000 --- a/test/simple/test-stream-readable-event.js +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var Readable = require('stream').Readable; - -(function first() { - // First test, not reading when the readable is added. - // make sure that on('readable', ...) triggers a readable event. - var r = new Readable({ - highWaterMark: 3 - }); - - var _readCalled = false; - r._read = function(n) { - _readCalled = true; - }; - - // This triggers a 'readable' event, which is lost. - r.push(new Buffer('blerg')); - - var caughtReadable = false; - setTimeout(function() { - // we're testing what we think we are - assert(!r._readableState.reading); - r.on('readable', function() { - caughtReadable = true; - }); - }); - - process.on('exit', function() { - // we're testing what we think we are - assert(!_readCalled); - - assert(caughtReadable); - console.log('ok 1'); - }); -})(); - -(function second() { - // second test, make sure that readable is re-emitted if there's - // already a length, while it IS reading. - - var r = new Readable({ - highWaterMark: 3 - }); - - var _readCalled = false; - r._read = function(n) { - _readCalled = true; - }; - - // This triggers a 'readable' event, which is lost. - r.push(new Buffer('bl')); - - var caughtReadable = false; - setTimeout(function() { - // assert we're testing what we think we are - assert(r._readableState.reading); - r.on('readable', function() { - caughtReadable = true; - }); - }); - - process.on('exit', function() { - // we're testing what we think we are - assert(_readCalled); - - assert(caughtReadable); - console.log('ok 2'); - }); -})(); - -(function third() { - // Third test, not reading when the stream has not passed - // the highWaterMark but *has* reached EOF. - var r = new Readable({ - highWaterMark: 30 - }); - - var _readCalled = false; - r._read = function(n) { - _readCalled = true; - }; - - // This triggers a 'readable' event, which is lost. - r.push(new Buffer('blerg')); - r.push(null); - - var caughtReadable = false; - setTimeout(function() { - // assert we're testing what we think we are - assert(!r._readableState.reading); - r.on('readable', function() { - caughtReadable = true; - }); - }); - - process.on('exit', function() { - // we're testing what we think we are - assert(!_readCalled); - - assert(caughtReadable); - console.log('ok 3'); - }); -})(); diff --git a/test/simple/test-stream-readable-flow-recursion.js b/test/simple/test-stream-readable-flow-recursion.js deleted file mode 100644 index 2891ad6db8db..000000000000 --- a/test/simple/test-stream-readable-flow-recursion.js +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// this test verifies that passing a huge number to read(size) -// will push up the highWaterMark, and cause the stream to read -// more data continuously, but without triggering a nextTick -// warning or RangeError. - -var Readable = require('stream').Readable; - -// throw an error if we trigger a nextTick warning. -process.throwDeprecation = true; - -var stream = new Readable({ highWaterMark: 2 }); -var reads = 0; -var total = 5000; -stream._read = function(size) { - reads++; - size = Math.min(size, total); - total -= size; - if (size === 0) - stream.push(null); - else - stream.push(new Buffer(size)); -}; - -var depth = 0; - -function flow(stream, size, callback) { - depth += 1; - var chunk = stream.read(size); - - if (!chunk) - stream.once('readable', flow.bind(null, stream, size, callback)); - else - callback(chunk); - - depth -= 1; - console.log('flow(' + depth + '): exit'); -} - -flow(stream, 5000, function() { - console.log('complete (' + depth + ')'); -}); - -process.on('exit', function(code) { - assert.equal(reads, 2); - // we pushed up the high water mark - assert.equal(stream._readableState.highWaterMark, 8192); - // length is 0 right now, because we pulled it all out. - assert.equal(stream._readableState.length, 0); - assert(!code); - assert.equal(depth, 0); - console.log('ok'); -}); diff --git a/test/simple/test-stream-transform-objectmode-falsey-value.js b/test/simple/test-stream-transform-objectmode-falsey-value.js deleted file mode 100644 index 31b5bbaaf5b6..000000000000 --- a/test/simple/test-stream-transform-objectmode-falsey-value.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var stream = require('stream'); -var PassThrough = stream.PassThrough; - -var src = new PassThrough({ objectMode: true }); -var tx = new PassThrough({ objectMode: true }); -var dest = new PassThrough({ objectMode: true }); - -var expect = [ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; -var results = []; -process.on('exit', function() { - assert.deepEqual(results, expect); - console.log('ok'); -}); - -dest.on('data', function(x) { - results.push(x); -}); - -src.pipe(tx).pipe(dest); - -var i = -1; -var int = setInterval(function() { - if (i > 10) { - src.end(); - clearInterval(int); - } else { - src.write(i++); - } -}); diff --git a/test/simple/test-stream-unshift-empty-chunk.js b/test/simple/test-stream-unshift-empty-chunk.js deleted file mode 100644 index 0c9647650f2b..000000000000 --- a/test/simple/test-stream-unshift-empty-chunk.js +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// This test verifies that stream.unshift(Buffer(0)) or -// stream.unshift('') does not set state.reading=false. -var Readable = require('stream').Readable; - -var r = new Readable(); -var nChunks = 10; -var chunk = new Buffer(10); -chunk.fill('x'); - -r._read = function(n) { - setTimeout(function() { - r.push(--nChunks === 0 ? null : chunk); - }); -}; - -var readAll = false; -var seen = []; -r.on('readable', function() { - var chunk; - while (chunk = r.read()) { - seen.push(chunk.toString()); - // simulate only reading a certain amount of the data, - // and then putting the rest of the chunk back into the - // stream, like a parser might do. We just fill it with - // 'y' so that it's easy to see which bits were touched, - // and which were not. - var putBack = new Buffer(readAll ? 0 : 5); - putBack.fill('y'); - readAll = !readAll; - r.unshift(putBack); - } -}); - -var expect = - [ 'xxxxxxxxxx', - 'yyyyy', - 'xxxxxxxxxx', - 'yyyyy', - 'xxxxxxxxxx', - 'yyyyy', - 'xxxxxxxxxx', - 'yyyyy', - 'xxxxxxxxxx', - 'yyyyy', - 'xxxxxxxxxx', - 'yyyyy', - 'xxxxxxxxxx', - 'yyyyy', - 'xxxxxxxxxx', - 'yyyyy', - 'xxxxxxxxxx', - 'yyyyy' ]; - -r.on('end', function() { - assert.deepEqual(seen, expect); - console.log('ok'); -}); diff --git a/test/simple/test-stream-unshift-read-race.js b/test/simple/test-stream-unshift-read-race.js deleted file mode 100644 index 83fd9fa203e4..000000000000 --- a/test/simple/test-stream-unshift-read-race.js +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// This test verifies that: -// 1. unshift() does not cause colliding _read() calls. -// 2. unshift() after the 'end' event is an error, but after the EOF -// signalling null, it is ok, and just creates a new readable chunk. -// 3. push() after the EOF signaling null is an error. -// 4. _read() is not called after pushing the EOF null chunk. - -var stream = require('stream'); -var hwm = 10; -var r = stream.Readable({ highWaterMark: hwm }); -var chunks = 10; -var t = (chunks * 5); - -var data = new Buffer(chunks * hwm + Math.ceil(hwm / 2)); -for (var i = 0; i < data.length; i++) { - var c = 'asdf'.charCodeAt(i % 4); - data[i] = c; -} - -var pos = 0; -var pushedNull = false; -r._read = function(n) { - assert(!pushedNull, '_read after null push'); - - // every third chunk is fast - push(!(chunks % 3)); - - function push(fast) { - assert(!pushedNull, 'push() after null push'); - var c = pos >= data.length ? null : data.slice(pos, pos + n); - pushedNull = c === null; - if (fast) { - pos += n; - r.push(c); - if (c === null) pushError(); - } else { - setTimeout(function() { - pos += n; - r.push(c); - if (c === null) pushError(); - }); - } - } -}; - -function pushError() { - assert.throws(function() { - r.push(new Buffer(1)); - }); -} - - -var w = stream.Writable(); -var written = []; -w._write = function(chunk, encoding, cb) { - written.push(chunk.toString()); - cb(); -}; - -var ended = false; -r.on('end', function() { - assert(!ended, 'end emitted more than once'); - assert.throws(function() { - r.unshift(new Buffer(1)); - }); - ended = true; - w.end(); -}); - -r.on('readable', function() { - var chunk; - while (null !== (chunk = r.read(10))) { - w.write(chunk); - if (chunk.length > 4) - r.unshift(new Buffer('1234')); - } -}); - -var finished = false; -w.on('finish', function() { - finished = true; - // each chunk should start with 1234, and then be asfdasdfasdf... - // The first got pulled out before the first unshift('1234'), so it's - // lacking that piece. - assert.equal(written[0], 'asdfasdfas'); - var asdf = 'd'; - console.error('0: %s', written[0]); - for (var i = 1; i < written.length; i++) { - console.error('%s: %s', i.toString(32), written[i]); - assert.equal(written[i].slice(0, 4), '1234'); - for (var j = 4; j < written[i].length; j++) { - var c = written[i].charAt(j); - assert.equal(c, asdf); - switch (asdf) { - case 'a': asdf = 's'; break; - case 's': asdf = 'd'; break; - case 'd': asdf = 'f'; break; - case 'f': asdf = 'a'; break; - } - } - } -}); - -process.on('exit', function() { - assert.equal(written.length, 18); - assert(ended, 'stream ended'); - assert(finished, 'stream finished'); - console.log('ok'); -}); diff --git a/test/simple/test-stream-writable-decoded-encoding.js b/test/simple/test-stream-writable-decoded-encoding.js deleted file mode 100644 index 8e2624b259ff..000000000000 --- a/test/simple/test-stream-writable-decoded-encoding.js +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var stream = require('stream'); -var util = require('util'); - -function MyWritable(fn, options) { - stream.Writable.call(this, options); - this.fn = fn; -}; - -util.inherits(MyWritable, stream.Writable); - -MyWritable.prototype._write = function (chunk, encoding, callback) { - this.fn(Buffer.isBuffer(chunk), typeof chunk, encoding); - callback(); -}; - -;(function decodeStringsTrue() { - var m = new MyWritable(function(isBuffer, type, enc) { - assert(isBuffer); - assert.equal(type, 'object'); - assert.equal(enc, 'buffer'); - console.log('ok - decoded string is decoded'); - }, { decodeStrings: true }); - m.write('some-text', 'utf8'); - m.end(); -})(); - -;(function decodeStringsFalse() { - var m = new MyWritable(function(isBuffer, type, enc) { - assert(!isBuffer); - assert.equal(type, 'string'); - assert.equal(enc, 'utf8'); - console.log('ok - un-decoded string is not decoded'); - }, { decodeStrings: false }); - m.write('some-text', 'utf8'); - m.end(); -})(); diff --git a/test/simple/test-stream2-base64-single-char-read-end.js b/test/simple/test-stream2-base64-single-char-read-end.js deleted file mode 100644 index 5a3834128c67..000000000000 --- a/test/simple/test-stream2-base64-single-char-read-end.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common.js'); -var R = require('_stream_readable'); -var W = require('_stream_writable'); -var assert = require('assert'); - -var src = new R({encoding: 'base64'}); -var dst = new W(); -var hasRead = false; -var accum = []; -var timeout; - -src._read = function(n) { - if(!hasRead) { - hasRead = true; - process.nextTick(function() { - src.push(new Buffer('1')); - src.push(null); - }); - }; -}; - -dst._write = function(chunk, enc, cb) { - accum.push(chunk); - cb(); -}; - -src.on('end', function() { - assert.equal(Buffer.concat(accum) + '', 'MQ=='); - clearTimeout(timeout); -}) - -src.pipe(dst); - -timeout = setTimeout(function() { - assert.fail('timed out waiting for _write'); -}, 100); diff --git a/test/simple/test-stream2-basic.js b/test/simple/test-stream2-basic.js deleted file mode 100644 index 512231b43892..000000000000 --- a/test/simple/test-stream2-basic.js +++ /dev/null @@ -1,475 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common.js'); -var R = require('_stream_readable'); -var assert = require('assert'); - -var util = require('util'); -var EE = require('events').EventEmitter; - -function TestReader(n) { - R.apply(this); - this._buffer = new Buffer(n || 100); - this._buffer.fill('x'); - this._pos = 0; - this._bufs = 10; -} - -util.inherits(TestReader, R); - -TestReader.prototype.read = function(n) { - if (n === 0) return null; - var max = this._buffer.length - this._pos; - n = n || max; - n = Math.max(n, 0); - var toRead = Math.min(n, max); - if (toRead === 0) { - // simulate the read buffer filling up with some more bytes some time - // in the future. - setTimeout(function() { - this._pos = 0; - this._bufs -= 1; - if (this._bufs <= 0) { - // read them all! - if (!this.ended) { - this.emit('end'); - this.ended = true; - } - } else { - this.emit('readable'); - } - }.bind(this), 10); - return null; - } - - var ret = this._buffer.slice(this._pos, this._pos + toRead); - this._pos += toRead; - return ret; -}; - -///// - -function TestWriter() { - EE.apply(this); - this.received = []; - this.flush = false; -} - -util.inherits(TestWriter, EE); - -TestWriter.prototype.write = function(c) { - this.received.push(c.toString()); - this.emit('write', c); - return true; -}; - -TestWriter.prototype.end = function(c) { - if (c) this.write(c); - this.emit('end', this.received); -}; - -//////// - -// tiny node-tap lookalike. -var tests = []; -var count = 0; - -function test(name, fn) { - count++; - tests.push([name, fn]); -} - -function run() { - var next = tests.shift(); - if (!next) - return console.error('ok'); - - var name = next[0]; - var fn = next[1]; - console.log('# %s', name); - fn({ - same: assert.deepEqual, - ok: assert, - equal: assert.equal, - end: function () { - count--; - run(); - } - }); -} - -// ensure all tests have run -process.on("exit", function () { - assert.equal(count, 0); -}); - -process.nextTick(run); - - -test('a most basic test', function(t) { - var r = new TestReader(20); - - var reads = []; - var expect = [ 'x', - 'xx', - 'xxx', - 'xxxx', - 'xxxxx', - 'xxxxx', - 'xxxxxxxx', - 'xxxxxxxxx', - 'xxx', - 'xxxxxxxxxxxx', - 'xxxxxxxx', - 'xxxxxxxxxxxxxxx', - 'xxxxx', - 'xxxxxxxxxxxxxxxxxx', - 'xx', - 'xxxxxxxxxxxxxxxxxxxx', - 'xxxxxxxxxxxxxxxxxxxx', - 'xxxxxxxxxxxxxxxxxxxx', - 'xxxxxxxxxxxxxxxxxxxx', - 'xxxxxxxxxxxxxxxxxxxx' ]; - - r.on('end', function() { - t.same(reads, expect); - t.end(); - }); - - var readSize = 1; - function flow() { - var res; - while (null !== (res = r.read(readSize++))) { - reads.push(res.toString()); - } - r.once('readable', flow); - } - - flow(); -}); - -test('pipe', function(t) { - var r = new TestReader(5); - - var expect = [ 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx' ] - - var w = new TestWriter; - var flush = true; - - w.on('end', function(received) { - t.same(received, expect); - t.end(); - }); - - r.pipe(w); -}); - - - -[1,2,3,4,5,6,7,8,9].forEach(function(SPLIT) { - test('unpipe', function(t) { - var r = new TestReader(5); - - // unpipe after 3 writes, then write to another stream instead. - var expect = [ 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx' ]; - expect = [ expect.slice(0, SPLIT), expect.slice(SPLIT) ]; - - var w = [ new TestWriter(), new TestWriter() ]; - - var writes = SPLIT; - w[0].on('write', function() { - if (--writes === 0) { - r.unpipe(); - t.equal(r._readableState.pipes, null); - w[0].end(); - r.pipe(w[1]); - t.equal(r._readableState.pipes, w[1]); - } - }); - - var ended = 0; - - var ended0 = false; - var ended1 = false; - w[0].on('end', function(results) { - t.equal(ended0, false); - ended0 = true; - ended++; - t.same(results, expect[0]); - }); - - w[1].on('end', function(results) { - t.equal(ended1, false); - ended1 = true; - ended++; - t.equal(ended, 2); - t.same(results, expect[1]); - t.end(); - }); - - r.pipe(w[0]); - }); -}); - - -// both writers should get the same exact data. -test('multipipe', function(t) { - var r = new TestReader(5); - var w = [ new TestWriter, new TestWriter ]; - - var expect = [ 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx' ]; - - var c = 2; - w[0].on('end', function(received) { - t.same(received, expect, 'first'); - if (--c === 0) t.end(); - }); - w[1].on('end', function(received) { - t.same(received, expect, 'second'); - if (--c === 0) t.end(); - }); - - r.pipe(w[0]); - r.pipe(w[1]); -}); - - -[1,2,3,4,5,6,7,8,9].forEach(function(SPLIT) { - test('multi-unpipe', function(t) { - var r = new TestReader(5); - - // unpipe after 3 writes, then write to another stream instead. - var expect = [ 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx', - 'xxxxx' ]; - expect = [ expect.slice(0, SPLIT), expect.slice(SPLIT) ]; - - var w = [ new TestWriter(), new TestWriter(), new TestWriter() ]; - - var writes = SPLIT; - w[0].on('write', function() { - if (--writes === 0) { - r.unpipe(); - w[0].end(); - r.pipe(w[1]); - } - }); - - var ended = 0; - - w[0].on('end', function(results) { - ended++; - t.same(results, expect[0]); - }); - - w[1].on('end', function(results) { - ended++; - t.equal(ended, 2); - t.same(results, expect[1]); - t.end(); - }); - - r.pipe(w[0]); - r.pipe(w[2]); - }); -}); - -test('back pressure respected', function (t) { - function noop() {} - - var r = new R({ objectMode: true }); - r._read = noop; - var counter = 0; - r.push(["one"]); - r.push(["two"]); - r.push(["three"]); - r.push(["four"]); - r.push(null); - - var w1 = new R(); - w1.write = function (chunk) { - assert.equal(chunk[0], "one"); - w1.emit("close"); - process.nextTick(function () { - r.pipe(w2); - r.pipe(w3); - }) - }; - w1.end = noop; - - r.pipe(w1); - - var expected = ["two", "two", "three", "three", "four", "four"]; - - var w2 = new R(); - w2.write = function (chunk) { - assert.equal(chunk[0], expected.shift()); - assert.equal(counter, 0); - - counter++; - - if (chunk[0] === "four") { - return true; - } - - setTimeout(function () { - counter--; - w2.emit("drain"); - }, 10); - - return false; - } - w2.end = noop; - - var w3 = new R(); - w3.write = function (chunk) { - assert.equal(chunk[0], expected.shift()); - assert.equal(counter, 1); - - counter++; - - if (chunk[0] === "four") { - return true; - } - - setTimeout(function () { - counter--; - w3.emit("drain"); - }, 50); - - return false; - }; - w3.end = function () { - assert.equal(counter, 2); - assert.equal(expected.length, 0); - t.end(); - }; -}); - -test('read(0) for ended streams', function (t) { - var r = new R(); - var written = false; - var ended = false; - r._read = function (n) {}; - - r.push(new Buffer("foo")); - r.push(null); - - var v = r.read(0); - - assert.equal(v, null); - - var w = new R(); - - w.write = function (buffer) { - written = true; - assert.equal(ended, false); - assert.equal(buffer.toString(), "foo") - }; - - w.end = function () { - ended = true; - assert.equal(written, true); - t.end(); - }; - - r.pipe(w); -}) - -test('sync _read ending', function (t) { - var r = new R(); - var called = false; - r._read = function (n) { - r.push(null); - }; - - r.once('end', function () { - called = true; - }) - - r.read(); - - process.nextTick(function () { - assert.equal(called, true); - t.end(); - }) -}); - -test('adding readable triggers data flow', function(t) { - var r = new R({ highWaterMark: 5 }); - var onReadable = false; - var readCalled = 0; - - r._read = function(n) { - if (readCalled++ === 2) - r.push(null); - else - r.push(new Buffer('asdf')); - }; - - var called = false; - r.on('readable', function() { - onReadable = true; - r.read(); - }); - - r.on('end', function() { - t.equal(readCalled, 3); - t.ok(onReadable); - t.end(); - }); -}); diff --git a/test/simple/test-stream2-compatibility.js b/test/simple/test-stream2-compatibility.js deleted file mode 100644 index 2b98c1fa8f0e..000000000000 --- a/test/simple/test-stream2-compatibility.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common.js'); -var R = require('_stream_readable'); -var assert = require('assert'); - -var util = require('util'); -var EE = require('events').EventEmitter; - -var ondataCalled = 0; - -function TestReader() { - R.apply(this); - this._buffer = new Buffer(100); - this._buffer.fill('x'); - - this.on('data', function() { - ondataCalled++; - }); -} - -util.inherits(TestReader, R); - -TestReader.prototype._read = function(n) { - this.push(this._buffer); - this._buffer = new Buffer(0); -}; - -var reader = new TestReader(); -assert.equal(ondataCalled, 1); diff --git a/test/simple/test-stream2-finish-pipe.js b/test/simple/test-stream2-finish-pipe.js deleted file mode 100644 index 39b274f977cb..000000000000 --- a/test/simple/test-stream2-finish-pipe.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var stream = require('stream'); -var Buffer = require('buffer').Buffer; - -var r = new stream.Readable(); -r._read = function(size) { - r.push(new Buffer(size)); -}; - -var w = new stream.Writable(); -w._write = function(data, encoding, cb) { - cb(null); -}; - -r.pipe(w); - -// This might sound unrealistic, but it happens in net.js. When -// `socket.allowHalfOpen === false`, EOF will cause `.destroySoon()` call which -// ends the writable side of net.Socket. -w.end(); diff --git a/test/simple/test-stream2-fs.js b/test/simple/test-stream2-fs.js deleted file mode 100644 index e16240628771..000000000000 --- a/test/simple/test-stream2-fs.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common.js'); -var R = require('_stream_readable'); -var assert = require('assert'); - -var fs = require('fs'); -var FSReadable = fs.ReadStream; - -var path = require('path'); -var file = path.resolve(common.fixturesDir, 'x1024.txt'); - -var size = fs.statSync(file).size; - -var expectLengths = [1024]; - -var util = require('util'); -var Stream = require('stream'); - -util.inherits(TestWriter, Stream); - -function TestWriter() { - Stream.apply(this); - this.buffer = []; - this.length = 0; -} - -TestWriter.prototype.write = function(c) { - this.buffer.push(c.toString()); - this.length += c.length; - return true; -}; - -TestWriter.prototype.end = function(c) { - if (c) this.buffer.push(c.toString()); - this.emit('results', this.buffer); -} - -var r = new FSReadable(file); -var w = new TestWriter(); - -w.on('results', function(res) { - console.error(res, w.length); - assert.equal(w.length, size); - var l = 0; - assert.deepEqual(res.map(function (c) { - return c.length; - }), expectLengths); - console.log('ok'); -}); - -r.pipe(w); diff --git a/test/simple/test-stream2-httpclient-response-end.js b/test/simple/test-stream2-httpclient-response-end.js deleted file mode 100644 index 15cffc2ac9a7..000000000000 --- a/test/simple/test-stream2-httpclient-response-end.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var assert = require('assert'); -var http = require('http'); -var msg = 'Hello'; -var readable_event = false; -var end_event = false; -var server = http.createServer(function(req, res) { - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end(msg); -}).listen(common.PORT, function() { - http.get({port: common.PORT}, function(res) { - var data = ''; - res.on('readable', function() { - console.log('readable event'); - readable_event = true; - data += res.read(); - }); - res.on('end', function() { - console.log('end event'); - end_event = true; - assert.strictEqual(msg, data); - server.close(); - }); - }); -}); - -process.on('exit', function() { - assert(readable_event); - assert(end_event); -}); - diff --git a/test/simple/test-stream2-large-read-stall.js b/test/simple/test-stream2-large-read-stall.js deleted file mode 100644 index 2fbfbcab3f1f..000000000000 --- a/test/simple/test-stream2-large-read-stall.js +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var assert = require('assert'); - -// If everything aligns so that you do a read(n) of exactly the -// remaining buffer, then make sure that 'end' still emits. - -var READSIZE = 100; -var PUSHSIZE = 20; -var PUSHCOUNT = 1000; -var HWM = 50; - -var Readable = require('stream').Readable; -var r = new Readable({ - highWaterMark: HWM -}); -var rs = r._readableState; - -r._read = push; - -r.on('readable', function() { - console.error('>> readable'); - do { - console.error(' > read(%d)', READSIZE); - var ret = r.read(READSIZE); - console.error(' < %j (%d remain)', ret && ret.length, rs.length); - } while (ret && ret.length === READSIZE); - - console.error('<< after read()', - ret && ret.length, - rs.needReadable, - rs.length); -}); - -var endEmitted = false; -r.on('end', function() { - endEmitted = true; - console.error('end'); -}); - -var pushes = 0; -function push() { - if (pushes > PUSHCOUNT) - return; - - if (pushes++ === PUSHCOUNT) { - console.error(' push(EOF)'); - return r.push(null); - } - - console.error(' push #%d', pushes); - if (r.push(new Buffer(PUSHSIZE))) - setTimeout(push); -} - -// start the flow -var ret = r.read(0); - -process.on('exit', function() { - assert.equal(pushes, PUSHCOUNT + 1); - assert(endEmitted); -}); diff --git a/test/simple/test-stream2-objects.js b/test/simple/test-stream2-objects.js deleted file mode 100644 index ba626cb1e795..000000000000 --- a/test/simple/test-stream2-objects.js +++ /dev/null @@ -1,348 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common.js'); -var Readable = require('_stream_readable'); -var Writable = require('_stream_writable'); -var assert = require('assert'); - -// tiny node-tap lookalike. -var tests = []; -var count = 0; - -function test(name, fn) { - count++; - tests.push([name, fn]); -} - -function run() { - var next = tests.shift(); - if (!next) - return console.error('ok'); - - var name = next[0]; - var fn = next[1]; - console.log('# %s', name); - fn({ - same: assert.deepEqual, - equal: assert.equal, - end: function() { - count--; - run(); - } - }); -} - -// ensure all tests have run -process.on('exit', function() { - assert.equal(count, 0); -}); - -process.nextTick(run); - -function toArray(callback) { - var stream = new Writable({ objectMode: true }); - var list = []; - stream.write = function(chunk) { - list.push(chunk); - }; - - stream.end = function() { - callback(list); - }; - - return stream; -} - -function fromArray(list) { - var r = new Readable({ objectMode: true }); - r._read = noop; - list.forEach(function(chunk) { - r.push(chunk); - }); - r.push(null); - - return r; -} - -function noop() {} - -test('can read objects from stream', function(t) { - var r = fromArray([{ one: '1'}, { two: '2' }]); - - var v1 = r.read(); - var v2 = r.read(); - var v3 = r.read(); - - assert.deepEqual(v1, { one: '1' }); - assert.deepEqual(v2, { two: '2' }); - assert.deepEqual(v3, null); - - t.end(); -}); - -test('can pipe objects into stream', function(t) { - var r = fromArray([{ one: '1'}, { two: '2' }]); - - r.pipe(toArray(function(list) { - assert.deepEqual(list, [ - { one: '1' }, - { two: '2' } - ]); - - t.end(); - })); -}); - -test('read(n) is ignored', function(t) { - var r = fromArray([{ one: '1'}, { two: '2' }]); - - var value = r.read(2); - - assert.deepEqual(value, { one: '1' }); - - t.end(); -}); - -test('can read objects from _read (sync)', function(t) { - var r = new Readable({ objectMode: true }); - var list = [{ one: '1'}, { two: '2' }]; - r._read = function(n) { - var item = list.shift(); - r.push(item || null); - }; - - r.pipe(toArray(function(list) { - assert.deepEqual(list, [ - { one: '1' }, - { two: '2' } - ]); - - t.end(); - })); -}); - -test('can read objects from _read (async)', function(t) { - var r = new Readable({ objectMode: true }); - var list = [{ one: '1'}, { two: '2' }]; - r._read = function(n) { - var item = list.shift(); - process.nextTick(function() { - r.push(item || null); - }); - }; - - r.pipe(toArray(function(list) { - assert.deepEqual(list, [ - { one: '1' }, - { two: '2' } - ]); - - t.end(); - })); -}); - -test('can read strings as objects', function(t) { - var r = new Readable({ - objectMode: true - }); - r._read = noop; - var list = ['one', 'two', 'three']; - list.forEach(function(str) { - r.push(str); - }); - r.push(null); - - r.pipe(toArray(function(array) { - assert.deepEqual(array, list); - - t.end(); - })); -}); - -test('read(0) for object streams', function(t) { - var r = new Readable({ - objectMode: true - }); - r._read = noop; - - r.push('foobar'); - r.push(null); - - var v = r.read(0); - - r.pipe(toArray(function(array) { - assert.deepEqual(array, ['foobar']); - - t.end(); - })); -}); - -test('falsey values', function(t) { - var r = new Readable({ - objectMode: true - }); - r._read = noop; - - r.push(false); - r.push(0); - r.push(''); - r.push(null); - - r.pipe(toArray(function(array) { - assert.deepEqual(array, [false, 0, '']); - - t.end(); - })); -}); - -test('high watermark _read', function(t) { - var r = new Readable({ - highWaterMark: 6, - objectMode: true - }); - var calls = 0; - var list = ['1', '2', '3', '4', '5', '6', '7', '8']; - - r._read = function(n) { - calls++; - }; - - list.forEach(function(c) { - r.push(c); - }); - - var v = r.read(); - - assert.equal(calls, 0); - assert.equal(v, '1'); - - var v2 = r.read(); - - assert.equal(calls, 1); - assert.equal(v2, '2'); - - t.end(); -}); - -test('high watermark push', function(t) { - var r = new Readable({ - highWaterMark: 6, - objectMode: true - }); - r._read = function(n) {}; - for (var i = 0; i < 6; i++) { - var bool = r.push(i); - assert.equal(bool, i === 5 ? false : true); - } - - t.end(); -}); - -test('can write objects to stream', function(t) { - var w = new Writable({ objectMode: true }); - - w._write = function(chunk, encoding, cb) { - assert.deepEqual(chunk, { foo: 'bar' }); - cb(); - }; - - w.on('finish', function() { - t.end(); - }); - - w.write({ foo: 'bar' }); - w.end(); -}); - -test('can write multiple objects to stream', function(t) { - var w = new Writable({ objectMode: true }); - var list = []; - - w._write = function(chunk, encoding, cb) { - list.push(chunk); - cb(); - }; - - w.on('finish', function() { - assert.deepEqual(list, [0, 1, 2, 3, 4]); - - t.end(); - }); - - w.write(0); - w.write(1); - w.write(2); - w.write(3); - w.write(4); - w.end(); -}); - -test('can write strings as objects', function(t) { - var w = new Writable({ - objectMode: true - }); - var list = []; - - w._write = function(chunk, encoding, cb) { - list.push(chunk); - process.nextTick(cb); - }; - - w.on('finish', function() { - assert.deepEqual(list, ['0', '1', '2', '3', '4']); - - t.end(); - }); - - w.write('0'); - w.write('1'); - w.write('2'); - w.write('3'); - w.write('4'); - w.end(); -}); - -test('buffers finish until cb is called', function(t) { - var w = new Writable({ - objectMode: true - }); - var called = false; - - w._write = function(chunk, encoding, cb) { - assert.equal(chunk, 'foo'); - - process.nextTick(function() { - called = true; - cb(); - }); - }; - - w.on('finish', function() { - assert.equal(called, true); - - t.end(); - }); - - w.write('foo'); - w.end(); -}); diff --git a/test/simple/test-stream2-pipe-error-handling.js b/test/simple/test-stream2-pipe-error-handling.js deleted file mode 100644 index cf7531cbd3a6..000000000000 --- a/test/simple/test-stream2-pipe-error-handling.js +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var stream = require('stream'); - -(function testErrorListenerCatches() { - var count = 1000; - - var source = new stream.Readable(); - source._read = function(n) { - n = Math.min(count, n); - count -= n; - source.push(new Buffer(n)); - }; - - var unpipedDest; - source.unpipe = function(dest) { - unpipedDest = dest; - stream.Readable.prototype.unpipe.call(this, dest); - }; - - var dest = new stream.Writable(); - dest._write = function(chunk, encoding, cb) { - cb(); - }; - - source.pipe(dest); - - var gotErr = null; - dest.on('error', function(err) { - gotErr = err; - }); - - var unpipedSource; - dest.on('unpipe', function(src) { - unpipedSource = src; - }); - - var err = new Error('This stream turned into bacon.'); - dest.emit('error', err); - assert.strictEqual(gotErr, err); - assert.strictEqual(unpipedSource, source); - assert.strictEqual(unpipedDest, dest); -})(); - -(function testErrorWithoutListenerThrows() { - var count = 1000; - - var source = new stream.Readable(); - source._read = function(n) { - n = Math.min(count, n); - count -= n; - source.push(new Buffer(n)); - }; - - var unpipedDest; - source.unpipe = function(dest) { - unpipedDest = dest; - stream.Readable.prototype.unpipe.call(this, dest); - }; - - var dest = new stream.Writable(); - dest._write = function(chunk, encoding, cb) { - cb(); - }; - - source.pipe(dest); - - var unpipedSource; - dest.on('unpipe', function(src) { - unpipedSource = src; - }); - - var err = new Error('This stream turned into bacon.'); - - var gotErr = null; - try { - dest.emit('error', err); - } catch (e) { - gotErr = e; - } - assert.strictEqual(gotErr, err); - assert.strictEqual(unpipedSource, source); - assert.strictEqual(unpipedDest, dest); -})(); diff --git a/test/simple/test-stream2-pipe-error-once-listener.js b/test/simple/test-stream2-pipe-error-once-listener.js deleted file mode 100755 index 5e8e3cb28311..000000000000 --- a/test/simple/test-stream2-pipe-error-once-listener.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common.js'); -var assert = require('assert'); - -var util = require('util'); -var stream = require('stream'); - - -var Read = function() { - stream.Readable.call(this); -}; -util.inherits(Read, stream.Readable); - -Read.prototype._read = function(size) { - this.push('x'); - this.push(null); -}; - - -var Write = function() { - stream.Writable.call(this); -}; -util.inherits(Write, stream.Writable); - -Write.prototype._write = function(buffer, encoding, cb) { - this.emit('error', new Error('boom')); - this.emit('alldone'); -}; - -var read = new Read(); -var write = new Write(); - -write.once('error', function(err) {}); -write.once('alldone', function(err) { - console.log('ok'); -}); - -process.on('exit', function(c) { - console.error('error thrown even with listener'); -}); - -read.pipe(write); - diff --git a/test/simple/test-stream2-push.js b/test/simple/test-stream2-push.js deleted file mode 100644 index b63edc308460..000000000000 --- a/test/simple/test-stream2-push.js +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var stream = require('stream'); -var Readable = stream.Readable; -var Writable = stream.Writable; -var assert = require('assert'); - -var util = require('util'); -var EE = require('events').EventEmitter; - - -// a mock thing a bit like the net.Socket/tcp_wrap.handle interaction - -var stream = new Readable({ - highWaterMark: 16, - encoding: 'utf8' -}); - -var source = new EE; - -stream._read = function() { - console.error('stream._read'); - readStart(); -}; - -var ended = false; -stream.on('end', function() { - ended = true; -}); - -source.on('data', function(chunk) { - var ret = stream.push(chunk); - console.error('data', stream._readableState.length); - if (!ret) - readStop(); -}); - -source.on('end', function() { - stream.push(null); -}); - -var reading = false; - -function readStart() { - console.error('readStart'); - reading = true; -} - -function readStop() { - console.error('readStop'); - reading = false; - process.nextTick(function() { - var r = stream.read(); - if (r !== null) - writer.write(r); - }); -} - -var writer = new Writable({ - decodeStrings: false -}); - -var written = []; - -var expectWritten = - [ 'asdfgasdfgasdfgasdfg', - 'asdfgasdfgasdfgasdfg', - 'asdfgasdfgasdfgasdfg', - 'asdfgasdfgasdfgasdfg', - 'asdfgasdfgasdfgasdfg', - 'asdfgasdfgasdfgasdfg' ]; - -writer._write = function(chunk, encoding, cb) { - console.error('WRITE %s', chunk); - written.push(chunk); - process.nextTick(cb); -}; - -writer.on('finish', finish); - - -// now emit some chunks. - -var chunk = "asdfg"; - -var set = 0; -readStart(); -data(); -function data() { - assert(reading); - source.emit('data', chunk); - assert(reading); - source.emit('data', chunk); - assert(reading); - source.emit('data', chunk); - assert(reading); - source.emit('data', chunk); - assert(!reading); - if (set++ < 5) - setTimeout(data, 10); - else - end(); -} - -function finish() { - console.error('finish'); - assert.deepEqual(written, expectWritten); - console.log('ok'); -} - -function end() { - source.emit('end'); - assert(!reading); - writer.end(stream.read()); - setTimeout(function() { - assert(ended); - }); -} diff --git a/test/simple/test-stream2-read-sync-stack.js b/test/simple/test-stream2-read-sync-stack.js deleted file mode 100644 index e8a73053c8c2..000000000000 --- a/test/simple/test-stream2-read-sync-stack.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var Readable = require('stream').Readable; -var r = new Readable(); -var N = 256 * 1024; - -// Go ahead and allow the pathological case for this test. -// Yes, it's an infinite loop, that's the point. -process.maxTickDepth = N + 2; - -var reads = 0; -r._read = function(n) { - var chunk = reads++ === N ? null : new Buffer(1); - r.push(chunk); -}; - -r.on('readable', function onReadable() { - if (!(r._readableState.length % 256)) - console.error('readable', r._readableState.length); - r.read(N * 2); -}); - -var ended = false; -r.on('end', function onEnd() { - ended = true; -}); - -r.read(0); - -process.on('exit', function() { - assert(ended); - console.log('ok'); -}); diff --git a/test/simple/test-stream2-readable-empty-buffer-no-eof.js b/test/simple/test-stream2-readable-empty-buffer-no-eof.js deleted file mode 100644 index cd301785802f..000000000000 --- a/test/simple/test-stream2-readable-empty-buffer-no-eof.js +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var Readable = require('stream').Readable; - -test1(); -test2(); - -function test1() { - var r = new Readable(); - - // should not end when we get a Buffer(0) or '' as the _read result - // that just means that there is *temporarily* no data, but to go - // ahead and try again later. - // - // note that this is very unusual. it only works for crypto streams - // because the other side of the stream will call read(0) to cycle - // data through openssl. that's why we set the timeouts to call - // r.read(0) again later, otherwise there is no more work being done - // and the process just exits. - - var buf = new Buffer(5); - buf.fill('x'); - var reads = 5; - r._read = function(n) { - switch (reads--) { - case 0: - return r.push(null); // EOF - case 1: - return r.push(buf); - case 2: - setTimeout(r.read.bind(r, 0), 10); - return r.push(new Buffer(0)); // Not-EOF! - case 3: - setTimeout(r.read.bind(r, 0), 10); - return process.nextTick(function() { - return r.push(new Buffer(0)); - }); - case 4: - setTimeout(r.read.bind(r, 0), 10); - return setTimeout(function() { - return r.push(new Buffer(0)); - }); - case 5: - return setTimeout(function() { - return r.push(buf); - }); - default: - throw new Error('unreachable'); - } - }; - - var results = []; - function flow() { - var chunk; - while (null !== (chunk = r.read())) - results.push(chunk + ''); - } - r.on('readable', flow); - r.on('end', function() { - results.push('EOF'); - }); - flow(); - - process.on('exit', function() { - assert.deepEqual(results, [ 'xxxxx', 'xxxxx', 'EOF' ]); - console.log('ok'); - }); -} - -function test2() { - var r = new Readable({ encoding: 'base64' }); - var reads = 5; - r._read = function(n) { - if (!reads--) - return r.push(null); // EOF - else - return r.push(new Buffer('x')); - }; - - var results = []; - function flow() { - var chunk; - while (null !== (chunk = r.read())) - results.push(chunk + ''); - } - r.on('readable', flow); - r.on('end', function() { - results.push('EOF'); - }); - flow(); - - process.on('exit', function() { - assert.deepEqual(results, [ 'eHh4', 'eHg=', 'EOF' ]); - console.log('ok'); - }); -} diff --git a/test/simple/test-stream2-readable-from-list.js b/test/simple/test-stream2-readable-from-list.js deleted file mode 100644 index 7c96ffe00c4e..000000000000 --- a/test/simple/test-stream2-readable-from-list.js +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var common = require('../common.js'); -var fromList = require('_stream_readable')._fromList; - -// tiny node-tap lookalike. -var tests = []; -var count = 0; - -function test(name, fn) { - count++; - tests.push([name, fn]); -} - -function run() { - var next = tests.shift(); - if (!next) - return console.error('ok'); - - var name = next[0]; - var fn = next[1]; - console.log('# %s', name); - fn({ - same: assert.deepEqual, - equal: assert.equal, - end: function () { - count--; - run(); - } - }); -} - -// ensure all tests have run -process.on("exit", function () { - assert.equal(count, 0); -}); - -process.nextTick(run); - - - -test('buffers', function(t) { - // have a length - var len = 16; - var list = [ new Buffer('foog'), - new Buffer('bark'), - new Buffer('bazy'), - new Buffer('kuel') ]; - - // read more than the first element. - var ret = fromList(6, { buffer: list, length: 16 }); - t.equal(ret.toString(), 'foogba'); - - // read exactly the first element. - ret = fromList(2, { buffer: list, length: 10 }); - t.equal(ret.toString(), 'rk'); - - // read less than the first element. - ret = fromList(2, { buffer: list, length: 8 }); - t.equal(ret.toString(), 'ba'); - - // read more than we have. - ret = fromList(100, { buffer: list, length: 6 }); - t.equal(ret.toString(), 'zykuel'); - - // all consumed. - t.same(list, []); - - t.end(); -}); - -test('strings', function(t) { - // have a length - var len = 16; - var list = [ 'foog', - 'bark', - 'bazy', - 'kuel' ]; - - // read more than the first element. - var ret = fromList(6, { buffer: list, length: 16, decoder: true }); - t.equal(ret, 'foogba'); - - // read exactly the first element. - ret = fromList(2, { buffer: list, length: 10, decoder: true }); - t.equal(ret, 'rk'); - - // read less than the first element. - ret = fromList(2, { buffer: list, length: 8, decoder: true }); - t.equal(ret, 'ba'); - - // read more than we have. - ret = fromList(100, { buffer: list, length: 6, decoder: true }); - t.equal(ret, 'zykuel'); - - // all consumed. - t.same(list, []); - - t.end(); -}); diff --git a/test/simple/test-stream2-readable-legacy-drain.js b/test/simple/test-stream2-readable-legacy-drain.js deleted file mode 100644 index 675da8e90dea..000000000000 --- a/test/simple/test-stream2-readable-legacy-drain.js +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var Stream = require('stream'); -var Readable = Stream.Readable; - -var r = new Readable(); -var N = 256; -var reads = 0; -r._read = function(n) { - return r.push(++reads === N ? null : new Buffer(1)); -}; - -var rended = false; -r.on('end', function() { - rended = true; -}); - -var w = new Stream(); -w.writable = true; -var writes = 0; -var buffered = 0; -w.write = function(c) { - writes += c.length; - buffered += c.length; - process.nextTick(drain); - return false; -}; - -function drain() { - assert(buffered <= 2); - buffered = 0; - w.emit('drain'); -} - - -var wended = false; -w.end = function() { - wended = true; -}; - -// Just for kicks, let's mess with the drain count. -// This verifies that even if it gets negative in the -// pipe() cleanup function, we'll still function properly. -r.on('readable', function() { - w.emit('drain'); -}); - -r.pipe(w); -process.on('exit', function() { - assert(rended); - assert(wended); - console.error('ok'); -}); diff --git a/test/simple/test-stream2-readable-non-empty-end.js b/test/simple/test-stream2-readable-non-empty-end.js deleted file mode 100644 index 7314ae77b138..000000000000 --- a/test/simple/test-stream2-readable-non-empty-end.js +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var common = require('../common.js'); -var Readable = require('_stream_readable'); - -var len = 0; -var chunks = new Array(10); -for (var i = 1; i <= 10; i++) { - chunks[i-1] = new Buffer(i); - len += i; -} - -var test = new Readable(); -var n = 0; -test._read = function(size) { - var chunk = chunks[n++]; - setTimeout(function() { - test.push(chunk); - }); -}; - -test.on('end', thrower); -function thrower() { - throw new Error('this should not happen!'); -} - -var bytesread = 0; -test.on('readable', function() { - var b = len - bytesread - 1; - var res = test.read(b); - if (res) { - bytesread += res.length; - console.error('br=%d len=%d', bytesread, len); - setTimeout(next); - } - test.read(0); -}); -test.read(0); - -function next() { - // now let's make 'end' happen - test.removeListener('end', thrower); - - var endEmitted = false; - process.on('exit', function() { - assert(endEmitted, 'end should be emitted by now'); - }); - test.on('end', function() { - endEmitted = true; - }); - - // one to get the last byte - var r = test.read(); - assert(r); - assert.equal(r.length, 1); - r = test.read(); - assert.equal(r, null); -} diff --git a/test/simple/test-stream2-readable-wrap-empty.js b/test/simple/test-stream2-readable-wrap-empty.js deleted file mode 100644 index c7042f1b12e5..000000000000 --- a/test/simple/test-stream2-readable-wrap-empty.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var Readable = require('_stream_readable'); -var EE = require('events').EventEmitter; - -var oldStream = new EE(); -oldStream.pause = function(){}; -oldStream.resume = function(){}; - -var newStream = new Readable().wrap(oldStream); - -var ended = false; -newStream - .on('readable', function(){}) - .on('end', function(){ ended = true; }); - -oldStream.emit('end'); - -process.on('exit', function(){ - assert.ok(ended); -}); \ No newline at end of file diff --git a/test/simple/test-stream2-readable-wrap.js b/test/simple/test-stream2-readable-wrap.js deleted file mode 100644 index 233e7fd26df2..000000000000 --- a/test/simple/test-stream2-readable-wrap.js +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var Readable = require('_stream_readable'); -var Writable = require('_stream_writable'); -var EE = require('events').EventEmitter; - -var testRuns = 0, completedRuns = 0; -function runTest(highWaterMark, objectMode, produce) { - testRuns++; - - var old = new EE; - var r = new Readable({ highWaterMark: highWaterMark, objectMode: objectMode }); - assert.equal(r, r.wrap(old)); - - var ended = false; - r.on('end', function() { - ended = true; - }); - - var pauses = 0; - var resumes = 0; - - old.pause = function() { - pauses++; - old.emit('pause'); - flowing = false; - }; - - old.resume = function() { - resumes++; - old.emit('resume'); - flow(); - }; - - var flowing; - var chunks = 10; - var oldEnded = false; - var expected = []; - function flow() { - flowing = true; - while (flowing && chunks-- > 0) { - var item = produce(); - expected.push(item); - console.log('emit', chunks); - old.emit('data', item); - } - if (chunks <= 0) { - oldEnded = true; - console.log('old end', chunks, flowing); - old.emit('end'); - } - } - - var w = new Writable({ highWaterMark: highWaterMark * 2, objectMode: objectMode }); - var written = []; - w._write = function(chunk, encoding, cb) { - console.log(chunk); - written.push(chunk); - setTimeout(cb); - }; - - w.on('finish', function() { - completedRuns++; - performAsserts(); - }); - - r.pipe(w); - - flow(); - - function performAsserts() { - assert(ended); - assert(oldEnded); - assert.deepEqual(written, expected); - assert.equal(pauses, 10); - assert.equal(resumes, 9); - } -} - -runTest(10, false, function(){ return new Buffer('xxxxxxxxxx'); }); -runTest(1, true, function(){ return { foo: 'bar' }; }); - -var objectChunks = [ 5, 'a', false, 0, '', 'xyz', { x: 4 }, 7, [], 555 ]; -runTest(1, true, function(){ return objectChunks.shift() }); - -process.on('exit', function() { - assert.equal(testRuns, completedRuns); - console.log('ok'); -}); diff --git a/test/simple/test-stream2-set-encoding.js b/test/simple/test-stream2-set-encoding.js deleted file mode 100644 index 5d2c32a2d0e7..000000000000 --- a/test/simple/test-stream2-set-encoding.js +++ /dev/null @@ -1,361 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common.js'); -var assert = require('assert'); -var R = require('_stream_readable'); -var util = require('util'); - -// tiny node-tap lookalike. -var tests = []; -var count = 0; - -function test(name, fn) { - count++; - tests.push([name, fn]); -} - -function run() { - var next = tests.shift(); - if (!next) - return console.error('ok'); - - var name = next[0]; - var fn = next[1]; - console.log('# %s', name); - fn({ - same: assert.deepEqual, - equal: assert.equal, - end: function () { - count--; - run(); - } - }); -} - -// ensure all tests have run -process.on("exit", function () { - assert.equal(count, 0); -}); - -process.nextTick(run); - -///// - -util.inherits(TestReader, R); - -function TestReader(n, opts) { - R.call(this, opts); - - this.pos = 0; - this.len = n || 100; -} - -TestReader.prototype._read = function(n) { - setTimeout(function() { - - if (this.pos >= this.len) { - // double push(null) to test eos handling - this.push(null); - return this.push(null); - } - - n = Math.min(n, this.len - this.pos); - if (n <= 0) { - // double push(null) to test eos handling - this.push(null); - return this.push(null); - } - - this.pos += n; - var ret = new Buffer(n); - ret.fill('a'); - - console.log("this.push(ret)", ret) - - return this.push(ret); - }.bind(this), 1); -}; - -test('setEncoding utf8', function(t) { - var tr = new TestReader(100); - tr.setEncoding('utf8'); - var out = []; - var expect = - [ 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa' ]; - - tr.on('readable', function flow() { - var chunk; - while (null !== (chunk = tr.read(10))) - out.push(chunk); - }); - - tr.on('end', function() { - t.same(out, expect); - t.end(); - }); -}); - - -test('setEncoding hex', function(t) { - var tr = new TestReader(100); - tr.setEncoding('hex'); - var out = []; - var expect = - [ '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161' ]; - - tr.on('readable', function flow() { - var chunk; - while (null !== (chunk = tr.read(10))) - out.push(chunk); - }); - - tr.on('end', function() { - t.same(out, expect); - t.end(); - }); -}); - -test('setEncoding hex with read(13)', function(t) { - var tr = new TestReader(100); - tr.setEncoding('hex'); - var out = []; - var expect = - [ "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "16161" ]; - - tr.on('readable', function flow() { - console.log("readable once") - var chunk; - while (null !== (chunk = tr.read(13))) - out.push(chunk); - }); - - tr.on('end', function() { - console.log("END") - t.same(out, expect); - t.end(); - }); -}); - -test('setEncoding base64', function(t) { - var tr = new TestReader(100); - tr.setEncoding('base64'); - var out = []; - var expect = - [ 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYQ==' ]; - - tr.on('readable', function flow() { - var chunk; - while (null !== (chunk = tr.read(10))) - out.push(chunk); - }); - - tr.on('end', function() { - t.same(out, expect); - t.end(); - }); -}); - -test('encoding: utf8', function(t) { - var tr = new TestReader(100, { encoding: 'utf8' }); - var out = []; - var expect = - [ 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa', - 'aaaaaaaaaa' ]; - - tr.on('readable', function flow() { - var chunk; - while (null !== (chunk = tr.read(10))) - out.push(chunk); - }); - - tr.on('end', function() { - t.same(out, expect); - t.end(); - }); -}); - - -test('encoding: hex', function(t) { - var tr = new TestReader(100, { encoding: 'hex' }); - var out = []; - var expect = - [ '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161', - '6161616161' ]; - - tr.on('readable', function flow() { - var chunk; - while (null !== (chunk = tr.read(10))) - out.push(chunk); - }); - - tr.on('end', function() { - t.same(out, expect); - t.end(); - }); -}); - -test('encoding: hex with read(13)', function(t) { - var tr = new TestReader(100, { encoding: 'hex' }); - var out = []; - var expect = - [ "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "1616161616161", - "6161616161616", - "16161" ]; - - tr.on('readable', function flow() { - var chunk; - while (null !== (chunk = tr.read(13))) - out.push(chunk); - }); - - tr.on('end', function() { - t.same(out, expect); - t.end(); - }); -}); - -test('encoding: base64', function(t) { - var tr = new TestReader(100, { encoding: 'base64' }); - var out = []; - var expect = - [ 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYWFhYWFh', - 'YWFhYWFhYW', - 'FhYQ==' ]; - - tr.on('readable', function flow() { - var chunk; - while (null !== (chunk = tr.read(10))) - out.push(chunk); - }); - - tr.on('end', function() { - t.same(out, expect); - t.end(); - }); -}); diff --git a/test/simple/test-stream2-stderr-sync.js b/test/simple/test-stream2-stderr-sync.js deleted file mode 100644 index 2b83617e9da7..000000000000 --- a/test/simple/test-stream2-stderr-sync.js +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Make sure that sync writes to stderr get processed before exiting. - -var common = require('../common.js'); -var assert = require('assert'); - -function parent() { - var spawn = require('child_process').spawn; - var assert = require('assert'); - var i = 0; - children.forEach(function(_, c) { - var child = spawn(process.execPath, [__filename, '' + c]); - var err = ''; - - child.stderr.on('data', function(c) { - err += c; - }); - - child.on('close', function() { - assert.equal(err, 'child ' + c + '\nfoo\nbar\nbaz\n'); - console.log('ok %d child #%d', ++i, c); - if (i === children.length) - console.log('1..' + i); - }); - }); -} - -function child0() { - // Just a very simple wrapper around TTY(2) - // Essentially the same as stderr, but without all the net stuff. - var Writable = require('stream').Writable; - var util = require('util'); - - // a lowlevel stderr writer - var TTY = process.binding('tty_wrap').TTY; - var handle = new TTY(2, false); - - util.inherits(W, Writable); - - function W(opts) { - Writable.call(this, opts); - } - - W.prototype._write = function(chunk, encoding, cb) { - var req = handle.writeUtf8String(chunk.toString() + '\n'); - // here's the problem. - // it needs to tell the Writable machinery that it's ok to write - // more, but that the current buffer length is handle.writeQueueSize - req.oncomplete = afterWrite - if (req.writeQueueSize === 0) - req.cb = cb; - else - cb(); - } - function afterWrite(status, handle, req) { - if (req.cb) - req.cb(); - } - - var w = new W - w.write('child 0'); - w.write('foo'); - w.write('bar'); - w.write('baz'); -} - -// using console.error -function child1() { - console.error('child 1'); - console.error('foo'); - console.error('bar'); - console.error('baz'); -} - -// using process.stderr -function child2() { - process.stderr.write('child 2\n'); - process.stderr.write('foo\n'); - process.stderr.write('bar\n'); - process.stderr.write('baz\n'); -} - -// using a net socket -function child3() { - var net = require('net'); - var socket = new net.Socket({ fd: 2 }); - socket.write('child 3\n'); - socket.write('foo\n'); - socket.write('bar\n'); - socket.write('baz\n'); -} - - -function child4() { - console.error('child 4\nfoo\nbar\nbaz'); -} - -function child5() { - process.stderr.write('child 5\nfoo\nbar\nbaz\n'); -} - -var children = [ child0, child1, child2, child3, child4, child5 ]; - -if (!process.argv[2]) { - parent(); -} else { - children[process.argv[2]](); - // immediate process.exit to kill any waiting stuff. - process.exit(); -} diff --git a/test/simple/test-stream2-transform.js b/test/simple/test-stream2-transform.js deleted file mode 100644 index 7a32a3cce8b8..000000000000 --- a/test/simple/test-stream2-transform.js +++ /dev/null @@ -1,471 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); -var common = require('../common.js'); -var PassThrough = require('_stream_passthrough'); -var Transform = require('_stream_transform'); - -// tiny node-tap lookalike. -var tests = []; -var count = 0; - -function test(name, fn) { - count++; - tests.push([name, fn]); -} - -function run() { - var next = tests.shift(); - if (!next) - return console.error('ok'); - - var name = next[0]; - var fn = next[1]; - console.log('# %s', name); - fn({ - same: assert.deepEqual, - equal: assert.equal, - ok: assert, - end: function () { - count--; - run(); - } - }); -} - -// ensure all tests have run -process.on("exit", function () { - assert.equal(count, 0); -}); - -process.nextTick(run); - -///// - -test('writable side consumption', function(t) { - var tx = new Transform({ - highWaterMark: 10 - }); - - var transformed = 0; - tx._transform = function(chunk, encoding, cb) { - transformed += chunk.length; - tx.push(chunk); - cb(); - }; - - for (var i = 1; i <= 10; i++) { - tx.write(new Buffer(i)); - } - tx.end(); - - t.equal(tx._readableState.length, 10); - t.equal(transformed, 10); - t.equal(tx._transformState.writechunk.length, 5); - t.same(tx._writableState.buffer.map(function(c) { - return c.chunk.length; - }), [6, 7, 8, 9, 10]); - - t.end(); -}); - -test('passthrough', function(t) { - var pt = new PassThrough(); - - pt.write(new Buffer('foog')); - pt.write(new Buffer('bark')); - pt.write(new Buffer('bazy')); - pt.write(new Buffer('kuel')); - pt.end(); - - t.equal(pt.read(5).toString(), 'foogb'); - t.equal(pt.read(5).toString(), 'arkba'); - t.equal(pt.read(5).toString(), 'zykue'); - t.equal(pt.read(5).toString(), 'l'); - t.end(); -}); - -test('simple transform', function(t) { - var pt = new Transform; - pt._transform = function(c, e, cb) { - var ret = new Buffer(c.length); - ret.fill('x'); - pt.push(ret); - cb(); - }; - - pt.write(new Buffer('foog')); - pt.write(new Buffer('bark')); - pt.write(new Buffer('bazy')); - pt.write(new Buffer('kuel')); - pt.end(); - - t.equal(pt.read(5).toString(), 'xxxxx'); - t.equal(pt.read(5).toString(), 'xxxxx'); - t.equal(pt.read(5).toString(), 'xxxxx'); - t.equal(pt.read(5).toString(), 'x'); - t.end(); -}); - -test('async passthrough', function(t) { - var pt = new Transform; - pt._transform = function(chunk, encoding, cb) { - setTimeout(function() { - pt.push(chunk); - cb(); - }, 10); - }; - - pt.write(new Buffer('foog')); - pt.write(new Buffer('bark')); - pt.write(new Buffer('bazy')); - pt.write(new Buffer('kuel')); - pt.end(); - - pt.on('finish', function() { - t.equal(pt.read(5).toString(), 'foogb'); - t.equal(pt.read(5).toString(), 'arkba'); - t.equal(pt.read(5).toString(), 'zykue'); - t.equal(pt.read(5).toString(), 'l'); - t.end(); - }); -}); - -test('assymetric transform (expand)', function(t) { - var pt = new Transform; - - // emit each chunk 2 times. - pt._transform = function(chunk, encoding, cb) { - setTimeout(function() { - pt.push(chunk); - setTimeout(function() { - pt.push(chunk); - cb(); - }, 10) - }, 10); - }; - - pt.write(new Buffer('foog')); - pt.write(new Buffer('bark')); - pt.write(new Buffer('bazy')); - pt.write(new Buffer('kuel')); - pt.end(); - - pt.on('finish', function() { - t.equal(pt.read(5).toString(), 'foogf'); - t.equal(pt.read(5).toString(), 'oogba'); - t.equal(pt.read(5).toString(), 'rkbar'); - t.equal(pt.read(5).toString(), 'kbazy'); - t.equal(pt.read(5).toString(), 'bazyk'); - t.equal(pt.read(5).toString(), 'uelku'); - t.equal(pt.read(5).toString(), 'el'); - t.end(); - }); -}); - -test('assymetric transform (compress)', function(t) { - var pt = new Transform; - - // each output is the first char of 3 consecutive chunks, - // or whatever's left. - pt.state = ''; - - pt._transform = function(chunk, encoding, cb) { - if (!chunk) - chunk = ''; - var s = chunk.toString(); - setTimeout(function() { - this.state += s.charAt(0); - if (this.state.length === 3) { - pt.push(new Buffer(this.state)); - this.state = ''; - } - cb(); - }.bind(this), 10); - }; - - pt._flush = function(cb) { - // just output whatever we have. - pt.push(new Buffer(this.state)); - this.state = ''; - cb(); - }; - - pt.write(new Buffer('aaaa')); - pt.write(new Buffer('bbbb')); - pt.write(new Buffer('cccc')); - pt.write(new Buffer('dddd')); - pt.write(new Buffer('eeee')); - pt.write(new Buffer('aaaa')); - pt.write(new Buffer('bbbb')); - pt.write(new Buffer('cccc')); - pt.write(new Buffer('dddd')); - pt.write(new Buffer('eeee')); - pt.write(new Buffer('aaaa')); - pt.write(new Buffer('bbbb')); - pt.write(new Buffer('cccc')); - pt.write(new Buffer('dddd')); - pt.end(); - - // 'abcdeabcdeabcd' - pt.on('finish', function() { - t.equal(pt.read(5).toString(), 'abcde'); - t.equal(pt.read(5).toString(), 'abcde'); - t.equal(pt.read(5).toString(), 'abcd'); - t.end(); - }); -}); - -// this tests for a stall when data is written to a full stream -// that has empty transforms. -test('complex transform', function(t) { - var count = 0; - var saved = null; - var pt = new Transform({highWaterMark:3}); - pt._transform = function(c, e, cb) { - if (count++ === 1) - saved = c; - else { - if (saved) { - pt.push(saved); - saved = null; - } - pt.push(c); - } - - cb(); - }; - - pt.once('readable', function() { - process.nextTick(function() { - pt.write(new Buffer('d')); - pt.write(new Buffer('ef'), function() { - pt.end(); - t.end(); - }); - t.equal(pt.read().toString(), 'abc'); - t.equal(pt.read().toString(), 'def'); - t.equal(pt.read(), null); - }); - }); - - pt.write(new Buffer('abc')); -}); - - -test('passthrough event emission', function(t) { - var pt = new PassThrough(); - var emits = 0; - pt.on('readable', function() { - var state = pt._readableState; - console.error('>>> emit readable %d', emits); - emits++; - }); - - var i = 0; - - pt.write(new Buffer('foog')); - - console.error('need emit 0'); - pt.write(new Buffer('bark')); - - console.error('should have emitted readable now 1 === %d', emits); - t.equal(emits, 1); - - t.equal(pt.read(5).toString(), 'foogb'); - t.equal(pt.read(5) + '', 'null'); - - console.error('need emit 1'); - - pt.write(new Buffer('bazy')); - console.error('should have emitted, but not again'); - pt.write(new Buffer('kuel')); - - console.error('should have emitted readable now 2 === %d', emits); - t.equal(emits, 2); - - t.equal(pt.read(5).toString(), 'arkba'); - t.equal(pt.read(5).toString(), 'zykue'); - t.equal(pt.read(5), null); - - console.error('need emit 2'); - - pt.end(); - - t.equal(emits, 3); - - t.equal(pt.read(5).toString(), 'l'); - t.equal(pt.read(5), null); - - console.error('should not have emitted again'); - t.equal(emits, 3); - t.end(); -}); - -test('passthrough event emission reordered', function(t) { - var pt = new PassThrough; - var emits = 0; - pt.on('readable', function() { - console.error('emit readable', emits) - emits++; - }); - - pt.write(new Buffer('foog')); - console.error('need emit 0'); - pt.write(new Buffer('bark')); - console.error('should have emitted readable now 1 === %d', emits); - t.equal(emits, 1); - - t.equal(pt.read(5).toString(), 'foogb'); - t.equal(pt.read(5), null); - - console.error('need emit 1'); - pt.once('readable', function() { - t.equal(pt.read(5).toString(), 'arkba'); - - t.equal(pt.read(5), null); - - console.error('need emit 2'); - pt.once('readable', function() { - t.equal(pt.read(5).toString(), 'zykue'); - t.equal(pt.read(5), null); - pt.once('readable', function() { - t.equal(pt.read(5).toString(), 'l'); - t.equal(pt.read(5), null); - t.equal(emits, 4); - t.end(); - }); - pt.end(); - }); - pt.write(new Buffer('kuel')); - }); - - pt.write(new Buffer('bazy')); -}); - -test('passthrough facaded', function(t) { - console.error('passthrough facaded'); - var pt = new PassThrough; - var datas = []; - pt.on('data', function(chunk) { - datas.push(chunk.toString()); - }); - - pt.on('end', function() { - t.same(datas, ['foog', 'bark', 'bazy', 'kuel']); - t.end(); - }); - - pt.write(new Buffer('foog')); - setTimeout(function() { - pt.write(new Buffer('bark')); - setTimeout(function() { - pt.write(new Buffer('bazy')); - setTimeout(function() { - pt.write(new Buffer('kuel')); - setTimeout(function() { - pt.end(); - }, 10); - }, 10); - }, 10); - }, 10); -}); - -test('object transform (json parse)', function(t) { - console.error('json parse stream'); - var jp = new Transform({ objectMode: true }); - jp._transform = function(data, encoding, cb) { - try { - jp.push(JSON.parse(data)); - cb(); - } catch (er) { - cb(er); - } - }; - - // anything except null/undefined is fine. - // those are "magic" in the stream API, because they signal EOF. - var objects = [ - { foo: 'bar' }, - 100, - "string", - { nested: { things: [ { foo: 'bar' }, 100, "string" ] } } - ]; - - var ended = false; - jp.on('end', function() { - ended = true; - }); - - objects.forEach(function(obj) { - jp.write(JSON.stringify(obj)); - var res = jp.read(); - t.same(res, obj); - }); - - jp.end(); - - process.nextTick(function() { - t.ok(ended); - t.end(); - }) -}); - -test('object transform (json stringify)', function(t) { - console.error('json parse stream'); - var js = new Transform({ objectMode: true }); - js._transform = function(data, encoding, cb) { - try { - js.push(JSON.stringify(data)); - cb(); - } catch (er) { - cb(er); - } - }; - - // anything except null/undefined is fine. - // those are "magic" in the stream API, because they signal EOF. - var objects = [ - { foo: 'bar' }, - 100, - "string", - { nested: { things: [ { foo: 'bar' }, 100, "string" ] } } - ]; - - var ended = false; - js.on('end', function() { - ended = true; - }); - - objects.forEach(function(obj) { - js.write(obj); - var res = js.read(); - t.equal(res, JSON.stringify(obj)); - }); - - js.end(); - - process.nextTick(function() { - t.ok(ended); - t.end(); - }) -}); diff --git a/test/simple/test-stream2-unpipe-drain.js b/test/simple/test-stream2-unpipe-drain.js deleted file mode 100644 index d66dc3cbece4..000000000000 --- a/test/simple/test-stream2-unpipe-drain.js +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common.js'); -var assert = require('assert'); -var stream = require('stream'); -var crypto = require('crypto'); - -var util = require('util'); - -function TestWriter() { - stream.Writable.call(this); -} -util.inherits(TestWriter, stream.Writable); - -TestWriter.prototype._write = function (buffer, encoding, callback) { - console.log('write called'); - // super slow write stream (callback never called) -}; - -var dest = new TestWriter(); - -function TestReader(id) { - stream.Readable.call(this); - this.reads = 0; -} -util.inherits(TestReader, stream.Readable); - -TestReader.prototype._read = function (size) { - this.reads += 1; - this.push(crypto.randomBytes(size)); -}; - -var src1 = new TestReader(); -var src2 = new TestReader(); - -src1.pipe(dest); - -src1.once('readable', function () { - process.nextTick(function () { - - src2.pipe(dest); - - src2.once('readable', function () { - process.nextTick(function () { - - src1.unpipe(dest); - }); - }); - }); -}); - - -process.on('exit', function () { - assert.equal(src1.reads, 2); - assert.equal(src2.reads, 2); -}); diff --git a/test/simple/test-stream2-unpipe-leak.js b/test/simple/test-stream2-unpipe-leak.js deleted file mode 100644 index b9e8a960d8ac..000000000000 --- a/test/simple/test-stream2-unpipe-leak.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common.js'); -var assert = require('assert'); -var stream = require('stream'); - -var chunk = new Buffer('hallo'); - -var util = require('util'); - -function TestWriter() { - stream.Writable.call(this); -} -util.inherits(TestWriter, stream.Writable); - -TestWriter.prototype._write = function(buffer, encoding, callback) { - callback(null); -}; - -var dest = new TestWriter(); - -// Set this high so that we'd trigger a nextTick warning -// and/or RangeError if we do maybeReadMore wrong. -function TestReader() { - stream.Readable.call(this, { highWaterMark: 0x10000 }); -} -util.inherits(TestReader, stream.Readable); - -TestReader.prototype._read = function(size) { - this.push(chunk); -}; - -var src = new TestReader(); - -for (var i = 0; i < 10; i++) { - src.pipe(dest); - src.unpipe(dest); -} - -assert.equal(src.listeners('end').length, 0); -assert.equal(src.listeners('readable').length, 0); - -assert.equal(dest.listeners('unpipe').length, 0); -assert.equal(dest.listeners('drain').length, 0); -assert.equal(dest.listeners('error').length, 0); -assert.equal(dest.listeners('close').length, 0); -assert.equal(dest.listeners('finish').length, 0); - -console.error(src._readableState); -process.on('exit', function() { - assert(src._readableState.length >= src._readableState.highWaterMark); - src._readableState.buffer.length = 0; - console.error(src._readableState); -}); diff --git a/test/simple/test-stream2-writable.js b/test/simple/test-stream2-writable.js deleted file mode 100644 index e0f384cb2ad6..000000000000 --- a/test/simple/test-stream2-writable.js +++ /dev/null @@ -1,377 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var W = require('_stream_writable'); -var D = require('_stream_duplex'); -var assert = require('assert'); - -var util = require('util'); -util.inherits(TestWriter, W); - -function TestWriter() { - W.apply(this, arguments); - this.buffer = []; - this.written = 0; -} - -TestWriter.prototype._write = function(chunk, encoding, cb) { - // simulate a small unpredictable latency - setTimeout(function() { - this.buffer.push(chunk.toString()); - this.written += chunk.length; - cb(); - }.bind(this), Math.floor(Math.random() * 10)); -}; - -var chunks = new Array(50); -for (var i = 0; i < chunks.length; i++) { - chunks[i] = new Array(i + 1).join('x'); -} - -// tiny node-tap lookalike. -var tests = []; -var count = 0; - -function test(name, fn) { - count++; - tests.push([name, fn]); -} - -function run() { - var next = tests.shift(); - if (!next) - return console.error('ok'); - - var name = next[0]; - var fn = next[1]; - console.log('# %s', name); - fn({ - same: assert.deepEqual, - equal: assert.equal, - end: function () { - count--; - run(); - } - }); -} - -// ensure all tests have run -process.on("exit", function () { - assert.equal(count, 0); -}); - -process.nextTick(run); - -test('write fast', function(t) { - var tw = new TestWriter({ - highWaterMark: 100 - }); - - tw.on('finish', function() { - t.same(tw.buffer, chunks, 'got chunks in the right order'); - t.end(); - }); - - chunks.forEach(function(chunk) { - // screw backpressure. Just buffer it all up. - tw.write(chunk); - }); - tw.end(); -}); - -test('write slow', function(t) { - var tw = new TestWriter({ - highWaterMark: 100 - }); - - tw.on('finish', function() { - t.same(tw.buffer, chunks, 'got chunks in the right order'); - t.end(); - }); - - var i = 0; - (function W() { - tw.write(chunks[i++]); - if (i < chunks.length) - setTimeout(W, 10); - else - tw.end(); - })(); -}); - -test('write backpressure', function(t) { - var tw = new TestWriter({ - highWaterMark: 50 - }); - - var drains = 0; - - tw.on('finish', function() { - t.same(tw.buffer, chunks, 'got chunks in the right order'); - t.equal(drains, 17); - t.end(); - }); - - tw.on('drain', function() { - drains++; - }); - - var i = 0; - (function W() { - do { - var ret = tw.write(chunks[i++]); - } while (ret !== false && i < chunks.length); - - if (i < chunks.length) { - assert(tw._writableState.length >= 50); - tw.once('drain', W); - } else { - tw.end(); - } - })(); -}); - -test('write bufferize', function(t) { - var tw = new TestWriter({ - highWaterMark: 100 - }); - - var encodings = - [ 'hex', - 'utf8', - 'utf-8', - 'ascii', - 'binary', - 'base64', - 'ucs2', - 'ucs-2', - 'utf16le', - 'utf-16le', - undefined ]; - - tw.on('finish', function() { - t.same(tw.buffer, chunks, 'got the expected chunks'); - }); - - chunks.forEach(function(chunk, i) { - var enc = encodings[ i % encodings.length ]; - chunk = new Buffer(chunk); - tw.write(chunk.toString(enc), enc); - }); - t.end(); -}); - -test('write no bufferize', function(t) { - var tw = new TestWriter({ - highWaterMark: 100, - decodeStrings: false - }); - - tw._write = function(chunk, encoding, cb) { - assert(typeof chunk === 'string'); - chunk = new Buffer(chunk, encoding); - return TestWriter.prototype._write.call(this, chunk, encoding, cb); - }; - - var encodings = - [ 'hex', - 'utf8', - 'utf-8', - 'ascii', - 'binary', - 'base64', - 'ucs2', - 'ucs-2', - 'utf16le', - 'utf-16le', - undefined ]; - - tw.on('finish', function() { - t.same(tw.buffer, chunks, 'got the expected chunks'); - }); - - chunks.forEach(function(chunk, i) { - var enc = encodings[ i % encodings.length ]; - chunk = new Buffer(chunk); - tw.write(chunk.toString(enc), enc); - }); - t.end(); -}); - -test('write callbacks', function (t) { - var callbacks = chunks.map(function(chunk, i) { - return [i, function(er) { - callbacks._called[i] = chunk; - }]; - }).reduce(function(set, x) { - set['callback-' + x[0]] = x[1]; - return set; - }, {}); - callbacks._called = []; - - var tw = new TestWriter({ - highWaterMark: 100 - }); - - tw.on('finish', function() { - process.nextTick(function() { - t.same(tw.buffer, chunks, 'got chunks in the right order'); - t.same(callbacks._called, chunks, 'called all callbacks'); - t.end(); - }); - }); - - chunks.forEach(function(chunk, i) { - tw.write(chunk, callbacks['callback-' + i]); - }); - tw.end(); -}); - -test('end callback', function (t) { - var tw = new TestWriter(); - tw.end(function () { - t.end(); - }); -}); - -test('end callback with chunk', function (t) { - var tw = new TestWriter(); - tw.end(new Buffer('hello world'), function () { - t.end(); - }); -}); - -test('end callback with chunk and encoding', function (t) { - var tw = new TestWriter(); - tw.end('hello world', 'ascii', function () { - t.end(); - }); -}); - -test('end callback after .write() call', function (t) { - var tw = new TestWriter(); - tw.write(new Buffer('hello world')); - tw.end(function () { - t.end(); - }); -}); - -test('end callback called after write callback', function (t) { - var tw = new TestWriter(); - var writeCalledback = false; - tw.write(new Buffer('hello world'), function() { - writeCalledback = true; - }); - tw.end(function () { - t.equal(writeCalledback, true); - t.end(); - }); -}); - -test('encoding should be ignored for buffers', function(t) { - var tw = new W(); - var hex = '018b5e9a8f6236ffe30e31baf80d2cf6eb'; - tw._write = function(chunk, encoding, cb) { - t.equal(chunk.toString('hex'), hex); - t.end(); - }; - var buf = new Buffer(hex, 'hex'); - tw.write(buf, 'binary'); -}); - -test('writables are not pipable', function(t) { - var w = new W(); - w._write = function() {}; - var gotError = false; - w.on('error', function(er) { - gotError = true; - }); - w.pipe(process.stdout); - assert(gotError); - t.end(); -}); - -test('duplexes are pipable', function(t) { - var d = new D(); - d._read = function() {}; - d._write = function() {}; - var gotError = false; - d.on('error', function(er) { - gotError = true; - }); - d.pipe(process.stdout); - assert(!gotError); - t.end(); -}); - -test('end(chunk) two times is an error', function(t) { - var w = new W(); - w._write = function() {}; - var gotError = false; - w.on('error', function(er) { - gotError = true; - t.equal(er.message, 'write after end'); - }); - w.end('this is the end'); - w.end('and so is this'); - process.nextTick(function() { - assert(gotError); - t.end(); - }); -}); - -test('dont end while writing', function(t) { - var w = new W(); - var wrote = false; - w._write = function(chunk, e, cb) { - assert(!this.writing); - wrote = true; - this.writing = true; - setTimeout(function() { - this.writing = false; - cb(); - }); - }; - w.on('finish', function() { - assert(wrote); - t.end(); - }); - w.write(Buffer(0)); - w.end(); -}); - -test('finish does not come before write cb', function(t) { - var w = new W(); - var writeCb = false; - w._write = function(chunk, e, cb) { - setTimeout(function() { - writeCb = true; - cb(); - }, 10); - }; - w.on('finish', function() { - assert(writeCb); - t.end(); - }); - w.write(Buffer(0)); - w.end(); -}); diff --git a/test/simple/test-string-decoder-end.js b/test/simple/test-string-decoder-end.js deleted file mode 100644 index fea55d410b75..000000000000 --- a/test/simple/test-string-decoder-end.js +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// verify that the string decoder works getting 1 byte at a time, -// the whole buffer at once, and that both match the .toString(enc) -// result of the entire buffer. - -var assert = require('assert'); -var SD = require('string_decoder').StringDecoder; -var encodings = ['base64', 'hex', 'utf8', 'utf16le', 'ucs2']; - -var bufs = [ '☃💩', 'asdf' ].map(function(b) { - return new Buffer(b); -}); - -// also test just arbitrary bytes from 0-15. -for (var i = 1; i <= 16; i++) { - var bytes = new Array(i).join('.').split('.').map(function(_, j) { - return j + 0x78; - }); - bufs.push(new Buffer(bytes)); -} - -encodings.forEach(testEncoding); - -console.log('ok'); - -function testEncoding(encoding) { - bufs.forEach(function(buf) { - testBuf(encoding, buf); - }); -} - -function testBuf(encoding, buf) { - console.error('# %s', encoding, buf); - - // write one byte at a time. - var s = new SD(encoding); - var res1 = ''; - for (var i = 0; i < buf.length; i++) { - res1 += s.write(buf.slice(i, i + 1)); - } - res1 += s.end(); - - // write the whole buffer at once. - var res2 = ''; - var s = new SD(encoding); - res2 += s.write(buf); - res2 += s.end(); - - // .toString() on the buffer - var res3 = buf.toString(encoding); - - console.log('expect=%j', res3); - assert.equal(res1, res3, 'one byte at a time should match toString'); - assert.equal(res2, res3, 'all bytes at once should match toString'); -} diff --git a/test/simple/test-string-decoder.js b/test/simple/test-string-decoder.js deleted file mode 100644 index 9f47d131bbcb..000000000000 --- a/test/simple/test-string-decoder.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var StringDecoder = require('string_decoder').StringDecoder; - -process.stdout.write('scanning '); - -// UTF-8 -test('utf-8', new Buffer('$', 'utf-8'), '$'); -test('utf-8', new Buffer('¢', 'utf-8'), '¢'); -test('utf-8', new Buffer('€', 'utf-8'), '€'); -test('utf-8', new Buffer('𤭢', 'utf-8'), '𤭢'); -// A mixed ascii and non-ascii string -// Test stolen from deps/v8/test/cctest/test-strings.cc -// U+02E4 -> CB A4 -// U+0064 -> 64 -// U+12E4 -> E1 8B A4 -// U+0030 -> 30 -// U+3045 -> E3 81 85 -test( - 'utf-8', - new Buffer([0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, 0x30, 0xE3, 0x81, 0x85]), - '\u02e4\u0064\u12e4\u0030\u3045' -); - -// CESU-8 -test('utf-8', new Buffer('EDA0BDEDB18D', 'hex'), '\ud83d\udc4d'); // thumbs up - -// UCS-2 -test('ucs2', new Buffer('ababc', 'ucs2'), 'ababc'); - -// UTF-16LE -test('ucs2', new Buffer('3DD84DDC', 'hex'), '\ud83d\udc4d'); // thumbs up - -console.log(' crayon!'); - -// test verifies that StringDecoder will correctly decode the given input -// buffer with the given encoding to the expected output. It will attempt all -// possible ways to write() the input buffer, see writeSequences(). The -// singleSequence allows for easy debugging of a specific sequence which is -// useful in case of test failures. -function test(encoding, input, expected, singleSequence) { - var sequences; - if (!singleSequence) { - sequences = writeSequences(input.length); - } else { - sequences = [singleSequence]; - } - sequences.forEach(function(sequence) { - var decoder = new StringDecoder(encoding); - var output = ''; - sequence.forEach(function(write) { - output += decoder.write(input.slice(write[0], write[1])); - }); - process.stdout.write('.'); - if (output !== expected) { - var message = - 'Expected "'+unicodeEscape(expected)+'", '+ - 'but got "'+unicodeEscape(output)+'"\n'+ - 'Write sequence: '+JSON.stringify(sequence)+'\n'+ - 'Decoder charBuffer: 0x'+decoder.charBuffer.toString('hex')+'\n'+ - 'Full Decoder State: '+JSON.stringify(decoder, null, 2); - assert.fail(output, expected, message); - } - }); -} - -// unicodeEscape prints the str contents as unicode escape codes. -function unicodeEscape(str) { - var r = ''; - for (var i = 0; i < str.length; i++) { - r += '\\u'+str.charCodeAt(i).toString(16); - } - return r; -} - -// writeSequences returns an array of arrays that describes all possible ways a -// buffer of the given length could be split up and passed to sequential write -// calls. -// -// e.G. writeSequences(3) will return: [ -// [ [ 0, 3 ] ], -// [ [ 0, 2 ], [ 2, 3 ] ], -// [ [ 0, 1 ], [ 1, 3 ] ], -// [ [ 0, 1 ], [ 1, 2 ], [ 2, 3 ] ] -// ] -function writeSequences(length, start, sequence) { - if (start === undefined) { - start = 0; - sequence = [] - } else if (start === length) { - return [sequence]; - } - var sequences = []; - for (var end = length; end > start; end--) { - var subSequence = sequence.concat([[start, end]]); - var subSequences = writeSequences(length, end, subSequence, sequences); - sequences = sequences.concat(subSequences); - } - return sequences; -} - diff --git a/test/simple/test-sync-fileread.js b/test/simple/test-sync-fileread.js deleted file mode 100644 index 428838a8cddc..000000000000 --- a/test/simple/test-sync-fileread.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); - -var fixture = path.join(__dirname, '../fixtures/x.txt'); - -assert.equal('xyz\n', fs.readFileSync(fixture)); diff --git a/test/simple/test-sys.js b/test/simple/test-sys.js deleted file mode 100644 index 6ea33161c557..000000000000 --- a/test/simple/test-sys.js +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -assert.equal('0', common.inspect(0)); -assert.equal('1', common.inspect(1)); -assert.equal('false', common.inspect(false)); -assert.equal("''", common.inspect('')); -assert.equal("'hello'", common.inspect('hello')); -assert.equal('[Function]', common.inspect(function() {})); -assert.equal('undefined', common.inspect(undefined)); -assert.equal('null', common.inspect(null)); -assert.equal('/foo(bar\\n)?/gi', common.inspect(/foo(bar\n)?/gi)); -assert.equal(new Date('2010-02-14T12:48:40+01:00').toString(), - common.inspect(new Date('Sun, 14 Feb 2010 11:48:40 GMT'))); - -assert.equal("'\\n\\u0001'", common.inspect('\n\u0001')); - -assert.equal('[]', common.inspect([])); -assert.equal('{}', common.inspect(Object.create([]))); -assert.equal('[ 1, 2 ]', common.inspect([1, 2])); -assert.equal('[ 1, [ 2, 3 ] ]', common.inspect([1, [2, 3]])); - -assert.equal('{}', common.inspect({})); -assert.equal('{ a: 1 }', common.inspect({a: 1})); -assert.equal('{ a: [Function] }', common.inspect({a: function() {}})); -assert.equal('{ a: 1, b: 2 }', common.inspect({a: 1, b: 2})); -assert.equal('{ a: {} }', common.inspect({'a': {}})); -assert.equal('{ a: { b: 2 } }', common.inspect({'a': {'b': 2}})); -assert.equal('{ a: { b: { c: [Object] } } }', - common.inspect({'a': {'b': { 'c': { 'd': 2 }}}})); -assert.equal('{ a: { b: { c: { d: 2 } } } }', - common.inspect({'a': {'b': { 'c': { 'd': 2 }}}}, false, null)); -assert.equal('[ 1, 2, 3, [length]: 3 ]', common.inspect([1, 2, 3], true)); -assert.equal('{ a: [Object] }', - common.inspect({'a': {'b': { 'c': 2}}}, false, 0)); -assert.equal('{ a: { b: [Object] } }', - common.inspect({'a': {'b': { 'c': 2}}}, false, 1)); -assert.equal('{ visible: 1 }', - common.inspect(Object.create({}, - {visible: {value: 1, enumerable: true}, hidden: {value: 2}})) -); - -// Due to the hash seed randomization it's not deterministic the order that -// the following ways this hash is displayed. -// See http://codereview.chromium.org/9124004/ - -var out = common.inspect(Object.create({}, - {visible: {value: 1, enumerable: true}, hidden: {value: 2}}), true); -if (out !== '{ [hidden]: 2, visible: 1 }' && - out !== '{ visible: 1, [hidden]: 2 }') { - assert.ok(false); -} - - -// Objects without prototype -var out = common.inspect(Object.create(null, - { name: {value: 'Tim', enumerable: true}, - hidden: {value: 'secret'}}), true); -if (out !== "{ [hidden]: 'secret', name: 'Tim' }" && - out !== "{ name: 'Tim', [hidden]: 'secret' }") { - assert(false); -} - - -assert.equal('{ name: \'Tim\' }', - common.inspect(Object.create(null, - {name: {value: 'Tim', enumerable: true}, - hidden: {value: 'secret'}})) -); - - -// Dynamic properties -assert.equal('{ readonly: [Getter] }', - common.inspect({get readonly() {}})); - -assert.equal('{ readwrite: [Getter/Setter] }', - common.inspect({get readwrite() {},set readwrite(val) {}})); - -assert.equal('{ writeonly: [Setter] }', - common.inspect({set writeonly(val) {}})); - -var value = {}; -value['a'] = value; -assert.equal('{ a: [Circular] }', common.inspect(value)); - -// Array with dynamic properties -value = [1, 2, 3]; -value.__defineGetter__('growingLength', function() { - this.push(true); return this.length; -}); -assert.equal('[ 1, 2, 3, growingLength: [Getter] ]', common.inspect(value)); - -// Function with properties -value = function() {}; -value.aprop = 42; -assert.equal('{ [Function] aprop: 42 }', common.inspect(value)); - -// Regular expressions with properties -value = /123/ig; -value.aprop = 42; -assert.equal('{ /123/gi aprop: 42 }', common.inspect(value)); - -// Dates with properties -value = new Date('Sun, 14 Feb 2010 11:48:40 GMT'); -value.aprop = 42; -assert.equal('{ Sun, 14 Feb 2010 11:48:40 GMT aprop: 42 }', - common.inspect(value) -); diff --git a/test/simple/test-tcp-wrap-connect.js b/test/simple/test-tcp-wrap-connect.js deleted file mode 100644 index 3da8d932e17a..000000000000 --- a/test/simple/test-tcp-wrap-connect.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var TCP = process.binding('tcp_wrap').TCP; - -function makeConnection() { - var client = new TCP(); - - var req = client.connect('127.0.0.1', common.PORT); - req.oncomplete = function(status, client_, req_) { - assert.equal(0, status); - assert.equal(client, client_); - assert.equal(req, req_); - - console.log('connected'); - var shutdownReq = client.shutdown(); - shutdownReq.oncomplete = function(status, client_, req_) { - console.log('shutdown complete'); - assert.equal(0, status); - assert.equal(client, client_); - assert.equal(shutdownReq, req_); - shutdownCount++; - client.close(); - }; - }; -} - -///// - -var connectCount = 0; -var endCount = 0; -var shutdownCount = 0; - -var server = require('net').Server(function(s) { - console.log('got connection'); - connectCount++; - s.resume(); - s.on('end', function() { - console.log('got eof'); - endCount++; - s.destroy(); - server.close(); - }); -}); - -server.listen(common.PORT, makeConnection); - -process.on('exit', function() { - assert.equal(1, shutdownCount); - assert.equal(1, connectCount); - assert.equal(1, endCount); -}); diff --git a/test/simple/test-tcp-wrap-listen.js b/test/simple/test-tcp-wrap-listen.js deleted file mode 100644 index a272a193d26d..000000000000 --- a/test/simple/test-tcp-wrap-listen.js +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var TCP = process.binding('tcp_wrap').TCP; - -var server = new TCP(); - -var r = server.bind('0.0.0.0', common.PORT); -assert.equal(0, r); - -server.listen(128); - -var slice, sliceCount = 0, eofCount = 0; - -var writeCount = 0; -var recvCount = 0; - -server.onconnection = function(client) { - assert.equal(0, client.writeQueueSize); - console.log('got connection'); - - function maybeCloseClient() { - if (client.pendingWrites.length == 0 && client.gotEOF) { - console.log('close client'); - client.close(); - } - } - - client.readStart(); - client.pendingWrites = []; - client.onread = function(buffer, offset, length) { - if (buffer) { - assert.ok(length > 0); - - assert.equal(0, client.writeQueueSize); - - var req = client.writeBuffer(buffer.slice(offset, offset + length)); - client.pendingWrites.push(req); - - console.log('client.writeQueueSize: ' + client.writeQueueSize); - // 11 bytes should flush - assert.equal(0, client.writeQueueSize); - - req.oncomplete = function(status, client_, req_) { - assert.equal(req, client.pendingWrites.shift()); - - // Check parameters. - assert.equal(0, status); - assert.equal(client, client_); - assert.equal(req, req_); - - console.log('client.writeQueueSize: ' + client.writeQueueSize); - assert.equal(0, client.writeQueueSize); - - writeCount++; - console.log('write ' + writeCount); - maybeCloseClient(); - }; - - sliceCount++; - } else { - console.log('eof'); - client.gotEOF = true; - server.close(); - eofCount++; - maybeCloseClient(); - } - }; -}; - -var net = require('net'); - -var c = net.createConnection(common.PORT); -c.on('connect', function() { - c.end('hello world'); -}); - -c.setEncoding('utf8'); -c.on('data', function(d) { - assert.equal('hello world', d); - recvCount++; -}); - -c.on('close', function() { - console.error('client closed'); -}); - -process.on('exit', function() { - assert.equal(1, sliceCount); - assert.equal(1, eofCount); - assert.equal(1, writeCount); - assert.equal(1, recvCount); -}); - - diff --git a/test/simple/test-tcp-wrap.js b/test/simple/test-tcp-wrap.js deleted file mode 100644 index 10f7038c8315..000000000000 --- a/test/simple/test-tcp-wrap.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var TCP = process.binding('tcp_wrap').TCP; - -var handle = new TCP(); - -// Should be able to bind to the common.PORT -var r = handle.bind('0.0.0.0', common.PORT); -assert.equal(0, r); - -// Should not be able to bind to the same port again -var r = handle.bind('0.0.0.0', common.PORT); -assert.equal(-1, r); -console.log(process._errno); -assert.equal(process._errno, 'EINVAL'); - -handle.close(); diff --git a/test/simple/test-timers-blocking-callback.js b/test/simple/test-timers-blocking-callback.js deleted file mode 100644 index c4a6dedb229a..000000000000 --- a/test/simple/test-timers-blocking-callback.js +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * This is a regression test for https://github.com/joyent/node/issues/15447 - * and https://github.com/joyent/node/issues/9333. - * - * When a timer is added in another timer's callback, its underlying timer - * handle was started with a timeout that was actually incorrect. - * - * The reason was that the value that represents the current time was not - * updated between the time the original callback was called and the time - * the added timer was processed by timers.listOnTimeout. That lead the - * logic in timers.listOnTimeout to do an incorrect computation that made - * the added timer fire with a timeout of scheduledTimeout + - * timeSpentInCallback. - * - * This test makes sure that a timer added by another timer's callback - * fire with the expected timeout. - * - * It makes sure that it works when the timers list for a given timeout is - * empty (see testAddingTimerToEmptyTimersList) and when the timers list - * is not empty (see testAddingTimerToNonEmptyTimersList). - */ - -var assert = require('assert'); -var common = require('../common'); - -var TIMEOUT = 100; - -var nbBlockingCallbackCalls = 0; -var latestDelay = 0; -var timeCallbackScheduled = 0; - -function initTest() { - nbBlockingCallbackCalls = 0; - latestDelay = 0; - timeCallbackScheduled = 0; -} - -function blockingCallback(callback) { - ++nbBlockingCallbackCalls; - - if (nbBlockingCallbackCalls > 1) { - latestDelay = new Date().getTime() - timeCallbackScheduled; - // Even if timers can fire later than when they've been scheduled - // to fire, they should more than 50% later with a timeout of - // 100ms. Firing later than that would mean that we hit the regression - // highlighted in - // https://github.com/joyent/node/issues/15447 and - // https://github.com/joyent/node/issues/9333. - assert(latestDelay < TIMEOUT * 1.5); - if (callback) - return callback(); - } else { - // block by busy-looping to trigger the issue - common.busyLoop(TIMEOUT); - - timeCallbackScheduled = new Date().getTime(); - setTimeout(blockingCallback, TIMEOUT); - } -} - -function testAddingTimerToEmptyTimersList(callback) { - initTest(); - // Call setTimeout just once to make sure the timers list is - // empty when blockingCallback is called. - setTimeout(blockingCallback.bind(global, callback), TIMEOUT); -} - -function testAddingTimerToNonEmptyTimersList() { - initTest(); - // Call setTimeout twice with the same timeout to make - // sure the timers list is not empty when blockingCallback is called. - setTimeout(blockingCallback, TIMEOUT); - setTimeout(blockingCallback, TIMEOUT); -} - -// Run the test for the empty timers list case, and then for the non-empty -// timers list one -testAddingTimerToEmptyTimersList(testAddingTimerToNonEmptyTimersList); diff --git a/test/simple/test-timers-first-fire.js b/test/simple/test-timers-first-fire.js deleted file mode 100644 index e97b7ec85235..000000000000 --- a/test/simple/test-timers-first-fire.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var TIMEOUT = 50; -var last = process.hrtime(); -setTimeout(function() { - var hr = process.hrtime(last); - var ms = (hr[0] * 1e3) + (hr[1] / 1e6); - var delta = ms - TIMEOUT; - console.log('timer fired in', delta); - assert.ok(delta > 0, 'Timer fired early'); -}, TIMEOUT); diff --git a/test/simple/test-timers-immediate.js b/test/simple/test-timers-immediate.js deleted file mode 100644 index 0bd8ae9642ee..000000000000 --- a/test/simple/test-timers-immediate.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var immediateA = false, - immediateB = false, - immediateC = [], - before; - -setImmediate(function() { - try { - immediateA = process.hrtime(before); - } catch(e) { - console.log('failed to get hrtime with offset'); - } - clearImmediate(immediateB); -}); - -before = process.hrtime(); - -immediateB = setImmediate(function() { - immediateB = true; -}); - -setImmediate(function(x, y, z) { - immediateC = [x, y, z]; -}, 1, 2, 3); - -process.on('exit', function() { - assert.ok(immediateA, 'Immediate should happen after normal execution'); - assert.notStrictEqual(immediateB, true, 'immediateB should not fire'); - assert.deepEqual(immediateC, [1, 2, 3], 'immediateC args should match'); -}); diff --git a/test/simple/test-timers-linked-list.js b/test/simple/test-timers-linked-list.js deleted file mode 100644 index 0b6bf4bef8fd..000000000000 --- a/test/simple/test-timers-linked-list.js +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var L = require('_linklist'); - - -var list = { name: 'list' }; -var A = { name: 'A' }; -var B = { name: 'B' }; -var C = { name: 'C' }; -var D = { name: 'D' }; - - -L.init(list); -L.init(A); -L.init(B); -L.init(C); -L.init(D); - -assert.ok(L.isEmpty(list)); -assert.equal(null, L.peek(list)); - -L.append(list, A); -// list -> A -assert.equal(A, L.peek(list)); - -L.append(list, B); -// list -> A -> B -assert.equal(A, L.peek(list)); - -L.append(list, C); -// list -> A -> B -> C -assert.equal(A, L.peek(list)); - -L.append(list, D); -// list -> A -> B -> C -> D -assert.equal(A, L.peek(list)); - -var x = L.shift(list); -assert.equal(A, x); -// list -> B -> C -> D -assert.equal(B, L.peek(list)); - -x = L.shift(list); -assert.equal(B, x); -// list -> C -> D -assert.equal(C, L.peek(list)); - -// B is already removed, so removing it again shouldn't hurt. -L.remove(B); -// list -> C -> D -assert.equal(C, L.peek(list)); - -// Put B back on the list -L.append(list, B); -// list -> C -> D -> B -assert.equal(C, L.peek(list)); - -L.remove(C); -// list -> D -> B -assert.equal(D, L.peek(list)); - -L.remove(B); -// list -> D -assert.equal(D, L.peek(list)); - -L.remove(D); -// list -assert.equal(null, L.peek(list)); - - -assert.ok(L.isEmpty(list)); - - -L.append(list, D); -// list -> D -assert.equal(D, L.peek(list)); - -L.append(list, C); -L.append(list, B); -L.append(list, A); -// list -> D -> C -> B -> A - -// Append should REMOVE C from the list and append it to the end. -L.append(list, C); - -// list -> D -> B -> A -> C -assert.equal(D, L.shift(list)); -// list -> B -> A -> C -assert.equal(B, L.peek(list)); -assert.equal(B, L.shift(list)); -// list -> A -> C -assert.equal(A, L.peek(list)); -assert.equal(A, L.shift(list)); -// list -> C -assert.equal(C, L.peek(list)); -assert.equal(C, L.shift(list)); -// list -assert.ok(L.isEmpty(list)); - diff --git a/test/simple/test-timers-non-integer-delay.js b/test/simple/test-timers-non-integer-delay.js deleted file mode 100644 index db9bedafa801..000000000000 --- a/test/simple/test-timers-non-integer-delay.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * This test makes sure that non-integer timer delays do not make the process - * hang. See https://github.com/joyent/node/issues/8065 and - * https://github.com/joyent/node/issues/8068 which have been fixed by - * https://github.com/joyent/node/pull/8073. - * - * If the process hangs, this test will make the tests suite timeout, - * otherwise it will exit very quickly (after 50 timers with a short delay - * fire). - * - * We have to set at least several timers with a non-integer delay to - * reproduce the issue. Sometimes, a timer with a non-integer delay will - * expire correctly. 50 timers has always been more than enough to reproduce - * it 100%. - */ - -var assert = require('assert'); - -var TIMEOUT_DELAY = 1.1; -var NB_TIMEOUTS_FIRED = 50; - -var nbTimeoutFired = 0; -var interval = setInterval(function() { - ++nbTimeoutFired; - if (nbTimeoutFired === NB_TIMEOUTS_FIRED) { - clearInterval(interval); - process.exit(0); - } -}, TIMEOUT_DELAY); diff --git a/test/simple/test-timers-ordering.js b/test/simple/test-timers-ordering.js deleted file mode 100644 index 0a32d48d5935..000000000000 --- a/test/simple/test-timers-ordering.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var i; - -var N = 30; - -var last_i = 0; -var last_ts = 0; -var start = Date.now(); - -var f = function(i) { - if (i <= N) { - // check order - assert.equal(i, last_i + 1, 'order is broken: ' + i + ' != ' + last_i + ' + 1'); - last_i = i; - - // check that this iteration is fired at least 1ms later than the previous - var now = Date.now(); - console.log(i, now); - assert(now >= last_ts + 1, 'current ts ' + now + ' < prev ts ' + last_ts + ' + 1'); - last_ts = now; - - // schedule next iteration - setTimeout(f, 1, i + 1); - } -}; -f(1); diff --git a/test/simple/test-timers-socket-timeout-removes-other-socket-unref-timer.js b/test/simple/test-timers-socket-timeout-removes-other-socket-unref-timer.js deleted file mode 100644 index 3d7263c63480..000000000000 --- a/test/simple/test-timers-socket-timeout-removes-other-socket-unref-timer.js +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * This test is a regression test for joyent/node#8897. - */ - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); - -var clients = []; - -var server = net.createServer(function onClient(client) { - clients.push(client); - - if (clients.length === 2) { - /* - * Enroll two timers, and make the one supposed to fire first - * unenroll the other one supposed to fire later. This mutates - * the list of unref timers when traversing it, and exposes the - * original issue in joyent/node#8897. - */ - clients[0].setTimeout(1, function onTimeout() { - clients[1].setTimeout(0); - clients[0].end(); - clients[1].end(); - }); - - // Use a delay that is higher than the lowest timer resolution accross all - // supported platforms, so that the two timers don't fire at the same time. - clients[1].setTimeout(50); - } -}); - -server.listen(common.PORT, '127.0.0.1', function() { - var nbClientsEnded = 0; - - function addEndedClient(client) { - ++nbClientsEnded; - if (nbClientsEnded === 2) { - server.close(); - } - } - - var client1 = net.connect({ port: common.PORT }) - client1.on('end', addEndedClient); - - var client2 = net.connect({ port: common.PORT }); - client2.on('end', addEndedClient); -}); diff --git a/test/simple/test-timers-this.js b/test/simple/test-timers-this.js deleted file mode 100644 index 3d23e61dff14..000000000000 --- a/test/simple/test-timers-this.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var assert = require('assert'); - -var immediateThis, intervalThis, timeoutThis, - immediateArgsThis, intervalArgsThis, timeoutArgsThis; - -var immediateHandler = setImmediate(function () { - immediateThis = this; -}); - -var immediateArgsHandler = setImmediate(function () { - immediateArgsThis = this; -}, "args ..."); - -var intervalHandler = setInterval(function () { - clearInterval(intervalHandler); - - intervalThis = this; -}); - -var intervalArgsHandler = setInterval(function () { - clearInterval(intervalArgsHandler); - - intervalArgsThis = this; -}, 0, "args ..."); - -var timeoutHandler = setTimeout(function () { - timeoutThis = this; -}); - -var timeoutArgsHandler = setTimeout(function () { - timeoutArgsThis = this; -}, 0, "args ..."); - -process.once('exit', function () { - assert.strictEqual(immediateThis, immediateHandler); - assert.strictEqual(immediateArgsThis, immediateArgsHandler); - - assert.strictEqual(intervalThis, intervalHandler); - assert.strictEqual(intervalArgsThis, intervalArgsHandler); - - assert.strictEqual(timeoutThis, timeoutHandler); - assert.strictEqual(timeoutArgsThis, timeoutArgsHandler); -}); diff --git a/test/simple/test-timers-uncaught-exception.js b/test/simple/test-timers-uncaught-exception.js deleted file mode 100644 index 6e07fe084e16..000000000000 --- a/test/simple/test-timers-uncaught-exception.js +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var exceptions = 0; -var timer1 = 0; -var timer2 = 0; - -// the first timer throws... -console.error('set first timer'); -setTimeout(function() { - console.error('first timer'); - timer1++; - throw new Error('BAM!'); -}, 100); - -// ...but the second one should still run -console.error('set second timer'); -setTimeout(function() { - console.error('second timer'); - assert.equal(timer1, 1); - timer2++; -}, 100); - -function uncaughtException(err) { - console.error('uncaught handler'); - assert.equal(err.message, 'BAM!'); - exceptions++; -} -process.on('uncaughtException', uncaughtException); - -var exited = false; -process.on('exit', function() { - assert(!exited); - exited = true; - process.removeListener('uncaughtException', uncaughtException); - assert.equal(exceptions, 1); - assert.equal(timer1, 1); - assert.equal(timer2, 1); -}); diff --git a/test/simple/test-timers-unref-active.js b/test/simple/test-timers-unref-active.js deleted file mode 100644 index ce07c2dee621..000000000000 --- a/test/simple/test-timers-unref-active.js +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * This test is aimed at making sure that unref timers queued with - * timers._unrefActive work correctly. - * - * Basically, it queues one timer in the unref queue, and then queues - * it again each time its timeout callback is fired until the callback - * has been called ten times. - * - * At that point, it unenrolls the unref timer so that its timeout callback - * is not fired ever again. - * - * Finally, a ref timeout is used with a delay large enough to make sure that - * all 10 timeouts had the time to expire. - */ - -var timers = require('timers'); -var assert = require('assert'); - -var someObject = {}; -var nbTimeouts = 0; - -/* - * libuv 0.10.x uses GetTickCount on Windows to implement timers, which uses - * system's timers whose resolution is between 10 and 16ms. See - * http://msdn.microsoft.com/en-us/library/windows/desktop/ms724408.aspx - * for more information. That's the lowest resolution for timers across all - * supported platforms. We're using it as the lowest common denominator, - * and thus expect 5 timers to be able to fire in under 100 ms. - */ -var N = 5; -var TEST_DURATION = 100; - -timers.unenroll(someObject); -timers.enroll(someObject, 1); - -someObject._onTimeout = function _onTimeout() { - ++nbTimeouts; - - if (nbTimeouts === N) timers.unenroll(someObject); - - timers._unrefActive(someObject); -} - -function startTimer() { timers._unrefActive(someObject); } - -startTimer(); - -setTimeout(function() { - assert.equal(nbTimeouts, N); -}, TEST_DURATION); diff --git a/test/simple/test-timers-unref-remove-other-unref-timers-only-one-fires.js b/test/simple/test-timers-unref-remove-other-unref-timers-only-one-fires.js deleted file mode 100644 index b1da5841b48c..000000000000 --- a/test/simple/test-timers-unref-remove-other-unref-timers-only-one-fires.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * The goal of this test is to make sure that, after the regression introduced - * by 934bfe23a16556d05bfb1844ef4d53e8c9887c3d, the fix preserves the following - * behavior of unref timers: if two timers are scheduled to fire at the same - * time, if one unenrolls the other one in its _onTimeout callback, the other - * one will *not* fire. - * - * This behavior is a private implementation detail and should not be - * considered public interface. - */ -var timers = require('timers'); -var assert = require('assert'); - -var nbTimersFired = 0; - -var foo = new function() { - this._onTimeout = function() { - ++nbTimersFired; - timers.unenroll(bar); - }; -}(); - -var bar = new function() { - this._onTimeout = function() { - ++nbTimersFired; - timers.unenroll(foo); - }; -}(); - -timers.enroll(bar, 1); -timers._unrefActive(bar); - -timers.enroll(foo, 1); -timers._unrefActive(foo); - -setTimeout(function() { - assert.notEqual(nbTimersFired, 2); -}, 20); diff --git a/test/simple/test-timers-unref-remove-other-unref-timers.js b/test/simple/test-timers-unref-remove-other-unref-timers.js deleted file mode 100644 index 160e4824c97e..000000000000 --- a/test/simple/test-timers-unref-remove-other-unref-timers.js +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * This test is a regression test for joyent/node#8897. - * - * It tests some private implementation details that should not be - * considered public interface. - */ -var timers = require('timers'); - -var foo = new function() { - this._onTimeout = function() {}; -}(); - -var bar = new function() { - this._onTimeout = function() { - timers.unenroll(foo); - }; -}(); - -// We use timers with expiration times that are sufficiently apart to make -// sure that they're not fired at the same time on platforms where the timer -// resolution is a bit coarse (e.g Windows with a default resolution of ~15ms). -timers.enroll(bar, 1); -timers._unrefActive(bar); - -timers.enroll(foo, 50); -timers._unrefActive(foo); - -setTimeout(function() {}, 100); diff --git a/test/simple/test-timers-unref.js b/test/simple/test-timers-unref.js deleted file mode 100644 index 1c362cb836f1..000000000000 --- a/test/simple/test-timers-unref.js +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var interval_fired = false, - timeout_fired = false, - unref_interval = false, - unref_timer = false, - interval, check_unref, checks = 0; - -var LONG_TIME = 10 * 1000; -var SHORT_TIME = 100; - -setInterval(function() { - interval_fired = true; -}, LONG_TIME).unref(); - -setTimeout(function() { - timeout_fired = true; -}, LONG_TIME).unref(); - -interval = setInterval(function() { - unref_interval = true; - clearInterval(interval); -}, SHORT_TIME).unref(); - -setTimeout(function() { - unref_timer = true; -}, SHORT_TIME).unref(); - -check_unref = setInterval(function() { - if (checks > 5 || (unref_interval && unref_timer)) - clearInterval(check_unref); - checks += 1; -}, 100); - -// Should not assert on args.Holder()->InternalFieldCount() > 0. See #4261. -(function() { - var t = setInterval(function() {}, 1); - process.nextTick(t.unref.bind({})); - process.nextTick(t.unref.bind(t)); -})(); - -process.on('exit', function() { - assert.strictEqual(interval_fired, false, 'Interval should not fire'); - assert.strictEqual(timeout_fired, false, 'Timeout should not fire'); - assert.strictEqual(unref_timer, true, 'An unrefd timeout should still fire'); - assert.strictEqual(unref_interval, true, 'An unrefd interval should still fire'); -}); diff --git a/test/simple/test-timers-unrefd-interval-still-fires.js b/test/simple/test-timers-unrefd-interval-still-fires.js deleted file mode 100644 index 796ed9f81f32..000000000000 --- a/test/simple/test-timers-unrefd-interval-still-fires.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * This test is a regression test for joyent/node#8900. - */ -var assert = require('assert'); - -var N = 5; -var nbIntervalFired = 0; -var timer = setInterval(function() { - ++nbIntervalFired; - if (nbIntervalFired === N) - clearInterval(timer); -}, 1); - -timer.unref(); - -setTimeout(function onTimeout() { - assert.strictEqual(nbIntervalFired, N); -}, 100); diff --git a/test/simple/test-timers-zero-timeout.js b/test/simple/test-timers-zero-timeout.js deleted file mode 100644 index eb43f183f89d..000000000000 --- a/test/simple/test-timers-zero-timeout.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// https://github.com/joyent/node/issues/2079 - zero timeout drops extra args -(function() { - var ncalled = 0; - - setTimeout(f, 0, 'foo', 'bar', 'baz'); - var timer = setTimeout(function() {}, 0); - - function f(a, b, c) { - assert.equal(a, 'foo'); - assert.equal(b, 'bar'); - assert.equal(c, 'baz'); - ncalled++; - } - - process.on('exit', function() { - assert.equal(ncalled, 1); - }); -})(); - -(function() { - var ncalled = 0; - - var iv = setInterval(f, 0, 'foo', 'bar', 'baz'); - - function f(a, b, c) { - assert.equal(a, 'foo'); - assert.equal(b, 'bar'); - assert.equal(c, 'baz'); - if (++ncalled == 3) clearTimeout(iv); - } - - process.on('exit', function() { - assert.equal(ncalled, 3); - }); -})(); diff --git a/test/simple/test-timers.js b/test/simple/test-timers.js deleted file mode 100644 index 98e6bc3def1d..000000000000 --- a/test/simple/test-timers.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var inputs = [ - undefined, - null, - true, - false, - '', - [], - {}, - NaN, - +Infinity, - -Infinity, - (1.0 / 0.0), // sanity check - parseFloat('x'), // NaN - -10, - -1, - -0.5, - -0.0, - 0, - 0.0, - 0.5, - 1, - 1.0, - 10, - 2147483648, // browser behaviour: timeouts > 2^31-1 run on next tick - 12345678901234 // ditto -]; - -var timeouts = []; -var intervals = []; - -inputs.forEach(function(value, index) { - setTimeout(function() { - timeouts[index] = true; - }, value); - - var handle = setInterval(function() { - clearInterval(handle); // disarm timer or we'll never finish - intervals[index] = true; - }, value); -}); - -process.on('exit', function() { - // assert that all timers have run - inputs.forEach(function(value, index) { - assert.equal(true, timeouts[index]); - assert.equal(true, intervals[index]); - }); -}); diff --git a/test/simple/test-tls-check-server-identity.js b/test/simple/test-tls-check-server-identity.js deleted file mode 100644 index 487f16292a6f..000000000000 --- a/test/simple/test-tls-check-server-identity.js +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var util = require('util'); -var tls = require('tls'); - -var tests = [ - // Basic CN handling - { host: 'a.com', cert: { subject: { CN: 'a.com' } }, result: true }, - { host: 'a.com', cert: { subject: { CN: 'A.COM' } }, result: true }, - { host: 'a.com', cert: { subject: { CN: 'b.com' } }, result: false }, - { host: 'a.com', cert: { subject: { CN: 'a.com.' } }, result: true }, - - // Wildcards in CN - { host: 'b.a.com', cert: { subject: { CN: '*.a.com' } }, result: true }, - { host: 'b.a.com', cert: { - subjectaltname: 'DNS:omg.com', - subject: { CN: '*.a.com' } }, - result: false - }, - - // Multiple CN fields - { - host: 'foo.com', cert: { - subject: { CN: ['foo.com', 'bar.com'] } // CN=foo.com; CN=bar.com; - }, - result: true - }, - - // DNS names and CN - { - host: 'a.com', cert: { - subjectaltname: 'DNS:*', - subject: { CN: 'b.com' } - }, - result: false - }, - { - host: 'a.com', cert: { - subjectaltname: 'DNS:*.com', - subject: { CN: 'b.com' } - }, - result: false - }, - { - host: 'a.co.uk', cert: { - subjectaltname: 'DNS:*.co.uk', - subject: { CN: 'b.com' } - }, - result: true - }, - { - host: 'a.com', cert: { - subjectaltname: 'DNS:*.a.com', - subject: { CN: 'a.com' } - }, - result: false - }, - { - host: 'a.com', cert: { - subjectaltname: 'DNS:*.a.com', - subject: { CN: 'b.com' } - }, - result: false - }, - { - host: 'a.com', cert: { - subjectaltname: 'DNS:a.com', - subject: { CN: 'b.com' } - }, - result: true - }, - { - host: 'a.com', cert: { - subjectaltname: 'DNS:A.COM', - subject: { CN: 'b.com' } - }, - result: true - }, - - // DNS names - { - host: 'a.com', cert: { - subjectaltname: 'DNS:*.a.com', - subject: {} - }, - result: false - }, - { - host: 'b.a.com', cert: { - subjectaltname: 'DNS:*.a.com', - subject: {} - }, - result: true - }, - { - host: 'c.b.a.com', cert: { - subjectaltname: 'DNS:*.a.com', - subject: {} - }, - result: false - }, - { - host: 'b.a.com', cert: { - subjectaltname: 'DNS:*b.a.com', - subject: {} - }, - result: true - }, - { - host: 'a-cb.a.com', cert: { - subjectaltname: 'DNS:*b.a.com', - subject: {} - }, - result: true - }, - { - host: 'a.b.a.com', cert: { - subjectaltname: 'DNS:*b.a.com', - subject: {} - }, - result: false - }, - // Mutliple DNS names - { - host: 'a.b.a.com', cert: { - subjectaltname: 'DNS:*b.a.com, DNS:a.b.a.com', - subject: {} - }, - result: true - }, - // URI names - { - host: 'a.b.a.com', cert: { - subjectaltname: 'URI:http://a.b.a.com/', - subject: {} - }, - result: true - }, - { - host: 'a.b.a.com', cert: { - subjectaltname: 'URI:http://*.b.a.com/', - subject: {} - }, - result: false - }, - // IP addresses - { - host: 'a.b.a.com', cert: { - subjectaltname: 'IP Address:127.0.0.1', - subject: {} - }, - result: false - }, - { - host: '127.0.0.1', cert: { - subjectaltname: 'IP Address:127.0.0.1', - subject: {} - }, - result: true - }, - { - host: '127.0.0.2', cert: { - subjectaltname: 'IP Address:127.0.0.1', - subject: {} - }, - result: false - }, - { - host: '127.0.0.1', cert: { - subjectaltname: 'DNS:a.com', - subject: {} - }, - result: false - }, - { - host: 'localhost', cert: { - subjectaltname: 'DNS:a.com', - subject: { CN: 'localhost' } - }, - result: false - }, -]; - -tests.forEach(function(test, i) { - assert.equal(tls.checkServerIdentity(test.host, test.cert), - test.result, - 'Test#' + i + ' failed: ' + util.inspect(test)); -}); diff --git a/test/simple/test-tls-client-abort.js b/test/simple/test-tls-client-abort.js deleted file mode 100644 index 8958ceb15854..000000000000 --- a/test/simple/test-tls-client-abort.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var tls = require('tls'); -var path = require('path'); - -var cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); -var key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); - -var conn = tls.connect({cert: cert, key: key, port: common.PORT}, function() { - assert.ok(false); // callback should never be executed -}); -conn.on('error', function() { -}); -assert.doesNotThrow(function() { - conn.destroy(); -}); - diff --git a/test/simple/test-tls-client-abort2.js b/test/simple/test-tls-client-abort2.js deleted file mode 100644 index f8119627687e..000000000000 --- a/test/simple/test-tls-client-abort2.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); - -var errors = 0; - -var conn = tls.connect(common.PORT, function() { - assert(false); // callback should never be executed -}); -conn.on('error', function() { - ++errors; - assert.doesNotThrow(function() { - conn.destroy(); - }); -}); - -process.on('exit', function() { - assert.equal(errors, 1); -}); diff --git a/test/simple/test-tls-client-abort3.js b/test/simple/test-tls-client-abort3.js deleted file mode 100644 index 72725187c4b2..000000000000 --- a/test/simple/test-tls-client-abort3.js +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var common = require('../common'); -var tls = require('tls'); -var fs = require('fs'); -var assert = require('assert'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/test_key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/test_cert.pem') -}; - -var gotError = 0, - gotRequest = 0, - connected = 0; - -var server = tls.createServer(options, function(c) { - gotRequest++; - c.on('data', function(data) { - console.log(data.toString()); - }); - - c.on('close', function() { - server.close(); - }); -}).listen(common.PORT, function() { - var c = tls.connect(common.PORT, { rejectUnauthorized: false }, function() { - connected++; - c.pair.ssl.shutdown(); - c.write('123'); - c.destroy(); - }); - - c.once('error', function() { - gotError++; - }); -}); - -process.once('exit', function() { - assert.equal(gotError, 1); - assert.equal(gotRequest, 1); - assert.equal(connected, 1); -}); diff --git a/test/simple/test-tls-client-destroy-soon.js b/test/simple/test-tls-client-destroy-soon.js deleted file mode 100644 index 529b84a73432..000000000000 --- a/test/simple/test-tls-client-destroy-soon.js +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Create an ssl server. First connection, validate that not resume. -// Cache session and close connection. Use session on second connection. -// ASSERT resumption. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') -}; - -var big = new Buffer(2 * 1024 * 1024); -var connections = 0; -var bytesRead = 0; - -big.fill('Y'); - -// create server -var server = tls.createServer(options, function(socket) { - socket.end(big); - socket.destroySoon(); - connections++; -}); - -// start listening -server.listen(common.PORT, function() { - var client = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - client.on('readable', function() { - var d = client.read(); - if (d) - bytesRead += d.length; - }); - - client.on('end', function() { - server.close(); - }); - }); -}); - -process.on('exit', function() { - assert.equal(1, connections); - assert.equal(big.length, bytesRead); -}); diff --git a/test/simple/test-tls-client-reject.js b/test/simple/test-tls-client-reject.js deleted file mode 100644 index 410096fc1547..000000000000 --- a/test/simple/test-tls-client-reject.js +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var path = require('path'); - -var options = { - key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), - cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) -}; - -var connectCount = 0; - -var server = tls.createServer(options, function(socket) { - ++connectCount; - socket.on('data', function(data) { - common.debug(data.toString()); - assert.equal(data, 'ok'); - }); -}).listen(common.PORT, function() { - unauthorized(); -}); - -function unauthorized() { - var socket = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - assert(!socket.authorized); - socket.end(); - rejectUnauthorized(); - }); - socket.on('error', function(err) { - assert(false); - }); - socket.write('ok'); -} - -function rejectUnauthorized() { - var socket = tls.connect(common.PORT, function() { - assert(false); - }); - socket.on('error', function(err) { - common.debug(err); - authorized(); - }); - socket.write('ng'); -} - -function authorized() { - var socket = tls.connect(common.PORT, { - ca: [fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))] - }, function() { - assert(socket.authorized); - socket.end(); - server.close(); - }); - socket.on('error', function(err) { - assert(false); - }); - socket.write('ok'); -} - -process.on('exit', function() { - assert.equal(connectCount, 3); -}); diff --git a/test/simple/test-tls-client-resume.js b/test/simple/test-tls-client-resume.js deleted file mode 100644 index 7271134df1cf..000000000000 --- a/test/simple/test-tls-client-resume.js +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Create an ssl server. First connection, validate that not resume. -// Cache session and close connection. Use session on second connection. -// ASSERT resumption. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') -}; - -var connections = 0; - -// create server -var server = tls.Server(options, function(socket) { - socket.end('Goodbye'); - connections++; -}); - -// start listening -server.listen(common.PORT, function() { - - var session1 = null; - var client1 = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - console.log('connect1'); - assert.ok(!client1.isSessionReused(), 'Session *should not* be reused.'); - session1 = client1.getSession(); - }); - - client1.on('close', function() { - console.log('close1'); - - var opts = { - port: common.PORT, - rejectUnauthorized: false, - session: session1 - }; - - var client2 = tls.connect(opts, function() { - console.log('connect2'); - assert.ok(client2.isSessionReused(), 'Session *should* be reused.'); - }); - - client2.on('close', function() { - console.log('close2'); - server.close(); - }); - }); -}); - -process.on('exit', function() { - assert.equal(2, connections); -}); diff --git a/test/simple/test-tls-client-verify.js b/test/simple/test-tls-client-verify.js deleted file mode 100644 index cc4e21572e82..000000000000 --- a/test/simple/test-tls-client-verify.js +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - - -var hosterr = 'Hostname/IP doesn\'t match certificate\'s altnames'; -var testCases = - [{ ca: ['ca1-cert'], - key: 'agent2-key', - cert: 'agent2-cert', - servers: [ - { ok: true, key: 'agent1-key', cert: 'agent1-cert' }, - { ok: false, key: 'agent2-key', cert: 'agent2-cert' }, - { ok: false, key: 'agent3-key', cert: 'agent3-cert' } - ] - }, - - { ca: [], - key: 'agent2-key', - cert: 'agent2-cert', - servers: [ - { ok: false, key: 'agent1-key', cert: 'agent1-cert' }, - { ok: false, key: 'agent2-key', cert: 'agent2-cert' }, - { ok: false, key: 'agent3-key', cert: 'agent3-cert' } - ] - }, - - { ca: ['ca1-cert', 'ca2-cert'], - key: 'agent2-key', - cert: 'agent2-cert', - servers: [ - { ok: true, key: 'agent1-key', cert: 'agent1-cert' }, - { ok: false, key: 'agent2-key', cert: 'agent2-cert' }, - { ok: true, key: 'agent3-key', cert: 'agent3-cert' } - ] - } - ]; - - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var tls = require('tls'); - - -function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', n + '.pem'); -} - - -function loadPEM(n) { - return fs.readFileSync(filenamePEM(n)); -} - -var successfulTests = 0; - -function testServers(index, servers, clientOptions, cb) { - var serverOptions = servers[index]; - if (!serverOptions) { - cb(); - return; - } - - var ok = serverOptions.ok; - - if (serverOptions.key) { - serverOptions.key = loadPEM(serverOptions.key); - } - - if (serverOptions.cert) { - serverOptions.cert = loadPEM(serverOptions.cert); - } - - var server = tls.createServer(serverOptions, function(s) { - s.end('hello world\n'); - }); - - server.listen(common.PORT, function() { - var b = ''; - - console.error('connecting...'); - var client = tls.connect(clientOptions, function() { - var authorized = client.authorized || - client.authorizationError === hosterr; - - console.error('expected: ' + ok + ' authed: ' + authorized); - - assert.equal(ok, authorized); - server.close(); - }); - - client.on('data', function(d) { - b += d.toString(); - }); - - client.on('end', function() { - assert.equal('hello world\n', b); - }); - - client.on('close', function() { - testServers(index + 1, servers, clientOptions, cb); - }); - }); -} - - -function runTest(testIndex) { - var tcase = testCases[testIndex]; - if (!tcase) return; - - var clientOptions = { - port: common.PORT, - ca: tcase.ca.map(loadPEM), - key: loadPEM(tcase.key), - cert: loadPEM(tcase.cert), - rejectUnauthorized: false - }; - - - testServers(0, tcase.servers, clientOptions, function() { - successfulTests++; - runTest(testIndex + 1); - }); -} - - -runTest(0); - - -process.on('exit', function() { - console.log('successful tests: %d', successfulTests); - assert.equal(successfulTests, testCases.length); -}); diff --git a/test/simple/test-tls-close-notify.js b/test/simple/test-tls-close-notify.js deleted file mode 100644 index 95fa65320d2a..000000000000 --- a/test/simple/test-tls-close-notify.js +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var assert = require('assert'); -var fs = require('fs'); -var net = require('net'); -var tls = require('tls'); - -var common = require('../common'); - -var ended = 0; - -var server = tls.createServer({ - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}, function(c) { - // Send close-notify without shutting down TCP socket - if (c.pair.ssl.shutdown() !== 1) - c.pair.ssl.shutdown(); -}).listen(common.PORT, function() { - var c = tls.connect(common.PORT, { - rejectUnauthorized: false - }, function() { - // Ensure that we receive 'end' event anyway - c.on('end', function() { - ended++; - c.destroy(); - server.close(); - }); - }); -}); - -process.on('exit', function() { - assert.equal(ended, 1); -}); diff --git a/test/simple/test-tls-connect-given-socket.js b/test/simple/test-tls-connect-given-socket.js deleted file mode 100644 index 5cb62992fb56..000000000000 --- a/test/simple/test-tls-connect-given-socket.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var net = require('net'); -var fs = require('fs'); -var path = require('path'); - -var serverConnected = false; -var clientConnected = false; - -var options = { - key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), - cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) -}; - -var server = tls.createServer(options, function(socket) { - serverConnected = true; - socket.end('Hello'); -}).listen(common.PORT, function() { - var socket = net.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - var client = tls.connect({ - rejectUnauthorized: false, - socket: socket - }, function() { - clientConnected = true; - var data = ''; - client.on('data', function(chunk) { - data += chunk.toString(); - }); - client.on('end', function() { - assert.equal(data, 'Hello'); - server.close(); - }); - }); - }); -}); - -process.on('exit', function() { - assert(serverConnected); - assert(clientConnected); -}); diff --git a/test/simple/test-tls-connect-pipe.js b/test/simple/test-tls-connect-pipe.js deleted file mode 100644 index 98031c0ad18d..000000000000 --- a/test/simple/test-tls-connect-pipe.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); - -var clientConnected = 0; -var serverConnected = 0; - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var server = tls.Server(options, function(socket) { - ++serverConnected; - server.close(); -}); -server.listen(common.PIPE, function() { - var options = { rejectUnauthorized: false }; - var client = tls.connect(common.PIPE, options, function() { - ++clientConnected; - client.end(); - }); -}); - -process.on('exit', function() { - assert.equal(clientConnected, 1); - assert.equal(serverConnected, 1); -}); diff --git a/test/simple/test-tls-connect-simple.js b/test/simple/test-tls-connect-simple.js deleted file mode 100644 index e896dd9e22a5..000000000000 --- a/test/simple/test-tls-connect-simple.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); - -var clientConnected = 0; -var serverConnected = 0; - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var server = tls.Server(options, function(socket) { - if (++serverConnected === 2) { - server.close(); - } -}); - -server.listen(common.PORT, function() { - var client1 = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - ++clientConnected; - client1.end(); - }); - - var client2 = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }); - client2.on('secureConnect', function() { - ++clientConnected; - client2.end(); - }); -}); - -process.on('exit', function() { - assert.equal(clientConnected, 2); - assert.equal(serverConnected, 2); -}); diff --git a/test/simple/test-tls-connect.js b/test/simple/test-tls-connect.js deleted file mode 100644 index 616f76c05cf7..000000000000 --- a/test/simple/test-tls-connect.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var tls = require('tls'); -var path = require('path'); - -// https://github.com/joyent/node/issues/1218 -// uncatchable exception on TLS connection error -(function() { - var cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); - var key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); - - var errorEmitted = false; - - process.on('exit', function() { - assert.ok(errorEmitted); - }); - - var conn = tls.connect({cert: cert, key: key, port: common.PORT}, function() { - assert.ok(false); // callback should never be executed - }); - - conn.on('error', function() { - errorEmitted = true; - }); -})(); - -// SSL_accept/SSL_connect error handling -(function() { - var cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); - var key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); - - var errorEmitted = false; - - process.on('exit', function() { - assert.ok(errorEmitted); - }); - - var conn = tls.connect({ - cert: cert, - key: key, - port: common.PORT, - ciphers: 'rick-128-roll' - }, function() { - assert.ok(false); // callback should never be executed - }); - - conn.on('error', function() { - errorEmitted = true; - }); -})(); diff --git a/test/simple/test-tls-fast-writing.js b/test/simple/test-tls-fast-writing.js deleted file mode 100644 index 894ec346a5c1..000000000000 --- a/test/simple/test-tls-fast-writing.js +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var tls = require('tls'); -var fs = require('fs'); - -var PORT = common.PORT; -var dir = common.fixturesDir; -var options = { key: fs.readFileSync(dir + '/test_key.pem'), - cert: fs.readFileSync(dir + '/test_cert.pem'), - ca: [ fs.readFileSync(dir + '/test_ca.pem') ] }; - -var server = tls.createServer(options, onconnection); -var gotChunk = false; -var gotDrain = false; - -var timer = setTimeout(function() { - console.log('not ok - timed out'); - process.exit(1); -}, 500); - -function onconnection(conn) { - conn.on('data', function(c) { - if (!gotChunk) { - gotChunk = true; - console.log('ok - got chunk'); - } - - // just some basic sanity checks. - assert(c.length); - assert(Buffer.isBuffer(c)); - - if (gotDrain) - process.exit(0); - }); -} - -server.listen(PORT, function() { - var chunk = new Buffer(1024); - chunk.fill('x'); - var opt = { port: PORT, rejectUnauthorized: false }; - var conn = tls.connect(opt, function() { - conn.on('drain', ondrain); - write(); - }); - function ondrain() { - if (!gotDrain) { - gotDrain = true; - console.log('ok - got drain'); - } - if (gotChunk) - process.exit(0); - write(); - } - function write() { - // this needs to return false eventually - while (false !== conn.write(chunk)); - } -}); diff --git a/test/simple/test-tls-getcipher.js b/test/simple/test-tls-getcipher.js deleted file mode 100644 index 22a280e58743..000000000000 --- a/test/simple/test-tls-getcipher.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var cipher_list = ['RC4-SHA', 'AES256-SHA']; -var cipher_version_pattern = /TLS|SSL/; -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'), - ciphers: cipher_list.join(':'), - honorCipherOrder: true -}; - -var nconns = 0; - -process.on('exit', function() { - assert.equal(nconns, 1); -}); - -var server = tls.createServer(options, function(cleartextStream) { - nconns++; -}); - -server.listen(common.PORT, '127.0.0.1', function() { - var client = tls.connect({ - host: '127.0.0.1', - port: common.PORT, - rejectUnauthorized: false - }, function() { - var cipher = client.getCipher(); - assert.equal(cipher.name, cipher_list[0]); - assert(cipher_version_pattern.test(cipher.version)); - client.end(); - server.close(); - }); -}); diff --git a/test/simple/test-tls-handshake-nohang.js b/test/simple/test-tls-handshake-nohang.js deleted file mode 100644 index de36ebb500b4..000000000000 --- a/test/simple/test-tls-handshake-nohang.js +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); - -// neither should hang -tls.createSecurePair(null, false, false, false); -tls.createSecurePair(null, true, false, false); diff --git a/test/simple/test-tls-hello-parser-failure.js b/test/simple/test-tls-hello-parser-failure.js deleted file mode 100644 index b6c0ac228393..000000000000 --- a/test/simple/test-tls-hello-parser-failure.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var tls = require('tls'); -var net = require('net'); -var fs = require('fs'); -var assert = require('assert'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/test_key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/test_cert.pem') -}; - -var bonkers = new Buffer(1024 * 1024); -bonkers.fill(42); - -var server = tls.createServer(options, function(c) { - -}).listen(common.PORT, function() { - var client = net.connect(common.PORT, function() { - client.write(bonkers); - }); - - var once = false; - - var writeAgain = setTimeout(function() { - client.write(bonkers); - }); - - client.on('error', function(err) { - if (!once) { - clearTimeout(writeAgain); - once = true; - client.destroy(); - server.close(); - } - }); - - client.on('close', function (hadError) { - assert.strictEqual(hadError, true, 'Client never errored'); - }); -}); diff --git a/test/simple/test-tls-honorcipherorder-secureOptions.js b/test/simple/test-tls-honorcipherorder-secureOptions.js deleted file mode 100644 index e70cfb1ef4a4..000000000000 --- a/test/simple/test-tls-honorcipherorder-secureOptions.js +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var nconns = 0; -var SSL_Method = 'SSLv23_method'; -var localhost = '127.0.0.1'; -var opCipher = process.binding('constants').SSL_OP_CIPHER_SERVER_PREFERENCE; - -/* - * This test is to make sure we are preserving secureOptions that are passed - * to the server. - * - * Also that if honorCipherOrder is passed we are preserving that in the - * options. - * - * And that if we are passing in secureOptions no new options (aside from the - * honorCipherOrder case) are added to the secureOptions - */ - - -process.on('exit', function() { - assert.equal(nconns, 6); -}); - -function test(honorCipherOrder, clientCipher, expectedCipher, secureOptions, cb) { - var soptions = { - secureProtocol: SSL_Method, - key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'), - ciphers: 'AES256-SHA:RC4-SHA:DES-CBC-SHA', - secureOptions: secureOptions, - honorCipherOrder: !!honorCipherOrder - }; - - var server = tls.createServer(soptions, function(cleartextStream) { - nconns++; - }); - - if (!!honorCipherOrder) { - assert.strictEqual(server.secureOptions & opCipher, opCipher, 'we should preserve cipher preference'); - } - - if (secureOptions) { - var expectedSecureOpts = secureOptions; - if (!!honorCipherOrder) expectedSecureOpts |= opCipher; - - assert.strictEqual(server.secureOptions & expectedSecureOpts, - expectedSecureOpts, 'we should preserve secureOptions'); - assert.strictEqual(server.secureOptions & ~expectedSecureOpts, - 0, - 'we should not add extra options'); - } - - server.listen(common.PORT, localhost, function() { - var coptions = { - rejectUnauthorized: false, - secureProtocol: SSL_Method - }; - if (clientCipher) { - coptions.ciphers = clientCipher; - } - var client = tls.connect(common.PORT, localhost, coptions, function() { - var cipher = client.getCipher(); - client.end(); - server.close(); - assert.equal(cipher.name, expectedCipher); - if (cb) cb(); - }); - }); -} - -test1(); - -function test1() { - // Client has the preference of cipher suites by default - test(false, 'DES-CBC-SHA:RC4-SHA:AES256-SHA','DES-CBC-SHA', 0, test2); -} - -function test2() { - // Server has the preference of cipher suites where AES256-SHA is in - // the first. - test(true, 'DES-CBC-SHA:RC4-SHA:AES256-SHA', 'AES256-SHA', 0, test3); -} - -function test3() { - // Server has the preference of cipher suites. RC4-SHA is given - // higher priority over DES-CBC-SHA among client cipher suites. - test(true, 'DES-CBC-SHA:RC4-SHA', 'RC4-SHA', 0, test4); -} - -function test4() { - // As client has only one cipher, server has no choice in regardless - // of honorCipherOrder. - test(true, 'DES-CBC-SHA', 'DES-CBC-SHA', 0, test5); -} - -function test5() { - test(false, - 'DES-CBC-SHA', - 'DES-CBC-SHA', - process.binding('constants').SSL_OP_SINGLE_DH_USE, test6); -} - -function test6() { - test(true, - 'DES-CBC-SHA', - 'DES-CBC-SHA', - process.binding('constants').SSL_OP_SINGLE_DH_USE); -} diff --git a/test/simple/test-tls-honorcipherorder.js b/test/simple/test-tls-honorcipherorder.js deleted file mode 100644 index 539a12abf4ef..000000000000 --- a/test/simple/test-tls-honorcipherorder.js +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var nconns = 0; -// test only in TLSv1 to use DES which is no longer supported TLSv1.2 -// to be safe when the default method is updated in the future -var SSL_Method = 'TLSv1_method'; -var localhost = '127.0.0.1'; - -process.on('exit', function() { - assert.equal(nconns, 4); -}); - -function test(honorCipherOrder, clientCipher, expectedCipher, cb) { - var soptions = { - secureProtocol: SSL_Method, - key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'), - ciphers: 'AES256-SHA:RC4-SHA:DES-CBC-SHA', - honorCipherOrder: !!honorCipherOrder - }; - - var server = tls.createServer(soptions, function(cleartextStream) { - nconns++; - }); - server.listen(common.PORT, localhost, function() { - var coptions = { - rejectUnauthorized: false, - secureProtocol: SSL_Method - }; - if (clientCipher) { - coptions.ciphers = clientCipher; - } - var client = tls.connect(common.PORT, localhost, coptions, function() { - var cipher = client.getCipher(); - client.end(); - server.close(); - assert.equal(cipher.name, expectedCipher); - if (cb) cb(); - }); - }); -} - -test1(); - -function test1() { - // Client has the preference of cipher suites by default - test(false, 'DES-CBC-SHA:RC4-SHA:AES256-SHA','DES-CBC-SHA', test2); -} - -function test2() { - // Server has the preference of cipher suites where AES256-SHA is in - // the first. - test(true, 'DES-CBC-SHA:RC4-SHA:AES256-SHA', 'AES256-SHA', test3); -} - -function test3() { - // Server has the preference of cipher suites. RC4-SHA is given - // higher priority over DES-CBC-SHA among client cipher suites. - test(true, 'DES-CBC-SHA:RC4-SHA', 'RC4-SHA', test4); -} - -function test4() { - // As client has only one cipher, server has no choice in regardless - // of honorCipherOrder. - test(true, 'DES-CBC-SHA', 'DES-CBC-SHA'); -} diff --git a/test/simple/test-tls-interleave.js b/test/simple/test-tls-interleave.js deleted file mode 100644 index 8bebb807e548..000000000000 --- a/test/simple/test-tls-interleave.js +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var tls = require('tls'); -var fs = require('fs'); - -var PORT = common.PORT; -var dir = common.fixturesDir; -var options = { key: fs.readFileSync(dir + '/test_key.pem'), - cert: fs.readFileSync(dir + '/test_cert.pem'), - ca: [ fs.readFileSync(dir + '/test_ca.pem') ] }; - -var writes = [ - 'some server data', - 'and a separate packet', - 'and one more', -]; -var receivedWrites = 0; - -var server = tls.createServer(options, function(c) { - writes.forEach(function(str) { - c.write(str); - }); -}).listen(PORT, function() { - var c = tls.connect(PORT, { rejectUnauthorized: false }, function() { - c.write('some client data'); - c.on('readable', function() { - var data = c.read(); - if (data === null) - return; - - data = data.toString(); - while (data.length !== 0) { - assert.strictEqual(data.indexOf(writes[receivedWrites]), 0); - data = data.slice(writes[receivedWrites].length); - - if (++receivedWrites === writes.length) { - c.end(); - server.close(); - } - } - }); - }); -}); - -process.on('exit', function() { - assert.equal(receivedWrites, writes.length); -}); diff --git a/test/simple/test-tls-invalid-key.js b/test/simple/test-tls-invalid-key.js deleted file mode 100644 index b4d842f2ef7c..000000000000 --- a/test/simple/test-tls-invalid-key.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var path = require('path'); - -var options = { - key: fs.readFileSync(path.join(common.fixturesDir, 'keys/agent1-key.pem')), - cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) -}; -var serverErrorHappened = false; -var clientErrorHappened = false; - -var server = tls.Server(options, function(socket) { - assert(false); -}); -server.on('clientError', function(err) { - serverErrorHappened = true; - common.debug('Server: ' + err); - server.close(); -}); - -server.listen(common.PORT, function() { - var client = tls.connect(common.PORT, function() { - assert(false); - }); - client.on('error', function(err) { - clientErrorHappened = true; - common.debug('Client: ' + err); - }); -}); - -process.on('exit', function() { - assert(serverErrorHappened); - assert(clientErrorHappened); -}); diff --git a/test/simple/test-tls-junk-closes-server.js b/test/simple/test-tls-junk-closes-server.js deleted file mode 100644 index 57db7f5a39d2..000000000000 --- a/test/simple/test-tls-junk-closes-server.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var tls = require('tls'); -var fs = require('fs'); -var net = require('net'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') -}; - -var server = tls.createServer(options, function(s) { - s.write('welcome!\n'); - s.pipe(s); -}); - -server.listen(common.PORT, function() { - var c = net.createConnection(common.PORT); - - c.on('connect', function() { - c.write('blah\nblah\nblah\n'); - }); - - c.on('end', function() { - server.close(); - }); - -}); - diff --git a/test/simple/test-tls-npn-server-client.js b/test/simple/test-tls-npn-server-client.js deleted file mode 100644 index ef89bd235e40..000000000000 --- a/test/simple/test-tls-npn-server-client.js +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.features.tls_npn) { - console.error('Skipping because node compiled without OpenSSL or ' + - 'with old OpenSSL version.'); - process.exit(0); -} - -var common = require('../common'), - assert = require('assert'), - fs = require('fs'), - tls = require('tls'), - crypto = require('crypto'); - -function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', n + '.pem'); -} - -function loadPEM(n) { - return fs.readFileSync(filenamePEM(n)); -} - -var serverOptions = { - key: loadPEM('agent2-key'), - cert: loadPEM('agent2-cert'), - crl: loadPEM('ca2-crl'), - SNICallback: function() { - return crypto.createCredentials({ - key: loadPEM('agent2-key'), - cert: loadPEM('agent2-cert'), - crl: loadPEM('ca2-crl'), - }).context; - }, - NPNProtocols: ['a', 'b', 'c'] -}; - -var serverPort = common.PORT; - -var clientsOptions = [{ - port: serverPort, - key: serverOptions.key, - cert: serverOptions.cert, - crl: serverOptions.crl, - NPNProtocols: ['a', 'b', 'c'], - rejectUnauthorized: false -},{ - port: serverPort, - key: serverOptions.key, - cert: serverOptions.cert, - crl: serverOptions.crl, - NPNProtocols: ['c', 'b', 'e'], - rejectUnauthorized: false -},{ - port: serverPort, - key: serverOptions.key, - cert: serverOptions.cert, - crl: serverOptions.crl, - rejectUnauthorized: false -},{ - port: serverPort, - key: serverOptions.key, - cert: serverOptions.cert, - crl: serverOptions.crl, - NPNProtocols: ['first-priority-unsupported', 'x', 'y'], - rejectUnauthorized: false -}]; - -var serverResults = [], - clientsResults = []; - -var server = tls.createServer(serverOptions, function(c) { - serverResults.push(c.npnProtocol); -}); -server.listen(serverPort, startTest); - -function startTest() { - function connectClient(options, callback) { - var client = tls.connect(options, function() { - clientsResults.push(client.npnProtocol); - client.destroy(); - - callback(); - }); - }; - - connectClient(clientsOptions[0], function() { - connectClient(clientsOptions[1], function() { - connectClient(clientsOptions[2], function() { - connectClient(clientsOptions[3], function() { - server.close(); - }); - }); - }); - }); -} - -process.on('exit', function() { - assert.equal(serverResults[0], clientsResults[0]); - assert.equal(serverResults[1], clientsResults[1]); - assert.equal(serverResults[2], 'http/1.1'); - assert.equal(clientsResults[2], false); - assert.equal(serverResults[3], 'first-priority-unsupported'); - assert.equal(clientsResults[3], false); -}); diff --git a/test/simple/test-tls-ondata.js b/test/simple/test-tls-ondata.js deleted file mode 100644 index e9096b2f0ac6..000000000000 --- a/test/simple/test-tls-ondata.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var server = tls.Server(options, function(socket) { - socket.end('hello world'); -}); - -server.listen(common.PORT, function() { - var client = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }); - // test that setting the `ondata` function *prevents* data from - // being pushed to the streams2 interface of the socket - client.ondata = function (buf, start, length) { - var b = buf.slice(start, length); - process.nextTick(function () { - var b2 = client.read(); - if (b2) { - assert.notEqual(b.toString(), b2.toString()); - } - client.destroy(); - server.close(); - }); - }; -}); diff --git a/test/simple/test-tls-over-http-tunnel.js b/test/simple/test-tls-over-http-tunnel.js deleted file mode 100644 index 9fa82ae3ee26..000000000000 --- a/test/simple/test-tls-over-http-tunnel.js +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); - -var fs = require('fs'); -var net = require('net'); -var http = require('http'); -var https = require('https'); - -var proxyPort = common.PORT + 1; -var gotRequest = false; - -var key = fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'); -var cert = fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'); - -var options = { - key: key, - cert: cert -}; - -var server = https.createServer(options, function(req, res) { - console.log('SERVER: got request'); - res.writeHead(200, { - 'content-type': 'text/plain' - }); - console.log('SERVER: sending response'); - res.end('hello world\n'); -}); - -var proxy = net.createServer(function(clientSocket) { - console.log('PROXY: got a client connection'); - - var serverSocket = null; - - clientSocket.on('data', function(chunk) { - if (!serverSocket) { - // Verify the CONNECT request - assert.equal('CONNECT localhost:' + common.PORT + ' HTTP/1.1\r\n' + - 'Proxy-Connections: keep-alive\r\n' + - 'Host: localhost:' + proxyPort + '\r\n\r\n', - chunk); - - console.log('PROXY: got CONNECT request'); - console.log('PROXY: creating a tunnel'); - - // create the tunnel - serverSocket = net.connect(common.PORT, function() { - console.log('PROXY: replying to client CONNECT request'); - - // Send the response - clientSocket.write('HTTP/1.1 200 OK\r\nProxy-Connections: keep' + - '-alive\r\nConnections: keep-alive\r\nVia: ' + - 'localhost:' + proxyPort + '\r\n\r\n'); - }); - - serverSocket.on('data', function(chunk) { - clientSocket.write(chunk); - }); - - serverSocket.on('end', function() { - clientSocket.destroy(); - }); - } else { - serverSocket.write(chunk); - } - }); - - clientSocket.on('end', function() { - serverSocket.destroy(); - }); -}); - -server.listen(common.PORT); - -proxy.listen(proxyPort, function() { - console.log('CLIENT: Making CONNECT request'); - - var req = http.request({ - port: proxyPort, - method: 'CONNECT', - path: 'localhost:' + common.PORT, - headers: { - 'Proxy-Connections': 'keep-alive' - } - }); - req.useChunkedEncodingByDefault = false; // for v0.6 - req.on('response', onResponse); // for v0.6 - req.on('upgrade', onUpgrade); // for v0.6 - req.on('connect', onConnect); // for v0.7 or later - req.end(); - - function onResponse(res) { - // Very hacky. This is necessary to avoid http-parser leaks. - res.upgrade = true; - } - - function onUpgrade(res, socket, head) { - // Hacky. - process.nextTick(function() { - onConnect(res, socket, head); - }); - } - - function onConnect(res, socket, header) { - assert.equal(200, res.statusCode); - console.log('CLIENT: got CONNECT response'); - - // detach the socket - socket.removeAllListeners('data'); - socket.removeAllListeners('close'); - socket.removeAllListeners('error'); - socket.removeAllListeners('drain'); - socket.removeAllListeners('end'); - socket.ondata = null; - socket.onend = null; - socket.ondrain = null; - - console.log('CLIENT: Making HTTPS request'); - - https.get({ - path: '/foo', - key: key, - cert: cert, - socket: socket, // reuse the socket - agent: false, - rejectUnauthorized: false - }, function(res) { - assert.equal(200, res.statusCode); - - res.on('data', function(chunk) { - assert.equal('hello world\n', chunk); - console.log('CLIENT: got HTTPS response'); - gotRequest = true; - }); - - res.on('end', function() { - proxy.close(); - server.close(); - }); - }).on('error', function(er) { - // We're ok with getting ECONNRESET in this test, but it's - // timing-dependent, and thus unreliable. Any other errors - // are just failures, though. - if (er.code !== 'ECONNRESET') - throw er; - }).end(); - } -}); - -process.on('exit', function() { - assert.ok(gotRequest); -}); diff --git a/test/simple/test-tls-passphrase.js b/test/simple/test-tls-passphrase.js deleted file mode 100644 index e9a5c5a5df0a..000000000000 --- a/test/simple/test-tls-passphrase.js +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var path = require('path'); - -var key = fs.readFileSync(path.join(common.fixturesDir, 'pass-key.pem')); -var cert = fs.readFileSync(path.join(common.fixturesDir, 'pass-cert.pem')); - -var server = tls.Server({ - key: key, - passphrase: 'passphrase', - cert: cert, - ca: [cert], - requestCert: true, - rejectUnauthorized: true -}, function(s) { - s.end(); -}); - -var connectCount = 0; -server.listen(common.PORT, function() { - var c = tls.connect({ - port: common.PORT, - key: key, - passphrase: 'passphrase', - cert: cert, - rejectUnauthorized: false - }, function() { - ++connectCount; - }); - c.on('end', function() { - server.close(); - }); -}); - -assert.throws(function() { - tls.connect({ - port: common.PORT, - key: key, - passphrase: 'invalid', - cert: cert, - rejectUnauthorized: false - }); -}); - -process.on('exit', function() { - assert.equal(connectCount, 1); -}); diff --git a/test/simple/test-tls-pause-close.js b/test/simple/test-tls-pause-close.js deleted file mode 100644 index 8e5d897d170f..000000000000 --- a/test/simple/test-tls-pause-close.js +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var path = require('path'); - -var serverClosed = false; -var serverSocketClosed = false; -var clientClosed = false; -var clientSocketClosed = false; - -var options = { - key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), - cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) -}; - -var server = tls.createServer(options, function(s) { - console.log('server connected'); - s.socket.on('end', function() { - console.log('server socket ended'); - }); - s.socket.on('close', function() { - console.log('server socket closed'); - serverSocketClosed = true; - }); - s.on('end', function() { - console.log('server ended'); - }); - s.on('close', function() { - console.log('server closed'); - serverClosed = true; - }); - s.pause(); - console.log('server paused'); - process.nextTick(function() { - s.resume(); - console.log('server resumed'); - }); - s.end(); -}); - -server.listen(common.PORT, function() { - var c = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - console.log('client connected'); - c.socket.on('end', function() { - console.log('client socket ended'); - }); - c.socket.on('close', function() { - console.log('client socket closed'); - clientSocketClosed = true; - }); - c.pause(); - console.log('client paused'); - process.nextTick(function() { - c.resume(); - console.log('client resumed'); - }); - }); - c.on('end', function() { - console.log('client ended'); - }); - c.on('close', function() { - console.log('client closed'); - clientClosed = true; - server.close(); - }); -}); - -process.on('exit', function() { - assert(serverClosed); - assert(serverSocketClosed); - assert(clientClosed); - assert(clientSocketClosed); -}); diff --git a/test/simple/test-tls-pause.js b/test/simple/test-tls-pause.js deleted file mode 100644 index 5eaac8da1992..000000000000 --- a/test/simple/test-tls-pause.js +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var path = require('path'); - -var options = { - key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), - cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) -}; - -var bufSize = 1024 * 1024; -var sent = 0; -var received = 0; - -var server = tls.Server(options, function(socket) { - socket.pipe(socket); - socket.on('data', function(c) { - console.error('data', c.length); - }); -}); - -server.listen(common.PORT, function() { - var resumed = false; - var client = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - console.error('connected'); - client.pause(); - common.debug('paused'); - send(); - function send() { - console.error('sending'); - var ret = client.write(new Buffer(bufSize)); - console.error('write => %j', ret); - if (false !== ret) { - console.error('write again'); - sent += bufSize; - assert.ok(sent < 100 * 1024 * 1024); // max 100MB - return process.nextTick(send); - } - sent += bufSize; - common.debug('sent: ' + sent); - resumed = true; - client.resume(); - console.error('resumed', client); - } - }); - client.on('data', function(data) { - console.error('data'); - assert.ok(resumed); - received += data.length; - console.error('received', received); - console.error('sent', sent); - if (received >= sent) { - common.debug('received: ' + received); - client.end(); - server.close(); - } - }); -}); - -process.on('exit', function() { - assert.equal(sent, received); -}); diff --git a/test/simple/test-tls-peer-certificate-multi-keys.js b/test/simple/test-tls-peer-certificate-multi-keys.js deleted file mode 100644 index a321d2cbaa3a..000000000000 --- a/test/simple/test-tls-peer-certificate-multi-keys.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var util = require('util'); -var join = require('path').join; -var spawn = require('child_process').spawn; - -var options = { - key: fs.readFileSync(join(common.fixturesDir, 'agent.key')), - cert: fs.readFileSync(join(common.fixturesDir, 'multi-alice.crt')) -}; -var verified = false; - -var server = tls.createServer(options, function(cleartext) { - cleartext.end('World'); -}); -server.listen(common.PORT, function() { - var socket = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - var peerCert = socket.getPeerCertificate(); - common.debug(util.inspect(peerCert)); - assert.deepEqual(peerCert.subject.OU, - ['Information Technology', 'Engineering', 'Marketing']); - verified = true; - server.close(); - }); - socket.end('Hello'); -}); - -process.on('exit', function() { - assert.ok(verified); -}); diff --git a/test/simple/test-tls-peer-certificate.js b/test/simple/test-tls-peer-certificate.js deleted file mode 100644 index 2f0b72797304..000000000000 --- a/test/simple/test-tls-peer-certificate.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var util = require('util'); -var join = require('path').join; -var spawn = require('child_process').spawn; - -var options = { - key: fs.readFileSync(join(common.fixturesDir, 'agent.key')), - cert: fs.readFileSync(join(common.fixturesDir, 'alice.crt')) -}; -var verified = false; - -var server = tls.createServer(options, function(cleartext) { - cleartext.end('World'); -}); -server.listen(common.PORT, function() { - var socket = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - var peerCert = socket.getPeerCertificate(); - common.debug(util.inspect(peerCert)); - assert.equal(peerCert.subject.subjectAltName, - 'uniformResourceIdentifier:http://localhost:8000/alice.foaf#me'); - verified = true; - server.close(); - }); - socket.end('Hello'); -}); - -process.on('exit', function() { - assert.ok(verified); -}); diff --git a/test/simple/test-tls-remote.js b/test/simple/test-tls-remote.js deleted file mode 100644 index c711a294a547..000000000000 --- a/test/simple/test-tls-remote.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var path = require('path'); - -var options = { - key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), - cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) -}; - -var server = tls.Server(options, function(s) { - assert.equal(s.address().address, s.socket.address().address); - assert.equal(s.address().port, s.socket.address().port); - - assert.equal(s.remoteAddress, s.socket.remoteAddress); - assert.equal(s.remotePort, s.socket.remotePort); - s.end(); -}); - -server.listen(common.PORT, '127.0.0.1', function() { - assert.equal(server.address().address, '127.0.0.1'); - assert.equal(server.address().port, common.PORT); - - var c = tls.connect({ - host: '127.0.0.1', - port: common.PORT, - rejectUnauthorized: false - }, function() { - assert.equal(c.address().address, c.socket.address().address); - assert.equal(c.address().port, c.socket.address().port); - - assert.equal(c.remoteAddress, '127.0.0.1'); - assert.equal(c.remotePort, common.PORT); - }); - c.on('end', function() { - server.close(); - }); -}); diff --git a/test/simple/test-tls-request-timeout.js b/test/simple/test-tls-request-timeout.js deleted file mode 100644 index 7f46bd213032..000000000000 --- a/test/simple/test-tls-request-timeout.js +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); - -var hadTimeout = false; - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var server = tls.Server(options, function(socket) { - socket.setTimeout(100); - - socket.on('timeout', function(err) { - hadTimeout = true; - socket.end(); - server.close(); - }); -}); - -server.listen(common.PORT, function() { - var socket = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }); -}); - -process.on('exit', function() { - assert.ok(hadTimeout); -}); diff --git a/test/simple/test-tls-securepair-client.js b/test/simple/test-tls-securepair-client.js deleted file mode 100644 index e361a1472371..000000000000 --- a/test/simple/test-tls-securepair-client.js +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var join = require('path').join; -var net = require('net'); -var assert = require('assert'); -var fs = require('fs'); -var crypto = require('crypto'); -var tls = require('tls'); -var exec = require('child_process').exec; -var spawn = require('child_process').spawn; - -maybe(test1); - -// There is a bug with 'openssl s_server' which makes it not flush certain -// important events to stdout when done over a pipe. Therefore we skip this -// test for all openssl versions less than 1.0.0. -function maybe(cb) { - exec('openssl version', function(err, data) { - if (err) throw err; - if (/OpenSSL 0\./.test(data)) { - console.error('Skipping due to old OpenSSL version.'); - return; - } - cb(); - }); -} - -// simple/test-tls-securepair-client -function test1() { - test('agent.key', 'agent.crt', null, test2); -} - -// simple/test-tls-ext-key-usage -function test2() { - function check(pair) { - // "TLS Web Client Authentication" - assert.equal(pair.cleartext.getPeerCertificate().ext_key_usage.length, 1); - assert.equal(pair.cleartext.getPeerCertificate().ext_key_usage[0], - '1.3.6.1.5.5.7.3.2'); - } - test('keys/agent4-key.pem', 'keys/agent4-cert.pem', check); -} - -function test(keyfn, certfn, check, next) { - // FIXME: Avoid the common PORT as this test currently hits a C-level - // assertion error with node_g. The program aborts without HUPing - // the openssl s_server thus causing many tests to fail with - // EADDRINUSE. - var PORT = common.PORT + 5; - - var connections = 0; - - keyfn = join(common.fixturesDir, keyfn); - var key = fs.readFileSync(keyfn).toString(); - - certfn = join(common.fixturesDir, certfn); - var cert = fs.readFileSync(certfn).toString(); - - var server = spawn('openssl', ['s_server', - '-accept', PORT, - '-cert', certfn, - '-key', keyfn]); - server.stdout.pipe(process.stdout); - server.stderr.pipe(process.stdout); - - - var state = 'WAIT-ACCEPT'; - - var serverStdoutBuffer = ''; - server.stdout.setEncoding('utf8'); - server.stdout.on('data', function(s) { - serverStdoutBuffer += s; - console.error(state); - switch (state) { - case 'WAIT-ACCEPT': - if (/ACCEPT/g.test(serverStdoutBuffer)) { - // Give s_server half a second to start up. - setTimeout(startClient, 500); - state = 'WAIT-HELLO'; - } - break; - - case 'WAIT-HELLO': - if (/hello/g.test(serverStdoutBuffer)) { - - // End the current SSL connection and exit. - // See s_server(1ssl). - server.stdin.write('Q'); - - state = 'WAIT-SERVER-CLOSE'; - } - break; - - default: - break; - } - }); - - - var timeout = setTimeout(function() { - server.kill(); - process.exit(1); - }, 5000); - - var gotWriteCallback = false; - var serverExitCode = -1; - - server.on('exit', function(code) { - serverExitCode = code; - clearTimeout(timeout); - if (next) next(); - }); - - - function startClient() { - var s = new net.Stream(); - - var sslcontext = crypto.createCredentials({key: key, cert: cert}); - sslcontext.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA'); - - var pair = tls.createSecurePair(sslcontext, false); - - assert.ok(pair.encrypted.writable); - assert.ok(pair.cleartext.writable); - - pair.encrypted.pipe(s); - s.pipe(pair.encrypted); - - s.connect(PORT); - - s.on('connect', function() { - console.log('client connected'); - }); - - pair.on('secure', function() { - console.log('client: connected+secure!'); - console.log('client pair.cleartext.getPeerCertificate(): %j', - pair.cleartext.getPeerCertificate()); - console.log('client pair.cleartext.getCipher(): %j', - pair.cleartext.getCipher()); - if (check) check(pair); - setTimeout(function() { - pair.cleartext.write('hello\r\n', function() { - gotWriteCallback = true; - }); - }, 500); - }); - - pair.cleartext.on('data', function(d) { - console.log('cleartext: %s', d.toString()); - }); - - s.on('close', function() { - console.log('client close'); - }); - - pair.encrypted.on('error', function(err) { - console.log('encrypted error: ' + err); - }); - - s.on('error', function(err) { - console.log('socket error: ' + err); - }); - - pair.on('error', function(err) { - console.log('secure error: ' + err); - }); - } - - - process.on('exit', function() { - assert.equal(0, serverExitCode); - assert.equal('WAIT-SERVER-CLOSE', state); - assert.ok(gotWriteCallback); - }); -} diff --git a/test/simple/test-tls-securepair-server.js b/test/simple/test-tls-securepair-server.js deleted file mode 100644 index 3b4eec1eef1f..000000000000 --- a/test/simple/test-tls-securepair-server.js +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - - -var common = require('../common'); -var assert = require('assert'); - -var join = require('path').join; -var net = require('net'); -var fs = require('fs'); -var crypto = require('crypto'); -var tls = require('tls'); -var spawn = require('child_process').spawn; - -var connections = 0; -var key = fs.readFileSync(join(common.fixturesDir, 'agent.key')).toString(); -var cert = fs.readFileSync(join(common.fixturesDir, 'agent.crt')).toString(); - -function log(a) { - console.error('***server*** ' + a); -} - -var server = net.createServer(function(socket) { - connections++; - log('connection fd=' + socket.fd); - var sslcontext = crypto.createCredentials({key: key, cert: cert}); - sslcontext.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA'); - - var pair = tls.createSecurePair(sslcontext, true); - - assert.ok(pair.encrypted.writable); - assert.ok(pair.cleartext.writable); - - pair.encrypted.pipe(socket); - socket.pipe(pair.encrypted); - - log('i set it secure'); - - pair.on('secure', function() { - log('connected+secure!'); - pair.cleartext.write('hello\r\n'); - log(pair.cleartext.getPeerCertificate()); - log(pair.cleartext.getCipher()); - }); - - pair.cleartext.on('data', function(data) { - log('read bytes ' + data.length); - pair.cleartext.write(data); - }); - - socket.on('end', function() { - log('socket end'); - }); - - pair.cleartext.on('error', function(err) { - log('got error: '); - log(err); - log(err.stack); - socket.destroy(); - }); - - pair.encrypted.on('error', function(err) { - log('encrypted error: '); - log(err); - log(err.stack); - socket.destroy(); - }); - - socket.on('error', function(err) { - log('socket error: '); - log(err); - log(err.stack); - socket.destroy(); - }); - - socket.on('close', function(err) { - log('socket closed'); - }); - - pair.on('error', function(err) { - log('secure error: '); - log(err); - log(err.stack); - socket.destroy(); - }); -}); - -var gotHello = false; -var sentWorld = false; -var gotWorld = false; -var opensslExitCode = -1; - -server.listen(common.PORT, function() { - // To test use: openssl s_client -connect localhost:8000 - var client = spawn('openssl', ['s_client', '-connect', '127.0.0.1:' + - common.PORT]); - - - var out = ''; - - client.stdout.setEncoding('utf8'); - client.stdout.on('data', function(d) { - out += d; - - if (!gotHello && /hello/.test(out)) { - gotHello = true; - client.stdin.write('world\r\n'); - sentWorld = true; - } - - if (!gotWorld && /world/.test(out)) { - gotWorld = true; - client.stdin.end(); - } - }); - - client.stdout.pipe(process.stdout, { end: false }); - - client.on('exit', function(code) { - opensslExitCode = code; - server.close(); - }); -}); - -process.on('exit', function() { - assert.equal(1, connections); - assert.ok(gotHello); - assert.ok(sentWorld); - assert.ok(gotWorld); - assert.equal(0, opensslExitCode); -}); diff --git a/test/simple/test-tls-server-large-request.js b/test/simple/test-tls-server-large-request.js deleted file mode 100644 index 9928e8547ed5..000000000000 --- a/test/simple/test-tls-server-large-request.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); -var stream = require('stream'); -var util = require('util'); - -var clientConnected = 0; -var serverConnected = 0; -var request = new Buffer(new Array(1024 * 256).join('ABCD')); // 1mb - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -function Mediator() { - stream.Writable.call(this); - this.buf = ''; -}; -util.inherits(Mediator, stream.Writable); - -Mediator.prototype._write = function write(data, enc, cb) { - this.buf += data; - setTimeout(cb, 0); - - if (this.buf.length >= request.length) { - assert.equal(this.buf, request.toString()); - server.close(); - } -}; - -var mediator = new Mediator(); - -var server = tls.Server(options, function(socket) { - socket.pipe(mediator); - serverConnected++; -}); - -server.listen(common.PORT, function() { - var client1 = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - ++clientConnected; - client1.end(request); - }); -}); - -process.on('exit', function() { - assert.equal(clientConnected, 1); - assert.equal(serverConnected, 1); -}); diff --git a/test/simple/test-tls-server-missing-options.js b/test/simple/test-tls-server-missing-options.js deleted file mode 100644 index 53846d1f2b5b..000000000000 --- a/test/simple/test-tls-server-missing-options.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var https = require('https'); -var tls = require('tls'); - -assert.throws(function() { - tls.createServer({ /* empty */}).listen(0); -}, /missing.+certificate/i); - -assert.throws(function() { - https.createServer({ /* empty */}).listen(0); -}, /missing.+certificate/i); diff --git a/test/simple/test-tls-server-slab.js b/test/simple/test-tls-server-slab.js deleted file mode 100644 index de4ac01f4f5d..000000000000 --- a/test/simple/test-tls-server-slab.js +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); - -var clientConnected = 0; -var serverConnected = 0; - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -tls.SLAB_BUFFER_SIZE = 100 * 1024; - -var server = tls.Server(options, function(socket) { - assert(socket._buffer.pool.length == tls.SLAB_BUFFER_SIZE); - if (++serverConnected === 2) { - server.close(); - } -}); - -server.listen(common.PORT, function() { - var client1 = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }, function() { - ++clientConnected; - client1.end(); - }); - - var client2 = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }); - client2.on('secureConnect', function() { - ++clientConnected; - client2.end(); - }); -}); - -process.on('exit', function() { - assert.equal(clientConnected, 2); - assert.equal(serverConnected, 2); -}); diff --git a/test/simple/test-tls-server-verify.js b/test/simple/test-tls-server-verify.js deleted file mode 100644 index 377f95b6ba06..000000000000 --- a/test/simple/test-tls-server-verify.js +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); - -if (!common.opensslCli) { - console.error('Skipping because node compiled without OpenSSL CLI.'); - process.exit(0); -} - -// This is a rather complex test which sets up various TLS servers with node -// and connects to them using the 'openssl s_client' command line utility -// with various keys. Depending on the certificate authority and other -// parameters given to the server, the various clients are -// - rejected, -// - accepted and "unauthorized", or -// - accepted and "authorized". - -var testCases = - [{ title: 'Do not request certs. Everyone is unauthorized.', - requestCert: false, - rejectUnauthorized: false, - CAs: ['ca1-cert'], - clients: - [{ name: 'agent1', shouldReject: false, shouldAuth: false }, - { name: 'agent2', shouldReject: false, shouldAuth: false }, - { name: 'agent3', shouldReject: false, shouldAuth: false }, - { name: 'nocert', shouldReject: false, shouldAuth: false } - ] - }, - - { title: 'Allow both authed and unauthed connections with CA1', - requestCert: true, - rejectUnauthorized: false, - CAs: ['ca1-cert'], - clients: - [{ name: 'agent1', shouldReject: false, shouldAuth: true }, - { name: 'agent2', shouldReject: false, shouldAuth: false }, - { name: 'agent3', shouldReject: false, shouldAuth: false }, - { name: 'nocert', shouldReject: false, shouldAuth: false } - ] - }, - - { title: 'Allow only authed connections with CA1', - requestCert: true, - rejectUnauthorized: true, - CAs: ['ca1-cert'], - clients: - [{ name: 'agent1', shouldReject: false, shouldAuth: true }, - { name: 'agent2', shouldReject: true }, - { name: 'agent3', shouldReject: true }, - { name: 'nocert', shouldReject: true } - ] - }, - - { title: 'Allow only authed connections with CA1 and CA2', - requestCert: true, - rejectUnauthorized: true, - CAs: ['ca1-cert', 'ca2-cert'], - clients: - [{ name: 'agent1', shouldReject: false, shouldAuth: true }, - { name: 'agent2', shouldReject: true }, - { name: 'agent3', shouldReject: false, shouldAuth: true }, - { name: 'nocert', shouldReject: true } - ] - }, - - - { title: 'Allow only certs signed by CA2 but not in the CRL', - requestCert: true, - rejectUnauthorized: true, - CAs: ['ca2-cert'], - crl: 'ca2-crl', - clients: - [ - { name: 'agent1', shouldReject: true, shouldAuth: false }, - { name: 'agent2', shouldReject: true, shouldAuth: false }, - { name: 'agent3', shouldReject: false, shouldAuth: true }, - // Agent4 has a cert in the CRL. - { name: 'agent4', shouldReject: true, shouldAuth: false }, - { name: 'nocert', shouldReject: true } - ] - } - ]; - - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var tls = require('tls'); -var spawn = require('child_process').spawn; - - -function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', n + '.pem'); -} - - -function loadPEM(n) { - return fs.readFileSync(filenamePEM(n)); -} - - -var serverKey = loadPEM('agent2-key'); -var serverCert = loadPEM('agent2-cert'); - - -function runClient(options, cb) { - - // Client can connect in three ways: - // - Self-signed cert - // - Certificate, but not signed by CA. - // - Certificate signed by CA. - - var args = ['s_client', '-connect', '127.0.0.1:' + common.PORT]; - - - console.log(' connecting with', options.name); - - switch (options.name) { - case 'agent1': - // Signed by CA1 - args.push('-key'); - args.push(filenamePEM('agent1-key')); - args.push('-cert'); - args.push(filenamePEM('agent1-cert')); - break; - - case 'agent2': - // Self-signed - // This is also the key-cert pair that the server will use. - args.push('-key'); - args.push(filenamePEM('agent2-key')); - args.push('-cert'); - args.push(filenamePEM('agent2-cert')); - break; - - case 'agent3': - // Signed by CA2 - args.push('-key'); - args.push(filenamePEM('agent3-key')); - args.push('-cert'); - args.push(filenamePEM('agent3-cert')); - break; - - case 'agent4': - // Signed by CA2 (rejected by ca2-crl) - args.push('-key'); - args.push(filenamePEM('agent4-key')); - args.push('-cert'); - args.push(filenamePEM('agent4-cert')); - break; - - case 'nocert': - // Do not send certificate - break; - - default: - throw new Error('Unknown agent name'); - } - - // To test use: openssl s_client -connect localhost:8000 - console.log(common.opensslCli, args); - var client = spawn(common.opensslCli, args); - - var out = ''; - - var rejected = true; - var authed = false; - - client.stdout.setEncoding('utf8'); - client.stdout.on('data', function(d) { - out += d; - - if (/_unauthed/g.test(out)) { - console.error(' * unauthed'); - client.stdin.end('goodbye\n'); - authed = false; - rejected = false; - } - - if (/_authed/g.test(out)) { - console.error(' * authed'); - client.stdin.end('goodbye\n'); - authed = true; - rejected = false; - } - }); - - //client.stdout.pipe(process.stdout); - - client.on('exit', function(code) { - //assert.equal(0, code, options.name + - // ": s_client exited with error code " + code); - if (options.shouldReject) { - assert.equal(true, rejected, options.name + - ' NOT rejected, but should have been'); - } else { - assert.equal(false, rejected, options.name + - ' rejected, but should NOT have been'); - assert.equal(options.shouldAuth, authed); - } - - cb(); - }); -} - - -// Run the tests -var successfulTests = 0; -function runTest(testIndex) { - var tcase = testCases[testIndex]; - if (!tcase) return; - - console.error("Running '%s'", tcase.title); - - var cas = tcase.CAs.map(loadPEM); - - var crl = tcase.crl ? loadPEM(tcase.crl) : null; - - var serverOptions = { - key: serverKey, - cert: serverCert, - ca: cas, - crl: crl, - requestCert: tcase.requestCert, - rejectUnauthorized: tcase.rejectUnauthorized - }; - - var connections = 0; - - var server = tls.Server(serverOptions, function(c) { - connections++; - if (c.authorized) { - console.error('- authed connection: ' + - c.getPeerCertificate().subject.CN); - c.write('\n_authed\n'); - } else { - console.error('- unauthed connection: %s', c.authorizationError); - c.write('\n_unauthed\n'); - } - }); - - function runNextClient(clientIndex) { - var options = tcase.clients[clientIndex]; - if (options) { - runClient(options, function() { - runNextClient(clientIndex + 1); - }); - } else { - server.close(); - successfulTests++; - runTest(testIndex + 1); - } - } - - server.listen(common.PORT, function() { - if (tcase.debug) { - console.error('TLS server running on port ' + common.PORT); - } else { - runNextClient(0); - } - }); -} - - -runTest(0); - - -process.on('exit', function() { - assert.equal(successfulTests, testCases.length); -}); diff --git a/test/simple/test-tls-session-cache.js b/test/simple/test-tls-session-cache.js deleted file mode 100644 index fdc4ae17ddb7..000000000000 --- a/test/simple/test-tls-session-cache.js +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} -require('child_process').exec('openssl version', function(err) { - if (err !== null) { - console.error('Skipping because openssl command is not available.'); - process.exit(0); - } - doTest(); -}); - -function doTest() { - var common = require('../common'); - var assert = require('assert'); - var tls = require('tls'); - var fs = require('fs'); - var join = require('path').join; - var spawn = require('child_process').spawn; - - var keyFile = join(common.fixturesDir, 'agent.key'); - var certFile = join(common.fixturesDir, 'agent.crt'); - var key = fs.readFileSync(keyFile); - var cert = fs.readFileSync(certFile); - var options = { - key: key, - cert: cert, - ca: [cert], - requestCert: true - }; - var requestCount = 0; - var session; - var badOpenSSL = false; - - var server = tls.createServer(options, function(cleartext) { - cleartext.on('error', function(er) { - // We're ok with getting ECONNRESET in this test, but it's - // timing-dependent, and thus unreliable. Any other errors - // are just failures, though. - if (er.code !== 'ECONNRESET') - throw er; - }); - ++requestCount; - cleartext.end(); - }); - server.on('newSession', function(id, data) { - assert.ok(!session); - session = { - id: id, - data: data - }; - }); - server.on('resumeSession', function(id, callback) { - assert.ok(session); - assert.equal(session.id.toString('hex'), id.toString('hex')); - - // Just to check that async really works there - setTimeout(function() { - callback(null, session.data); - }, 100); - }); - server.listen(common.PORT, function() { - var client = spawn('openssl', [ - 's_client', - '-connect', 'localhost:' + common.PORT, - '-key', join(common.fixturesDir, 'agent.key'), - '-cert', join(common.fixturesDir, 'agent.crt'), - '-reconnect', - '-no_ticket' - ], { - stdio: [ 0, 1, 'pipe' ] - }); - var err = ''; - client.stderr.setEncoding('utf8'); - client.stderr.on('data', function(chunk) { - err += chunk; - }); - client.on('exit', function(code) { - if (/^unknown option/.test(err)) { - // using an incompatible version of openssl - assert(code); - badOpenSSL = true; - } else - assert.equal(code, 0); - server.close(); - }); - }); - - process.on('exit', function() { - if (!badOpenSSL) { - assert.ok(session); - - // initial request + reconnect requests (5 times) - assert.equal(requestCount, 6); - } - }); -} diff --git a/test/simple/test-tls-set-ciphers.js b/test/simple/test-tls-set-ciphers.js deleted file mode 100644 index a473a1d2678f..000000000000 --- a/test/simple/test-tls-set-ciphers.js +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var exec = require('child_process').exec; -var tls = require('tls'); -var fs = require('fs'); - -if (process.platform === 'win32') { - console.log("Skipping test, you probably don't have openssl installed."); - process.exit(); -} - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'), - ciphers: 'RC4-MD5' -}; - -var reply = 'I AM THE WALRUS'; // something recognizable -var nconns = 0; -var response = ''; - -process.on('exit', function() { - assert.equal(nconns, 1); - assert.notEqual(response.indexOf(reply), -1); -}); - -var server = tls.createServer(options, function(conn) { - conn.end(reply); - nconns++; -}); - -server.listen(common.PORT, '127.0.0.1', function() { - var cmd = 'openssl s_client -cipher ' + options.ciphers + - ' -connect 127.0.0.1:' + common.PORT; - - exec(cmd, function(err, stdout, stderr) { - if (err) throw err; - response = stdout; - server.close(); - }); -}); diff --git a/test/simple/test-tls-set-encoding.js b/test/simple/test-tls-set-encoding.js deleted file mode 100644 index 0f6beafd1dd5..000000000000 --- a/test/simple/test-tls-set-encoding.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); - - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') -}; - -var connections = 0; -var message = 'hello world\n'; - - -var server = tls.Server(options, function(socket) { - socket.end(message); - connections++; -}); - - -server.listen(common.PORT, function() { - var client = tls.connect({ - port: common.PORT, - rejectUnauthorized: false - }); - - var buffer = ''; - - client.setEncoding('utf8'); - - client.on('data', function(d) { - assert.ok(typeof d === 'string'); - buffer += d; - }); - - - client.on('close', function() { - // readyState is deprecated but we want to make - // sure this isn't triggering an assert in lib/net.js - // See issue #1069. - assert.equal('closed', client.readyState); - - assert.equal(buffer, message); - console.log(message); - server.close(); - }); -}); - - -process.on('exit', function() { - assert.equal(1, connections); -}); diff --git a/test/simple/test-tls-sni-server-client.js b/test/simple/test-tls-sni-server-client.js deleted file mode 100644 index 8de57e2d4c35..000000000000 --- a/test/simple/test-tls-sni-server-client.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -if (!process.features.tls_sni) { - console.error('Skipping because node compiled without OpenSSL or ' + - 'with old OpenSSL version.'); - process.exit(0); -} - -var common = require('../common'), - assert = require('assert'), - fs = require('fs'), - tls = require('tls'); - -function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', n + '.pem'); -} - -function loadPEM(n) { - return fs.readFileSync(filenamePEM(n)); -} - -var serverOptions = { - key: loadPEM('agent2-key'), - cert: loadPEM('agent2-cert') -}; - -var SNIContexts = { - 'a.example.com': { - key: loadPEM('agent1-key'), - cert: loadPEM('agent1-cert') - }, - 'asterisk.test.com': { - key: loadPEM('agent3-key'), - cert: loadPEM('agent3-cert') - } -}; - -var serverPort = common.PORT; - -var clientsOptions = [{ - port: serverPort, - key: loadPEM('agent1-key'), - cert: loadPEM('agent1-cert'), - ca: [loadPEM('ca1-cert')], - servername: 'a.example.com', - rejectUnauthorized: false -},{ - port: serverPort, - key: loadPEM('agent2-key'), - cert: loadPEM('agent2-cert'), - ca: [loadPEM('ca2-cert')], - servername: 'b.test.com', - rejectUnauthorized: false -},{ - port: serverPort, - key: loadPEM('agent3-key'), - cert: loadPEM('agent3-cert'), - ca: [loadPEM('ca1-cert')], - servername: 'c.wrong.com', - rejectUnauthorized: false -}]; - -var serverResults = [], - clientResults = []; - -var server = tls.createServer(serverOptions, function(c) { - serverResults.push(c.servername); -}); - -server.addContext('a.example.com', SNIContexts['a.example.com']); -server.addContext('*.test.com', SNIContexts['asterisk.test.com']); - -server.listen(serverPort, startTest); - -function startTest() { - function connectClient(options, callback) { - var client = tls.connect(options, function() { - clientResults.push( - client.authorizationError && - /Hostname\/IP doesn't/.test(client.authorizationError)); - client.destroy(); - - callback(); - }); - }; - - connectClient(clientsOptions[0], function() { - connectClient(clientsOptions[1], function() { - connectClient(clientsOptions[2], function() { - server.close(); - }); - }); - }); -} - -process.on('exit', function() { - assert.deepEqual(serverResults, ['a.example.com', 'b.test.com', - 'c.wrong.com']); - assert.deepEqual(clientResults, [true, true, false]); -}); diff --git a/test/simple/test-tls-timeout-server-2.js b/test/simple/test-tls-timeout-server-2.js deleted file mode 100644 index dfa9be3dee12..000000000000 --- a/test/simple/test-tls-timeout-server-2.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) process.exit(); - -var common = require('../common'); -var assert = require('assert'); -var tls = require('tls'); -var fs = require('fs'); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') -}; - -var server = tls.createServer(options, function(cleartext) { - cleartext.setTimeout(50, function() { - cleartext.destroy(); - server.close(); - }); -}); - -server.listen(common.PORT, function() { - tls.connect({ - host: '127.0.0.1', - port: common.PORT, - rejectUnauthorized: false - }); -}); diff --git a/test/simple/test-tls-timeout-server.js b/test/simple/test-tls-timeout-server.js deleted file mode 100644 index 2c9b973ab318..000000000000 --- a/test/simple/test-tls-timeout-server.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) process.exit(); - -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var tls = require('tls'); -var fs = require('fs'); - -var clientErrors = 0; - -process.on('exit', function() { - assert.equal(clientErrors, 1); -}); - -var options = { - key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), - cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), - handshakeTimeout: 50 -}; - -var server = tls.createServer(options, assert.fail); - -server.on('clientError', function(err, conn) { - conn.destroy(); - server.close(); - clientErrors++; -}); - -server.listen(common.PORT, function() { - net.connect({ host: '127.0.0.1', port: common.PORT }); -}); diff --git a/test/simple/test-tls-zero-clear-in.js b/test/simple/test-tls-zero-clear-in.js deleted file mode 100644 index 22f45b663485..000000000000 --- a/test/simple/test-tls-zero-clear-in.js +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -if (!process.versions.openssl) { - console.error('Skipping because node compiled without OpenSSL.'); - process.exit(0); -} - -var common = require('../common'); -var assert = require('assert'); -var fs = require('fs'); -var tls = require('tls'); -var path = require('path'); - -var cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); -var key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); - -var errorEmitted = false; - -var server = tls.createServer({ - cert: cert, - key: key -}, function(c) { - // Nop - setTimeout(function() { - c.destroy(); - server.close(); - }, 20); -}).listen(common.PORT, function() { - var conn = tls.connect({ - cert: cert, - key: key, - rejectUnauthorized: false, - port: common.PORT - }, function() { - setTimeout(function() { - conn.destroy(); - }, 20); - }); - - // SSL_write() call's return value, when called 0 bytes, should not be - // treated as error. - conn.end(''); - - conn.on('error', function(err) { - console.log(err); - errorEmitted = true; - }); -}); - -process.on('exit', function() { - assert.ok(!errorEmitted); -}); diff --git a/test/simple/test-tty-stdout-end.js b/test/simple/test-tty-stdout-end.js deleted file mode 100644 index 1fc27906834c..000000000000 --- a/test/simple/test-tty-stdout-end.js +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Can't test this when 'make test' doesn't assign a tty to the stdout. -var common = require('../common'); -var assert = require('assert'); - -var exceptionCaught = false; - -try { - process.stdout.end(); -} catch (e) { - exceptionCaught = true; - assert.ok(common.isError(e)); - assert.equal('process.stdout cannot be closed.', e.message); -} - -assert.ok(exceptionCaught); diff --git a/test/simple/test-tty-wrap.js b/test/simple/test-tty-wrap.js deleted file mode 100644 index 610b92b43fd9..000000000000 --- a/test/simple/test-tty-wrap.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var TTY = process.binding('tty_wrap').TTY; -var isTTY = process.binding('tty_wrap').isTTY; - -if (isTTY(1) == false) { - console.error('fd 1 is not a tty. skipping test.'); - process.exit(0); -} - -var handle = new TTY(1); -var callbacks = 0; - -var req1 = handle.writeBuffer(Buffer('hello world\n')); -req1.oncomplete = function() { - callbacks++; -}; - -var req2 = handle.writeBuffer(Buffer('hello world\n')); -req2.oncomplete = function() { - callbacks++; -}; - -process.on('exit', function() { - assert.equal(2, callbacks); -}); diff --git a/test/simple/test-typed-arrays.js b/test/simple/test-typed-arrays.js deleted file mode 100644 index 9b55ee87c93a..000000000000 --- a/test/simple/test-typed-arrays.js +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. - -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: - -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * Test to verify we are using Typed Arrays - * (http://www.khronos.org/registry/typedarray/specs/latest/) correctly Test to - * verify Buffer can used in Typed Arrays - */ - -var common = require('../common'); -var assert = require('assert'); - -[ - 'ArrayBuffer', - 'Int8Array', - 'Uint8Array', - 'Int16Array', - 'Uint16Array', - 'Int32Array', - 'Uint32Array', - 'Float32Array', - 'Float64Array', - 'Uint8ClampedArray' -].forEach(function(name) { - var expected = '[object ' + name + ']'; - var clazz = global[name]; - var obj = new clazz(1); - - assert.equal(obj.toString(), expected); - assert.equal(Object.prototype.toString.call(obj), expected); - - obj = new DataView(obj.buffer || obj); - assert.equal(obj.toString(), '[object DataView]'); - assert.equal(Object.prototype.toString.call(obj), '[object DataView]'); - - // Calling constructor as function should work. - clazz(32); -}); - -// Calling constructor as function should work. -DataView(ArrayBuffer(32)); - -var buffer = new ArrayBuffer(16); -var uint8 = new Uint8Array(buffer); -var uint16 = new Uint16Array(buffer); -var uint16slice = new Uint16Array(buffer, 2, 2); -var uint32 = new Uint32Array(buffer); - -assert.equal(uint8.BYTES_PER_ELEMENT, 1); -assert.equal(uint16.BYTES_PER_ELEMENT, 2); -assert.equal(uint16slice.BYTES_PER_ELEMENT, 2); -assert.equal(uint32.BYTES_PER_ELEMENT, 4); - -// now change the underlying buffer -buffer[0] = 0x08; -buffer[1] = 0x09; -buffer[2] = 0x0a; -buffer[3] = 0x0b; -buffer[4] = 0x0c; -buffer[5] = 0x0d; -buffer[6] = 0x0e; -buffer[7] = 0x0f; - -/* - This is what we expect the variables to look like at this point (on - little-endian machines): - - uint8 | 0x08 | 0x09 | 0x0a | 0x0b | 0x0c | 0x0d | 0x0e | 0x0f | - uint16 | 0x0908 | 0x0b0a | 0x0d0c | 0x0f0e | - uint16slice --------------| 0x0b0a | 0x0d0c |-------------- - uint32 | 0x0b0a0908 | 0x0f0e0d0c | -*/ - -assert.equal(uint8[0], 0x08); -assert.equal(uint8[1], 0x09); -assert.equal(uint8[2], 0x0a); -assert.equal(uint8[3], 0x0b); -assert.equal(uint8[4], 0x0c); -assert.equal(uint8[5], 0x0d); -assert.equal(uint8[6], 0x0e); -assert.equal(uint8[7], 0x0f); - -// determine whether or not typed array values are stored little-endian first -// internally -var IS_LITTLE_ENDIAN = (new Uint16Array([0x1234])).buffer[0] === 0x34; - -if (IS_LITTLE_ENDIAN) { - assert.equal(uint16[0], 0x0908); - assert.equal(uint16[1], 0x0b0a); - assert.equal(uint16[2], 0x0d0c); - assert.equal(uint16[3], 0x0f0e); - - assert.equal(uint16slice[0], 0x0b0a); - assert.equal(uint16slice[1], 0x0d0c); - - assert.equal(uint32[0], 0x0b0a0908); - assert.equal(uint32[1], 0x0f0e0d0c); -} else { - assert.equal(uint16[0], 0x0809); - assert.equal(uint16[1], 0x0a0b); - assert.equal(uint16[2], 0x0c0d); - assert.equal(uint16[3], 0x0e0f); - - assert.equal(uint16slice[0], 0x0a0b); - assert.equal(uint16slice[1], 0x0c0d); - - assert.equal(uint32[0], 0x08090a0b); - assert.equal(uint32[1], 0x0c0d0e0f); -} - -// test .subarray(begin, end) -var sub = uint8.subarray(2, 4); - -assert.ok(sub instanceof Uint8Array); -assert.equal(sub[0], 0x0a); -assert.equal(sub[1], 0x0b); - -// modifications of a value in the subarray of `uint8` should propagate to -// the other views -sub[0] = 0x12; -sub[1] = 0x34; - -assert.equal(uint8[2], 0x12); -assert.equal(uint8[3], 0x34); - -// test .set(index, value), .set(arr, offset) and .get(index) -uint8.set(1, 0x09); -uint8.set([0x0a, 0x0b], 2); - -assert.equal(uint8.get(1), 0x09); -assert.equal(uint8.get(2), 0x0a); -assert.equal(uint8.get(3), 0x0b); - -// test clamped array -var uint8c = new Uint8ClampedArray(buffer); -uint8c[0] = -1; -uint8c[1] = 257; - -assert.equal(uint8c[0], 0); -assert.equal(uint8c[1], 255); - -uint8c.set(0, -10); -uint8c.set(1, 260); - -assert.equal(uint8c[0], 0); -assert.equal(uint8c[1], 255); - -(function() { - var numbers = []; - for (var i = 128; i <= 255; ++i) numbers.push(i); - var array = new Uint8Array(numbers); - var view = new DataView(array.buffer); - for (var i = 128; i <= 255; ++i) assert.equal(view.getInt8(i - 128), i - 256); -})(); - -assert.throws(function() { - var buf = new DataView(new ArrayBuffer(8)); - buf.getFloat64(0xffffffff, true); -}, /Index out of range/); - -assert.throws(function() { - var buf = new DataView(new ArrayBuffer(8)); - buf.setFloat64(0xffffffff, 0.0, true); -}, /Index out of range/); - -// DataView::setGeneric() default endianness regression test, -// see https://github.com/joyent/node/issues/4626 -(function() { - var buf = new Uint8Array(2); - var view = new DataView(buf.buffer); - view.setUint16(0, 1); - assert.equal(view.getUint16(0), 1); -})(); - -(function() { - // Typed array should make a copy of the buffer object, i.e. it's not shared. - var b = new Buffer([0]); - var a = new Uint8Array(b); - assert.notEqual(a.buffer, b); - assert.equal(a[0], 0); - assert.equal(b[0], 0); - a[0] = 1; - assert.equal(a[0], 1); - assert.equal(b[0], 0); - a[0] = 0; - b[0] = 1; - assert.equal(a[0], 0); - assert.equal(b[0], 1); -})(); - -(function() { - // Backing store should not be shared. - var a = new Uint8Array(1); - var b = new Uint8Array(a); - a[0] = 0; - b[0] = 1; - assert.equal(a[0], 0); - assert.equal(b[0], 1); - assert.notEqual(a, b.buffer); - assert.notEqual(a.buffer, b.buffer); -})(); - -(function() { - // Backing store should not be shared. - var a = new Uint8Array(2); - var b = new Uint16Array(a); - a[0] = 0; - a[1] = 0; - b[0] = 257; - assert.equal(a[0], 0); - assert.equal(a[1], 0); - assert.equal(b[0], 257); - assert.notEqual(a, b.buffer); - assert.notEqual(a.buffer, b.buffer); -})(); - -(function() { - // Backing store should be shared. - var abuf = new ArrayBuffer(32); - var a = new Uint8Array(abuf); - var b = new Uint8Array(abuf); - a[0] = 0; - b[0] = 1; - assert.equal(a[0], 1); - assert.equal(b[0], 1); - assert.equal(a.buffer, b.buffer); -})(); - -assert.throws(function() { - new DataView(new Int8Array(1)); -}); diff --git a/test/simple/test-umask.js b/test/simple/test-umask.js deleted file mode 100644 index a41c46b55f94..000000000000 --- a/test/simple/test-umask.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// Note in Windows one can only set the "user" bits. -var mask; -if (process.platform == 'win32') { - mask = '0600'; -} else { - mask = '0664'; -} - -var old = process.umask(mask); - -assert.equal(parseInt(mask, 8), process.umask(old)); - -// confirm reading the umask does not modify it. -// 1. If the test fails, this call will succeed, but the mask will be set to 0 -assert.equal(old, process.umask()); -// 2. If the test fails, process.umask() will return 0 -assert.equal(old, process.umask()); diff --git a/test/simple/test-url.js b/test/simple/test-url.js deleted file mode 100644 index 95f50a23c396..000000000000 --- a/test/simple/test-url.js +++ /dev/null @@ -1,1485 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var url = require('url'), - util = require('util'); - -// URLs to parse, and expected data -// { url : parsed } -var parseTests = { - '//some_path' : { - 'href': '//some_path', - 'pathname': '//some_path', - 'path': '//some_path' - }, - - 'http:\\\\evil-phisher\\foo.html#h\\a\\s\\h': { - protocol: 'http:', - slashes: true, - host: 'evil-phisher', - hostname: 'evil-phisher', - pathname: '/foo.html', - path: '/foo.html', - hash: '#h\\a\\s\\h', - href: 'http://evil-phisher/foo.html#h\\a\\s\\h' - }, - - - 'http:\\\\evil-phisher\\foo.html': { - protocol: 'http:', - slashes: true, - host: 'evil-phisher', - hostname: 'evil-phisher', - pathname: '/foo.html', - path: '/foo.html', - href: 'http://evil-phisher/foo.html' - }, - - 'HTTP://www.example.com/' : { - 'href': 'http://www.example.com/', - 'protocol': 'http:', - 'slashes': true, - 'host': 'www.example.com', - 'hostname': 'www.example.com', - 'pathname': '/', - 'path': '/' - }, - - 'HTTP://www.example.com' : { - 'href': 'http://www.example.com/', - 'protocol': 'http:', - 'slashes': true, - 'host': 'www.example.com', - 'hostname': 'www.example.com', - 'pathname': '/', - 'path': '/' - }, - - 'http://www.ExAmPlE.com/' : { - 'href': 'http://www.example.com/', - 'protocol': 'http:', - 'slashes': true, - 'host': 'www.example.com', - 'hostname': 'www.example.com', - 'pathname': '/', - 'path': '/' - }, - - 'http://user:pw@www.ExAmPlE.com/' : { - 'href': 'http://user:pw@www.example.com/', - 'protocol': 'http:', - 'slashes': true, - 'auth': 'user:pw', - 'host': 'www.example.com', - 'hostname': 'www.example.com', - 'pathname': '/', - 'path': '/' - }, - - 'http://USER:PW@www.ExAmPlE.com/' : { - 'href': 'http://USER:PW@www.example.com/', - 'protocol': 'http:', - 'slashes': true, - 'auth': 'USER:PW', - 'host': 'www.example.com', - 'hostname': 'www.example.com', - 'pathname': '/', - 'path': '/' - }, - - 'http://user@www.example.com/' : { - 'href': 'http://user@www.example.com/', - 'protocol': 'http:', - 'slashes': true, - 'auth': 'user', - 'host': 'www.example.com', - 'hostname': 'www.example.com', - 'pathname': '/', - 'path': '/' - }, - - 'http://user%3Apw@www.example.com/' : { - 'href': 'http://user:pw@www.example.com/', - 'protocol': 'http:', - 'slashes': true, - 'auth': 'user:pw', - 'host': 'www.example.com', - 'hostname': 'www.example.com', - 'pathname': '/', - 'path': '/' - }, - - 'http://x.com/path?that\'s#all, folks' : { - 'href': 'http://x.com/path?that%27s#all,%20folks', - 'protocol': 'http:', - 'slashes': true, - 'host': 'x.com', - 'hostname': 'x.com', - 'search': '?that%27s', - 'query': 'that%27s', - 'pathname': '/path', - 'hash': '#all,%20folks', - 'path': '/path?that%27s' - }, - - 'HTTP://X.COM/Y' : { - 'href': 'http://x.com/Y', - 'protocol': 'http:', - 'slashes': true, - 'host': 'x.com', - 'hostname': 'x.com', - 'pathname': '/Y', - 'path': '/Y' - }, - - // an unexpected invalid char in the hostname. - 'HtTp://x.y.cOm*a/b/c?d=e#f gi' : { - 'href': 'http://x.y.com/*a/b/c?d=e#f%20g%3Ch%3Ei', - 'protocol': 'http:', - 'slashes': true, - 'host': 'x.y.com', - 'hostname': 'x.y.com', - 'pathname': '/*a/b/c', - 'search': '?d=e', - 'query': 'd=e', - 'hash': '#f%20g%3Ch%3Ei', - 'path': '/*a/b/c?d=e' - }, - - // make sure that we don't accidentally lcast the path parts. - 'HtTp://x.y.cOm*A/b/c?d=e#f gi' : { - 'href': 'http://x.y.com/*A/b/c?d=e#f%20g%3Ch%3Ei', - 'protocol': 'http:', - 'slashes': true, - 'host': 'x.y.com', - 'hostname': 'x.y.com', - 'pathname': '/*A/b/c', - 'search': '?d=e', - 'query': 'd=e', - 'hash': '#f%20g%3Ch%3Ei', - 'path': '/*A/b/c?d=e' - }, - - 'http://x...y...#p': { - 'href': 'http://x...y.../#p', - 'protocol': 'http:', - 'slashes': true, - 'host': 'x...y...', - 'hostname': 'x...y...', - 'hash': '#p', - 'pathname': '/', - 'path': '/' - }, - - 'http://x/p/"quoted"': { - 'href': 'http://x/p/%22quoted%22', - 'protocol': 'http:', - 'slashes': true, - 'host': 'x', - 'hostname': 'x', - 'pathname': '/p/%22quoted%22', - 'path': '/p/%22quoted%22' - }, - - ' Is a URL!': { - 'href': '%3Chttp://goo.corn/bread%3E%20Is%20a%20URL!', - 'pathname': '%3Chttp://goo.corn/bread%3E%20Is%20a%20URL!', - 'path': '%3Chttp://goo.corn/bread%3E%20Is%20a%20URL!' - }, - - 'http://www.narwhaljs.org/blog/categories?id=news' : { - 'href': 'http://www.narwhaljs.org/blog/categories?id=news', - 'protocol': 'http:', - 'slashes': true, - 'host': 'www.narwhaljs.org', - 'hostname': 'www.narwhaljs.org', - 'search': '?id=news', - 'query': 'id=news', - 'pathname': '/blog/categories', - 'path': '/blog/categories?id=news' - }, - - 'http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=' : { - 'href': 'http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=', - 'protocol': 'http:', - 'slashes': true, - 'host': 'mt0.google.com', - 'hostname': 'mt0.google.com', - 'pathname': '/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=', - 'path': '/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=' - }, - - 'http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=' : { - 'href': 'http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api' + - '&x=2&y=2&z=3&s=', - 'protocol': 'http:', - 'slashes': true, - 'host': 'mt0.google.com', - 'hostname': 'mt0.google.com', - 'search': '???&hl=en&src=api&x=2&y=2&z=3&s=', - 'query': '??&hl=en&src=api&x=2&y=2&z=3&s=', - 'pathname': '/vt/lyrs=m@114', - 'path': '/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=' - }, - - 'http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=': - { - 'href': 'http://user:pass@mt0.google.com/vt/lyrs=m@114???' + - '&hl=en&src=api&x=2&y=2&z=3&s=', - 'protocol': 'http:', - 'slashes': true, - 'host': 'mt0.google.com', - 'auth': 'user:pass', - 'hostname': 'mt0.google.com', - 'search': '???&hl=en&src=api&x=2&y=2&z=3&s=', - 'query': '??&hl=en&src=api&x=2&y=2&z=3&s=', - 'pathname': '/vt/lyrs=m@114', - 'path': '/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=' - }, - - 'file:///etc/passwd' : { - 'href': 'file:///etc/passwd', - 'slashes': true, - 'protocol': 'file:', - 'pathname': '/etc/passwd', - 'hostname': '', - 'host': '', - 'path': '/etc/passwd' - }, - - 'file://localhost/etc/passwd' : { - 'href': 'file://localhost/etc/passwd', - 'protocol': 'file:', - 'slashes': true, - 'pathname': '/etc/passwd', - 'hostname': 'localhost', - 'host': 'localhost', - 'path': '/etc/passwd' - }, - - 'file://foo/etc/passwd' : { - 'href': 'file://foo/etc/passwd', - 'protocol': 'file:', - 'slashes': true, - 'pathname': '/etc/passwd', - 'hostname': 'foo', - 'host': 'foo', - 'path': '/etc/passwd' - }, - - 'file:///etc/node/' : { - 'href': 'file:///etc/node/', - 'slashes': true, - 'protocol': 'file:', - 'pathname': '/etc/node/', - 'hostname': '', - 'host': '', - 'path': '/etc/node/' - }, - - 'file://localhost/etc/node/' : { - 'href': 'file://localhost/etc/node/', - 'protocol': 'file:', - 'slashes': true, - 'pathname': '/etc/node/', - 'hostname': 'localhost', - 'host': 'localhost', - 'path': '/etc/node/' - }, - - 'file://foo/etc/node/' : { - 'href': 'file://foo/etc/node/', - 'protocol': 'file:', - 'slashes': true, - 'pathname': '/etc/node/', - 'hostname': 'foo', - 'host': 'foo', - 'path': '/etc/node/' - }, - - 'http:/baz/../foo/bar' : { - 'href': 'http:/baz/../foo/bar', - 'protocol': 'http:', - 'pathname': '/baz/../foo/bar', - 'path': '/baz/../foo/bar' - }, - - 'http://user:pass@example.com:8000/foo/bar?baz=quux#frag' : { - 'href': 'http://user:pass@example.com:8000/foo/bar?baz=quux#frag', - 'protocol': 'http:', - 'slashes': true, - 'host': 'example.com:8000', - 'auth': 'user:pass', - 'port': '8000', - 'hostname': 'example.com', - 'hash': '#frag', - 'search': '?baz=quux', - 'query': 'baz=quux', - 'pathname': '/foo/bar', - 'path': '/foo/bar?baz=quux' - }, - - '//user:pass@example.com:8000/foo/bar?baz=quux#frag' : { - 'href': '//user:pass@example.com:8000/foo/bar?baz=quux#frag', - 'slashes': true, - 'host': 'example.com:8000', - 'auth': 'user:pass', - 'port': '8000', - 'hostname': 'example.com', - 'hash': '#frag', - 'search': '?baz=quux', - 'query': 'baz=quux', - 'pathname': '/foo/bar', - 'path': '/foo/bar?baz=quux' - }, - - '/foo/bar?baz=quux#frag' : { - 'href': '/foo/bar?baz=quux#frag', - 'hash': '#frag', - 'search': '?baz=quux', - 'query': 'baz=quux', - 'pathname': '/foo/bar', - 'path': '/foo/bar?baz=quux' - }, - - 'http:/foo/bar?baz=quux#frag' : { - 'href': 'http:/foo/bar?baz=quux#frag', - 'protocol': 'http:', - 'hash': '#frag', - 'search': '?baz=quux', - 'query': 'baz=quux', - 'pathname': '/foo/bar', - 'path': '/foo/bar?baz=quux' - }, - - 'mailto:foo@bar.com?subject=hello' : { - 'href': 'mailto:foo@bar.com?subject=hello', - 'protocol': 'mailto:', - 'host': 'bar.com', - 'auth' : 'foo', - 'hostname' : 'bar.com', - 'search': '?subject=hello', - 'query': 'subject=hello', - 'path': '?subject=hello' - }, - - 'javascript:alert(\'hello\');' : { - 'href': 'javascript:alert(\'hello\');', - 'protocol': 'javascript:', - 'pathname': 'alert(\'hello\');', - 'path': 'alert(\'hello\');' - }, - - 'xmpp:isaacschlueter@jabber.org' : { - 'href': 'xmpp:isaacschlueter@jabber.org', - 'protocol': 'xmpp:', - 'host': 'jabber.org', - 'auth': 'isaacschlueter', - 'hostname': 'jabber.org' - }, - - 'http://atpass:foo%40bar@127.0.0.1:8080/path?search=foo#bar' : { - 'href' : 'http://atpass:foo%40bar@127.0.0.1:8080/path?search=foo#bar', - 'protocol' : 'http:', - 'slashes': true, - 'host' : '127.0.0.1:8080', - 'auth' : 'atpass:foo@bar', - 'hostname' : '127.0.0.1', - 'port' : '8080', - 'pathname': '/path', - 'search' : '?search=foo', - 'query' : 'search=foo', - 'hash' : '#bar', - 'path': '/path?search=foo' - }, - - 'svn+ssh://foo/bar': { - 'href': 'svn+ssh://foo/bar', - 'host': 'foo', - 'hostname': 'foo', - 'protocol': 'svn+ssh:', - 'pathname': '/bar', - 'path': '/bar', - 'slashes': true - }, - - 'dash-test://foo/bar': { - 'href': 'dash-test://foo/bar', - 'host': 'foo', - 'hostname': 'foo', - 'protocol': 'dash-test:', - 'pathname': '/bar', - 'path': '/bar', - 'slashes': true - }, - - 'dash-test:foo/bar': { - 'href': 'dash-test:foo/bar', - 'host': 'foo', - 'hostname': 'foo', - 'protocol': 'dash-test:', - 'pathname': '/bar', - 'path': '/bar' - }, - - 'dot.test://foo/bar': { - 'href': 'dot.test://foo/bar', - 'host': 'foo', - 'hostname': 'foo', - 'protocol': 'dot.test:', - 'pathname': '/bar', - 'path': '/bar', - 'slashes': true - }, - - 'dot.test:foo/bar': { - 'href': 'dot.test:foo/bar', - 'host': 'foo', - 'hostname': 'foo', - 'protocol': 'dot.test:', - 'pathname': '/bar', - 'path': '/bar' - }, - - // IDNA tests - 'http://www.日本語.com/' : { - 'href': 'http://www.xn--wgv71a119e.com/', - 'protocol': 'http:', - 'slashes': true, - 'host': 'www.xn--wgv71a119e.com', - 'hostname': 'www.xn--wgv71a119e.com', - 'pathname': '/', - 'path': '/' - }, - - 'http://example.Bücher.com/' : { - 'href': 'http://example.xn--bcher-kva.com/', - 'protocol': 'http:', - 'slashes': true, - 'host': 'example.xn--bcher-kva.com', - 'hostname': 'example.xn--bcher-kva.com', - 'pathname': '/', - 'path': '/' - }, - - 'http://www.Äffchen.com/' : { - 'href': 'http://www.xn--ffchen-9ta.com/', - 'protocol': 'http:', - 'slashes': true, - 'host': 'www.xn--ffchen-9ta.com', - 'hostname': 'www.xn--ffchen-9ta.com', - 'pathname': '/', - 'path': '/' - }, - - 'http://www.Äffchen.cOm*A/b/c?d=e#f gi' : { - 'href': 'http://www.xn--ffchen-9ta.com/*A/b/c?d=e#f%20g%3Ch%3Ei', - 'protocol': 'http:', - 'slashes': true, - 'host': 'www.xn--ffchen-9ta.com', - 'hostname': 'www.xn--ffchen-9ta.com', - 'pathname': '/*A/b/c', - 'search': '?d=e', - 'query': 'd=e', - 'hash': '#f%20g%3Ch%3Ei', - 'path': '/*A/b/c?d=e' - }, - - 'http://SÉLIER.COM/' : { - 'href': 'http://xn--slier-bsa.com/', - 'protocol': 'http:', - 'slashes': true, - 'host': 'xn--slier-bsa.com', - 'hostname': 'xn--slier-bsa.com', - 'pathname': '/', - 'path': '/' - }, - - 'http://ليهمابتكلموشعربي؟.ي؟/' : { - 'href': 'http://xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f/', - 'protocol': 'http:', - 'slashes': true, - 'host': 'xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f', - 'hostname': 'xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f', - 'pathname': '/', - 'path': '/' - }, - - 'http://➡.ws/➡' : { - 'href': 'http://xn--hgi.ws/➡', - 'protocol': 'http:', - 'slashes': true, - 'host': 'xn--hgi.ws', - 'hostname': 'xn--hgi.ws', - 'pathname': '/➡', - 'path': '/➡' - }, - - 'http://bucket_name.s3.amazonaws.com/image.jpg': { - protocol: 'http:', - 'slashes': true, - slashes: true, - host: 'bucket_name.s3.amazonaws.com', - hostname: 'bucket_name.s3.amazonaws.com', - pathname: '/image.jpg', - href: 'http://bucket_name.s3.amazonaws.com/image.jpg', - 'path': '/image.jpg' - }, - - 'git+http://github.com/joyent/node.git': { - protocol: 'git+http:', - slashes: true, - host: 'github.com', - hostname: 'github.com', - pathname: '/joyent/node.git', - path: '/joyent/node.git', - href: 'git+http://github.com/joyent/node.git' - }, - - //if local1@domain1 is uses as a relative URL it may - //be parse into auth@hostname, but here there is no - //way to make it work in url.parse, I add the test to be explicit - 'local1@domain1': { - 'pathname': 'local1@domain1', - 'path': 'local1@domain1', - 'href': 'local1@domain1' - }, - - //While this may seem counter-intuitive, a browser will parse - // as a path. - 'www.example.com' : { - 'href': 'www.example.com', - 'pathname': 'www.example.com', - 'path': 'www.example.com' - }, - - // ipv6 support - '[fe80::1]': { - 'href': '[fe80::1]', - 'pathname': '[fe80::1]', - 'path': '[fe80::1]' - }, - - 'coap://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]': { - 'protocol': 'coap:', - 'slashes': true, - 'host': '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]', - 'hostname': 'fedc:ba98:7654:3210:fedc:ba98:7654:3210', - 'href': 'coap://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/', - 'pathname': '/', - 'path': '/' - }, - - 'coap://[1080:0:0:0:8:800:200C:417A]:61616/': { - 'protocol': 'coap:', - 'slashes': true, - 'host': '[1080:0:0:0:8:800:200c:417a]:61616', - 'port': '61616', - 'hostname': '1080:0:0:0:8:800:200c:417a', - 'href': 'coap://[1080:0:0:0:8:800:200c:417a]:61616/', - 'pathname': '/', - 'path': '/' - }, - - 'http://user:password@[3ffe:2a00:100:7031::1]:8080': { - 'protocol': 'http:', - 'slashes': true, - 'auth': 'user:password', - 'host': '[3ffe:2a00:100:7031::1]:8080', - 'port': '8080', - 'hostname': '3ffe:2a00:100:7031::1', - 'href': 'http://user:password@[3ffe:2a00:100:7031::1]:8080/', - 'pathname': '/', - 'path': '/' - }, - - 'coap://u:p@[::192.9.5.5]:61616/.well-known/r?n=Temperature': { - 'protocol': 'coap:', - 'slashes': true, - 'auth': 'u:p', - 'host': '[::192.9.5.5]:61616', - 'port': '61616', - 'hostname': '::192.9.5.5', - 'href': 'coap://u:p@[::192.9.5.5]:61616/.well-known/r?n=Temperature', - 'search': '?n=Temperature', - 'query': 'n=Temperature', - 'pathname': '/.well-known/r', - 'path': '/.well-known/r?n=Temperature' - }, - - // empty port - 'http://example.com:': { - 'protocol': 'http:', - 'slashes': true, - 'host': 'example.com', - 'hostname': 'example.com', - 'href': 'http://example.com/', - 'pathname': '/', - 'path': '/' - }, - - 'http://example.com:/a/b.html': { - 'protocol': 'http:', - 'slashes': true, - 'host': 'example.com', - 'hostname': 'example.com', - 'href': 'http://example.com/a/b.html', - 'pathname': '/a/b.html', - 'path': '/a/b.html' - }, - - 'http://example.com:?a=b': { - 'protocol': 'http:', - 'slashes': true, - 'host': 'example.com', - 'hostname': 'example.com', - 'href': 'http://example.com/?a=b', - 'search': '?a=b', - 'query': 'a=b', - 'pathname': '/', - 'path': '/?a=b' - }, - - 'http://example.com:#abc': { - 'protocol': 'http:', - 'slashes': true, - 'host': 'example.com', - 'hostname': 'example.com', - 'href': 'http://example.com/#abc', - 'hash': '#abc', - 'pathname': '/', - 'path': '/' - }, - - 'http://[fe80::1]:/a/b?a=b#abc': { - 'protocol': 'http:', - 'slashes': true, - 'host': '[fe80::1]', - 'hostname': 'fe80::1', - 'href': 'http://[fe80::1]/a/b?a=b#abc', - 'search': '?a=b', - 'query': 'a=b', - 'hash': '#abc', - 'pathname': '/a/b', - 'path': '/a/b?a=b' - }, - - 'http://-lovemonsterz.tumblr.com/rss': { - 'protocol': 'http:', - 'slashes': true, - 'host': '-lovemonsterz.tumblr.com', - 'hostname': '-lovemonsterz.tumblr.com', - 'href': 'http://-lovemonsterz.tumblr.com/rss', - 'pathname': '/rss', - 'path': '/rss', - }, - - 'http://-lovemonsterz.tumblr.com:80/rss': { - 'protocol': 'http:', - 'slashes': true, - 'port': '80', - 'host': '-lovemonsterz.tumblr.com:80', - 'hostname': '-lovemonsterz.tumblr.com', - 'href': 'http://-lovemonsterz.tumblr.com:80/rss', - 'pathname': '/rss', - 'path': '/rss', - }, - - 'http://user:pass@-lovemonsterz.tumblr.com/rss': { - 'protocol': 'http:', - 'slashes': true, - 'auth': 'user:pass', - 'host': '-lovemonsterz.tumblr.com', - 'hostname': '-lovemonsterz.tumblr.com', - 'href': 'http://user:pass@-lovemonsterz.tumblr.com/rss', - 'pathname': '/rss', - 'path': '/rss', - }, - - 'http://user:pass@-lovemonsterz.tumblr.com:80/rss': { - 'protocol': 'http:', - 'slashes': true, - 'auth': 'user:pass', - 'port': '80', - 'host': '-lovemonsterz.tumblr.com:80', - 'hostname': '-lovemonsterz.tumblr.com', - 'href': 'http://user:pass@-lovemonsterz.tumblr.com:80/rss', - 'pathname': '/rss', - 'path': '/rss', - }, - - 'http://_jabber._tcp.google.com/test': { - 'protocol': 'http:', - 'slashes': true, - 'host': '_jabber._tcp.google.com', - 'hostname': '_jabber._tcp.google.com', - 'href': 'http://_jabber._tcp.google.com/test', - 'pathname': '/test', - 'path': '/test', - }, - - 'http://user:pass@_jabber._tcp.google.com/test': { - 'protocol': 'http:', - 'slashes': true, - 'auth': 'user:pass', - 'host': '_jabber._tcp.google.com', - 'hostname': '_jabber._tcp.google.com', - 'href': 'http://user:pass@_jabber._tcp.google.com/test', - 'pathname': '/test', - 'path': '/test', - }, - - 'http://_jabber._tcp.google.com:80/test': { - 'protocol': 'http:', - 'slashes': true, - 'port': '80', - 'host': '_jabber._tcp.google.com:80', - 'hostname': '_jabber._tcp.google.com', - 'href': 'http://_jabber._tcp.google.com:80/test', - 'pathname': '/test', - 'path': '/test', - }, - - 'http://user:pass@_jabber._tcp.google.com:80/test': { - 'protocol': 'http:', - 'slashes': true, - 'auth': 'user:pass', - 'port': '80', - 'host': '_jabber._tcp.google.com:80', - 'hostname': '_jabber._tcp.google.com', - 'href': 'http://user:pass@_jabber._tcp.google.com:80/test', - 'pathname': '/test', - 'path': '/test', - }, - - 'http://a@b@c/': { - protocol: 'http:', - slashes: true, - auth: 'a@b', - host: 'c', - hostname: 'c', - href: 'http://a%40b@c/', - path: '/', - pathname: '/' - }, - - 'http://a@b?@c': { - protocol: 'http:', - slashes: true, - auth: 'a', - host: 'b', - hostname: 'b', - href: 'http://a@b/?@c', - path: '/?@c', - pathname: '/', - search: '?@c', - query: '@c' - }, - - 'http://a\r" \t\n<\'b:b@c\r\nd/e?f':{ - protocol: 'http:', - slashes: true, - auth: 'a\r" \t\n<\'b:b', - host: 'c', - port: null, - hostname: 'c', - hash: null, - search: '?f', - query: 'f', - pathname: '%0D%0Ad/e', - path: '%0D%0Ad/e?f', - href: 'http://a%0D%22%20%09%0A%3C\'b:b@c/%0D%0Ad/e?f' - } - -}; - -for (var u in parseTests) { - var actual = url.parse(u), - spaced = url.parse(' \t ' + u + '\n\t'); - expected = parseTests[u]; - - Object.keys(actual).forEach(function (i) { - if (expected[i] === undefined && actual[i] === null) { - expected[i] = null; - } - }); - - assert.deepEqual(actual, expected); - assert.deepEqual(spaced, expected); - - var expected = parseTests[u].href, - actual = url.format(parseTests[u]); - - assert.equal(actual, expected, - 'format(' + u + ') == ' + u + '\nactual:' + actual); -} - -var parseTestsWithQueryString = { - '/foo/bar?baz=quux#frag' : { - 'href': '/foo/bar?baz=quux#frag', - 'hash': '#frag', - 'search': '?baz=quux', - 'query': { - 'baz': 'quux' - }, - 'pathname': '/foo/bar', - 'path': '/foo/bar?baz=quux' - }, - 'http://example.com' : { - 'href': 'http://example.com/', - 'protocol': 'http:', - 'slashes': true, - 'host': 'example.com', - 'hostname': 'example.com', - 'query': {}, - 'search': '', - 'pathname': '/', - 'path': '/' - } -}; -for (var u in parseTestsWithQueryString) { - var actual = url.parse(u, true); - var expected = parseTestsWithQueryString[u]; - for (var i in actual) { - if (actual[i] === null && expected[i] === undefined) { - expected[i] = null; - } - } - - assert.deepEqual(actual, expected); -} - -// some extra formatting tests, just to verify -// that it'll format slightly wonky content to a valid url. -var formatTests = { - 'http://example.com?' : { - 'href': 'http://example.com/?', - 'protocol': 'http:', - 'slashes': true, - 'host': 'example.com', - 'hostname': 'example.com', - 'search': '?', - 'query': {}, - 'pathname': '/' - }, - 'http://example.com?foo=bar#frag' : { - 'href': 'http://example.com/?foo=bar#frag', - 'protocol': 'http:', - 'host': 'example.com', - 'hostname': 'example.com', - 'hash': '#frag', - 'search': '?foo=bar', - 'query': 'foo=bar', - 'pathname': '/' - }, - 'http://example.com?foo=@bar#frag' : { - 'href': 'http://example.com/?foo=@bar#frag', - 'protocol': 'http:', - 'host': 'example.com', - 'hostname': 'example.com', - 'hash': '#frag', - 'search': '?foo=@bar', - 'query': 'foo=@bar', - 'pathname': '/' - }, - 'http://example.com?foo=/bar/#frag' : { - 'href': 'http://example.com/?foo=/bar/#frag', - 'protocol': 'http:', - 'host': 'example.com', - 'hostname': 'example.com', - 'hash': '#frag', - 'search': '?foo=/bar/', - 'query': 'foo=/bar/', - 'pathname': '/' - }, - 'http://example.com?foo=?bar/#frag' : { - 'href': 'http://example.com/?foo=?bar/#frag', - 'protocol': 'http:', - 'host': 'example.com', - 'hostname': 'example.com', - 'hash': '#frag', - 'search': '?foo=?bar/', - 'query': 'foo=?bar/', - 'pathname': '/' - }, - 'http://example.com#frag=?bar/#frag' : { - 'href': 'http://example.com/#frag=?bar/#frag', - 'protocol': 'http:', - 'host': 'example.com', - 'hostname': 'example.com', - 'hash': '#frag=?bar/#frag', - 'pathname': '/' - }, - 'http://google.com" onload="alert(42)/' : { - 'href': 'http://google.com/%22%20onload=%22alert(42)/', - 'protocol': 'http:', - 'host': 'google.com', - 'pathname': '/%22%20onload=%22alert(42)/' - }, - 'http://a.com/a/b/c?s#h' : { - 'href': 'http://a.com/a/b/c?s#h', - 'protocol': 'http', - 'host': 'a.com', - 'pathname': 'a/b/c', - 'hash': 'h', - 'search': 's' - }, - 'xmpp:isaacschlueter@jabber.org' : { - 'href': 'xmpp:isaacschlueter@jabber.org', - 'protocol': 'xmpp:', - 'host': 'jabber.org', - 'auth': 'isaacschlueter', - 'hostname': 'jabber.org' - }, - 'http://atpass:foo%40bar@127.0.0.1/' : { - 'href': 'http://atpass:foo%40bar@127.0.0.1/', - 'auth': 'atpass:foo@bar', - 'hostname': '127.0.0.1', - 'protocol': 'http:', - 'pathname': '/' - }, - 'http://atslash%2F%40:%2F%40@foo/' : { - 'href': 'http://atslash%2F%40:%2F%40@foo/', - 'auth': 'atslash/@:/@', - 'hostname': 'foo', - 'protocol': 'http:', - 'pathname': '/' - }, - 'svn+ssh://foo/bar': { - 'href': 'svn+ssh://foo/bar', - 'hostname': 'foo', - 'protocol': 'svn+ssh:', - 'pathname': '/bar', - 'slashes': true - }, - 'dash-test://foo/bar': { - 'href': 'dash-test://foo/bar', - 'hostname': 'foo', - 'protocol': 'dash-test:', - 'pathname': '/bar', - 'slashes': true - }, - 'dash-test:foo/bar': { - 'href': 'dash-test:foo/bar', - 'hostname': 'foo', - 'protocol': 'dash-test:', - 'pathname': '/bar' - }, - 'dot.test://foo/bar': { - 'href': 'dot.test://foo/bar', - 'hostname': 'foo', - 'protocol': 'dot.test:', - 'pathname': '/bar', - 'slashes': true - }, - 'dot.test:foo/bar': { - 'href': 'dot.test:foo/bar', - 'hostname': 'foo', - 'protocol': 'dot.test:', - 'pathname': '/bar' - }, - // ipv6 support - 'coap:u:p@[::1]:61616/.well-known/r?n=Temperature': { - 'href': 'coap:u:p@[::1]:61616/.well-known/r?n=Temperature', - 'protocol': 'coap:', - 'auth': 'u:p', - 'hostname': '::1', - 'port': '61616', - 'pathname': '/.well-known/r', - 'search': 'n=Temperature' - }, - 'coap:[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616/s/stopButton': { - 'href': 'coap:[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616/s/stopButton', - 'protocol': 'coap', - 'host': '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616', - 'pathname': '/s/stopButton' - }, - - // encode context-specific delimiters in path and query, but do not touch - // other non-delimiter chars like `%`. - // - - // `#`,`?` in path - '/path/to/%%23%3F+=&.txt?foo=theA1#bar' : { - href : '/path/to/%%23%3F+=&.txt?foo=theA1#bar', - pathname: '/path/to/%#?+=&.txt', - query: { - foo: 'theA1' - }, - hash: "#bar" - }, - - // `#`,`?` in path + `#` in query - '/path/to/%%23%3F+=&.txt?foo=the%231#bar' : { - href : '/path/to/%%23%3F+=&.txt?foo=the%231#bar', - pathname: '/path/to/%#?+=&.txt', - query: { - foo: 'the#1' - }, - hash: "#bar" - }, - - // `?` and `#` in path and search - 'http://ex.com/foo%3F100%m%23r?abc=the%231?&foo=bar#frag': { - href: 'http://ex.com/foo%3F100%m%23r?abc=the%231?&foo=bar#frag', - protocol: 'http:', - hostname: 'ex.com', - hash: '#frag', - search: '?abc=the#1?&foo=bar', - pathname: '/foo?100%m#r', - }, - - // `?` and `#` in search only - 'http://ex.com/fooA100%mBr?abc=the%231?&foo=bar#frag': { - href: 'http://ex.com/fooA100%mBr?abc=the%231?&foo=bar#frag', - protocol: 'http:', - hostname: 'ex.com', - hash: '#frag', - search: '?abc=the#1?&foo=bar', - pathname: '/fooA100%mBr', - } -}; -for (var u in formatTests) { - var expect = formatTests[u].href; - delete formatTests[u].href; - var actual = url.format(u); - var actualObj = url.format(formatTests[u]); - assert.equal(actual, expect, - 'wonky format(' + u + ') == ' + expect + - '\nactual:' + actual); - assert.equal(actualObj, expect, - 'wonky format(' + JSON.stringify(formatTests[u]) + - ') == ' + expect + - '\nactual: ' + actualObj); -} - -/* - [from, path, expected] -*/ -var relativeTests = [ - ['/foo/bar/baz', 'quux', '/foo/bar/quux'], - ['/foo/bar/baz', 'quux/asdf', '/foo/bar/quux/asdf'], - ['/foo/bar/baz', 'quux/baz', '/foo/bar/quux/baz'], - ['/foo/bar/baz', '../quux/baz', '/foo/quux/baz'], - ['/foo/bar/baz', '/bar', '/bar'], - ['/foo/bar/baz/', 'quux', '/foo/bar/baz/quux'], - ['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'], - ['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'], - ['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'], - ['foo/bar', '../../../baz', '../../baz'], - ['foo/bar/', '../../../baz', '../baz'], - ['http://example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'], - ['http://example.com/b//c//d;p?q#blarg', - 'https:/p/a/t/h?s#hash2', - 'https://p/a/t/h?s#hash2'], - ['http://example.com/b//c//d;p?q#blarg', - 'https://u:p@h.com/p/a/t/h?s#hash2', - 'https://u:p@h.com/p/a/t/h?s#hash2'], - ['http://example.com/b//c//d;p?q#blarg', - 'https:/a/b/c/d', - 'https://a/b/c/d'], - ['http://example.com/b//c//d;p?q#blarg', - 'http:#hash2', - 'http://example.com/b//c//d;p?q#hash2'], - ['http://example.com/b//c//d;p?q#blarg', - 'http:/p/a/t/h?s#hash2', - 'http://example.com/p/a/t/h?s#hash2'], - ['http://example.com/b//c//d;p?q#blarg', - 'http://u:p@h.com/p/a/t/h?s#hash2', - 'http://u:p@h.com/p/a/t/h?s#hash2'], - ['http://example.com/b//c//d;p?q#blarg', - 'http:/a/b/c/d', - 'http://example.com/a/b/c/d'], - ['/foo/bar/baz', '/../etc/passwd', '/etc/passwd'] -]; -relativeTests.forEach(function(relativeTest) { - var a = url.resolve(relativeTest[0], relativeTest[1]), - e = relativeTest[2]; - assert.equal(a, e, - 'resolve(' + [relativeTest[0], relativeTest[1]] + ') == ' + e + - '\n actual=' + a); -}); - - -// https://github.com/joyent/node/issues/568 -[ - undefined, - null, - true, - false, - 0.0, - 0, - [], - {} -].forEach(function(val) { - assert.throws(function() { url.parse(val); }, TypeError); -}); - - -// -// Tests below taken from Chiron -// http://code.google.com/p/chironjs/source/browse/trunk/src/test/http/url.js -// -// Copyright (c) 2002-2008 Kris Kowal -// used with permission under MIT License -// -// Changes marked with @isaacs - -var bases = [ - 'http://a/b/c/d;p?q', - 'http://a/b/c/d;p?q=1/2', - 'http://a/b/c/d;p=1/2?q', - 'fred:///s//a/b/c', - 'http:///s//a/b/c' -]; - -//[to, from, result] -var relativeTests2 = [ - // http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html - ['../c', 'foo:a/b', 'foo:c'], - ['foo:.', 'foo:a', 'foo:'], - ['/foo/../../../bar', 'zz:abc', 'zz:/bar'], - ['/foo/../bar', 'zz:abc', 'zz:/bar'], - // @isaacs Disagree. Not how web browsers resolve this. - ['foo/../../../bar', 'zz:abc', 'zz:bar'], - // ['foo/../../../bar', 'zz:abc', 'zz:../../bar'], // @isaacs Added - ['foo/../bar', 'zz:abc', 'zz:bar'], - ['zz:.', 'zz:abc', 'zz:'], - ['/.', bases[0], 'http://a/'], - ['/.foo', bases[0], 'http://a/.foo'], - ['.foo', bases[0], 'http://a/b/c/.foo'], - - // http://gbiv.com/protocols/uri/test/rel_examples1.html - // examples from RFC 2396 - ['g:h', bases[0], 'g:h'], - ['g', bases[0], 'http://a/b/c/g'], - ['./g', bases[0], 'http://a/b/c/g'], - ['g/', bases[0], 'http://a/b/c/g/'], - ['/g', bases[0], 'http://a/g'], - ['//g', bases[0], 'http://g/'], - // changed with RFC 2396bis - //('?y', bases[0], 'http://a/b/c/d;p?y'], - ['?y', bases[0], 'http://a/b/c/d;p?y'], - ['g?y', bases[0], 'http://a/b/c/g?y'], - // changed with RFC 2396bis - //('#s', bases[0], CURRENT_DOC_URI + '#s'], - ['#s', bases[0], 'http://a/b/c/d;p?q#s'], - ['g#s', bases[0], 'http://a/b/c/g#s'], - ['g?y#s', bases[0], 'http://a/b/c/g?y#s'], - [';x', bases[0], 'http://a/b/c/;x'], - ['g;x', bases[0], 'http://a/b/c/g;x'], - ['g;x?y#s' , bases[0], 'http://a/b/c/g;x?y#s'], - // changed with RFC 2396bis - //('', bases[0], CURRENT_DOC_URI], - ['', bases[0], 'http://a/b/c/d;p?q'], - ['.', bases[0], 'http://a/b/c/'], - ['./', bases[0], 'http://a/b/c/'], - ['..', bases[0], 'http://a/b/'], - ['../', bases[0], 'http://a/b/'], - ['../g', bases[0], 'http://a/b/g'], - ['../..', bases[0], 'http://a/'], - ['../../', bases[0], 'http://a/'], - ['../../g' , bases[0], 'http://a/g'], - ['../../../g', bases[0], ('http://a/../g', 'http://a/g')], - ['../../../../g', bases[0], ('http://a/../../g', 'http://a/g')], - // changed with RFC 2396bis - //('/./g', bases[0], 'http://a/./g'], - ['/./g', bases[0], 'http://a/g'], - // changed with RFC 2396bis - //('/../g', bases[0], 'http://a/../g'], - ['/../g', bases[0], 'http://a/g'], - ['g.', bases[0], 'http://a/b/c/g.'], - ['.g', bases[0], 'http://a/b/c/.g'], - ['g..', bases[0], 'http://a/b/c/g..'], - ['..g', bases[0], 'http://a/b/c/..g'], - ['./../g', bases[0], 'http://a/b/g'], - ['./g/.', bases[0], 'http://a/b/c/g/'], - ['g/./h', bases[0], 'http://a/b/c/g/h'], - ['g/../h', bases[0], 'http://a/b/c/h'], - ['g;x=1/./y', bases[0], 'http://a/b/c/g;x=1/y'], - ['g;x=1/../y', bases[0], 'http://a/b/c/y'], - ['g?y/./x', bases[0], 'http://a/b/c/g?y/./x'], - ['g?y/../x', bases[0], 'http://a/b/c/g?y/../x'], - ['g#s/./x', bases[0], 'http://a/b/c/g#s/./x'], - ['g#s/../x', bases[0], 'http://a/b/c/g#s/../x'], - ['http:g', bases[0], ('http:g', 'http://a/b/c/g')], - ['http:', bases[0], ('http:', bases[0])], - // not sure where this one originated - ['/a/b/c/./../../g', bases[0], 'http://a/a/g'], - - // http://gbiv.com/protocols/uri/test/rel_examples2.html - // slashes in base URI's query args - ['g', bases[1], 'http://a/b/c/g'], - ['./g', bases[1], 'http://a/b/c/g'], - ['g/', bases[1], 'http://a/b/c/g/'], - ['/g', bases[1], 'http://a/g'], - ['//g', bases[1], 'http://g/'], - // changed in RFC 2396bis - //('?y', bases[1], 'http://a/b/c/?y'], - ['?y', bases[1], 'http://a/b/c/d;p?y'], - ['g?y', bases[1], 'http://a/b/c/g?y'], - ['g?y/./x' , bases[1], 'http://a/b/c/g?y/./x'], - ['g?y/../x', bases[1], 'http://a/b/c/g?y/../x'], - ['g#s', bases[1], 'http://a/b/c/g#s'], - ['g#s/./x' , bases[1], 'http://a/b/c/g#s/./x'], - ['g#s/../x', bases[1], 'http://a/b/c/g#s/../x'], - ['./', bases[1], 'http://a/b/c/'], - ['../', bases[1], 'http://a/b/'], - ['../g', bases[1], 'http://a/b/g'], - ['../../', bases[1], 'http://a/'], - ['../../g' , bases[1], 'http://a/g'], - - // http://gbiv.com/protocols/uri/test/rel_examples3.html - // slashes in path params - // all of these changed in RFC 2396bis - ['g', bases[2], 'http://a/b/c/d;p=1/g'], - ['./g', bases[2], 'http://a/b/c/d;p=1/g'], - ['g/', bases[2], 'http://a/b/c/d;p=1/g/'], - ['g?y', bases[2], 'http://a/b/c/d;p=1/g?y'], - [';x', bases[2], 'http://a/b/c/d;p=1/;x'], - ['g;x', bases[2], 'http://a/b/c/d;p=1/g;x'], - ['g;x=1/./y', bases[2], 'http://a/b/c/d;p=1/g;x=1/y'], - ['g;x=1/../y', bases[2], 'http://a/b/c/d;p=1/y'], - ['./', bases[2], 'http://a/b/c/d;p=1/'], - ['../', bases[2], 'http://a/b/c/'], - ['../g', bases[2], 'http://a/b/c/g'], - ['../../', bases[2], 'http://a/b/'], - ['../../g' , bases[2], 'http://a/b/g'], - - // http://gbiv.com/protocols/uri/test/rel_examples4.html - // double and triple slash, unknown scheme - ['g:h', bases[3], 'g:h'], - ['g', bases[3], 'fred:///s//a/b/g'], - ['./g', bases[3], 'fred:///s//a/b/g'], - ['g/', bases[3], 'fred:///s//a/b/g/'], - ['/g', bases[3], 'fred:///g'], // may change to fred:///s//a/g - ['//g', bases[3], 'fred://g'], // may change to fred:///s//g - ['//g/x', bases[3], 'fred://g/x'], // may change to fred:///s//g/x - ['///g', bases[3], 'fred:///g'], - ['./', bases[3], 'fred:///s//a/b/'], - ['../', bases[3], 'fred:///s//a/'], - ['../g', bases[3], 'fred:///s//a/g'], - - ['../../', bases[3], 'fred:///s//'], - ['../../g' , bases[3], 'fred:///s//g'], - ['../../../g', bases[3], 'fred:///s/g'], - // may change to fred:///s//a/../../../g - ['../../../../g', bases[3], 'fred:///g'], - - // http://gbiv.com/protocols/uri/test/rel_examples5.html - // double and triple slash, well-known scheme - ['g:h', bases[4], 'g:h'], - ['g', bases[4], 'http:///s//a/b/g'], - ['./g', bases[4], 'http:///s//a/b/g'], - ['g/', bases[4], 'http:///s//a/b/g/'], - ['/g', bases[4], 'http:///g'], // may change to http:///s//a/g - ['//g', bases[4], 'http://g/'], // may change to http:///s//g - ['//g/x', bases[4], 'http://g/x'], // may change to http:///s//g/x - ['///g', bases[4], 'http:///g'], - ['./', bases[4], 'http:///s//a/b/'], - ['../', bases[4], 'http:///s//a/'], - ['../g', bases[4], 'http:///s//a/g'], - ['../../', bases[4], 'http:///s//'], - ['../../g' , bases[4], 'http:///s//g'], - // may change to http:///s//a/../../g - ['../../../g', bases[4], 'http:///s/g'], - // may change to http:///s//a/../../../g - ['../../../../g', bases[4], 'http:///g'], - - // from Dan Connelly's tests in http://www.w3.org/2000/10/swap/uripath.py - ['bar:abc', 'foo:xyz', 'bar:abc'], - ['../abc', 'http://example/x/y/z', 'http://example/x/abc'], - ['http://example/x/abc', 'http://example2/x/y/z', 'http://example/x/abc'], - ['../r', 'http://ex/x/y/z', 'http://ex/x/r'], - ['q/r', 'http://ex/x/y', 'http://ex/x/q/r'], - ['q/r#s', 'http://ex/x/y', 'http://ex/x/q/r#s'], - ['q/r#s/t', 'http://ex/x/y', 'http://ex/x/q/r#s/t'], - ['ftp://ex/x/q/r', 'http://ex/x/y', 'ftp://ex/x/q/r'], - ['', 'http://ex/x/y', 'http://ex/x/y'], - ['', 'http://ex/x/y/', 'http://ex/x/y/'], - ['', 'http://ex/x/y/pdq', 'http://ex/x/y/pdq'], - ['z/', 'http://ex/x/y/', 'http://ex/x/y/z/'], - ['#Animal', - 'file:/swap/test/animal.rdf', - 'file:/swap/test/animal.rdf#Animal'], - ['../abc', 'file:/e/x/y/z', 'file:/e/x/abc'], - ['/example/x/abc', 'file:/example2/x/y/z', 'file:/example/x/abc'], - ['../r', 'file:/ex/x/y/z', 'file:/ex/x/r'], - ['/r', 'file:/ex/x/y/z', 'file:/r'], - ['q/r', 'file:/ex/x/y', 'file:/ex/x/q/r'], - ['q/r#s', 'file:/ex/x/y', 'file:/ex/x/q/r#s'], - ['q/r#', 'file:/ex/x/y', 'file:/ex/x/q/r#'], - ['q/r#s/t', 'file:/ex/x/y', 'file:/ex/x/q/r#s/t'], - ['ftp://ex/x/q/r', 'file:/ex/x/y', 'ftp://ex/x/q/r'], - ['', 'file:/ex/x/y', 'file:/ex/x/y'], - ['', 'file:/ex/x/y/', 'file:/ex/x/y/'], - ['', 'file:/ex/x/y/pdq', 'file:/ex/x/y/pdq'], - ['z/', 'file:/ex/x/y/', 'file:/ex/x/y/z/'], - ['file://meetings.example.com/cal#m1', - 'file:/devel/WWW/2000/10/swap/test/reluri-1.n3', - 'file://meetings.example.com/cal#m1'], - ['file://meetings.example.com/cal#m1', - 'file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3', - 'file://meetings.example.com/cal#m1'], - ['./#blort', 'file:/some/dir/foo', 'file:/some/dir/#blort'], - ['./#', 'file:/some/dir/foo', 'file:/some/dir/#'], - // Ryan Lee - ['./', 'http://example/x/abc.efg', 'http://example/x/'], - - - // Graham Klyne's tests - // http://www.ninebynine.org/Software/HaskellUtils/Network/UriTest.xls - // 01-31 are from Connelly's cases - - // 32-49 - ['./q:r', 'http://ex/x/y', 'http://ex/x/q:r'], - ['./p=q:r', 'http://ex/x/y', 'http://ex/x/p=q:r'], - ['?pp/rr', 'http://ex/x/y?pp/qq', 'http://ex/x/y?pp/rr'], - ['y/z', 'http://ex/x/y?pp/qq', 'http://ex/x/y/z'], - ['local/qual@domain.org#frag', - 'mailto:local', - 'mailto:local/qual@domain.org#frag'], - ['more/qual2@domain2.org#frag', - 'mailto:local/qual1@domain1.org', - 'mailto:local/more/qual2@domain2.org#frag'], - ['y?q', 'http://ex/x/y?q', 'http://ex/x/y?q'], - ['/x/y?q', 'http://ex?p', 'http://ex/x/y?q'], - ['c/d', 'foo:a/b', 'foo:a/c/d'], - ['/c/d', 'foo:a/b', 'foo:/c/d'], - ['', 'foo:a/b?c#d', 'foo:a/b?c'], - ['b/c', 'foo:a', 'foo:b/c'], - ['../b/c', 'foo:/a/y/z', 'foo:/a/b/c'], - ['./b/c', 'foo:a', 'foo:b/c'], - ['/./b/c', 'foo:a', 'foo:/b/c'], - ['../../d', 'foo://a//b/c', 'foo://a/d'], - ['.', 'foo:a', 'foo:'], - ['..', 'foo:a', 'foo:'], - - // 50-57[cf. TimBL comments -- - // http://lists.w3.org/Archives/Public/uri/2003Feb/0028.html, - // http://lists.w3.org/Archives/Public/uri/2003Jan/0008.html) - ['abc', 'http://example/x/y%2Fz', 'http://example/x/abc'], - ['../../x%2Fabc', 'http://example/a/x/y/z', 'http://example/a/x%2Fabc'], - ['../x%2Fabc', 'http://example/a/x/y%2Fz', 'http://example/a/x%2Fabc'], - ['abc', 'http://example/x%2Fy/z', 'http://example/x%2Fy/abc'], - ['q%3Ar', 'http://ex/x/y', 'http://ex/x/q%3Ar'], - ['/x%2Fabc', 'http://example/x/y%2Fz', 'http://example/x%2Fabc'], - ['/x%2Fabc', 'http://example/x/y/z', 'http://example/x%2Fabc'], - ['/x%2Fabc', 'http://example/x/y%2Fz', 'http://example/x%2Fabc'], - - // 70-77 - ['local2@domain2', 'mailto:local1@domain1?query1', 'mailto:local2@domain2'], - ['local2@domain2?query2', - 'mailto:local1@domain1', - 'mailto:local2@domain2?query2'], - ['local2@domain2?query2', - 'mailto:local1@domain1?query1', - 'mailto:local2@domain2?query2'], - ['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'], - ['local@domain?query2', 'mailto:?query1', 'mailto:local@domain?query2'], - ['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'], - ['http://example/a/b?c/../d', 'foo:bar', 'http://example/a/b?c/../d'], - ['http://example/a/b#c/../d', 'foo:bar', 'http://example/a/b#c/../d'], - - // 82-88 - // @isaacs Disagree. Not how browsers do it. - // ['http:this', 'http://example.org/base/uri', 'http:this'], - // @isaacs Added - ['http:this', 'http://example.org/base/uri', 'http://example.org/base/this'], - ['http:this', 'http:base', 'http:this'], - ['.//g', 'f:/a', 'f://g'], - ['b/c//d/e', 'f://example.org/base/a', 'f://example.org/base/b/c//d/e'], - ['m2@example.ord/c2@example.org', - 'mid:m@example.ord/c@example.org', - 'mid:m@example.ord/m2@example.ord/c2@example.org'], - ['mini1.xml', - 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/', - 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml'], - ['../b/c', 'foo:a/y/z', 'foo:a/b/c'], - - //changeing auth - ['http://diff:auth@www.example.com', - 'http://asdf:qwer@www.example.com', - 'http://diff:auth@www.example.com/'] -]; -relativeTests2.forEach(function(relativeTest) { - var a = url.resolve(relativeTest[1], relativeTest[0]), - e = relativeTest[2]; - assert.equal(a, e, - 'resolve(' + [relativeTest[1], relativeTest[0]] + ') == ' + e + - '\n actual=' + a); -}); - -//if format and parse are inverse operations then -//resolveObject(parse(x), y) == parse(resolve(x, y)) - -//host and hostname are special, in this case a '' value is important -var emptyIsImportant = {'host': true, 'hostname': ''}; - -//format: [from, path, expected] -relativeTests.forEach(function(relativeTest) { - var actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]), - expected = url.parse(relativeTest[2]); - - - assert.deepEqual(actual, expected); - - expected = relativeTest[2]; - actual = url.format(actual); - - assert.equal(actual, expected, - 'format(' + actual + ') == ' + expected + '\nactual:' + actual); -}); - -//format: [to, from, result] -// the test: ['.//g', 'f:/a', 'f://g'] is a fundimental problem -// url.parse('f:/a') does not have a host -// url.resolve('f:/a', './/g') does not have a host becuase you have moved -// down to the g directory. i.e. f: //g, however when this url is parsed -// f:// will indicate that the host is g which is not the case. -// it is unclear to me how to keep this information from being lost -// it may be that a pathname of ////g should colapse to /g but this seems -// to be a lot of work for an edge case. Right now I remove the test -if (relativeTests2[181][0] === './/g' && - relativeTests2[181][1] === 'f:/a' && - relativeTests2[181][2] === 'f://g') { - relativeTests2.splice(181, 1); -} -relativeTests2.forEach(function(relativeTest) { - var actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]), - expected = url.parse(relativeTest[2]); - - assert.deepEqual(actual, expected); - - var expected = relativeTest[2], - actual = url.format(actual); - - assert.equal(actual, expected, - 'format(' + relativeTest[1] + ') == ' + expected + - '\nactual:' + actual); -}); - -// backslashes should be like forward slashes -var res = url.resolve('http://example.com/x', '\\\\foo.com\\bar'); -assert.equal(res, 'http://foo.com/bar'); diff --git a/test/simple/test-utf8-scripts.js b/test/simple/test-utf8-scripts.js deleted file mode 100644 index 4639304f8775..000000000000 --- a/test/simple/test-utf8-scripts.js +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -// üäö - -console.log('Σὲ γνωρίζω ἀπὸ τὴν κόψη'); - -assert.equal(true, /Hellö Wörld/.test('Hellö Wörld')); - diff --git a/test/simple/test-util-format.js b/test/simple/test-util-format.js deleted file mode 100644 index 16c3c56dd166..000000000000 --- a/test/simple/test-util-format.js +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var util = require('util'); - -assert.equal(util.format(), ''); -assert.equal(util.format(''), ''); -assert.equal(util.format([]), '[]'); -assert.equal(util.format({}), '{}'); -assert.equal(util.format(null), 'null'); -assert.equal(util.format(true), 'true'); -assert.equal(util.format(false), 'false'); -assert.equal(util.format('test'), 'test'); - -// CHECKME this is for console.log() compatibility - but is it *right*? -assert.equal(util.format('foo', 'bar', 'baz'), 'foo bar baz'); - -assert.equal(util.format('%d', 42.0), '42'); -assert.equal(util.format('%d', 42), '42'); -assert.equal(util.format('%s', 42), '42'); -assert.equal(util.format('%j', 42), '42'); - -assert.equal(util.format('%d', '42.0'), '42'); -assert.equal(util.format('%d', '42'), '42'); -assert.equal(util.format('%s', '42'), '42'); -assert.equal(util.format('%j', '42'), '"42"'); - -assert.equal(util.format('%%s%s', 'foo'), '%sfoo'); - -assert.equal(util.format('%s'), '%s'); -assert.equal(util.format('%s', undefined), 'undefined'); -assert.equal(util.format('%s', 'foo'), 'foo'); -assert.equal(util.format('%s:%s'), '%s:%s'); -assert.equal(util.format('%s:%s', undefined), 'undefined:%s'); -assert.equal(util.format('%s:%s', 'foo'), 'foo:%s'); -assert.equal(util.format('%s:%s', 'foo', 'bar'), 'foo:bar'); -assert.equal(util.format('%s:%s', 'foo', 'bar', 'baz'), 'foo:bar baz'); -assert.equal(util.format('%%%s%%', 'hi'), '%hi%'); -assert.equal(util.format('%%%s%%%%', 'hi'), '%hi%%'); - -// Errors -assert.equal(util.format(new Error('foo')), '[Error: foo]'); -function CustomError(msg) { - Error.call(this); - Object.defineProperty(this, 'message', { value: msg, enumerable: false }); - Object.defineProperty(this, 'name', { value: 'CustomError', enumerable: false }); -} -util.inherits(CustomError, Error); -assert.equal(util.format(new CustomError('bar')), '[CustomError: bar]'); diff --git a/test/simple/test-util-inspect.js b/test/simple/test-util-inspect.js deleted file mode 100644 index 0b04c93c73dc..000000000000 --- a/test/simple/test-util-inspect.js +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -var common = require('../common'); -var assert = require('assert'); -var util = require('util'); - -// test the internal isDate implementation -var Date2 = require('vm').runInNewContext('Date'); -var d = new Date2(); -var orig = util.inspect(d); -Date2.prototype.foo = 'bar'; -var after = util.inspect(d); -assert.equal(orig, after); - -// test for sparse array -var a = ['foo', 'bar', 'baz']; -assert.equal(util.inspect(a), '[ \'foo\', \'bar\', \'baz\' ]'); -delete a[1]; -assert.equal(util.inspect(a), '[ \'foo\', , \'baz\' ]'); -assert.equal(util.inspect(a, true), '[ \'foo\', , \'baz\', [length]: 3 ]'); -assert.equal(util.inspect(new Array(5)), '[ , , , , ]'); - -// test for property descriptors -var getter = Object.create(null, { - a: { - get: function() { return 'aaa'; } - } -}); -var setter = Object.create(null, { - b: { - set: function() {} - } -}); -var getterAndSetter = Object.create(null, { - c: { - get: function() { return 'ccc'; }, - set: function() {} - } -}); -assert.equal(util.inspect(getter, true), '{ [a]: [Getter] }'); -assert.equal(util.inspect(setter, true), '{ [b]: [Setter] }'); -assert.equal(util.inspect(getterAndSetter, true), '{ [c]: [Getter/Setter] }'); - -// exceptions should print the error message, not '{}' -assert.equal(util.inspect(new Error()), '[Error]'); -assert.equal(util.inspect(new Error('FAIL')), '[Error: FAIL]'); -assert.equal(util.inspect(new TypeError('FAIL')), '[TypeError: FAIL]'); -assert.equal(util.inspect(new SyntaxError('FAIL')), '[SyntaxError: FAIL]'); -try { - undef(); -} catch (e) { - assert.equal(util.inspect(e), '[ReferenceError: undef is not defined]'); -} -var ex = util.inspect(new Error('FAIL'), true); -assert.ok(ex.indexOf('[Error: FAIL]') != -1); -assert.ok(ex.indexOf('[stack]') != -1); -assert.ok(ex.indexOf('[message]') != -1); - -// GH-1941 -// should not throw: -assert.equal(util.inspect(Object.create(Date.prototype)), '{}'); - -// GH-1944 -assert.doesNotThrow(function() { - var d = new Date(); - d.toUTCString = null; - util.inspect(d); -}); - -assert.doesNotThrow(function() { - var r = /regexp/; - r.toString = null; - util.inspect(r); -}); - -// bug with user-supplied inspect function returns non-string -assert.doesNotThrow(function() { - util.inspect([{ - inspect: function() { return 123; } - }]); -}); - -// GH-2225 -var x = { inspect: util.inspect }; -assert.ok(util.inspect(x).indexOf('inspect') != -1); - -// util.inspect.styles and util.inspect.colors -function test_color_style(style, input, implicit) { - var color_name = util.inspect.styles[style]; - var color = ['', '']; - if(util.inspect.colors[color_name]) - color = util.inspect.colors[color_name]; - - var without_color = util.inspect(input, false, 0, false); - var with_color = util.inspect(input, false, 0, true); - var expect = '\u001b[' + color[0] + 'm' + without_color + - '\u001b[' + color[1] + 'm'; - assert.equal(with_color, expect, 'util.inspect color for style '+style); -} - -test_color_style('special', function(){}); -test_color_style('number', 123.456); -test_color_style('boolean', true); -test_color_style('undefined', undefined); -test_color_style('null', null); -test_color_style('string', 'test string'); -test_color_style('date', new Date); -test_color_style('regexp', /regexp/); - -// an object with "hasOwnProperty" overwritten should not throw -assert.doesNotThrow(function() { - util.inspect({ - hasOwnProperty: null - }); -}); - -// new API, accepts an "options" object -var subject = { foo: 'bar', hello: 31, a: { b: { c: { d: 0 } } } }; -Object.defineProperty(subject, 'hidden', { enumerable: false, value: null }); - -assert(util.inspect(subject, { showHidden: false }).indexOf('hidden') === -1); -assert(util.inspect(subject, { showHidden: true }).indexOf('hidden') !== -1); -assert(util.inspect(subject, { colors: false }).indexOf('\u001b[32m') === -1); -assert(util.inspect(subject, { colors: true }).indexOf('\u001b[32m') !== -1); -assert(util.inspect(subject, { depth: 2 }).indexOf('c: [Object]') !== -1); -assert(util.inspect(subject, { depth: 0 }).indexOf('a: [Object]') !== -1); -assert(util.inspect(subject, { depth: null }).indexOf('{ d: 0 }') !== -1); - -// "customInspect" option can enable/disable calling inspect() on objects -subject = { inspect: function() { return 123; } }; - -assert(util.inspect(subject, { customInspect: true }).indexOf('123') !== -1); -assert(util.inspect(subject, { customInspect: true }).indexOf('inspect') === -1); -assert(util.inspect(subject, { customInspect: false }).indexOf('123') === -1); -assert(util.inspect(subject, { customInspect: false }).indexOf('inspect') !== -1); diff --git a/test/simple/test-util.js b/test/simple/test-util.js deleted file mode 100644 index f4c4d82f5773..000000000000 --- a/test/simple/test-util.js +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var common = require('../common'); -var assert = require('assert'); -var util = require('util'); -var context = require('vm').runInNewContext; - -// isArray -assert.equal(true, util.isArray([])); -assert.equal(true, util.isArray(Array())); -assert.equal(true, util.isArray(new Array())); -assert.equal(true, util.isArray(new Array(5))); -assert.equal(true, util.isArray(new Array('with', 'some', 'entries'))); -assert.equal(true, util.isArray(context('Array')())); -assert.equal(false, util.isArray({})); -assert.equal(false, util.isArray({ push: function() {} })); -assert.equal(false, util.isArray(/regexp/)); -assert.equal(false, util.isArray(new Error)); -assert.equal(false, util.isArray(Object.create(Array.prototype))); - -// isRegExp -assert.equal(true, util.isRegExp(/regexp/)); -assert.equal(true, util.isRegExp(RegExp())); -assert.equal(true, util.isRegExp(new RegExp())); -assert.equal(true, util.isRegExp(context('RegExp')())); -assert.equal(false, util.isRegExp({})); -assert.equal(false, util.isRegExp([])); -assert.equal(false, util.isRegExp(new Date())); -assert.equal(false, util.isRegExp(Object.create(RegExp.prototype))); - -// isDate -assert.equal(true, util.isDate(new Date())); -assert.equal(true, util.isDate(new Date(0))); -assert.equal(true, util.isDate(new (context('Date')))); -assert.equal(false, util.isDate(Date())); -assert.equal(false, util.isDate({})); -assert.equal(false, util.isDate([])); -assert.equal(false, util.isDate(new Error)); -assert.equal(false, util.isDate(Object.create(Date.prototype))); - -// isError -assert.equal(true, util.isError(new Error)); -assert.equal(true, util.isError(new TypeError)); -assert.equal(true, util.isError(new SyntaxError)); -assert.equal(true, util.isError(new (context('Error')))); -assert.equal(true, util.isError(new (context('TypeError')))); -assert.equal(true, util.isError(new (context('SyntaxError')))); -assert.equal(false, util.isError({})); -assert.equal(false, util.isError({ name: 'Error', message: '' })); -assert.equal(false, util.isError([])); -assert.equal(true, util.isError(Object.create(Error.prototype))); - -// _extend -assert.deepEqual(util._extend({a:1}), {a:1}); -assert.deepEqual(util._extend({a:1}, []), {a:1}); -assert.deepEqual(util._extend({a:1}, null), {a:1}); -assert.deepEqual(util._extend({a:1}, true), {a:1}); -assert.deepEqual(util._extend({a:1}, false), {a:1}); -assert.deepEqual(util._extend({a:1}, {b:2}), {a:1, b:2}); -assert.deepEqual(util._extend({a:1, b:2}, {b:3}), {a:1, b:3}); diff --git a/test/simple/test-vm-create-context-accessors.js b/test/simple/test-vm-create-context-accessors.js deleted file mode 100644 index f0622245be16..000000000000 --- a/test/simple/test-vm-create-context-accessors.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var vm = require('vm'); - -var ctx = {}; - -Object.defineProperty(ctx, 'getter', { - get: function() { - return 'ok'; - } -}); - -var val; -Object.defineProperty(ctx, 'setter', { - set: function(_val) { - val = _val; - }, - get: function() { - return 'ok=' + val; - } -}); - -ctx = vm.createContext(ctx); - -var result = vm.runInContext('setter = "test";[getter,setter]', ctx); -assert.deepEqual(result, ['ok', 'ok=test']); diff --git a/test/simple/test-vm-create-context-arg.js b/test/simple/test-vm-create-context-arg.js deleted file mode 100644 index 27cd5e13cf04..000000000000 --- a/test/simple/test-vm-create-context-arg.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var vm = require('vm'); - -assert.throws(function() { - var ctx = vm.createContext('string is not supported'); -}); - -assert.doesNotThrow(function() { - var ctx = vm.createContext({ a: 1 }); - ctx = vm.createContext([0, 1, 2, 3]); -}); diff --git a/test/simple/test-vm-create-context-circular-reference.js b/test/simple/test-vm-create-context-circular-reference.js deleted file mode 100644 index ae5b48c81ce8..000000000000 --- a/test/simple/test-vm-create-context-circular-reference.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var vm = require('vm'); - -var sbx = {}; -sbx.window = sbx; - -sbx = vm.createContext(sbx); - -sbx.test = 123; - -assert.equal(sbx.window.window.window.window.window.test, 123); - diff --git a/test/simple/test-writedouble.js b/test/simple/test-writedouble.js deleted file mode 100644 index c4bdc1b10d2b..000000000000 --- a/test/simple/test-writedouble.js +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * Tests to verify we're writing doubles correctly - */ -var SlowBuffer = process.binding('buffer').SlowBuffer; -var common = require('../common'); -var ASSERT = require('assert'); - -function test(clazz) { - var buffer = new clazz(16); - - buffer.writeDoubleBE(2.225073858507201e-308, 0); - buffer.writeDoubleLE(2.225073858507201e-308, 8); - ASSERT.equal(0x00, buffer[0]); - ASSERT.equal(0x0f, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0xff, buffer[3]); - ASSERT.equal(0xff, buffer[4]); - ASSERT.equal(0xff, buffer[5]); - ASSERT.equal(0xff, buffer[6]); - ASSERT.equal(0xff, buffer[7]); - ASSERT.equal(0xff, buffer[8]); - ASSERT.equal(0xff, buffer[9]); - ASSERT.equal(0xff, buffer[10]); - ASSERT.equal(0xff, buffer[11]); - ASSERT.equal(0xff, buffer[12]); - ASSERT.equal(0xff, buffer[13]); - ASSERT.equal(0x0f, buffer[14]); - ASSERT.equal(0x00, buffer[15]); - - buffer.writeDoubleBE(1.0000000000000004, 0); - buffer.writeDoubleLE(1.0000000000000004, 8); - ASSERT.equal(0x3f, buffer[0]); - ASSERT.equal(0xf0, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x02, buffer[7]); - ASSERT.equal(0x02, buffer[8]); - ASSERT.equal(0x00, buffer[9]); - ASSERT.equal(0x00, buffer[10]); - ASSERT.equal(0x00, buffer[11]); - ASSERT.equal(0x00, buffer[12]); - ASSERT.equal(0x00, buffer[13]); - ASSERT.equal(0xf0, buffer[14]); - ASSERT.equal(0x3f, buffer[15]); - - buffer.writeDoubleBE(-2, 0); - buffer.writeDoubleLE(-2, 8); - ASSERT.equal(0xc0, buffer[0]); - ASSERT.equal(0x00, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - ASSERT.equal(0x00, buffer[8]); - ASSERT.equal(0x00, buffer[9]); - ASSERT.equal(0x00, buffer[10]); - ASSERT.equal(0x00, buffer[11]); - ASSERT.equal(0x00, buffer[12]); - ASSERT.equal(0x00, buffer[13]); - ASSERT.equal(0x00, buffer[14]); - ASSERT.equal(0xc0, buffer[15]); - - buffer.writeDoubleBE(1.7976931348623157e+308, 0); - buffer.writeDoubleLE(1.7976931348623157e+308, 8); - ASSERT.equal(0x7f, buffer[0]); - ASSERT.equal(0xef, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0xff, buffer[3]); - ASSERT.equal(0xff, buffer[4]); - ASSERT.equal(0xff, buffer[5]); - ASSERT.equal(0xff, buffer[6]); - ASSERT.equal(0xff, buffer[7]); - ASSERT.equal(0xff, buffer[8]); - ASSERT.equal(0xff, buffer[9]); - ASSERT.equal(0xff, buffer[10]); - ASSERT.equal(0xff, buffer[11]); - ASSERT.equal(0xff, buffer[12]); - ASSERT.equal(0xff, buffer[13]); - ASSERT.equal(0xef, buffer[14]); - ASSERT.equal(0x7f, buffer[15]); - - buffer.writeDoubleBE(0 * -1, 0); - buffer.writeDoubleLE(0 * -1, 8); - ASSERT.equal(0x80, buffer[0]); - ASSERT.equal(0x00, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - ASSERT.equal(0x00, buffer[8]); - ASSERT.equal(0x00, buffer[9]); - ASSERT.equal(0x00, buffer[10]); - ASSERT.equal(0x00, buffer[11]); - ASSERT.equal(0x00, buffer[12]); - ASSERT.equal(0x00, buffer[13]); - ASSERT.equal(0x00, buffer[14]); - ASSERT.equal(0x80, buffer[15]); - - buffer.writeDoubleBE(Infinity, 0); - buffer.writeDoubleLE(Infinity, 8); - ASSERT.equal(0x7F, buffer[0]); - ASSERT.equal(0xF0, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - ASSERT.equal(0x00, buffer[8]); - ASSERT.equal(0x00, buffer[9]); - ASSERT.equal(0x00, buffer[10]); - ASSERT.equal(0x00, buffer[11]); - ASSERT.equal(0x00, buffer[12]); - ASSERT.equal(0x00, buffer[13]); - ASSERT.equal(0xF0, buffer[14]); - ASSERT.equal(0x7F, buffer[15]); - ASSERT.equal(Infinity, buffer.readDoubleBE(0)); - ASSERT.equal(Infinity, buffer.readDoubleLE(8)); - - buffer.writeDoubleBE(-Infinity, 0); - buffer.writeDoubleLE(-Infinity, 8); - ASSERT.equal(0xFF, buffer[0]); - ASSERT.equal(0xF0, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - ASSERT.equal(0x00, buffer[8]); - ASSERT.equal(0x00, buffer[9]); - ASSERT.equal(0x00, buffer[10]); - ASSERT.equal(0x00, buffer[11]); - ASSERT.equal(0x00, buffer[12]); - ASSERT.equal(0x00, buffer[13]); - ASSERT.equal(0xF0, buffer[14]); - ASSERT.equal(0xFF, buffer[15]); - ASSERT.equal(-Infinity, buffer.readDoubleBE(0)); - ASSERT.equal(-Infinity, buffer.readDoubleLE(8)); - - buffer.writeDoubleBE(NaN, 0); - buffer.writeDoubleLE(NaN, 8); - // Darwin ia32 does the other kind of NaN. - // Compiler bug. No one really cares. - ASSERT(0x7F === buffer[0] || 0xFF === buffer[0]); - ASSERT.equal(0xF8, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - ASSERT.equal(0x00, buffer[8]); - ASSERT.equal(0x00, buffer[9]); - ASSERT.equal(0x00, buffer[10]); - ASSERT.equal(0x00, buffer[11]); - ASSERT.equal(0x00, buffer[12]); - ASSERT.equal(0x00, buffer[13]); - ASSERT.equal(0xF8, buffer[14]); - // Darwin ia32 does the other kind of NaN. - // Compiler bug. No one really cares. - ASSERT(0x7F === buffer[15] || 0xFF === buffer[15]); - ASSERT.ok(isNaN(buffer.readDoubleBE(0))); - ASSERT.ok(isNaN(buffer.readDoubleLE(8))); -} - - -test(Buffer); -test(SlowBuffer); diff --git a/test/simple/test-writefloat.js b/test/simple/test-writefloat.js deleted file mode 100644 index f72cedeee96c..000000000000 --- a/test/simple/test-writefloat.js +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * Tests to verify we're writing floats correctly - */ -var SlowBuffer = process.binding('buffer').SlowBuffer; -var common = require('../common'); -var ASSERT = require('assert'); - -function test(clazz) { - var buffer = new clazz(8); - - buffer.writeFloatBE(1, 0); - buffer.writeFloatLE(1, 4); - ASSERT.equal(0x3f, buffer[0]); - ASSERT.equal(0x80, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x80, buffer[6]); - ASSERT.equal(0x3f, buffer[7]); - - buffer.writeFloatBE(1 / 3, 0); - buffer.writeFloatLE(1 / 3, 4); - ASSERT.equal(0x3e, buffer[0]); - ASSERT.equal(0xaa, buffer[1]); - ASSERT.equal(0xaa, buffer[2]); - ASSERT.equal(0xab, buffer[3]); - ASSERT.equal(0xab, buffer[4]); - ASSERT.equal(0xaa, buffer[5]); - ASSERT.equal(0xaa, buffer[6]); - ASSERT.equal(0x3e, buffer[7]); - - buffer.writeFloatBE(3.4028234663852886e+38, 0); - buffer.writeFloatLE(3.4028234663852886e+38, 4); - ASSERT.equal(0x7f, buffer[0]); - ASSERT.equal(0x7f, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0xff, buffer[3]); - ASSERT.equal(0xff, buffer[4]); - ASSERT.equal(0xff, buffer[5]); - ASSERT.equal(0x7f, buffer[6]); - ASSERT.equal(0x7f, buffer[7]); - - buffer.writeFloatLE(1.1754943508222875e-38, 0); - buffer.writeFloatBE(1.1754943508222875e-38, 4); - ASSERT.equal(0x00, buffer[0]); - ASSERT.equal(0x00, buffer[1]); - ASSERT.equal(0x80, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x80, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - - buffer.writeFloatBE(0 * -1, 0); - buffer.writeFloatLE(0 * -1, 4); - ASSERT.equal(0x80, buffer[0]); - ASSERT.equal(0x00, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x80, buffer[7]); - - buffer.writeFloatBE(Infinity, 0); - buffer.writeFloatLE(Infinity, 4); - ASSERT.equal(0x7F, buffer[0]); - ASSERT.equal(0x80, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x80, buffer[6]); - ASSERT.equal(0x7F, buffer[7]); - ASSERT.equal(Infinity, buffer.readFloatBE(0)); - ASSERT.equal(Infinity, buffer.readFloatLE(4)); - - buffer.writeFloatBE(-Infinity, 0); - buffer.writeFloatLE(-Infinity, 4); - // Darwin ia32 does the other kind of NaN. - // Compiler bug. No one really cares. - ASSERT(0xFF === buffer[0] || 0x7F === buffer[0]); - ASSERT.equal(0x80, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x80, buffer[6]); - ASSERT.equal(0xFF, buffer[7]); - ASSERT.equal(-Infinity, buffer.readFloatBE(0)); - ASSERT.equal(-Infinity, buffer.readFloatLE(4)); - - buffer.writeFloatBE(NaN, 0); - buffer.writeFloatLE(NaN, 4); - // Darwin ia32 does the other kind of NaN. - // Compiler bug. No one really cares. - ASSERT(0x7F === buffer[0] || 0xFF === buffer[0]); - ASSERT.equal(0xc0, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0xc0, buffer[6]); - // Darwin ia32 does the other kind of NaN. - // Compiler bug. No one really cares. - ASSERT(0x7F === buffer[7] || 0xFF === buffer[7]); - ASSERT.ok(isNaN(buffer.readFloatBE(0))); - ASSERT.ok(isNaN(buffer.readFloatLE(4))); -} - - -test(Buffer); -test(SlowBuffer); diff --git a/test/simple/test-writeint.js b/test/simple/test-writeint.js deleted file mode 100644 index b7ebd6964f02..000000000000 --- a/test/simple/test-writeint.js +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * Tests to verify we're writing signed integers correctly - */ -var SlowBuffer = process.binding('buffer').SlowBuffer; -var common = require('../common'); -var ASSERT = require('assert'); - -function test8(clazz) { - var buffer = new clazz(2); - - buffer.writeInt8(0x23, 0); - buffer.writeInt8(-5, 1); - - ASSERT.equal(0x23, buffer[0]); - ASSERT.equal(0xfb, buffer[1]); - - /* Make sure we handle truncation correctly */ - ASSERT.throws(function() { - buffer.writeInt8(0xabc, 0); - }); - ASSERT.throws(function() { - buffer.writeInt8(0xabc, 0); - }); - - /* Make sure we handle min/max correctly */ - buffer.writeInt8(0x7f, 0); - buffer.writeInt8(-0x80, 1); - - ASSERT.equal(0x7f, buffer[0]); - ASSERT.equal(0x80, buffer[1]); - ASSERT.throws(function() { - buffer.writeInt8(0x7f + 1, 0); - }); - ASSERT.throws(function() { - buffer.writeInt8(-0x80 - 1, 0); - }); -} - - -function test16(clazz) { - var buffer = new clazz(6); - - buffer.writeInt16BE(0x0023, 0); - buffer.writeInt16LE(0x0023, 2); - ASSERT.equal(0x00, buffer[0]); - ASSERT.equal(0x23, buffer[1]); - ASSERT.equal(0x23, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - - buffer.writeInt16BE(-5, 0); - buffer.writeInt16LE(-5, 2); - ASSERT.equal(0xff, buffer[0]); - ASSERT.equal(0xfb, buffer[1]); - ASSERT.equal(0xfb, buffer[2]); - ASSERT.equal(0xff, buffer[3]); - - buffer.writeInt16BE(-1679, 1); - buffer.writeInt16LE(-1679, 3); - ASSERT.equal(0xf9, buffer[1]); - ASSERT.equal(0x71, buffer[2]); - ASSERT.equal(0x71, buffer[3]); - ASSERT.equal(0xf9, buffer[4]); - - /* Make sure we handle min/max correctly */ - buffer.writeInt16BE(0x7fff, 0); - buffer.writeInt16BE(-0x8000, 2); - ASSERT.equal(0x7f, buffer[0]); - ASSERT.equal(0xff, buffer[1]); - ASSERT.equal(0x80, buffer[2]); - ASSERT.equal(0x00, buffer[3]); - ASSERT.throws(function() { - buffer.writeInt16BE(0x7fff + 1, 0); - }); - ASSERT.throws(function() { - buffer.writeInt16BE(-0x8000 - 1, 0); - }); - - buffer.writeInt16LE(0x7fff, 0); - buffer.writeInt16LE(-0x8000, 2); - ASSERT.equal(0xff, buffer[0]); - ASSERT.equal(0x7f, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x80, buffer[3]); - ASSERT.throws(function() { - buffer.writeInt16LE(0x7fff + 1, 0); - }); - ASSERT.throws(function() { - buffer.writeInt16LE(-0x8000 - 1, 0); - }); -} - - -function test32(clazz) { - var buffer = new clazz(8); - - buffer.writeInt32BE(0x23, 0); - buffer.writeInt32LE(0x23, 4); - ASSERT.equal(0x00, buffer[0]); - ASSERT.equal(0x00, buffer[1]); - ASSERT.equal(0x00, buffer[2]); - ASSERT.equal(0x23, buffer[3]); - ASSERT.equal(0x23, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - - buffer.writeInt32BE(-5, 0); - buffer.writeInt32LE(-5, 4); - ASSERT.equal(0xff, buffer[0]); - ASSERT.equal(0xff, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0xfb, buffer[3]); - ASSERT.equal(0xfb, buffer[4]); - ASSERT.equal(0xff, buffer[5]); - ASSERT.equal(0xff, buffer[6]); - ASSERT.equal(0xff, buffer[7]); - - buffer.writeInt32BE(-805306713, 0); - buffer.writeInt32LE(-805306713, 4); - ASSERT.equal(0xcf, buffer[0]); - ASSERT.equal(0xff, buffer[1]); - ASSERT.equal(0xfe, buffer[2]); - ASSERT.equal(0xa7, buffer[3]); - ASSERT.equal(0xa7, buffer[4]); - ASSERT.equal(0xfe, buffer[5]); - ASSERT.equal(0xff, buffer[6]); - ASSERT.equal(0xcf, buffer[7]); - - /* Make sure we handle min/max correctly */ - buffer.writeInt32BE(0x7fffffff, 0); - buffer.writeInt32BE(-0x80000000, 4); - ASSERT.equal(0x7f, buffer[0]); - ASSERT.equal(0xff, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0xff, buffer[3]); - ASSERT.equal(0x80, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x00, buffer[7]); - ASSERT.throws(function() { - buffer.writeInt32BE(0x7fffffff + 1, 0); - }); - ASSERT.throws(function() { - buffer.writeInt32BE(-0x80000000 - 1, 0); - }); - - buffer.writeInt32LE(0x7fffffff, 0); - buffer.writeInt32LE(-0x80000000, 4); - ASSERT.equal(0xff, buffer[0]); - ASSERT.equal(0xff, buffer[1]); - ASSERT.equal(0xff, buffer[2]); - ASSERT.equal(0x7f, buffer[3]); - ASSERT.equal(0x00, buffer[4]); - ASSERT.equal(0x00, buffer[5]); - ASSERT.equal(0x00, buffer[6]); - ASSERT.equal(0x80, buffer[7]); - ASSERT.throws(function() { - buffer.writeInt32LE(0x7fffffff + 1, 0); - }); - ASSERT.throws(function() { - buffer.writeInt32LE(-0x80000000 - 1, 0); - }); -} - - -test8(Buffer); -test8(SlowBuffer); -test16(Buffer); -test16(SlowBuffer); -test32(Buffer); -test32(SlowBuffer); diff --git a/test/simple/test-writeuint.js b/test/simple/test-writeuint.js deleted file mode 100644 index 91b5c6c9c643..000000000000 --- a/test/simple/test-writeuint.js +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -/* - * A battery of tests to help us read a series of uints - */ -var SlowBuffer = process.binding('buffer').SlowBuffer; -var common = require('../common'); -var ASSERT = require('assert'); - -/* - * We need to check the following things: - * - We are correctly resolving big endian (doesn't mean anything for 8 bit) - * - Correctly resolving little endian (doesn't mean anything for 8 bit) - * - Correctly using the offsets - * - Correctly interpreting values that are beyond the signed range as unsigned - */ -function test8(clazz) { - var data = new clazz(4); - - data.writeUInt8(23, 0); - data.writeUInt8(23, 1); - data.writeUInt8(23, 2); - data.writeUInt8(23, 3); - ASSERT.equal(23, data[0]); - ASSERT.equal(23, data[1]); - ASSERT.equal(23, data[2]); - ASSERT.equal(23, data[3]); - - data.writeUInt8(23, 0); - data.writeUInt8(23, 1); - data.writeUInt8(23, 2); - data.writeUInt8(23, 3); - ASSERT.equal(23, data[0]); - ASSERT.equal(23, data[1]); - ASSERT.equal(23, data[2]); - ASSERT.equal(23, data[3]); - - data.writeUInt8(255, 0); - ASSERT.equal(255, data[0]); - - data.writeUInt8(255, 0); - ASSERT.equal(255, data[0]); -} - - -function test16(clazz) { - var value = 0x2343; - var data = new clazz(4); - - data.writeUInt16BE(value, 0); - ASSERT.equal(0x23, data[0]); - ASSERT.equal(0x43, data[1]); - - data.writeUInt16BE(value, 1); - ASSERT.equal(0x23, data[1]); - ASSERT.equal(0x43, data[2]); - - data.writeUInt16BE(value, 2); - ASSERT.equal(0x23, data[2]); - ASSERT.equal(0x43, data[3]); - - data.writeUInt16LE(value, 0); - ASSERT.equal(0x23, data[1]); - ASSERT.equal(0x43, data[0]); - - data.writeUInt16LE(value, 1); - ASSERT.equal(0x23, data[2]); - ASSERT.equal(0x43, data[1]); - - data.writeUInt16LE(value, 2); - ASSERT.equal(0x23, data[3]); - ASSERT.equal(0x43, data[2]); - - value = 0xff80; - data.writeUInt16LE(value, 0); - ASSERT.equal(0xff, data[1]); - ASSERT.equal(0x80, data[0]); - - data.writeUInt16BE(value, 0); - ASSERT.equal(0xff, data[0]); - ASSERT.equal(0x80, data[1]); -} - - -function test32(clazz) { - var data = new clazz(6); - var value = 0xe7f90a6d; - - data.writeUInt32BE(value, 0); - ASSERT.equal(0xe7, data[0]); - ASSERT.equal(0xf9, data[1]); - ASSERT.equal(0x0a, data[2]); - ASSERT.equal(0x6d, data[3]); - - data.writeUInt32BE(value, 1); - ASSERT.equal(0xe7, data[1]); - ASSERT.equal(0xf9, data[2]); - ASSERT.equal(0x0a, data[3]); - ASSERT.equal(0x6d, data[4]); - - data.writeUInt32BE(value, 2); - ASSERT.equal(0xe7, data[2]); - ASSERT.equal(0xf9, data[3]); - ASSERT.equal(0x0a, data[4]); - ASSERT.equal(0x6d, data[5]); - - data.writeUInt32LE(value, 0); - ASSERT.equal(0xe7, data[3]); - ASSERT.equal(0xf9, data[2]); - ASSERT.equal(0x0a, data[1]); - ASSERT.equal(0x6d, data[0]); - - data.writeUInt32LE(value, 1); - ASSERT.equal(0xe7, data[4]); - ASSERT.equal(0xf9, data[3]); - ASSERT.equal(0x0a, data[2]); - ASSERT.equal(0x6d, data[1]); - - data.writeUInt32LE(value, 2); - ASSERT.equal(0xe7, data[5]); - ASSERT.equal(0xf9, data[4]); - ASSERT.equal(0x0a, data[3]); - ASSERT.equal(0x6d, data[2]); -} - - -test8(Buffer); -test8(SlowBuffer); -test16(Buffer); -test16(SlowBuffer); -test32(Buffer); -test32(SlowBuffer); diff --git a/test/simple/test-zerolengthbufferbug.js b/test/simple/test-zerolengthbufferbug.js deleted file mode 100644 index 395e35baf551..000000000000 --- a/test/simple/test-zerolengthbufferbug.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Serving up a zero-length buffer should work. - -var common = require('../common'); -var assert = require('assert'); -var http = require('http'); - -var server = http.createServer(function(req, res) { - var buffer = new Buffer(0); - // FIXME: WTF gjslint want this? - res.writeHead(200, {'Content-Type': 'text/html', - 'Content-Length': buffer.length}); - res.end(buffer); -}); - -var gotResponse = false; -var resBodySize = 0; - -server.listen(common.PORT, function() { - http.get({ port: common.PORT }, function(res) { - gotResponse = true; - - res.on('data', function(d) { - resBodySize += d.length; - }); - - res.on('end', function(d) { - server.close(); - }); - }); -}); - -process.on('exit', function() { - assert.ok(gotResponse); - assert.equal(0, resBodySize); -}); - diff --git a/test/simple/test-zlib-close-after-write.js b/test/simple/test-zlib-close-after-write.js deleted file mode 100644 index f0f176008f9e..000000000000 --- a/test/simple/test-zlib-close-after-write.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var assert = require('assert'); -var zlib = require('zlib'); - -var closed = false; - -zlib.gzip('hello', function(err, out) { - var unzip = zlib.createGunzip(); - unzip.write(out); - unzip.close(function() { - closed = true; - }); -}); - -process.on('exit', function() { - assert(closed); -}); diff --git a/test/simple/test-zlib-dictionary-fail.js b/test/simple/test-zlib-dictionary-fail.js deleted file mode 100644 index fd35a0192aec..000000000000 --- a/test/simple/test-zlib-dictionary-fail.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var assert = require('assert'); -var zlib = require('zlib'); - -// Should raise an error, not trigger an assertion in src/node_zlib.cc -(function() { - var stream = zlib.createInflate(); - - stream.on('error', common.mustCall(function(err) { - assert(/Missing dictionary/.test(err.message)); - })); - - // String "test" encoded with dictionary "dict". - stream.write(Buffer([0x78,0xBB,0x04,0x09,0x01,0xA5])); -})(); - -// Should raise an error, not trigger an assertion in src/node_zlib.cc -(function() { - var stream = zlib.createInflate({ dictionary: Buffer('fail') }); - - stream.on('error', common.mustCall(function(err) { - assert(/Bad dictionary/.test(err.message)); - })); - - // String "test" encoded with dictionary "dict". - stream.write(Buffer([0x78,0xBB,0x04,0x09,0x01,0xA5])); -})(); diff --git a/test/simple/test-zlib-dictionary.js b/test/simple/test-zlib-dictionary.js deleted file mode 100644 index f3b1446071b9..000000000000 --- a/test/simple/test-zlib-dictionary.js +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// test compression/decompresion with dictionary - -var common = require('../common.js'); -var assert = require('assert'); -var zlib = require('zlib'); -var path = require('path'); - -var spdyDict = new Buffer([ - 'optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-', - 'languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi', - 'f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser', - '-agent10010120020120220320420520630030130230330430530630740040140240340440', - '5406407408409410411412413414415416417500501502503504505accept-rangesageeta', - 'glocationproxy-authenticatepublicretry-afterservervarywarningwww-authentic', - 'ateallowcontent-basecontent-encodingcache-controlconnectiondatetrailertran', - 'sfer-encodingupgradeviawarningcontent-languagecontent-lengthcontent-locati', - 'oncontent-md5content-rangecontent-typeetagexpireslast-modifiedset-cookieMo', - 'ndayTuesdayWednesdayThursdayFridaySaturdaySundayJanFebMarAprMayJunJulAugSe', - 'pOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplic', - 'ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1', - '.1statusversionurl\0' -].join('')); - -var deflate = zlib.createDeflate({ dictionary: spdyDict }); - -var input = [ - 'HTTP/1.1 200 Ok', - 'Server: node.js', - 'Content-Length: 0', - '' -].join('\r\n'); - -var called = 0; - -// -// We'll use clean-new inflate stream each time -// and .reset() old dirty deflate one -// -function run(num) { - var inflate = zlib.createInflate({ dictionary: spdyDict }); - - if (num === 2) { - deflate.reset(); - deflate.removeAllListeners('data'); - } - - // Put data into deflate stream - deflate.on('data', function(chunk) { - inflate.write(chunk); - }); - - // Get data from inflate stream - var output = []; - inflate.on('data', function(chunk) { - output.push(chunk); - }); - inflate.on('end', function() { - called++; - - assert.equal(output.join(''), input); - - if (num < 2) run(num + 1); - }); - - deflate.write(input); - deflate.flush(function() { - inflate.end(); - }); -} -run(1); - -process.on('exit', function() { - assert.equal(called, 2); -}); diff --git a/test/simple/test-zlib-from-gzip.js b/test/simple/test-zlib-from-gzip.js deleted file mode 100644 index 399354209991..000000000000 --- a/test/simple/test-zlib-from-gzip.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// test unzipping a file that was created with a non-node gzip lib, -// piped in as fast as possible. - -var common = require('../common.js'); -var assert = require('assert'); -var zlib = require('zlib'); -var path = require('path'); - -var gunzip = zlib.createGunzip(); - -var fs = require('fs'); - -var fixture = path.resolve(common.fixturesDir, 'person.jpg.gz'); -var unzippedFixture = path.resolve(common.fixturesDir, 'person.jpg'); -var outputFile = path.resolve(common.tmpDir, 'person.jpg'); -var expect = fs.readFileSync(unzippedFixture); -var inp = fs.createReadStream(fixture); -var out = fs.createWriteStream(outputFile); - -inp.pipe(gunzip).pipe(out); -out.on('close', function() { - var actual = fs.readFileSync(outputFile); - assert.equal(actual.length, expect.length, 'length should match'); - for (var i = 0, l = actual.length; i < l; i++) { - assert.equal(actual[i], expect[i], 'byte[' + i + ']'); - } -}); diff --git a/test/simple/test-zlib-from-string.js b/test/simple/test-zlib-from-string.js deleted file mode 100644 index 83bdeea83a90..000000000000 --- a/test/simple/test-zlib-from-string.js +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// test compressing and uncompressing a string with zlib - -var common = require('../common.js'); -var assert = require('assert'); -var zlib = require('zlib'); - -var inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing el' + - 'it. Morbi faucibus, purus at gravida dictum, libero arcu convallis la' + - 'cus, in commodo libero metus eu nisi. Nullam commodo, neque nec porta' + - ' placerat, nisi est fermentum augue, vitae gravida tellus sapien sit ' + - 'amet tellus. Aenean non diam orci. Proin quis elit turpis. Suspendiss' + - 'e non diam ipsum. Suspendisse nec ullamcorper odio. Vestibulum arcu m' + - 'i, sodales non suscipit id, ultrices ut massa. Sed ac sem sit amet ar' + - 'cu malesuada fermentum. Nunc sed. '; -var expectedBase64Deflate = 'eJxdUUtOQzEMvMoc4OndgT0gJCT2buJWlpI4jePeqZfpm' + - 'XAKLRKbLOzx/HK73q6vOrhCunlF1qIDJhNUeW5I2ozT5OkDlKWLJWkncJG5403HQXAkT3' + - 'Jw29B9uIEmToMukglZ0vS6ociBh4JG8sV4oVLEUCitK2kxq1WzPnChHDzsaGKy491Lofo' + - 'AbWh8do43oeuYhB5EPCjcLjzYJo48KrfQBvnJecNFJvHT1+RSQsGoC7dn2t/xjhduTA1N' + - 'WyQIZR0pbHwMDatnD+crPqKSqGPHp1vnlsWM/07ubf7bheF7kqSj84Bm0R1fYTfaK8vqq' + - 'qfKBtNMhe3OZh6N95CTvMX5HJJi4xOVzCgUOIMSLH7wmeOHaFE4RdpnGavKtrB5xzfO/Ll9'; -var expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN' + - '496pl+mZcAotEpss7PH8crverq86uEK6eUXWogMmE1R5bkjajNPk6QOUpYslaSdwkbnjT' + - 'cdBcCRPcnDb0H24gSZOgy6SCVnS9LqhyIGHgkbyxXihUsRQKK0raTGrVbM+cKEcPOxoYr' + - 'Lj3Uuh+gBtaHx2jjeh65iEHkQ8KNwuPNgmjjwqt9AG+cl5w0Um8dPX5FJCwagLt2fa3/G' + - 'OF25MDU1bJAhlHSlsfAwNq2cP5ys+opKoY8enW+eWxYz/Tu5t/tuF4XuSpKPzgGbRHV9h' + - 'N9ory+qqp8oG00yF7c5mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2s' + - 'HnHNzRtagj5AQAA'; - -zlib.deflate(inputString, function(err, buffer) { - assert.equal(buffer.toString('base64'), expectedBase64Deflate, - 'deflate encoded string should match'); -}); - -zlib.gzip(inputString, function(err, buffer) { - // Can't actually guarantee that we'll get exactly the same - // deflated bytes when we compress a string, since the header - // depends on stuff other than the input string itself. - // However, decrypting it should definitely yield the same - // result that we're expecting, and this should match what we get - // from inflating the known valid deflate data. - zlib.gunzip(buffer, function(err, gunzipped) { - assert.equal(gunzipped.toString(), inputString, - 'Should get original string after gzip/gunzip'); - }); -}); - -var buffer = new Buffer(expectedBase64Deflate, 'base64'); -zlib.unzip(buffer, function(err, buffer) { - assert.equal(buffer.toString(), inputString, - 'decoded inflated string should match'); -}); - -buffer = new Buffer(expectedBase64Gzip, 'base64'); -zlib.unzip(buffer, function(err, buffer) { - assert.equal(buffer.toString(), inputString, - 'decoded gunzipped string should match'); -}); diff --git a/test/simple/test-zlib-invalid-input.js b/test/simple/test-zlib-invalid-input.js deleted file mode 100644 index c3d8b5b47a5f..000000000000 --- a/test/simple/test-zlib-invalid-input.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// test uncompressing invalid input - -var common = require('../common.js'), - assert = require('assert'), - zlib = require('zlib'); - -var nonStringInputs = [1, true, {a: 1}, ['a']]; - -console.error('Doing the non-strings'); -nonStringInputs.forEach(function(input) { - // zlib.gunzip should not throw an error when called with bad input. - assert.doesNotThrow(function() { - zlib.gunzip(input, function(err, buffer) { - // zlib.gunzip should pass the error to the callback. - assert.ok(err); - }); - }); -}); - -console.error('Doing the unzips'); -// zlib.Unzip classes need to get valid data, or else they'll throw. -var unzips = [ zlib.Unzip(), - zlib.Gunzip(), - zlib.Inflate(), - zlib.InflateRaw() ]; -var hadError = []; -unzips.forEach(function (uz, i) { - console.error('Error for '+uz.constructor.name); - uz.on('error', function(er) { - console.error('Error event', er); - hadError[i] = true; - }); - - uz.on('end', function(er) { - throw new Error('end event should not be emitted '+uz.constructor.name); - }); - - // this will trigger error event - uz.write('this is not valid compressed data.'); -}); - -process.on('exit', function() { - assert.deepEqual(hadError, [true, true, true, true], 'expect 4 errors'); -}); diff --git a/test/simple/test-zlib-random-byte-pipes.js b/test/simple/test-zlib-random-byte-pipes.js deleted file mode 100644 index fc1db1cbba5e..000000000000 --- a/test/simple/test-zlib-random-byte-pipes.js +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var crypto = require('crypto'); -var stream = require('stream'); -var Stream = stream.Stream; -var util = require('util'); -var assert = require('assert'); -var zlib = require('zlib'); - - - -// emit random bytes, and keep a shasum -function RandomReadStream(opt) { - Stream.call(this); - - this.readable = true; - this._paused = false; - this._processing = false; - - this._hasher = crypto.createHash('sha1'); - opt = opt || {}; - - // base block size. - opt.block = opt.block || 256 * 1024; - - // total number of bytes to emit - opt.total = opt.total || 256 * 1024 * 1024; - this._remaining = opt.total; - - // how variable to make the block sizes - opt.jitter = opt.jitter || 1024; - - this._opt = opt; - - this._process = this._process.bind(this); - - process.nextTick(this._process); -} - -util.inherits(RandomReadStream, Stream); - -RandomReadStream.prototype.pause = function() { - this._paused = true; - this.emit('pause'); -}; - -RandomReadStream.prototype.resume = function() { - // console.error("rrs resume"); - this._paused = false; - this.emit('resume'); - this._process(); -}; - -RandomReadStream.prototype._process = function() { - if (this._processing) return; - if (this._paused) return; - - this._processing = true; - - if (!this._remaining) { - this._hash = this._hasher.digest('hex').toLowerCase().trim(); - this._processing = false; - - this.emit('end'); - return; - } - - // figure out how many bytes to output - // if finished, then just emit end. - var block = this._opt.block; - var jitter = this._opt.jitter; - if (jitter) { - block += Math.ceil(Math.random() * jitter - (jitter / 2)); - } - block = Math.min(block, this._remaining); - var buf = new Buffer(block); - for (var i = 0; i < block; i++) { - buf[i] = Math.random() * 256; - } - - this._hasher.update(buf); - - this._remaining -= block; - - console.error('block=%d\nremain=%d\n', block, this._remaining); - this._processing = false; - - this.emit('data', buf); - process.nextTick(this._process); -}; - - -// a filter that just verifies a shasum -function HashStream() { - Stream.call(this); - - this.readable = this.writable = true; - this._hasher = crypto.createHash('sha1'); -} - -util.inherits(HashStream, Stream); - -HashStream.prototype.write = function(c) { - // Simulate the way that an fs.ReadStream returns false - // on *every* write like a jerk, only to resume a - // moment later. - this._hasher.update(c); - process.nextTick(this.resume.bind(this)); - return false; -}; - -HashStream.prototype.resume = function() { - this.emit('resume'); - process.nextTick(this.emit.bind(this, 'drain')); -}; - -HashStream.prototype.end = function(c) { - if (c) { - this.write(c); - } - this._hash = this._hasher.digest('hex').toLowerCase().trim(); - this.emit('data', this._hash); - this.emit('end'); -}; - - - - -var inp = new RandomReadStream({ total: 1024, block: 256, jitter: 16 }); -var out = new HashStream(); -var gzip = zlib.createGzip(); -var gunz = zlib.createGunzip(); - -inp.pipe(gzip).pipe(gunz).pipe(out); - -inp.on('data', function(c) { - console.error('inp data', c.length); -}); - -gzip.on('data', function(c) { - console.error('gzip data', c.length); -}); - -gunz.on('data', function(c) { - console.error('gunz data', c.length); -}); - -out.on('data', function(c) { - console.error('out data', c.length); -}); - -var didSomething = false; -out.on('data', function(c) { - didSomething = true; - console.error('hash=%s', c); - assert.equal(c, inp._hash, 'hashes should match'); -}); - -process.on('exit', function() { - assert(didSomething, 'should have done something'); -}); diff --git a/test/simple/test-zlib-write-after-close.js b/test/simple/test-zlib-write-after-close.js deleted file mode 100644 index d3f3d4e6b3c4..000000000000 --- a/test/simple/test-zlib-write-after-close.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var assert = require('assert'); -var zlib = require('zlib'); - -var closed = false; - -zlib.gzip('hello', function(err, out) { - var unzip = zlib.createGunzip(); - unzip.close(function() { - closed = true; - }); - assert.throws(function() { - unzip.write(out); - }); -}); - -process.on('exit', function() { - assert(closed); -}); diff --git a/test/simple/test-zlib-write-after-flush.js b/test/simple/test-zlib-write-after-flush.js deleted file mode 100644 index e13871ecb62e..000000000000 --- a/test/simple/test-zlib-write-after-flush.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); -var zlib = require('zlib'); -var fs = require('fs'); - -var gzip = zlib.createGzip(); -var gunz = zlib.createUnzip(); - -gzip.pipe(gunz); - -var output = ''; -var input = 'A line of data\n'; -gunz.setEncoding('utf8'); -gunz.on('data', function(c) { - output += c; -}); - -process.on('exit', function() { - assert.equal(output, input); - - // Make sure that the flush flag was set back to normal - assert.equal(gzip._flushFlag, zlib.Z_NO_FLUSH); - - console.log('ok'); -}); - -// make sure that flush/write doesn't trigger an assert failure -gzip.flush(); write(); -function write() { - gzip.write(input); - gzip.end(); - gunz.read(0); -} diff --git a/test/simple/test-zlib-zero-byte.js b/test/simple/test-zlib-zero-byte.js deleted file mode 100644 index 31ac86bd6ab1..000000000000 --- a/test/simple/test-zlib-zero-byte.js +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common'); -var assert = require('assert'); - -var zlib = require('zlib'); -var gz = zlib.Gzip() -var emptyBuffer = new Buffer(0); -var received = 0; -gz.on('data', function(c) { - received += c.length; -}); -var ended = false; -gz.on('end', function() { - ended = true; -}); -var finished = false; -gz.on('finish', function() { - finished = true; -}); -gz.write(emptyBuffer); -gz.end(); - -process.on('exit', function() { - assert.equal(received, 20); - assert(ended); - assert(finished); - console.log('ok'); -}); diff --git a/test/simple/test-zlib.js b/test/simple/test-zlib.js deleted file mode 100644 index b9267525ee44..000000000000 --- a/test/simple/test-zlib.js +++ /dev/null @@ -1,229 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var common = require('../common.js'); -var assert = require('assert'); -var zlib = require('zlib'); -var path = require('path'); - -var zlibPairs = - [[zlib.Deflate, zlib.Inflate], - [zlib.Gzip, zlib.Gunzip], - [zlib.Deflate, zlib.Unzip], - [zlib.Gzip, zlib.Unzip], - [zlib.DeflateRaw, zlib.InflateRaw]]; - -// how fast to trickle through the slowstream -var trickle = [128, 1024, 1024 * 1024]; - -// tunable options for zlib classes. - -// several different chunk sizes -var chunkSize = [128, 1024, 1024 * 16, 1024 * 1024]; - -// this is every possible value. -var level = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; -var windowBits = [8, 9, 10, 11, 12, 13, 14, 15]; -var memLevel = [1, 2, 3, 4, 5, 6, 7, 8, 9]; -var strategy = [0, 1, 2, 3, 4]; - -// it's nice in theory to test every combination, but it -// takes WAY too long. Maybe a pummel test could do this? -if (!process.env.PUMMEL) { - trickle = [1024]; - chunkSize = [1024 * 16]; - level = [6]; - memLevel = [8]; - windowBits = [15]; - strategy = [0]; -} - -var fs = require('fs'); - -var testFiles = ['person.jpg', 'elipses.txt', 'empty.txt']; - -if (process.env.FAST) { - zlibPairs = [[zlib.Gzip, zlib.Unzip]]; - var testFiles = ['person.jpg']; -} - -var tests = {}; -testFiles.forEach(function(file) { - tests[file] = fs.readFileSync(path.resolve(common.fixturesDir, file)); -}); - -var util = require('util'); -var stream = require('stream'); - - -// stream that saves everything -function BufferStream() { - this.chunks = []; - this.length = 0; - this.writable = true; - this.readable = true; -} - -util.inherits(BufferStream, stream.Stream); - -BufferStream.prototype.write = function(c) { - this.chunks.push(c); - this.length += c.length; - return true; -}; - -BufferStream.prototype.end = function(c) { - if (c) this.write(c); - // flatten - var buf = new Buffer(this.length); - var i = 0; - this.chunks.forEach(function(c) { - c.copy(buf, i); - i += c.length; - }); - this.emit('data', buf); - this.emit('end'); - return true; -}; - - -function SlowStream(trickle) { - this.trickle = trickle; - this.offset = 0; - this.readable = this.writable = true; -} - -util.inherits(SlowStream, stream.Stream); - -SlowStream.prototype.write = function() { - throw new Error('not implemented, just call ss.end(chunk)'); -}; - -SlowStream.prototype.pause = function() { - this.paused = true; - this.emit('pause'); -}; - -SlowStream.prototype.resume = function() { - var self = this; - if (self.ended) return; - self.emit('resume'); - if (!self.chunk) return; - self.paused = false; - emit(); - function emit() { - if (self.paused) return; - if (self.offset >= self.length) { - self.ended = true; - return self.emit('end'); - } - var end = Math.min(self.offset + self.trickle, self.length); - var c = self.chunk.slice(self.offset, end); - self.offset += c.length; - self.emit('data', c); - process.nextTick(emit); - } -}; - -SlowStream.prototype.end = function(chunk) { - // walk over the chunk in blocks. - var self = this; - self.chunk = chunk; - self.length = chunk.length; - self.resume(); - return self.ended; -}; - - - -// for each of the files, make sure that compressing and -// decompressing results in the same data, for every combination -// of the options set above. -var failures = 0; -var total = 0; -var done = 0; - -Object.keys(tests).forEach(function(file) { - var test = tests[file]; - chunkSize.forEach(function(chunkSize) { - trickle.forEach(function(trickle) { - windowBits.forEach(function(windowBits) { - level.forEach(function(level) { - memLevel.forEach(function(memLevel) { - strategy.forEach(function(strategy) { - zlibPairs.forEach(function(pair) { - var Def = pair[0]; - var Inf = pair[1]; - var opts = { level: level, - windowBits: windowBits, - memLevel: memLevel, - strategy: strategy }; - - total++; - - var def = new Def(opts); - var inf = new Inf(opts); - var ss = new SlowStream(trickle); - var buf = new BufferStream(); - - // verify that the same exact buffer comes out the other end. - buf.on('data', function(c) { - var msg = file + ' ' + - chunkSize + ' ' + - JSON.stringify(opts) + ' ' + - Def.name + ' -> ' + Inf.name; - var ok = true; - var testNum = ++done; - for (var i = 0; i < Math.max(c.length, test.length); i++) { - if (c[i] !== test[i]) { - ok = false; - failures++; - break; - } - } - if (ok) { - console.log('ok ' + (testNum) + ' ' + msg); - } else { - console.log('not ok ' + (testNum) + ' ' + msg); - console.log(' ...'); - console.log(' testfile: ' + file); - console.log(' type: ' + Def.name + ' -> ' + Inf.name); - console.log(' position: ' + i); - console.log(' options: ' + JSON.stringify(opts)); - console.log(' expect: ' + test[i]); - console.log(' actual: ' + c[i]); - console.log(' chunkSize: ' + chunkSize); - console.log(' ---'); - } - }); - - // the magic happens here. - ss.pipe(def).pipe(inf).pipe(buf); - ss.end(test); - }); - }); }); }); }); }); }); // sad stallman is sad. -}); - -process.on('exit', function(code) { - console.log('1..' + done); - assert.equal(done, total, (total - done) + ' tests left unfinished'); - assert.ok(!failures, 'some test failures'); -});