mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 22:45:25 +00:00
fix(bru-2035): form-urlencoded logic updates (#5820)
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
meta {
|
||||
name: array body
|
||||
type: http
|
||||
seq: 8
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{echo-host}}
|
||||
body: formUrlEncoded
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
req.setBody([
|
||||
{name: "empty", value: ""},
|
||||
{name: "null", value: null},
|
||||
{name: "undefined", value: undefined},
|
||||
{name: "zero", value: 0},
|
||||
{name: "false", value: false},
|
||||
{name: "", value: "empty_key"},
|
||||
{name: "key", value: "value1"},
|
||||
{name: "name", value: "bruno"},
|
||||
{name: "key", value: "value2"},
|
||||
]);
|
||||
}
|
||||
|
||||
tests {
|
||||
test("req.setBody() with edge cases - request body", function() {
|
||||
const data = req.getBody();
|
||||
const expected = [
|
||||
"empty=",
|
||||
"null=",
|
||||
"undefined=",
|
||||
"zero=0",
|
||||
"false=false",
|
||||
"=empty_key",
|
||||
"key=value1",
|
||||
"name=bruno",
|
||||
"key=value2"
|
||||
].join("&");
|
||||
|
||||
expect(data).to.eql(expected);
|
||||
});
|
||||
|
||||
test("req.setBody() with edge cases - response body", function() {
|
||||
const data = res.getBody();
|
||||
const expected = [
|
||||
"empty=",
|
||||
"null=",
|
||||
"undefined=",
|
||||
"zero=0",
|
||||
"false=false",
|
||||
"=empty_key",
|
||||
"key=value1",
|
||||
"name=bruno",
|
||||
"key=value2"
|
||||
].join("&");
|
||||
|
||||
expect(data).to.eql(expected);
|
||||
});
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
meta {
|
||||
name: content-type via setHeader
|
||||
type: http
|
||||
seq: 7
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{echo-host}}
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
req.setHeader('content-type', 'application/x-www-form-urlencoded');
|
||||
req.setBody([
|
||||
{name: "key", value: "value"},
|
||||
{name: "name", value: "bruno"}
|
||||
]);
|
||||
}
|
||||
|
||||
tests {
|
||||
test("req.setBody() - request body", function() {
|
||||
const data = req.getBody();
|
||||
expect(data).to.eql("key=value&name=bruno");
|
||||
});
|
||||
|
||||
test("req.setBody() - response body", function() {
|
||||
const data = res.getBody();
|
||||
expect(data).to.eql("key=value&name=bruno");
|
||||
});
|
||||
|
||||
test("Content-Type header is set correctly", function() {
|
||||
const contentType = req.getHeader('content-type');
|
||||
expect(contentType).to.eql('application/x-www-form-urlencoded');
|
||||
});
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
meta {
|
||||
name: form-urlencoded
|
||||
seq: 1
|
||||
}
|
||||
|
||||
auth {
|
||||
mode: inherit
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
meta {
|
||||
name: object body
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{echo-host}}
|
||||
body: formUrlEncoded
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
req.setBody({
|
||||
"key": "value with spaces",
|
||||
"name": "bruno",
|
||||
"array": ["test", "value"],
|
||||
});
|
||||
}
|
||||
|
||||
tests {
|
||||
// https://github.com/usebruno/bruno/issues/5813
|
||||
test("req.setBody() with object - request body", function() {
|
||||
const data = req.getBody();
|
||||
expect(data).to.eql("key=value%20with%20spaces&name=bruno&array=test&array=value");
|
||||
});
|
||||
|
||||
test("req.setBody() with object - response body", function() {
|
||||
const data = res.getBody();
|
||||
expect(data).to.eql("key=value%20with%20spaces&name=bruno&array=test&array=value");
|
||||
});
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
meta {
|
||||
name: string body
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{echo-host}}
|
||||
body: formUrlEncoded
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
req.setBody("key=value&name=bruno");
|
||||
}
|
||||
|
||||
tests {
|
||||
test("req.setBody() with string format - request body", function() {
|
||||
const data = req.getBody();
|
||||
expect(data).to.eql("key=value&name=bruno");
|
||||
});
|
||||
|
||||
test("req.setBody() with string format - response body", function() {
|
||||
const data = res.getBody();
|
||||
expect(data).to.eql("key=value&name=bruno");
|
||||
});
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
Reference in New Issue
Block a user