- _mode |
- string - binary or text |
- text |
+ _encoding |
+ string - utf-8 or iso-8859-1 or undefined if binary |
+ undefined |
diff --git a/test/models/http/httpRequestTest.js b/test/models/http/httpRequestTest.js
index 10046123f..7f0995f92 100644
--- a/test/models/http/httpRequestTest.js
+++ b/test/models/http/httpRequestTest.js
@@ -15,7 +15,7 @@ describe('HttpRequest', function () {
socket: { remoteAddress: '', remotePort: '' },
setEncoding: mock(),
url: 'http://localhost/',
- rawHeaders: []
+ rawHeaders: ['Content-Type', 'text/plain']
});
});
@@ -127,6 +127,7 @@ describe('HttpRequest', function () {
it('should set body from data gzipped events', async function () {
request.rawHeaders = [
'Content-Encoding', 'gzip',
+ 'Content-Type', 'text/plain; charset=utf8',
'Host', '127.0.0.1:8000'
];
diff --git a/test/models/imposterTest.js b/test/models/imposterTest.js
index 281d3ae3f..997342ff0 100644
--- a/test/models/imposterTest.js
+++ b/test/models/imposterTest.js
@@ -232,7 +232,7 @@ describe('imposter', function () {
protocol: 'test',
port: 3535,
recordRequests: false,
- stubs: [{ responses: [{ is: { body: 'body' } }] }]
+ stubs: [{ responses: [{ is: { bodyEncoding: 'utf8', body: 'body' } }] }]
});
});
@@ -263,14 +263,14 @@ describe('imposter', function () {
assert.deepEqual(json.stubs, [
{
responses: [
- { is: { body: 'first' } },
+ { is: { bodyEncoding: 'utf8', body: 'first' } },
{ inject: 'inject' }
],
_links: { self: { href: '/imposters/3535/stubs/0' } }
},
{
responses: [
- { is: { body: 'second' } }
+ { is: { bodyEncoding: 'utf8', body: 'second' } }
],
_links: { self: { href: '/imposters/3535/stubs/1' } }
}
@@ -303,7 +303,7 @@ describe('imposter', function () {
assert.deepEqual(json.stubs, [
{
responses: [
- { is: { body: 'first' } },
+ { is: { bodyEncoding: 'utf8', body: 'first' } },
{ inject: 'inject' }
],
_links: { self: { href: '/imposters/3535/stubs/0' } }
diff --git a/test/models/predicates/containsTest.js b/test/models/predicates/containsTest.js
index ec73d1d04..9fe5ecad6 100644
--- a/test/models/predicates/containsTest.js
+++ b/test/models/predicates/containsTest.js
@@ -60,9 +60,9 @@ describe('predicates', function () {
});
it('should return true if contains binary sequence and encoding is base64', function () {
- const predicate = { contains: { field: Buffer.from([2, 3]).toString('base64') } },
- request = { field: Buffer.from([1, 2, 3, 4]).toString('base64') };
- assert.ok(predicates.evaluate(predicate, request, 'base64'));
+ const predicate = { contains: { body: Buffer.from([2, 3]).toString('base64') } },
+ request = { body: Buffer.from([1, 2, 3, 4]).toString('base64') };
+ assert.ok(predicates.evaluate(predicate, request));
});
it('should return false if not contains binary sequence and encoding is base64', function () {
diff --git a/test/models/predicates/endsWithTest.js b/test/models/predicates/endsWithTest.js
index d321434be..69ec39edb 100644
--- a/test/models/predicates/endsWithTest.js
+++ b/test/models/predicates/endsWithTest.js
@@ -48,8 +48,8 @@ describe('predicates', function () {
});
it('should return true if ends with binary sequence and encoding is base64', function () {
- const predicate = { endsWith: { field: Buffer.from([2, 3, 4]).toString('base64') } },
- request = { field: Buffer.from([1, 2, 3, 4]).toString('base64') };
+ const predicate = { endsWith: { body: Buffer.from([2, 3, 4]).toString('base64') } },
+ request = { body: Buffer.from([1, 2, 3, 4]).toString('base64') };
assert.ok(predicates.evaluate(predicate, request, 'base64'));
});
diff --git a/test/models/predicates/injectTest.js b/test/models/predicates/injectTest.js
index e3d0a419e..485a279aa 100644
--- a/test/models/predicates/injectTest.js
+++ b/test/models/predicates/injectTest.js
@@ -39,7 +39,7 @@ describe('predicates', function () {
request = {};
try {
- predicates.evaluate(predicate, request, 'utf8', logger);
+ predicates.evaluate(predicate, request, logger);
assert.fail('should have thrown exception');
}
catch (error) {
@@ -61,7 +61,7 @@ describe('predicates', function () {
},
predicate = { inject: fn.toString() },
request = { path: '/', method: 'GET' };
- assert.ok(predicates.evaluate(predicate, request, 'utf8', mockedLogger, mockedImposterState));
+ assert.ok(predicates.evaluate(predicate, request, mockedLogger, mockedImposterState));
assert.deepEqual(mockedImposterState, expectedImposterState);
});
diff --git a/test/models/predicates/jsonpathTest.js b/test/models/predicates/jsonpathTest.js
index 8b503d727..7e43ae927 100644
--- a/test/models/predicates/jsonpathTest.js
+++ b/test/models/predicates/jsonpathTest.js
@@ -251,7 +251,7 @@ describe('predicates', function () {
matches: { body: '111\\.222\\.333\\.*' },
jsonpath: { selector: '$.ipAddress' }
},
- request = { body: '{ "ipAddress": "111.222.333.456" }' };
+ request = { bodyEncoding: 'utf8', body: '{ "ipAddress": "111.222.333.456" }' };
assert.ok(predicates.evaluate(predicate, request));
});
});
diff --git a/test/models/predicates/matchesTest.js b/test/models/predicates/matchesTest.js
index 8b60877e5..20f9f86f5 100644
--- a/test/models/predicates/matchesTest.js
+++ b/test/models/predicates/matchesTest.js
@@ -55,14 +55,14 @@ describe('predicates', function () {
it('should throw an error if encoding is base64', function () {
try {
- const predicate = { matches: { field: 'dGVzdA==' } },
- request = { field: 'dGVzdA==' };
- predicates.evaluate(predicate, request, 'base64');
+ const predicate = { matches: { body: 'dGVzdA==' } },
+ request = { body: 'dGVzdA==' };
+ predicates.evaluate(predicate, request);
assert.fail('should have thrown');
}
catch (error) {
assert.strictEqual(error.code, 'bad data');
- assert.strictEqual(error.message, 'the matches predicate is not allowed in binary mode');
+ assert.strictEqual(error.message, 'the matches predicate is not allowed for binary bodies');
}
});
diff --git a/test/models/predicates/startsWithTest.js b/test/models/predicates/startsWithTest.js
index 6600feac2..39198b74e 100644
--- a/test/models/predicates/startsWithTest.js
+++ b/test/models/predicates/startsWithTest.js
@@ -48,9 +48,9 @@ describe('predicates', function () {
});
it('should return true if starts with binary sequence and encoding is base64', function () {
- const predicate = { startsWith: { field: Buffer.from([1, 2]).toString('base64') } },
- request = { field: Buffer.from([1, 2, 3, 4]).toString('base64') };
- assert.ok(predicates.evaluate(predicate, request, 'base64'));
+ const predicate = { startsWith: { body: Buffer.from([1, 2]).toString('base64') } },
+ request = { body: Buffer.from([1, 2, 3, 4]).toString('base64') };
+ assert.ok(predicates.evaluate(predicate, request));
});
it('should return false if does not start with binary sequence and encoding is base64', function () {
diff --git a/test/models/predicates/xpathTest.js b/test/models/predicates/xpathTest.js
index 58037dc10..879e9038c 100644
--- a/test/models/predicates/xpathTest.js
+++ b/test/models/predicates/xpathTest.js
@@ -317,14 +317,14 @@ describe('predicates', function () {
assert.ok(!predicates.evaluate(predicate, request));
});
- it('should throw an error if encoding is base64', function () {
+ it('should throw an error if body is binary', function () {
try {
const predicate = {
- equals: { field: 'dGVzdA==' },
+ equals: { body: 'dGVzdA==' },
xpath: { selector: 'dGVzdA==' }
},
- request = { field: 'dGVzdA==' };
- predicates.evaluate(predicate, request, 'base64');
+ request = { body: 'dGVzdA==' };
+ predicates.evaluate(predicate, request);
assert.fail('should have thrown');
}
catch (error) {