File tree Expand file tree Collapse file tree 6 files changed +36
-4
lines changed
androidMain/kotlin/com/algolia/search/helper
androidTest/kotlin/helper Expand file tree Collapse file tree 6 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ repositories {
3232 mavenCentral()
3333 maven { url = URI (" https://dl.bintray.com/kotlin/ktor" ) }
3434 maven { url = URI (" https://kotlin.bintray.com/kotlinx" ) }
35+ maven { url = URI (" https://oss.sonatype.org/content/repositories/snapshots" ) }
3536}
3637
3738version = Library .version
Original file line number Diff line number Diff line change @@ -2,5 +2,5 @@ object Robolectric : Dependency {
22
33 override val group = " org.robolectric"
44 override val artifact = " robolectric"
5- override val version = " 4.3.1 "
5+ override val version = " 4.4-SNAPSHOT " // TODO: Remove the `SNAPSHOT` and the gradle repository when the final version is out.
66}
Original file line number Diff line number Diff line change @@ -16,9 +16,9 @@ internal actual fun String.sha256(key: String): String {
1616}
1717
1818internal actual fun String.encodeBase64 (): String {
19- return Base64 .encodeToString(toByteArray(), Base64 .DEFAULT )
19+ return Base64 .encodeToString(toByteArray(), Base64 .NO_WRAP )
2020}
2121
2222internal actual fun String.decodeBase64 (): String {
23- return String (Base64 .decode(this , Base64 .DEFAULT ))
23+ return String (Base64 .decode(this , Base64 .NO_WRAP ))
2424}
Original file line number Diff line number Diff line change 1+ package helper
2+
3+ import android.os.Build
4+ import androidx.test.ext.junit.runners.AndroidJUnit4
5+ import org.junit.runner.RunWith
6+ import org.robolectric.annotation.Config
7+
8+ @RunWith(AndroidJUnit4 ::class )
9+ @Config(sdk = [Build .VERSION_CODES .P ])
10+ internal class TestHashingAndroid : TestHashing ()
Original file line number Diff line number Diff line change 11package helper
22
3+ import com.algolia.search.helper.decodeBase64
4+ import com.algolia.search.helper.encodeBase64
35import com.algolia.search.helper.sha256
46import shouldEqual
57import kotlin.test.Test
68
7- internal class TestHashing {
9+ internal abstract class TestHashing {
810
911 @Test
1012 fun sha256 () {
1113 " 1234" .sha256(" test" ) shouldEqual " 24c4f0295e1bea74f9a5cb5bc40525c8889d11c78c4255808be00defe666671f"
1214 }
15+
16+ @Test
17+ fun encoding () {
18+ val url = " AZ:/19&@';#"
19+ val hash = " QVo6LzE5JkAnOyM="
20+
21+ url.encodeBase64() shouldEqual hash
22+ }
23+
24+ @Test
25+ fun decoding () {
26+ val url = " AZ:/19&@';#"
27+ val hash = " QVo6LzE5JkAnOyM="
28+
29+ hash.decodeBase64() shouldEqual url
30+ }
1331}
Original file line number Diff line number Diff line change 1+ package helper
2+
3+ internal class TestHashingJVM : TestHashing ()
You can’t perform that action at this time.
0 commit comments