diff options
author | Thomas Dräbing <thomas.draebing@sap.com> | 2019-08-27 15:27:56 +0000 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2019-08-28 08:18:23 +0900 |
commit | 8d6ce84270668a433e73cff6cadc20c3d67f9198 (patch) | |
tree | 86332adf68519bae7d6bcbc97d11392ef6fdeb56 | |
parent | 300f911856800094ec6b8d5bac6b6c0f8daa6666 (diff) |
Revert "CreateAccount: Fail early when invalid SSH key is given"
This reverts commit b5d2b319dad13ccd87dd41667d6b6b0ed3489779.
Reason for revert: This change breaks user creation, if a SSH key
is added during the creation from at least stable-2.16 onwards. Also
it does not resolve the original issue per se, since it does still not
ensure that the complete account creation is only happening, if all
given data is valid.
Bug: Issue 11370
Change-Id: Ibed66e7ec3d901de7fc56b54fd1e349b35c8506d
-rw-r--r-- | gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java | 15 | ||||
-rw-r--r-- | gerrit-server/src/main/java/com/google/gerrit/server/account/CreateAccount.java | 18 |
2 files changed, 9 insertions, 24 deletions
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java index 4623675ef6..ac71e54734 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java @@ -280,21 +280,6 @@ public class AccountIT extends AbstractDaemonTest { } @Test - public void createWithInvalidSshKey() throws Exception { - AccountInput input = new AccountInput(); - input.username = name("test"); - input.sshKey = "invalid key"; - - // Invalid key should cause the creation to fail - BadRequestException thrown = - assertThrows(BadRequestException.class, () -> gApi.accounts().create(input)); - assertThat(thrown).hasMessageThat().isEqualTo("Invalid SSH Key"); - - // The account should not have been created - assertThrows(ResourceNotFoundException.class, () -> gApi.accounts().id(input.username).get()); - } - - @Test public void createWithInvalidEmailAddress() throws Exception { AccountInput input = new AccountInput(); input.username = name("test"); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateAccount.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateAccount.java index 3fa3de197c..ef1e8ccd44 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateAccount.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/CreateAccount.java @@ -141,15 +141,6 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn } } - if (input.sshKey != null) { - try { - authorizedKeys.addKey(id, input.sshKey); - sshKeyCache.evict(username); - } catch (InvalidSshKeyException e) { - throw new BadRequestException(e.getMessage()); - } - } - List<ExternalId> extIds = new ArrayList<>(); extIds.add(extUser); for (AccountExternalIdCreator c : externalIdCreators) { @@ -193,6 +184,15 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn } } + if (input.sshKey != null) { + try { + authorizedKeys.addKey(id, input.sshKey); + sshKeyCache.evict(username); + } catch (InvalidSshKeyException e) { + throw new BadRequestException(e.getMessage()); + } + } + AccountLoader loader = infoLoader.create(true); AccountInfo info = loader.get(id); loader.fill(); |