Convert `DeviceResponse` to a record and rename to `LinkDeviceResponse`
This commit is contained in:
parent
240a406964
commit
9b5c6e538b
|
@ -53,7 +53,7 @@ import org.whispersystems.textsecuregcm.entities.AccountAttributes;
|
||||||
import org.whispersystems.textsecuregcm.entities.DeviceActivationRequest;
|
import org.whispersystems.textsecuregcm.entities.DeviceActivationRequest;
|
||||||
import org.whispersystems.textsecuregcm.entities.DeviceInfo;
|
import org.whispersystems.textsecuregcm.entities.DeviceInfo;
|
||||||
import org.whispersystems.textsecuregcm.entities.DeviceInfoList;
|
import org.whispersystems.textsecuregcm.entities.DeviceInfoList;
|
||||||
import org.whispersystems.textsecuregcm.entities.DeviceResponse;
|
import org.whispersystems.textsecuregcm.entities.LinkDeviceResponse;
|
||||||
import org.whispersystems.textsecuregcm.entities.LinkDeviceRequest;
|
import org.whispersystems.textsecuregcm.entities.LinkDeviceRequest;
|
||||||
import org.whispersystems.textsecuregcm.entities.PreKeySignatureValidator;
|
import org.whispersystems.textsecuregcm.entities.PreKeySignatureValidator;
|
||||||
import org.whispersystems.textsecuregcm.entities.ProvisioningMessage;
|
import org.whispersystems.textsecuregcm.entities.ProvisioningMessage;
|
||||||
|
@ -222,7 +222,7 @@ public class DeviceController {
|
||||||
@ApiResponse(responseCode = "429", description = "Too many attempts", headers = @Header(
|
@ApiResponse(responseCode = "429", description = "Too many attempts", headers = @Header(
|
||||||
name = "Retry-After",
|
name = "Retry-After",
|
||||||
description = "If present, an positive integer indicating the number of seconds before a subsequent attempt could succeed"))
|
description = "If present, an positive integer indicating the number of seconds before a subsequent attempt could succeed"))
|
||||||
public DeviceResponse linkDevice(@HeaderParam(HttpHeaders.AUTHORIZATION) BasicAuthorizationHeader authorizationHeader,
|
public LinkDeviceResponse linkDevice(@HeaderParam(HttpHeaders.AUTHORIZATION) BasicAuthorizationHeader authorizationHeader,
|
||||||
@HeaderParam(HttpHeaders.USER_AGENT) @Nullable String userAgent,
|
@HeaderParam(HttpHeaders.USER_AGENT) @Nullable String userAgent,
|
||||||
@NotNull @Valid LinkDeviceRequest linkDeviceRequest,
|
@NotNull @Valid LinkDeviceRequest linkDeviceRequest,
|
||||||
@Context ContainerRequest containerRequest)
|
@Context ContainerRequest containerRequest)
|
||||||
|
@ -295,7 +295,7 @@ public class DeviceController {
|
||||||
deviceActivationRequest.aciPqLastResortPreKey(),
|
deviceActivationRequest.aciPqLastResortPreKey(),
|
||||||
deviceActivationRequest.pniPqLastResortPreKey()),
|
deviceActivationRequest.pniPqLastResortPreKey()),
|
||||||
linkDeviceRequest.verificationCode())
|
linkDeviceRequest.verificationCode())
|
||||||
.thenApply(accountAndDevice -> new DeviceResponse(
|
.thenApply(accountAndDevice -> new LinkDeviceResponse(
|
||||||
accountAndDevice.first().getIdentifier(IdentityType.ACI),
|
accountAndDevice.first().getIdentifier(IdentityType.ACI),
|
||||||
accountAndDevice.first().getIdentifier(IdentityType.PNI),
|
accountAndDevice.first().getIdentifier(IdentityType.PNI),
|
||||||
accountAndDevice.second().getId()))
|
accountAndDevice.second().getId()))
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013-2020 Signal Messenger, LLC
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.whispersystems.textsecuregcm.entities;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class DeviceResponse {
|
|
||||||
@JsonProperty
|
|
||||||
private UUID uuid;
|
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
private UUID pni;
|
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
private byte deviceId;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public DeviceResponse() {}
|
|
||||||
|
|
||||||
public DeviceResponse(UUID uuid, UUID pni, byte deviceId) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.pni = pni;
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getPni() {
|
|
||||||
return pni;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2013-2020 Signal Messenger, LLC
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.whispersystems.textsecuregcm.entities;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public record LinkDeviceResponse(UUID uuid, UUID pni, byte deviceId) {
|
||||||
|
}
|
|
@ -59,7 +59,7 @@ import org.whispersystems.textsecuregcm.entities.AccountAttributes;
|
||||||
import org.whispersystems.textsecuregcm.entities.ApnRegistrationId;
|
import org.whispersystems.textsecuregcm.entities.ApnRegistrationId;
|
||||||
import org.whispersystems.textsecuregcm.entities.DeviceActivationRequest;
|
import org.whispersystems.textsecuregcm.entities.DeviceActivationRequest;
|
||||||
import org.whispersystems.textsecuregcm.entities.DeviceInfo;
|
import org.whispersystems.textsecuregcm.entities.DeviceInfo;
|
||||||
import org.whispersystems.textsecuregcm.entities.DeviceResponse;
|
import org.whispersystems.textsecuregcm.entities.LinkDeviceResponse;
|
||||||
import org.whispersystems.textsecuregcm.entities.ECSignedPreKey;
|
import org.whispersystems.textsecuregcm.entities.ECSignedPreKey;
|
||||||
import org.whispersystems.textsecuregcm.entities.GcmRegistrationId;
|
import org.whispersystems.textsecuregcm.entities.GcmRegistrationId;
|
||||||
import org.whispersystems.textsecuregcm.entities.KEMSignedPreKey;
|
import org.whispersystems.textsecuregcm.entities.KEMSignedPreKey;
|
||||||
|
@ -214,13 +214,13 @@ class DeviceControllerTest {
|
||||||
accountAttributes,
|
accountAttributes,
|
||||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, apnRegistrationId, gcmRegistrationId));
|
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, apnRegistrationId, gcmRegistrationId));
|
||||||
|
|
||||||
final DeviceResponse response = resources.getJerseyTest()
|
final LinkDeviceResponse response = resources.getJerseyTest()
|
||||||
.target("/v1/devices/link")
|
.target("/v1/devices/link")
|
||||||
.request()
|
.request()
|
||||||
.header("Authorization", AuthHelper.getProvisioningAuthHeader(AuthHelper.VALID_NUMBER, "password1"))
|
.header("Authorization", AuthHelper.getProvisioningAuthHeader(AuthHelper.VALID_NUMBER, "password1"))
|
||||||
.put(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE), DeviceResponse.class);
|
.put(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE), LinkDeviceResponse.class);
|
||||||
|
|
||||||
assertThat(response.getDeviceId()).isEqualTo(NEXT_DEVICE_ID);
|
assertThat(response.deviceId()).isEqualTo(NEXT_DEVICE_ID);
|
||||||
|
|
||||||
final ArgumentCaptor<DeviceSpec> deviceSpecCaptor = ArgumentCaptor.forClass(DeviceSpec.class);
|
final ArgumentCaptor<DeviceSpec> deviceSpecCaptor = ArgumentCaptor.forClass(DeviceSpec.class);
|
||||||
verify(accountsManager).addDevice(eq(account), deviceSpecCaptor.capture(), any());
|
verify(accountsManager).addDevice(eq(account), deviceSpecCaptor.capture(), any());
|
||||||
|
|
Loading…
Reference in New Issue