cosmetics
This commit is contained in:
parent
d9bbe3c2a5
commit
c5acba1511
@ -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`
|
||||
}
|
||||
|
||||
|
@ -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 <reified T>toSuccess(loginToken: ByteArray,extraData: T): AuthenticationResult.Success {
|
||||
return AuthenticationResult.Success(
|
||||
loginName, loginToken, extraData
|
||||
loginName, loginToken, BossEncoder.encode(extraData)
|
||||
)
|
||||
}
|
||||
|
||||
inline fun <reified T>decodeOrNull(): T? = extraData?.let { it.decodeBoss() }
|
||||
inline fun <reified T>decodeOrThrow(): T = extraData?.let { it.decodeBoss() }
|
||||
inline fun <reified T>decodeOrNull(): T? = extraData?.let { it.decodeBoss<T>() }
|
||||
inline fun <reified T: Any>decodeOrThrow(): T = extraData?.let { it.decodeBoss<T>() }
|
||||
?: throw IllegalArgumentException("missing require extra data of type ${T::class.simpleName}")
|
||||
}
|
||||
|
||||
@ -99,4 +100,5 @@ class SuperloginServerApi<T: WithAdapter> : CommandHost<T>() {
|
||||
val slChangePasswordAndLogin by command <ChangePasswordArgs,AuthenticationResult>()
|
||||
|
||||
val slSendTestException by command<Unit,Unit>()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
expect suspend fun InitSuperlogin()
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package net.sergeych.superlogin
|
||||
|
||||
actual suspend fun initOperations() {
|
||||
actual suspend fun InitSuperlogin() {
|
||||
// Java version currently does not need initialization
|
||||
}
|
@ -159,7 +159,6 @@ inline fun <reified D, T : SLServerSession<D>, H : CommandHost<T>> AdapterBuilde
|
||||
payload.newLoginKey,
|
||||
payload.newLoginId
|
||||
)
|
||||
println(">> ${loginResult.loginToken} -- !")
|
||||
}
|
||||
loginResult
|
||||
} catch (_: IllegalArgumentException) {
|
||||
|
@ -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<S1>("ws://localhost:8081/api/p3")
|
||||
|
||||
val api = TestApiServer<WithAdapter>()
|
||||
val slc = SuperloginClient<TestData, S1>(client)
|
||||
assertEquals(LoginState.LoggedOut, slc.state.value)
|
||||
var rt = slc.register("foo", "passwd", TestData("bar!"))
|
||||
assertIs<Registration.Result.Success>(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<S1>("ws://localhost:8083/api/p3")
|
||||
|
||||
val api = TestApiServer<WithAdapter>()
|
||||
val slc = SuperloginClient<TestData, S1>(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)
|
||||
|
Loading…
Reference in New Issue
Block a user