summaryrefslogtreecommitdiffstats
path: root/test/fuzzing/client
diff options
context:
space:
mode:
Diffstat (limited to 'test/fuzzing/client')
-rw-r--r--test/fuzzing/client/client-fuzz-body.js28
-rw-r--r--test/fuzzing/client/client-fuzz-headers.js27
-rw-r--r--test/fuzzing/client/client-fuzz-options.js38
-rw-r--r--test/fuzzing/client/index.js7
4 files changed, 100 insertions, 0 deletions
diff --git a/test/fuzzing/client/client-fuzz-body.js b/test/fuzzing/client/client-fuzz-body.js
new file mode 100644
index 0000000..6643dda
--- /dev/null
+++ b/test/fuzzing/client/client-fuzz-body.js
@@ -0,0 +1,28 @@
+'use strict'
+
+const { request, errors } = require('../../..')
+
+const acceptableCodes = [
+ 'ERR_INVALID_ARG_TYPE'
+]
+
+// TODO: could make this a class with some inbuilt functionality that we can inherit
+async function fuzz (netServer, results, buf) {
+ const body = buf
+ results.body = body
+ try {
+ const data = await request(`http://localhost:${netServer.address().port}`, { body })
+ data.body.destroy().on('error', () => {})
+ } catch (err) {
+ results.err = err
+ // Handle any undici errors
+ if (Object.values(errors).some(undiciError => err instanceof undiciError)) {
+ // Okay error
+ } else if (!acceptableCodes.includes(err.code)) {
+ console.log(`=== Headers: ${JSON.stringify(body)} ===`)
+ throw err
+ }
+ }
+}
+
+module.exports = fuzz
diff --git a/test/fuzzing/client/client-fuzz-headers.js b/test/fuzzing/client/client-fuzz-headers.js
new file mode 100644
index 0000000..84f3390
--- /dev/null
+++ b/test/fuzzing/client/client-fuzz-headers.js
@@ -0,0 +1,27 @@
+'use strict'
+
+const { request, errors } = require('../../..')
+
+const acceptableCodes = [
+ 'ERR_INVALID_ARG_TYPE'
+]
+
+async function fuzz (netServer, results, buf) {
+ const headers = { buf: buf.toString() }
+ results.body = headers
+ try {
+ const data = await request(`http://localhost:${netServer.address().port}`, { headers })
+ data.body.destroy().on('error', () => {})
+ } catch (err) {
+ results.err = err
+ // Handle any undici errors
+ if (Object.values(errors).some(undiciError => err instanceof undiciError)) {
+ // Okay error
+ } else if (!acceptableCodes.includes(err.code)) {
+ console.log(`=== Headers: ${JSON.stringify(headers)} ===`)
+ throw err
+ }
+ }
+}
+
+module.exports = fuzz
diff --git a/test/fuzzing/client/client-fuzz-options.js b/test/fuzzing/client/client-fuzz-options.js
new file mode 100644
index 0000000..5be81b6
--- /dev/null
+++ b/test/fuzzing/client/client-fuzz-options.js
@@ -0,0 +1,38 @@
+'use strict'
+
+const { request, errors } = require('../../..')
+
+const acceptableCodes = [
+ 'ERR_INVALID_URL',
+ // These are included because '\\ABC' is interpreted as a Windows UNC path and can cause these errors.
+ 'ENOTFOUND',
+ 'EAI_AGAIN',
+ 'ECONNREFUSED'
+ // ----
+]
+
+async function fuzz (netServer, results, buf) {
+ const optionKeys = ['body', 'path', 'method', 'opaque', 'upgrade', buf]
+ const options = {}
+ for (const optionKey of optionKeys) {
+ if (Math.random() < 0.5) {
+ options[optionKey] = buf.toString()
+ }
+ }
+ results.options = options
+ try {
+ const data = await request(`http://localhost:${netServer.address().port}`, options)
+ data.body.destroy().on('error', () => {})
+ } catch (err) {
+ results.err = err
+ // Handle any undici errors
+ if (Object.values(errors).some(undiciError => err instanceof undiciError)) {
+ // Okay error
+ } else if (!acceptableCodes.includes(err.code)) {
+ console.log(`=== Options: ${JSON.stringify(options)} ===`)
+ throw err
+ }
+ }
+}
+
+module.exports = fuzz
diff --git a/test/fuzzing/client/index.js b/test/fuzzing/client/index.js
new file mode 100644
index 0000000..dac3d98
--- /dev/null
+++ b/test/fuzzing/client/index.js
@@ -0,0 +1,7 @@
+'use strict'
+
+module.exports = {
+ clientFuzzBody: require('./client-fuzz-body'),
+ clientFuzzHeaders: require('./client-fuzz-headers'),
+ clientFuzzOptions: require('./client-fuzz-options')
+}