Merge branch 'stable-2.13'
* stable-2.13: AccountSshKey: Strip newline characters out of public key string Change-Id: Ia6d8973e347af80c945ef7b4bb19c79e03d91b89
This commit is contained in:
@@ -67,7 +67,7 @@ public final class AccountSshKey {
|
||||
|
||||
public AccountSshKey(final AccountSshKey.Id i, final String pub) {
|
||||
id = i;
|
||||
sshPublicKey = pub;
|
||||
sshPublicKey = pub.replace("\n", "").replace("\r", "");
|
||||
valid = id.isValid();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,12 @@ public class AccountSshKeyTest {
|
||||
+ "vf8IZixgjCmiBhaL2gt3wff6pP+NXJpTSA4aeWE5DfNK5tZlxlSxqkKOS8JRSUeNQov5T"
|
||||
+ "w== john.doe@example.com";
|
||||
|
||||
private static final String KEY_WITH_NEWLINES =
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCgug5VyMXQGnem2H1KVC4/HcRcD4zzBqS\n"
|
||||
+ "uJBRWVonSSoz3RoAZ7bWXCVVGwchtXwUURD689wFYdiPecOrWOUgeeyRq754YWRhU+W28\n"
|
||||
+ "vf8IZixgjCmiBhaL2gt3wff6pP+NXJpTSA4aeWE5DfNK5tZlxlSxqkKOS8JRSUeNQov5T\n"
|
||||
+ "w== john.doe@example.com";
|
||||
|
||||
private final Account.Id accountId = new Account.Id(1);
|
||||
|
||||
@Test
|
||||
@@ -47,4 +53,14 @@ public class AccountSshKeyTest {
|
||||
assertThat(key.getEncodedKey()).isEqualTo(KEY.split(" ")[1]);
|
||||
assertThat(key.getComment()).isEqualTo(KEY.split(" ")[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyWithNewLines() throws Exception {
|
||||
AccountSshKey key = new AccountSshKey(
|
||||
new AccountSshKey.Id(accountId, 1), KEY_WITH_NEWLINES);
|
||||
assertThat(key.getSshPublicKey()).isEqualTo(KEY);
|
||||
assertThat(key.getAlgorithm()).isEqualTo(KEY.split(" ")[0]);
|
||||
assertThat(key.getEncodedKey()).isEqualTo(KEY.split(" ")[1]);
|
||||
assertThat(key.getComment()).isEqualTo(KEY.split(" ")[2]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user