mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2026-08-28 05:45:10 -06:00
auth stuff
This commit is contained in:
parent
7faa0a2c7c
commit
dbd01e1892
3 changed files with 80 additions and 0 deletions
20
Server/src/main/kotlin/rs09/auth/InMemoryAuthProvider.kt
Normal file
20
Server/src/main/kotlin/rs09/auth/InMemoryAuthProvider.kt
Normal 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
|
||||
}
|
||||
}
|
||||
27
Server/src/main/kotlin/rs09/auth/LoginResponse.kt
Normal file
27
Server/src/main/kotlin/rs09/auth/LoginResponse.kt
Normal 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
|
||||
}
|
||||
33
Server/src/test/kotlin/core/auth/AuthenticatorTests.kt
Normal file
33
Server/src/test/kotlin/core/auth/AuthenticatorTests.kt
Normal 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"))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue