Prevent creation of UUID-only recipients.

master
Greyson Parrelli 2019-11-05 17:51:04 -05:00 committed by Alan Evans
parent 5c0cf8c1f0
commit b3e66a9259
1 changed files with 26 additions and 7 deletions

View File

@ -155,14 +155,18 @@ public class Recipient {
return resolved(recipient.getId());
} else if (uuid != null) {
RecipientId id = db.getOrInsertFromUuid(uuid);
db.markRegistered(id, uuid);
if (FeatureFlags.UUIDS || e164 != null) {
RecipientId id = db.getOrInsertFromUuid(uuid);
db.markRegistered(id, uuid);
if (e164 != null) {
db.setPhoneNumber(id, e164);
if (e164 != null) {
db.setPhoneNumber(id, e164);
}
return resolved(id);
} else {
throw new UuidRecipientError();
}
return resolved(id);
} else if (e164 != null) {
Recipient recipient = resolved(db.getOrInsertFromE164(e164));
@ -196,7 +200,19 @@ public class Recipient {
RecipientId id = null;
if (UuidUtil.isUuid(identifier)) {
id = db.getOrInsertFromUuid(UuidUtil.parseOrThrow(identifier));
UUID uuid = UuidUtil.parseOrThrow(identifier);
if (FeatureFlags.UUIDS) {
id = db.getOrInsertFromUuid(uuid);
} else {
Optional<RecipientId> possibleId = db.getByUuid(uuid);
if (possibleId.isPresent()) {
id = possibleId.get();
} else {
throw new UuidRecipientError();
}
}
} else if (GroupUtil.isEncodedGroup(identifier)) {
id = db.getOrInsertFromGroupId(identifier);
} else if (NumberUtil.isValidEmail(identifier)) {
@ -628,4 +644,7 @@ public class Recipient {
private static class MissingAddressError extends AssertionError {
}
private static class UuidRecipientError extends AssertionError {
}
}