mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2026-09-10 10:36:43 -06:00
auth stuff
This commit is contained in:
parent
dbd01e1892
commit
6b7a1bb827
2 changed files with 0 additions and 53 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -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"))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue