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:
parent
3bc7ef7ed5
commit
1bbefca92e
2 changed files with 5 additions and 9 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue