Merge branch 'stable-3.0'
* stable-3.0: PutHttpPassword: Squash apply methods Clarify that account must have a username to be able to set HTTP password Change-Id: I8e7559e610541d8f750f04251b03b39cb521c0ae
This commit is contained in:
@@ -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[
|
in the request body inside a link:#http-password-input[
|
||||||
HttpPasswordInput] entity.
|
HttpPasswordInput] entity.
|
||||||
|
|
||||||
|
The account must have a username.
|
||||||
|
|
||||||
.Request
|
.Request
|
||||||
----
|
----
|
||||||
PUT /accounts/self/password.http HTTP/1.0
|
PUT /accounts/self/password.http HTTP/1.0
|
||||||
|
@@ -95,12 +95,8 @@ public class PutHttpPassword implements RestModifyView<AccountResource, HttpPass
|
|||||||
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
|
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
|
||||||
newPassword = input.httpPassword;
|
newPassword = input.httpPassword;
|
||||||
}
|
}
|
||||||
return apply(rsrc.getUser(), newPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response<String> apply(IdentifiedUser user, String newPassword)
|
IdentifiedUser user = rsrc.getUser();
|
||||||
throws ResourceNotFoundException, ResourceConflictException, IOException,
|
|
||||||
ConfigInvalidException {
|
|
||||||
String userName =
|
String userName =
|
||||||
user.getUserName().orElseThrow(() -> new ResourceConflictException("username must be set"));
|
user.getUserName().orElseThrow(() -> new ResourceConflictException("username must be set"));
|
||||||
Optional<ExternalId> optionalExtId =
|
Optional<ExternalId> optionalExtId =
|
||||||
|
@@ -2853,6 +2853,18 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
assertThat(gApi.accounts().id(user.username()).setHttpPassword(null)).isNull();
|
assertThat(gApi.accounts().id(user.username()).setHttpPassword(null)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cannotGenerateHttpPasswordWhenUsernameIsNotSet() throws Exception {
|
||||||
|
requestScopeOperations.setApiUser(admin.id());
|
||||||
|
int userId = accountCreator.create().id().get();
|
||||||
|
assertThat(gApi.accounts().id(userId).get().username).isNull();
|
||||||
|
ResourceConflictException thrown =
|
||||||
|
assertThrows(
|
||||||
|
ResourceConflictException.class,
|
||||||
|
() -> gApi.accounts().id(userId).generateHttpPassword());
|
||||||
|
assertThat(thrown).hasMessageThat().contains("username");
|
||||||
|
}
|
||||||
|
|
||||||
private void createDraft(PushOneCommit.Result r, String path, String message) throws Exception {
|
private void createDraft(PushOneCommit.Result r, String path, String message) throws Exception {
|
||||||
DraftInput in = new DraftInput();
|
DraftInput in = new DraftInput();
|
||||||
in.path = path;
|
in.path = path;
|
||||||
|
Reference in New Issue
Block a user