Accept any length group link password.
This commit is contained in:
parent
878b0c9275
commit
ffcb90da52
4 changed files with 8 additions and 30 deletions
|
@ -26,7 +26,6 @@ public final class GroupInviteLinkUrl {
|
|||
|
||||
public static GroupInviteLinkUrl forGroup(@NonNull GroupMasterKey groupMasterKey,
|
||||
@NonNull DecryptedGroup group)
|
||||
throws GroupLinkPassword.InvalidLengthException
|
||||
{
|
||||
return new GroupInviteLinkUrl(groupMasterKey, GroupLinkPassword.fromBytes(group.getInviteLinkPassword().toByteArray()));
|
||||
}
|
||||
|
@ -73,7 +72,7 @@ public final class GroupInviteLinkUrl {
|
|||
}
|
||||
default: throw new UnknownGroupLinkVersionException("Url contains no known group link content");
|
||||
}
|
||||
} catch (GroupLinkPassword.InvalidLengthException | InvalidInputException | IOException e){
|
||||
} catch (InvalidInputException | IOException e) {
|
||||
throw new InvalidGroupLinkException(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,7 @@ public final class GroupLinkPassword {
|
|||
return new GroupLinkPassword(Util.getSecretBytes(SIZE));
|
||||
}
|
||||
|
||||
public static @NonNull GroupLinkPassword fromBytes(@NonNull byte[] bytes) throws InvalidLengthException {
|
||||
if (bytes.length != SIZE) {
|
||||
throw new InvalidLengthException();
|
||||
}
|
||||
|
||||
public static @NonNull GroupLinkPassword fromBytes(@NonNull byte[] bytes) {
|
||||
return new GroupLinkPassword(bytes);
|
||||
}
|
||||
|
||||
|
@ -45,7 +41,4 @@ public final class GroupLinkPassword {
|
|||
public int hashCode() {
|
||||
return Arrays.hashCode(bytes);
|
||||
}
|
||||
|
||||
public static class InvalidLengthException extends Exception {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,11 @@ public final class GroupInviteLinkUrlTest {
|
|||
|
||||
givenGroup().withMasterKey("00f7e0c2a71ab064cc3ced4c04f08d7b7ef4b84b2c2206f69833be6cfe34df80")
|
||||
.andPassword("9bc324eec437cfda6ae5b8aefbf47ee8")
|
||||
.expectUrl("https://signal.group/#CjQKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEhCbwyTuxDfP2mrluK779H7o")
|
||||
.expectUrl("https://signal.group/#CjQKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEhCbwyTuxDfP2mrluK779H7o"),
|
||||
|
||||
givenGroup().withMasterKey("00f7e0c2a71ab064cc3ced4c04f08d7b7ef4b84b2c2206f69833be6cfe34df80")
|
||||
.andPassword("9b")
|
||||
.expectUrl("https://signal.group/#CiUKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEgGb")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -91,11 +95,7 @@ public final class GroupInviteLinkUrlTest {
|
|||
}
|
||||
|
||||
public Object[] expectUrl(String url) {
|
||||
try {
|
||||
return new Object[]{ groupMasterKey, GroupLinkPassword.fromBytes(passwordBytes), url };
|
||||
} catch (GroupLinkPassword.InvalidLengthException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return new Object[]{ groupMasterKey, GroupLinkPassword.fromBytes(passwordBytes), url };
|
||||
}
|
||||
}
|
||||
}
|
|
@ -92,20 +92,6 @@ public final class GroupInviteLinkUrl_InvalidGroupLinkException_Test {
|
|||
.hasCauseExactlyInstanceOf(InvalidInputException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bad_password_length() throws InvalidInputException {
|
||||
GroupMasterKey groupMasterKey = new GroupMasterKey(Util.getSecretBytes(32));
|
||||
byte[] passwordBytes = Util.getSecretBytes(15);
|
||||
|
||||
String encoding = createEncodedProtobuf(groupMasterKey.serialize(), passwordBytes);
|
||||
|
||||
String url = "https://signal.group/#" + encoding;
|
||||
|
||||
assertThatThrownBy(() -> GroupInviteLinkUrl.fromUrl(url))
|
||||
.isInstanceOf(GroupInviteLinkUrl.InvalidGroupLinkException.class)
|
||||
.hasCauseExactlyInstanceOf(GroupLinkPassword.InvalidLengthException.class);
|
||||
}
|
||||
|
||||
private static String createEncodedProtobuf(@NonNull byte[] groupMasterKey,
|
||||
@NonNull byte[] passwordBytes)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue