Fix StackOverflowError on calling bot.client in tests with TestSsoProcessor, fix #1332

This commit is contained in:
Him188 2021-06-15 20:47:50 +08:00
parent 794315e169
commit 750ab0db37
2 changed files with 11 additions and 2 deletions

View File

@ -9,6 +9,7 @@
package net.mamoe.mirai.internal.network.context
import net.mamoe.mirai.Bot
import net.mamoe.mirai.internal.BotAccount
import net.mamoe.mirai.internal.QQAndroidBot
import net.mamoe.mirai.internal.network.component.ComponentKey
@ -44,7 +45,7 @@ internal class SsoProcessorContextImpl(
override val bot: QQAndroidBot
) : SsoProcessorContext {
override val account: BotAccount get() = bot.account
override val device: DeviceInfo = configuration.deviceInfo?.invoke(bot) ?: DeviceInfo.random()
override val device: DeviceInfo = configuration.createDeviceInfo(bot)
override val protocol: BotConfiguration.MiraiProtocol get() = configuration.protocol
override val accountSecretsManager: AccountSecretsManager
get() = configuration.createAccountsSecretsManager(
@ -52,3 +53,5 @@ internal class SsoProcessorContextImpl(
)
override val configuration: BotConfiguration get() = bot.configuration
}
internal fun BotConfiguration.createDeviceInfo(bot: Bot): DeviceInfo = deviceInfo?.invoke(bot) ?: DeviceInfo.random()

View File

@ -12,16 +12,22 @@ package net.mamoe.mirai.internal.network.framework.components
import net.mamoe.mirai.internal.QQAndroidBot
import net.mamoe.mirai.internal.network.QQAndroidClient
import net.mamoe.mirai.internal.network.components.SsoProcessor
import net.mamoe.mirai.internal.network.context.AccountSecretsImpl
import net.mamoe.mirai.internal.network.context.SsoSession
import net.mamoe.mirai.internal.network.context.createDeviceInfo
import net.mamoe.mirai.internal.network.handler.NetworkHandler
import net.mamoe.mirai.internal.network.handler.logger
import net.mamoe.mirai.internal.network.handler.state.StateObserver
import net.mamoe.mirai.internal.network.protocol.data.jce.SvcRespRegister
import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc
import net.mamoe.mirai.utils.debug
import net.mamoe.mirai.utils.lateinitMutableProperty
internal open class TestSsoProcessor(private val bot: QQAndroidBot) : SsoProcessor {
override val client: QQAndroidClient get() = bot.client
val deviceInfo = bot.configuration.createDeviceInfo(bot)
override var client: QQAndroidClient by lateinitMutableProperty {
QQAndroidClient(bot.account, device = deviceInfo, accountSecrets = AccountSecretsImpl(deviceInfo, bot.account))
}
override val ssoSession: SsoSession get() = bot.client
override var firstLoginSucceed: Boolean = false
override var registerResp: StatSvc.Register.Response? = null