Encapsulate device ID in ProvisioningAddress
This commit is contained in:
parent
6a428b4da9
commit
2bc4412d66
|
@ -47,7 +47,7 @@ public class ProvisioningController {
|
|||
|
||||
rateLimiters.getMessagesLimiter().validate(auth.getAccount().getUuid());
|
||||
|
||||
if (!provisioningManager.sendProvisioningMessage(new ProvisioningAddress(destinationName, (byte) 0),
|
||||
if (!provisioningManager.sendProvisioningMessage(ProvisioningAddress.create(destinationName),
|
||||
Base64.getMimeDecoder().decode(message.body()))) {
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
}
|
||||
|
|
|
@ -10,8 +10,14 @@ import java.util.Base64;
|
|||
|
||||
public class ProvisioningAddress extends WebsocketAddress {
|
||||
|
||||
public ProvisioningAddress(String address, byte id) {
|
||||
super(address, id);
|
||||
public static byte DEVICE_ID = 0;
|
||||
|
||||
public static ProvisioningAddress create(String address) {
|
||||
return new ProvisioningAddress(address, DEVICE_ID);
|
||||
}
|
||||
|
||||
private ProvisioningAddress(String address, byte deviceId) {
|
||||
super(address, deviceId);
|
||||
}
|
||||
|
||||
public ProvisioningAddress(String serialized) throws InvalidWebsocketAddressException {
|
||||
|
@ -26,6 +32,6 @@ public class ProvisioningAddress extends WebsocketAddress {
|
|||
byte[] random = new byte[16];
|
||||
new SecureRandom().nextBytes(random);
|
||||
|
||||
return new ProvisioningAddress(Base64.getUrlEncoder().withoutPadding().encodeToString(random), (byte) 0);
|
||||
return create(Base64.getUrlEncoder().withoutPadding().encodeToString(random));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ class ProvisioningControllerTest {
|
|||
provisioningMessageCaptor.capture());
|
||||
|
||||
assertEquals(destination, provisioningAddressCaptor.getValue().getAddress());
|
||||
assertEquals(0, provisioningAddressCaptor.getValue().getDeviceId());
|
||||
assertEquals(ProvisioningAddress.DEVICE_ID, provisioningAddressCaptor.getValue().getDeviceId());
|
||||
|
||||
assertArrayEquals(messageBody, provisioningMessageCaptor.getValue());
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ class ProvisioningManagerTest {
|
|||
|
||||
@Test
|
||||
void sendProvisioningMessage() {
|
||||
final ProvisioningAddress address = new ProvisioningAddress("address", (byte) 0);
|
||||
final ProvisioningAddress address = ProvisioningAddress.create("address");
|
||||
|
||||
final byte[] content = new byte[16];
|
||||
new Random().nextBytes(content);
|
||||
|
@ -64,7 +64,7 @@ class ProvisioningManagerTest {
|
|||
|
||||
@Test
|
||||
void removeListener() {
|
||||
final ProvisioningAddress address = new ProvisioningAddress("address", (byte) 0);
|
||||
final ProvisioningAddress address = ProvisioningAddress.create("address");
|
||||
|
||||
final byte[] content = new byte[16];
|
||||
new Random().nextBytes(content);
|
||||
|
|
Loading…
Reference in New Issue