mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
Fix --content-type and --data inputs in curl command
content-type needs to be parsed (no automatic parsing from String) data was splitting on commas, meaning --data="key=value1,value2" was sent to the server as "key=value1&value2" NOTE - you'd expect there to already be a "do nothing splitter", right? But there isn't :/ ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=223346887
This commit is contained in:
parent
5d2bb892f3
commit
849ea0e0f3
2 changed files with 67 additions and 0 deletions
|
@ -79,6 +79,37 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
|||
eq("some data".getBytes(UTF_8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostInvocation_withContentType() throws Exception {
|
||||
runCommand(
|
||||
"--path=/foo/bar?a=1&b=2",
|
||||
"--data=some data",
|
||||
"--service=DEFAULT",
|
||||
"--content-type=application/json");
|
||||
verify(connection).withService(DEFAULT);
|
||||
verifyNoMoreInteractions(connection);
|
||||
verify(connectionForService)
|
||||
.sendPostRequest(
|
||||
eq("/foo/bar?a=1&b=2"),
|
||||
eq(ImmutableMap.<String, String>of()),
|
||||
eq(MediaType.JSON_UTF_8),
|
||||
eq("some data".getBytes(UTF_8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostInvocation_badContentType() throws Exception {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
runCommand(
|
||||
"--path=/foo/bar?a=1&b=2",
|
||||
"--data=some data",
|
||||
"--service=DEFAULT",
|
||||
"--content-type=bad"));
|
||||
verifyNoMoreInteractions(connection);
|
||||
verifyNoMoreInteractions(connectionForService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiDataPost() throws Exception {
|
||||
runCommand(
|
||||
|
@ -93,6 +124,20 @@ public class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
|||
eq("first=100&second=200".getBytes(UTF_8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataDoesntSplit() throws Exception {
|
||||
runCommand(
|
||||
"--path=/foo/bar?a=1&b=2", "--data=one,two", "--service=PUBAPI");
|
||||
verify(connection).withService(PUBAPI);
|
||||
verifyNoMoreInteractions(connection);
|
||||
verify(connectionForService)
|
||||
.sendPostRequest(
|
||||
eq("/foo/bar?a=1&b=2"),
|
||||
eq(ImmutableMap.<String, String>of()),
|
||||
eq(MediaType.PLAIN_TEXT_UTF_8),
|
||||
eq("one,two".getBytes(UTF_8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitPostInvocation() throws Exception {
|
||||
runCommand("--path=/foo/bar?a=1&b=2", "--request=POST", "--service=TOOLS");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue