[headless] Add first integration test for ContactController

This commit is contained in:
Torsten Grote
2018-11-06 10:52:02 -03:00
parent a5c9e7c74d
commit d857338ad0
9 changed files with 283 additions and 33 deletions

View File

@@ -13,17 +13,22 @@ import javax.annotation.concurrent.Immutable
import javax.inject.Inject
import javax.inject.Singleton
interface BriarService {
fun start()
fun stop()
}
@Immutable
@Singleton
internal class BriarService
internal class BriarServiceImpl
@Inject
constructor(
private val accountManager: AccountManager,
private val lifecycleManager: LifecycleManager,
private val passwordStrengthEstimator: PasswordStrengthEstimator
) {
) : BriarService {
fun start() {
override fun start() {
if (!accountManager.accountExists()) {
createAccount()
} else {
@@ -38,7 +43,7 @@ constructor(
lifecycleManager.startServices(dbKey)
}
fun stop() {
override fun stop() {
lifecycleManager.stopServices()
lifecycleManager.waitForShutdown()
}

View File

@@ -56,6 +56,10 @@ import javax.net.SocketFactory
)
internal class HeadlessModule(private val appDir: File) {
@Provides
@Singleton
internal fun provideBriarService(briarService: BriarServiceImpl): BriarService = briarService
@Provides
@Singleton
internal fun provideDatabaseConfig(): DatabaseConfig {
@@ -71,30 +75,21 @@ internal class HeadlessModule(private val appDir: File) {
locationUtils: LocationUtils, eventBus: EventBus, resourceProvider: ResourceProvider,
circumventionProvider: CircumventionProvider, batteryManager: BatteryManager, clock: Clock
): PluginConfig {
val torDirectory = File(appDir, "tor")
val duplex: List<DuplexPluginFactory>
if (isLinux() || isMac()) {
val duplex: List<DuplexPluginFactory> = if (isLinux() || isMac()) {
val torDirectory = File(appDir, "tor")
val tor = UnixTorPluginFactory(
ioExecutor, networkManager, locationUtils, eventBus, torSocketFactory,
backoffFactory, resourceProvider, circumventionProvider, batteryManager, clock,
torDirectory
)
duplex = listOf(tor)
listOf(tor)
} else {
duplex = emptyList()
emptyList()
}
return object : PluginConfig {
override fun getDuplexFactories(): Collection<DuplexPluginFactory> {
return duplex
}
override fun getSimplexFactories(): Collection<SimplexPluginFactory> {
return emptyList()
}
override fun shouldPoll(): Boolean {
return true
}
override fun getDuplexFactories(): Collection<DuplexPluginFactory> = duplex
override fun getSimplexFactories(): Collection<SimplexPluginFactory> = emptyList()
override fun shouldPoll(): Boolean = true
}
}
@@ -104,21 +99,14 @@ internal class HeadlessModule(private val appDir: File) {
return object : DevConfig {
override fun getDevPublicKey(): PublicKey {
try {
return crypto.messageKeyParser
.parsePublicKey(fromHexString(DEV_PUBLIC_KEY_HEX))
return crypto.messageKeyParser.parsePublicKey(fromHexString(DEV_PUBLIC_KEY_HEX))
} catch (e: GeneralSecurityException) {
throw RuntimeException(e)
}
}
override fun getDevOnionAddress(): String {
return DEV_ONION_ADDRESS
}
override fun getReportDir(): File {
return File(appDir, "reportDir")
}
override fun getDevOnionAddress(): String = DEV_ONION_ADDRESS
override fun getReportDir(): File = File(appDir, "reportDir")
}
}

View File

@@ -41,7 +41,7 @@ constructor(
private val logger = getLogger(Router::javaClass.name)
private val stopped = AtomicBoolean(false)
fun start(authToken: String, port: Int, debug: Boolean) {
internal fun start(authToken: String, port: Int, debug: Boolean) : Javalin {
briarService.start()
getRuntime().addShutdownHook(Thread(this::stop))
@@ -104,7 +104,7 @@ constructor(
webSocketController.sessions.remove(session)
}
}
app.start()
return app.start()
}
private fun serverStopped() {
@@ -112,7 +112,7 @@ constructor(
exit(1)
}
private fun stop() {
internal fun stop() {
if (!stopped.getAndSet(true)) {
briarService.stop()
}