From c5acba1511d5b93630650bfe2711b05f99d343a9 Mon Sep 17 00:00:00 2001 From: sergeych Date: Sat, 10 Dec 2022 21:27:45 +0100 Subject: [PATCH] cosmetics --- build.gradle.kts | 4 +-- .../kotlin/net.sergeych.superlogin/api.kt | 12 +++++---- .../kotlin/net.sergeych.superlogin/init.kt | 2 +- .../superlogin/AccessControlObjectTest.kt | 4 +-- .../kotlin/superlogin/RestoreKeyTest.kt | 4 +-- .../net/sergeych/superlogin/initOperations.kt | 2 +- .../net/sergeych/superlogin/initOperations.kt | 2 +- .../superlogin/server/SuperloginServer.kt | 1 - .../kotlin/net/sergeych/WsServerKtTest.kt | 25 +++++++++++++++++-- 9 files changed, 39 insertions(+), 17 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5494fcd..843889f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - kotlin("multiplatform") version "1.7.10" - kotlin("plugin.serialization") version "1.7.10" + kotlin("multiplatform") version "1.7.21" + kotlin("plugin.serialization") version "1.7.21" `maven-publish` } diff --git a/src/commonMain/kotlin/net.sergeych.superlogin/api.kt b/src/commonMain/kotlin/net.sergeych.superlogin/api.kt index 4bb2892..71bfc41 100644 --- a/src/commonMain/kotlin/net.sergeych.superlogin/api.kt +++ b/src/commonMain/kotlin/net.sergeych.superlogin/api.kt @@ -2,6 +2,7 @@ package net.sergeych.superlogin import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +import net.sergeych.boss_serialization_mp.BossEncoder import net.sergeych.boss_serialization_mp.decodeBoss import net.sergeych.parsec3.CommandHost import net.sergeych.parsec3.WithAdapter @@ -18,14 +19,14 @@ data class RegistrationArgs( val packedACO: ByteArray, val extraData: ByteArray? = null ) { - fun toSuccess(loginToken: ByteArray,extraData: ByteArray? = this.extraData): AuthenticationResult.Success { + inline fun toSuccess(loginToken: ByteArray,extraData: T): AuthenticationResult.Success { return AuthenticationResult.Success( - loginName, loginToken, extraData + loginName, loginToken, BossEncoder.encode(extraData) ) } - inline fun decodeOrNull(): T? = extraData?.let { it.decodeBoss() } - inline fun decodeOrThrow(): T = extraData?.let { it.decodeBoss() } + inline fun decodeOrNull(): T? = extraData?.let { it.decodeBoss() } + inline fun decodeOrThrow(): T = extraData?.let { it.decodeBoss() } ?: throw IllegalArgumentException("missing require extra data of type ${T::class.simpleName}") } @@ -99,4 +100,5 @@ class SuperloginServerApi : CommandHost() { val slChangePasswordAndLogin by command () val slSendTestException by command() -} \ No newline at end of file +} + diff --git a/src/commonMain/kotlin/net.sergeych.superlogin/init.kt b/src/commonMain/kotlin/net.sergeych.superlogin/init.kt index efa3a4e..428c71a 100644 --- a/src/commonMain/kotlin/net.sergeych.superlogin/init.kt +++ b/src/commonMain/kotlin/net.sergeych.superlogin/init.kt @@ -5,4 +5,4 @@ package net.sergeych.superlogin * Currently, it is mandatory for JS and is not needed on JVM platform, but * we recommend to call it anyway */ -expect suspend fun initOperations() \ No newline at end of file +expect suspend fun InitSuperlogin() \ No newline at end of file diff --git a/src/commonTest/kotlin/superlogin/AccessControlObjectTest.kt b/src/commonTest/kotlin/superlogin/AccessControlObjectTest.kt index cd32422..89c1c82 100644 --- a/src/commonTest/kotlin/superlogin/AccessControlObjectTest.kt +++ b/src/commonTest/kotlin/superlogin/AccessControlObjectTest.kt @@ -2,7 +2,7 @@ package superlogin import kotlinx.coroutines.test.runTest import net.sergeych.superlogin.AccessControlObject -import net.sergeych.superlogin.initOperations +import net.sergeych.superlogin.InitSuperlogin import net.sergeych.unikrypto.SymmetricKeys import kotlin.test.Test import kotlin.test.assertEquals @@ -13,7 +13,7 @@ internal class AccessControlObjectTest { @Test fun createRestoreTest() = runTest { - initOperations() + InitSuperlogin() val pk1 = SymmetricKeys.random() val pk2 = SymmetricKeys.random() diff --git a/src/commonTest/kotlin/superlogin/RestoreKeyTest.kt b/src/commonTest/kotlin/superlogin/RestoreKeyTest.kt index 2d19313..e50dcff 100644 --- a/src/commonTest/kotlin/superlogin/RestoreKeyTest.kt +++ b/src/commonTest/kotlin/superlogin/RestoreKeyTest.kt @@ -1,8 +1,8 @@ package superlogin import kotlinx.coroutines.test.runTest +import net.sergeych.superlogin.InitSuperlogin import net.sergeych.superlogin.RestoreKey -import net.sergeych.superlogin.initOperations import kotlin.test.Test import kotlin.test.assertContentEquals import kotlin.test.assertEquals @@ -12,7 +12,7 @@ internal class RestoreKeyTest { @Test fun checkRestoreKey() = runTest { - initOperations() + InitSuperlogin() val rk = RestoreKey.generate() val (id, k) = RestoreKey.parse(rk.secret) diff --git a/src/jsMain/kotlin/net/sergeych/superlogin/initOperations.kt b/src/jsMain/kotlin/net/sergeych/superlogin/initOperations.kt index 634c957..9bf5d39 100644 --- a/src/jsMain/kotlin/net/sergeych/superlogin/initOperations.kt +++ b/src/jsMain/kotlin/net/sergeych/superlogin/initOperations.kt @@ -3,7 +3,7 @@ package net.sergeych.superlogin import kotlinx.coroutines.await import net.sergeych.unikrypto.Unicrypto -actual suspend fun initOperations() { +actual suspend fun InitSuperlogin() { // library uses sync operations from unicrypto so: Unicrypto.unicryptoReady.await() } \ No newline at end of file diff --git a/src/jvmMain/kotlin/net/sergeych/superlogin/initOperations.kt b/src/jvmMain/kotlin/net/sergeych/superlogin/initOperations.kt index 2b6ac05..299d320 100644 --- a/src/jvmMain/kotlin/net/sergeych/superlogin/initOperations.kt +++ b/src/jvmMain/kotlin/net/sergeych/superlogin/initOperations.kt @@ -1,5 +1,5 @@ package net.sergeych.superlogin -actual suspend fun initOperations() { +actual suspend fun InitSuperlogin() { // Java version currently does not need initialization } \ No newline at end of file diff --git a/src/jvmMain/kotlin/net/sergeych/superlogin/server/SuperloginServer.kt b/src/jvmMain/kotlin/net/sergeych/superlogin/server/SuperloginServer.kt index a17a34a..dc6d7de 100644 --- a/src/jvmMain/kotlin/net/sergeych/superlogin/server/SuperloginServer.kt +++ b/src/jvmMain/kotlin/net/sergeych/superlogin/server/SuperloginServer.kt @@ -159,7 +159,6 @@ inline fun , H : CommandHost> AdapterBuilde payload.newLoginKey, payload.newLoginId ) - println(">> ${loginResult.loginToken} -- !") } loginResult } catch (_: IllegalArgumentException) { diff --git a/src/jvmTest/kotlin/net/sergeych/WsServerKtTest.kt b/src/jvmTest/kotlin/net/sergeych/WsServerKtTest.kt index 9c90144..1583738 100644 --- a/src/jvmTest/kotlin/net/sergeych/WsServerKtTest.kt +++ b/src/jvmTest/kotlin/net/sergeych/WsServerKtTest.kt @@ -158,12 +158,34 @@ internal class WsServerKtTest { class S1: WithAdapter() @Test - fun changePasswordTest() { + fun loginByPasswordTest() { embeddedServer(Netty, port = 8081, module = Application::testServerModule).start(wait = false) runBlocking { val client = Parsec3WSClient.withSession("ws://localhost:8081/api/p3") + val api = TestApiServer() + val slc = SuperloginClient(client) + assertEquals(LoginState.LoggedOut, slc.state.value) + var rt = slc.register("foo", "passwd", TestData("bar!")) + assertIs(rt) + slc.logout() + assertNull(slc.loginByPassword("foo", "passwd2")) + var ar = slc.loginByPassword("foo", "passwd") + assertNotNull(ar) + assertEquals("bar!", ar.data?.foo) + assertTrue { slc.isLoggedIn } + assertEquals("foo", slc.call(api.loginName)) + } + } + + @Test + fun changePasswordTest() { + embeddedServer(Netty, port = 8083, module = Application::testServerModule).start(wait = false) + + runBlocking { + val client = Parsec3WSClient.withSession("ws://localhost:8083/api/p3") + val api = TestApiServer() val slc = SuperloginClient(client) assertEquals(LoginState.LoggedOut, slc.state.value) @@ -197,7 +219,6 @@ internal class WsServerKtTest { } } - @Test fun testExceptions() { embeddedServer(Netty, port = 8082, module = Application::testServerModule).start(wait = false)