Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertJ -> AssertK #13841

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ dependencies {
}

testImplementation(testLibs.junit.junit)
testImplementation(testLibs.assertj.core)
testImplementation(testLibs.assertk)
testImplementation(testLibs.mockito.core)
testImplementation(testLibs.mockito.kotlin)
testImplementation(testLibs.androidx.test.core)
Expand Down
4 changes: 2 additions & 2 deletions app/proguard/proguard-automation.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
-dontwarn com.android.support.test.**
-dontwarn sun.reflect.**
-dontwarn sun.misc.**
-dontwarn org.assertj.**
-dontwarn assertk.**
-dontwarn org.hamcrest.**
-dontwarn org.mockito.**
-dontwarn com.squareup.**

-dontobfuscate
-dontobfuscate
2 changes: 1 addition & 1 deletion app/src/main/res/raw/third_party_licenses
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ The following dependencies are licensed under Apache License, Version 2.0:
* Android Tracing (https://developer.android.com/jetpack/androidx/releases/tracing#1.0.0)
* AndroidX Futures (https://developer.android.com/topic/libraries/architecture/index.html)
* AndroidX Test Library (https://developer.android.com/testing)
* AssertJ fluent assertions
* AutoValue Annotations (https://github.com/google/auto/tree/master/value)
* Byte Buddy (without dependencies)
* Byte Buddy agent
Expand Down Expand Up @@ -336,6 +335,7 @@ The following dependencies are licensed under The MIT License:
* annotations (http://robolectric.org)
* framework (http://robolectric.org)
* junit (http://robolectric.org)
* assertk (https://github.com/willowtreeapps/assertk)
* ktlint (https://github.com/pinterest/ktlint)
* ktlint-cli-reporter (https://github.com/pinterest/ktlint)
* ktlint-cli-ruleset-core (https://github.com/pinterest/ktlint)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package org.thoughtcrime.securesms.groups.v2

import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.hasMessage
import assertk.assertions.isInstanceOf
import assertk.assertions.isNull
import assertk.assertions.messageContains
import assertk.assertions.rootCause
import okio.ByteString
import org.junit.Test
import org.signal.core.util.Base64.encodeUrlSafeWithoutPadding
import org.signal.libsignal.zkgroup.InvalidInputException
import org.signal.storageservice.protos.groups.GroupInviteLink
import org.thoughtcrime.securesms.groups.v2.GroupInviteLinkUrl.InvalidGroupLinkException
import org.thoughtcrime.securesms.groups.v2.GroupInviteLinkUrl.UnknownGroupLinkVersionException
import org.thoughtcrime.securesms.util.Util
import java.io.IOException

@Suppress("ClassName")
class GroupInviteLinkUrl_InvalidGroupLinkException_Test {
@Test
fun empty_string() {
val uri = ""
assertThat(GroupInviteLinkUrl.fromUri(uri)).isNull()
}

@Test
fun not_a_url_string() {
val uri = "abc"
assertThat(GroupInviteLinkUrl.fromUri(uri)).isNull()
}

@Test
fun wrong_host() {
val uri = "https://x.signal.org/#CjQKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEhCbwyTuxDfP2mrluK779H7o"
assertThat(GroupInviteLinkUrl.fromUri(uri)).isNull()
}

@Test
fun wrong_scheme() {
val uri = "http://signal.group/#CjQKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEhCbwyTuxDfP2mrluK779H7o"
assertThat(GroupInviteLinkUrl.fromUri(uri)).isNull()
}

@Test
fun has_path() {
val uri = "https://signal.group/not_expected/#CjQKIAD34MKnGrBkzDztTATwjXt-9LhLLCIG9pgzvmz-NN-AEhCbwyTuxDfP2mrluK779H7o"
assertFailure { GroupInviteLinkUrl.fromUri(uri) }
.isInstanceOf<InvalidGroupLinkException>()
.hasMessage("No path was expected in uri")
}

@Test
fun missing_ref() {
val uri = "https://signal.group/"
assertFailure { GroupInviteLinkUrl.fromUri(uri) }
.isInstanceOf<InvalidGroupLinkException>()
.hasMessage("No reference was in the uri")
}

@Test
fun empty_ref() {
val uri = "https://signal.group/#"
assertFailure { GroupInviteLinkUrl.fromUri(uri) }
.isInstanceOf<InvalidGroupLinkException>()
.hasMessage("No reference was in the uri")
}

@Test
fun bad_base64() {
val uri = "https://signal.group/#CAESNAogpQEzURH6BON1bCS264cmTi37Yi6HTOReXZUEHdsBIgSEPCLfiL7k4wCX;mwVi31USVY"
assertFailure { GroupInviteLinkUrl.fromUri(uri) }
.isInstanceOf<InvalidGroupLinkException>()
.rootCause()
.isInstanceOf<IOException>()
}

@Test
fun bad_protobuf() {
val uri = "https://signal.group/#CAESNAogpQEzURH6BON1bCS264cmTi37Yi6HTOReXZUEHdsBIgSEPCLfiL7k4wCXmwVi31USVY"
assertFailure {
GroupInviteLinkUrl.fromUri(uri)
}.isInstanceOf<InvalidGroupLinkException>()
.rootCause()
.isInstanceOf<IllegalStateException>()
}

@Test
fun version_999_url() {
val url = "https://signal.group/#uj4zCiDMSxlNUvF4bQ3z3fYzGyZTFbJ1xEqWbPE3uZSD8bjOrxIP8NxV-0GUz3jpxMLR1rN3"
assertFailure { GroupInviteLinkUrl.fromUri(url) }
.isInstanceOf<UnknownGroupLinkVersionException>()
.messageContains("Url contains no known group link content")
}

@Test
fun bad_master_key_length() {
val masterKeyBytes = Util.getSecretBytes(33)
val password = GroupLinkPassword.createNew()

val encoding = createEncodedProtobuf(masterKeyBytes, password.serialize())

val url = "https://signal.group/#$encoding"

assertFailure { GroupInviteLinkUrl.fromUri(url) }
.isInstanceOf<InvalidGroupLinkException>()
.rootCause()
.isInstanceOf<InvalidInputException>()
}

companion object {
private fun createEncodedProtobuf(
groupMasterKey: ByteArray,
passwordBytes: ByteArray
): String {
return encodeUrlSafeWithoutPadding(
GroupInviteLink.Builder()
.v1Contents(
GroupInviteLink.GroupInviteLinkContentsV1.Builder()
.groupMasterKey(ByteString.of(*groupMasterKey))
.inviteLinkPassword(ByteString.of(*passwordBytes))
.build()
)
.build()
.encode()
)
}
}
}
Loading