auth stuff

This commit is contained in:
ceikry 2022-04-30 19:04:05 -05:00
parent dbd01e1892
commit 6b7a1bb827
2 changed files with 0 additions and 53 deletions

View file

@ -1,20 +0,0 @@
package rs09.auth
import rs09.storage.InMemoryStorageProvider
class InMemoryAuthProvider : AuthProvider<InMemoryStorageProvider>() {
override fun configureFor(provider: InMemoryStorageProvider) {
storageProvider = provider
}
override fun checkLogin(username: String, password: String): LoginResponse {
val info = storageProvider.getAccountInfo(username)
if(info.online || info.password != password || info.username != username) return LoginResponse.CouldNotLogin
return LoginResponse.Success
}
override fun createAccountWith(info: UserAccountInfo): Boolean {
storageProvider.store(info)
return true
}
}

View file

@ -1,33 +0,0 @@
package core.auth
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import rs09.auth.InMemoryAuthProvider
import rs09.auth.LoginResponse
import rs09.auth.UserAccountInfo
import rs09.storage.InMemoryStorageProvider
class AuthenticatorTests {
private val authProvider = InMemoryAuthProvider()
private val storageProvider = InMemoryStorageProvider()
init {
authProvider.configureFor(storageProvider)
}
@Test fun shouldAllowCheckingIfAccountExists() {
val info = UserAccountInfo.createDefault()
info.username = "Billy"
Assertions.assertEquals(true, authProvider.canCreateAccountWith(info))
authProvider.createAccountWith(info)
Assertions.assertEquals(false, authProvider.canCreateAccountWith(info))
}
@Test fun loginWithValidAccountInfoReturnsSuccess() {
Assertions.assertEquals(LoginResponse.Success, authProvider.checkLogin("Billy", ""))
}
@Test fun loginWithInvalidAccountInfoReturnsFailure() {
Assertions.assertNotEquals(LoginResponse.Success, authProvider.checkLogin("Bilbo", "ebbeb"))
}
}