AccountSshKey: Move from reviewdb.client package into server.account package

This class is no longer a ReviewDb class and shouldn't be used by the GWT UI.

Change-Id: I46b1b76c2375700ecaac5bc547e7507b11869d64
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-02-05 16:05:47 +01:00
parent 9640a61a84
commit a55c4396e8
22 changed files with 56 additions and 87 deletions

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.account;
import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountSshKey;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -29,6 +28,11 @@ public class AuthorizedKeysTest {
+ "uJBRWVonSSoz3RoAZ7bWXCVVGwchtXwUURD689wFYdiPecOrWOUgeeyRq754YWRhU+W28"
+ "vf8IZixgjCmiBhaL2gt3wff6pP+NXJpTSA4aeWE5DfNK5tZlxlSxqkKOS8JRSUeNQov5T"
+ "w== john.doe@example.com";
private static final String KEY1_WITH_NEWLINES =
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCgug5VyMXQGnem2H1KVC4/HcRcD4zzBqS\n"
+ "uJBRWVonSSoz3RoAZ7bWXCVVGwchtXwUURD689wFYdiPecOrWOUgeeyRq754YWRhU+W28\n"
+ "vf8IZixgjCmiBhaL2gt3wff6pP+NXJpTSA4aeWE5DfNK5tZlxlSxqkKOS8JRSUeNQov5T\n"
+ "w== john.doe@example.com";
private static final String KEY2 =
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDm5yP7FmEoqzQRDyskX+9+N0q9GrvZeh5"
+ "RG52EUpE4ms/Ujm3ewV1LoGzc/lYKJAIbdcZQNJ9+06EfWZaIRA3oOwAPe1eCnX+aLr8E"
@@ -50,6 +54,8 @@ public class AuthorizedKeysTest {
+ "zRuEL5e/QOu9yGq9xkWApCmg6edpWAHG+Bx4AldU78MiZvzoB7gMMdxc9RmZ1gYj/DjxV"
+ "w== john.doe@example.com";
private final Account.Id accountId = new Account.Id(1);
@Test
public void test() throws Exception {
List<Optional<AccountSshKey>> keys = new ArrayList<>();
@@ -105,6 +111,34 @@ public class AuthorizedKeysTest {
assertParse(authorizedKeys, keys);
}
@Test
public void validity() throws Exception {
AccountSshKey key = new AccountSshKey(new AccountSshKey.Id(accountId, -1), KEY1);
assertThat(key.isValid()).isFalse();
key = new AccountSshKey(new AccountSshKey.Id(accountId, 0), KEY1);
assertThat(key.isValid()).isFalse();
key = new AccountSshKey(new AccountSshKey.Id(accountId, 1), KEY1);
assertThat(key.isValid()).isTrue();
}
@Test
public void getters() throws Exception {
AccountSshKey key = new AccountSshKey(new AccountSshKey.Id(accountId, 1), KEY1);
assertThat(key.getSshPublicKey()).isEqualTo(KEY1);
assertThat(key.getAlgorithm()).isEqualTo(KEY1.split(" ")[0]);
assertThat(key.getEncodedKey()).isEqualTo(KEY1.split(" ")[1]);
assertThat(key.getComment()).isEqualTo(KEY1.split(" ")[2]);
}
@Test
public void keyWithNewLines() throws Exception {
AccountSshKey key = new AccountSshKey(new AccountSshKey.Id(accountId, 1), KEY1_WITH_NEWLINES);
assertThat(key.getSshPublicKey()).isEqualTo(KEY1);
assertThat(key.getAlgorithm()).isEqualTo(KEY1.split(" ")[0]);
assertThat(key.getEncodedKey()).isEqualTo(KEY1.split(" ")[1]);
assertThat(key.getComment()).isEqualTo(KEY1.split(" ")[2]);
}
private static String toWindowsLineEndings(String s) {
return s.replaceAll("\n", "\r\n");
}