Refactor the way that the console BE parses POST bodies (#2113)

This includes two changes:
1. Creating a base string-type adapter for use parsing to/from JSON
   classes that are represented as simple strings
2. Changing the object-provider methods so that the POST bodies should
   contain precisely the expected object(s) and nothing else. This way,
   it's easier for the frontend and backend to agree that, for instance,
   one POST endpoint might accept exactly a Registrar object, or a list
   of Contact objects.
This commit is contained in:
gbrodman
2023-08-17 15:51:21 -04:00
committed by GitHub
parent 655f05c58c
commit 9f551eb552
10 changed files with 69 additions and 80 deletions
@@ -251,9 +251,7 @@ class RegistrarsActionTest {
passcodeGenerator);
} else {
try {
doReturn(
new BufferedReader(
new StringReader("{\"registrar\":" + registrarParamMap.toString() + "}")))
doReturn(new BufferedReader(new StringReader(registrarParamMap.toString())))
.when(request)
.getReader();
} catch (IOException e) {
@@ -238,8 +238,7 @@ class ContactActionTest {
if (method.equals(Action.Method.GET)) {
return new ContactAction(request, authResult, response, GSON, registrarId, Optional.empty());
} else {
when(request.getReader())
.thenReturn(new BufferedReader(new StringReader("{\"contacts\":" + contacts + "}")));
when(request.getReader()).thenReturn(new BufferedReader(new StringReader(contacts)));
Optional<ImmutableSet<RegistrarPoc>> maybeContacts =
RegistrarConsoleModule.provideContacts(
GSON, RequestModule.provideJsonBody(request, GSON));
@@ -116,12 +116,9 @@ class SecurityActionTest {
private SecurityAction createAction(AuthResult authResult, String registrarId)
throws IOException {
doReturn(new BufferedReader(new StringReader("{\"registrar\":" + jsonRegistrar1 + "}")))
.when(request)
.getReader();
Optional<Registrar> maybeRegistrar =
RegistrarConsoleModule.provideRegistrar(
GSON, RequestModule.provideJsonBody(request, GSON));
doReturn(new BufferedReader(new StringReader(jsonRegistrar1))).when(request).getReader();
Optional<Registrar> maybeRegistrar =
RegistrarConsoleModule.provideRegistrar(GSON, RequestModule.provideJsonBody(request, GSON));
return new SecurityAction(
authResult,
response,