24672 remove linebreaks from basicauth base64 encoding to comply to standard

Signed-off-by: Sebastian Schuster <sebastian.schuster@bosch.io>
This commit is contained in:
Sebastian Schuster 2023-11-20 07:57:58 +01:00 committed by Marek Posolda
parent 3bc7ef7ed5
commit 1bbefca92e
2 changed files with 5 additions and 9 deletions

View file

@ -33,11 +33,7 @@ import java.nio.charset.StandardCharsets;
*/
public class BasicAuthHelper {
public static String createHeader(String username, String password) {
try {
return "Basic " + Base64.encodeBytes((username + ':' + password).getBytes(StandardCharsets.UTF_8), Base64.DO_BREAK_LINES);
} catch (IOException e) {
return null;
}
return "Basic " + Base64.encodeBytes((username + ':' + password).getBytes(StandardCharsets.UTF_8));
}
public static String[] parseHeader(String header) {
@ -49,7 +45,7 @@ public class BasicAuthHelper {
String val;
try {
val = new String(Base64.decode(header.substring(6), Base64.DO_BREAK_LINES));
val = new String(Base64.decode(header.substring(6)));
} catch (IOException e) {
return null;
}

View file

@ -9,10 +9,10 @@ public class BasicAuthHelperTest {
@Test
public void createHeader() {
String username = "Aladdin";
String password = "open sesame";
String password = "open sesameopen sesameopen sesameopen sesameopen sesameopen sesame";
String actual = BasicAuthHelper.createHeader(username, password);
String expect = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==";
String expect = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZW9wZW4gc2VzYW1lb3BlbiBzZXNhbWVvcGVuIHNlc2FtZW9wZW4gc2VzYW1lb3BlbiBzZXNhbWU=";
assertEquals(expect, actual);
}
@ -20,7 +20,7 @@ public class BasicAuthHelperTest {
@Test
public void parseHeader() {
String username = "Aladdin";
String password = "open sesame";
String password = "open sesameopen sesameopen sesameopen sesameopen sesameopen sesameopen sesame";
String header = BasicAuthHelper.createHeader(username, password);
String[] actual = BasicAuthHelper.parseHeader(header);