auth stuff

This commit is contained in:
ceikry 2022-04-30 16:28:20 -05:00
parent 7faa0a2c7c
commit dbd01e1892
3 changed files with 80 additions and 0 deletions

View file

@ -0,0 +1,20 @@
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

@ -0,0 +1,27 @@
package rs09.auth
enum class LoginResponse {
UnexpectedError,
CouldNotAd,
Success,
InvalidCredentials,
AccountDisabled,
AlreadyOnline,
Updated,
FullWorld,
LoginServerOffline,
LoginLimitExceeded,
BadSessionID,
WeakPassword,
MembersWorld,
CouldNotLogin,
Updating,
TooManyIncorrectLogins,
StandingInMembersArea,
AccountLocked,
ClosedBeta,
InvalidLoginServer,
MovingWorld,
ErrorLoadingProfile,
BannedUser
}

View file

@ -0,0 +1,33 @@
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"))
}
}