Skip to content

Commit

Permalink
Refactor character encoding method usage
Browse files Browse the repository at this point in the history
This commit simplifies the usage of character encoding methods. StandardCharsets.UTF_8.name() was replaced by StandardCharsets.UTF_8 in several places. This was done to improve code readability since StandardCharsets.UTF_8.name() and StandardCharsets.UTF_8 essentially do the same thing. Additionally, try-catch block related to encoding in RequestReceiver class has been removed since the encoding method used will not throw an exception, therefore the block was redundant.
  • Loading branch information
hduelme committed Aug 14, 2023
1 parent 8d27337 commit 2167619
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ private ModelAndView showErrorPage(String errorMessage)
*/
private ModelAndView showMiddlewarePage(String sessionId, String userAgent)
{
try
{
String ausweisappLink;
if (isMobileDevice(userAgent))
{
Expand All @@ -192,17 +190,12 @@ private ModelAndView showMiddlewarePage(String sessionId, String userAgent)
String tcTokenURL = requestHandler.getTcTokenURL(sessionId);
modelAndView.addObject("tcTokenURL", tcTokenURL);

ausweisappLink = ausweisappLink.concat(URLEncoder.encode(tcTokenURL, StandardCharsets.UTF_8.name()));
ausweisappLink = ausweisappLink.concat(URLEncoder.encode(tcTokenURL, StandardCharsets.UTF_8));
modelAndView.addObject("ausweisapp", ausweisappLink);

String linkToSelf = ContextPaths.EIDAS_CONTEXT_PATH + ContextPaths.REQUEST_RECEIVER + "?sessionId=" + sessionId;
modelAndView.addObject("linkToSelf", linkToSelf);
return modelAndView;
}
catch (UnsupportedEncodingException e)
{
return showErrorPage(e.getMessage());
}
}

private ModelAndView showSamlErrorPage(ErrorCodeWithResponseException e, String relayState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void testDoGetShouldReturnLandingPage() throws Exception
ModelMap modelMap = landingPage.getModelMap();
Assertions.assertEquals(3, modelMap.size());
Assertions.assertEquals(EID_CLIENT_URL
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8.name()),
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8),
modelMap.getAttribute("ausweisapp"));
Assertions.assertEquals(ContextPaths.EIDAS_CONTEXT_PATH + ContextPaths.REQUEST_RECEIVER + "?sessionId="
+ REQUEST_ID,
Expand All @@ -88,7 +88,7 @@ void testDoGetWithSessionIdShouldReturnLandingPage() throws Exception
ModelMap modelMap = landingPage.getModelMap();
Assertions.assertEquals(3, modelMap.size());
Assertions.assertEquals(EID_CLIENT_URL
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8.name()),
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8),
modelMap.getAttribute("ausweisapp"));
Assertions.assertEquals(ContextPaths.EIDAS_CONTEXT_PATH + ContextPaths.REQUEST_RECEIVER + "?sessionId="
+ REQUEST_ID,
Expand Down Expand Up @@ -197,7 +197,7 @@ void testDoPostShouldReturnLandingPage() throws Exception
ModelMap modelMap = landingPage.getModelMap();
Assertions.assertEquals(3, modelMap.size());
Assertions.assertEquals(EID_CLIENT_MOBIL_URL
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8.name()),
+ URLEncoder.encode(TC_TOKEN_URL + REQUEST_ID, StandardCharsets.UTF_8),
modelMap.getAttribute("ausweisapp"));
Assertions.assertEquals(ContextPaths.EIDAS_CONTEXT_PATH + ContextPaths.REQUEST_RECEIVER + "?sessionId="
+ REQUEST_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void testDateOfBirthAttributeString(String testDate) throws Exception
ByteArrayOutputStream bout = new ByteArrayOutputStream();
trans.transform(new DOMSource(all), new StreamResult(bout));

String attrString = new String(bout.toByteArray(), StandardCharsets.UTF_8.name());
String attrString = bout.toString(StandardCharsets.UTF_8);
assertTrue(attrString.contains(testDate));
}
}

0 comments on commit 2167619

Please sign in to comment.