summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <dpursehouse@collab.net>2019-05-10 13:52:24 +0900
committerDavid Pursehouse <dpursehouse@collab.net>2019-05-10 13:52:24 +0900
commitc8b9ee43c3fcf233a30f8a28be188f87d77c05ba (patch)
treef5e676f691fc450b68f92373f97ca6b24a677d7d
parentda21fa5ab2b7d3704880a6c9f822c436d3b90f27 (diff)
parent481a6e5bb9e2686feca72500cbf38fcc1c75490d (diff)
Merge branch 'stable-2.15' into stable-2.16
* stable-2.15: PutHttpPassword: Squash apply methods Clarify that account must have a username to be able to set HTTP password Change-Id: I4146d4a7fc00c855795e537f62c07d98026acaf1
-rw-r--r--Documentation/rest-api-accounts.txt2
-rw-r--r--java/com/google/gerrit/server/restapi/account/PutHttpPassword.java6
-rw-r--r--javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java10
3 files changed, 13 insertions, 5 deletions
diff --git a/Documentation/rest-api-accounts.txt b/Documentation/rest-api-accounts.txt
index de5f278655..8247212bfa 100644
--- a/Documentation/rest-api-accounts.txt
+++ b/Documentation/rest-api-accounts.txt
@@ -479,6 +479,8 @@ The options for setting/generating the HTTP password must be provided
in the request body inside a link:#http-password-input[
HttpPasswordInput] entity.
+The account must have a username.
+
.Request
----
PUT /accounts/self/password.http HTTP/1.0
diff --git a/java/com/google/gerrit/server/restapi/account/PutHttpPassword.java b/java/com/google/gerrit/server/restapi/account/PutHttpPassword.java
index 4bbd8fc813..85ec3792e5 100644
--- a/java/com/google/gerrit/server/restapi/account/PutHttpPassword.java
+++ b/java/com/google/gerrit/server/restapi/account/PutHttpPassword.java
@@ -96,12 +96,8 @@ public class PutHttpPassword implements RestModifyView<AccountResource, HttpPass
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
newPassword = input.httpPassword;
}
- return apply(rsrc.getUser(), newPassword);
- }
- public Response<String> apply(IdentifiedUser user, String newPassword)
- throws ResourceNotFoundException, ResourceConflictException, OrmException, IOException,
- ConfigInvalidException {
+ IdentifiedUser user = rsrc.getUser();
String userName =
user.getUserName().orElseThrow(() -> new ResourceConflictException("username must be set"));
Optional<ExternalId> optionalExtId =
diff --git a/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java b/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java
index b4b83bb806..8d2880515e 100644
--- a/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java
+++ b/javatests/com/google/gerrit/acceptance/api/accounts/AccountIT.java
@@ -2816,6 +2816,16 @@ public class AccountIT extends AbstractDaemonTest {
assertThat(gApi.accounts().id(user.username).setHttpPassword(null)).isNull();
}
+ @Test
+ public void cannotGenerateHttpPasswordWhenUsernameIsNotSet() throws Exception {
+ setApiUser(admin);
+ int userId = accountCreator.create().id.get();
+ assertThat(gApi.accounts().id(userId).get().username).isNull();
+ exception.expect(ResourceConflictException.class);
+ exception.expectMessage("username");
+ gApi.accounts().id(userId).generateHttpPassword();
+ }
+
private void createDraft(PushOneCommit.Result r, String path, String message) throws Exception {
DraftInput in = new DraftInput();
in.path = path;