Skip to content

Commit a96c886

Browse files
jamesonwilliamsgreyson-signal
authored andcommitted
Move from AssertJ to AssertK.
Resolves #13841
1 parent 56d53f0 commit a96c886

13 files changed

+431
-365
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ dependencies {
590590
}
591591

592592
testImplementation(testLibs.junit.junit)
593-
testImplementation(testLibs.assertj.core)
593+
testImplementation(testLibs.assertk)
594594
testImplementation(testLibs.androidx.test.core)
595595
testImplementation(testLibs.robolectric.robolectric) {
596596
exclude(group = "com.google.protobuf", module = "protobuf-java")

app/proguard/proguard-automation.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
-dontwarn com.android.support.test.**
66
-dontwarn sun.reflect.**
77
-dontwarn sun.misc.**
8-
-dontwarn org.assertj.**
8+
-dontwarn assertk.**
99
-dontwarn org.hamcrest.**
1010
-dontwarn com.squareup.**
1111

12-
-dontobfuscate
12+
-dontobfuscate

app/src/main/res/raw/third_party_licenses

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ The following dependencies are licensed under Apache License, Version 2.0:
2525
* Android Tracing (https://developer.android.com/jetpack/androidx/releases/tracing#1.0.0)
2626
* AndroidX Futures (https://developer.android.com/topic/libraries/architecture/index.html)
2727
* AndroidX Test Library (https://developer.android.com/testing)
28-
* AssertJ fluent assertions
2928
* AutoValue Annotations (https://github.com/google/auto/tree/master/value)
3029
* Byte Buddy (without dependencies)
3130
* Byte Buddy agent
@@ -336,6 +335,7 @@ The following dependencies are licensed under The MIT License:
336335
* annotations (http://robolectric.org)
337336
* framework (http://robolectric.org)
338337
* junit (http://robolectric.org)
338+
* assertk (https://github.com/willowtreeapps/assertk)
339339
* ktlint (https://github.com/pinterest/ktlint)
340340
* ktlint-cli-reporter (https://github.com/pinterest/ktlint)
341341
* ktlint-cli-ruleset-core (https://github.com/pinterest/ktlint)

app/src/test/java/org/thoughtcrime/securesms/groups/v2/GroupInviteLinkUrl_InvalidGroupLinkException_Test.java

Lines changed: 0 additions & 110 deletions
This file was deleted.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package org.thoughtcrime.securesms.groups.v2
2+
3+
import assertk.assertFailure
4+
import assertk.assertThat
5+
import assertk.assertions.hasMessage
6+
import assertk.assertions.isInstanceOf
7+
import assertk.assertions.isNull
8+
import assertk.assertions.messageContains
9+
import assertk.assertions.rootCause
10+
import okio.ByteString
11+
import org.junit.Test
12+
import org.signal.core.util.Base64.encodeUrlSafeWithoutPadding
13+
import org.signal.libsignal.zkgroup.InvalidInputException
14+
import org.signal.storageservice.protos.groups.GroupInviteLink
15+
import org.thoughtcrime.securesms.groups.v2.GroupInviteLinkUrl.InvalidGroupLinkException
16+
import org.thoughtcrime.securesms.groups.v2.GroupInviteLinkUrl.UnknownGroupLinkVersionException
17+
import org.thoughtcrime.securesms.util.Util
18+
import java.io.IOException
19+
20+
@Suppress("ClassName")
21+
class GroupInviteLinkUrl_InvalidGroupLinkException_Test {
22+
@Test
23+
fun empty_string() {
24+
val uri = ""
25+
assertThat(GroupInviteLinkUrl.fromUri(uri)).isNull()
26+
}
27+
28+
@Test
29+
fun not_a_url_string() {
30+
val uri = "abc"
31+
assertThat(GroupInviteLinkUrl.fromUri(uri)).isNull()
32+
}
33+
34+
@Test
35+
fun wrong_host() {
36+
val uri = "https://x.signal.org/#CjQKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEhCbwyTuxDfP2mrluK779H7o"
37+
assertThat(GroupInviteLinkUrl.fromUri(uri)).isNull()
38+
}
39+
40+
@Test
41+
fun wrong_scheme() {
42+
val uri = "http://signal.group/#CjQKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEhCbwyTuxDfP2mrluK779H7o"
43+
assertThat(GroupInviteLinkUrl.fromUri(uri)).isNull()
44+
}
45+
46+
@Test
47+
fun has_path() {
48+
val uri = "https://signal.group/not_expected/#CjQKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEhCbwyTuxDfP2mrluK779H7o"
49+
assertFailure { GroupInviteLinkUrl.fromUri(uri) }
50+
.isInstanceOf<InvalidGroupLinkException>()
51+
.hasMessage("No path was expected in uri")
52+
}
53+
54+
@Test
55+
fun missing_ref() {
56+
val uri = "https://signal.group/"
57+
assertFailure { GroupInviteLinkUrl.fromUri(uri) }
58+
.isInstanceOf<InvalidGroupLinkException>()
59+
.hasMessage("No reference was in the uri")
60+
}
61+
62+
@Test
63+
fun empty_ref() {
64+
val uri = "https://signal.group/#"
65+
assertFailure { GroupInviteLinkUrl.fromUri(uri) }
66+
.isInstanceOf<InvalidGroupLinkException>()
67+
.hasMessage("No reference was in the uri")
68+
}
69+
70+
@Test
71+
fun bad_base64() {
72+
val uri = "https://signal.group/#CAESNAogpQEzURH6BON1bCS264cmTi37Yi6HTOReXZUEHdsBIgSEPCLfiL7k4wCX;mwVi31USVY"
73+
assertFailure { GroupInviteLinkUrl.fromUri(uri) }
74+
.isInstanceOf<InvalidGroupLinkException>()
75+
.rootCause()
76+
.isInstanceOf<IOException>()
77+
}
78+
79+
@Test
80+
fun bad_protobuf() {
81+
val uri = "https://signal.group/#CAESNAogpQEzURH6BON1bCS264cmTi37Yi6HTOReXZUEHdsBIgSEPCLfiL7k4wCXmwVi31USVY"
82+
assertFailure {
83+
GroupInviteLinkUrl.fromUri(uri)
84+
}.isInstanceOf<InvalidGroupLinkException>()
85+
.rootCause()
86+
.isInstanceOf<IllegalStateException>()
87+
}
88+
89+
@Test
90+
fun version_999_url() {
91+
val url = "https://signal.group/#uj4zCiDMSxlNUvF4bQ3z3fYzGyZTFbJ1xEqWbPE3uZSD8bjOrxIP8NxV-0GUz3jpxMLR1rN3"
92+
assertFailure { GroupInviteLinkUrl.fromUri(url) }
93+
.isInstanceOf<UnknownGroupLinkVersionException>()
94+
.messageContains("Url contains no known group link content")
95+
}
96+
97+
@Test
98+
fun bad_master_key_length() {
99+
val masterKeyBytes = Util.getSecretBytes(33)
100+
val password = GroupLinkPassword.createNew()
101+
102+
val encoding = createEncodedProtobuf(masterKeyBytes, password.serialize())
103+
104+
val url = "https://signal.group/#$encoding"
105+
106+
assertFailure { GroupInviteLinkUrl.fromUri(url) }
107+
.isInstanceOf<InvalidGroupLinkException>()
108+
.rootCause()
109+
.isInstanceOf<InvalidInputException>()
110+
}
111+
112+
companion object {
113+
private fun createEncodedProtobuf(
114+
groupMasterKey: ByteArray,
115+
passwordBytes: ByteArray
116+
): String {
117+
return encodeUrlSafeWithoutPadding(
118+
GroupInviteLink.Builder()
119+
.v1Contents(
120+
GroupInviteLink.GroupInviteLinkContentsV1.Builder()
121+
.groupMasterKey(ByteString.of(*groupMasterKey))
122+
.inviteLinkPassword(ByteString.of(*passwordBytes))
123+
.build()
124+
)
125+
.build()
126+
.encode()
127+
)
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)