Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor character encoding method usage #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,33 +176,26 @@ private ModelAndView showErrorPage(String errorMessage)
*/
private ModelAndView showMiddlewarePage(String sessionId, String userAgent)
{
try
String ausweisappLink;
if (isMobileDevice(userAgent))
{
String ausweisappLink;
if (isMobileDevice(userAgent))
{
ausweisappLink = "eid://127.0.0.1:24727/eID-Client?tcTokenURL=";
}
else
{
ausweisappLink = "http://127.0.0.1:24727/eID-Client?tcTokenURL=";
}
ModelAndView modelAndView = new ModelAndView("middleware");

String tcTokenURL = requestHandler.getTcTokenURL(sessionId);
modelAndView.addObject("tcTokenURL", tcTokenURL);

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

String linkToSelf = ContextPaths.EIDAS_CONTEXT_PATH + ContextPaths.REQUEST_RECEIVER + "?sessionId=" + sessionId;
modelAndView.addObject("linkToSelf", linkToSelf);
return modelAndView;
ausweisappLink = "eid://127.0.0.1:24727/eID-Client?tcTokenURL=";
}
catch (UnsupportedEncodingException e)
else
{
return showErrorPage(e.getMessage());
ausweisappLink = "http://127.0.0.1:24727/eID-Client?tcTokenURL=";
}
ModelAndView modelAndView = new ModelAndView("middleware");

String tcTokenURL = requestHandler.getTcTokenURL(sessionId);
modelAndView.addObject("tcTokenURL", tcTokenURL);

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;
}

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));
}
}