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
This commit is contained in:
David Pursehouse 2019-05-10 13:52:24 +09:00
commit c8b9ee43c3
3 changed files with 13 additions and 5 deletions

View File

@ -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

View File

@ -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 =

View File

@ -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;