Browse Source

Merge branch 'issue_21' of jake/elseware into master

pbs
jake 5 years ago
committed by Gogs
parent
commit
d7a2cc3400
  1. 50
      src/login/login.rs

50
src/login/login.rs

@ -62,7 +62,12 @@ pub fn get_login_status(entity_gateway: &dyn EntityGateway, pkt: &Login) -> Resu
let user = entity_gateway.get_user_by_name(username).ok_or(AccountStatus::InvalidUser)?;
let verified = bcrypt::verify(password, user.password.as_str()).map_err(|_err| AccountStatus::Error)?;
match verified {
true => Ok(user),
true => if user.banned {
Err(AccountStatus::Banned)
}
else {
Ok(user)
},
false => Err(AccountStatus::InvalidPassword)
}
}
@ -279,4 +284,47 @@ mod test {
caps: 258
}))])
}
#[test]
fn test_banned_user() {
struct TestData {
}
impl EntityGateway for TestData {
fn get_user_by_name(&self, name: String) -> Option<UserAccount> {
assert!(name == "testuser");
Some(UserAccount {
id: 1,
username: "testuser".to_owned(),
password: bcrypt::hash("mypassword", 5).unwrap(),
guildcard: None,
team_id: None,
banned: true,
muted_until: SystemTime::now(),
created_at: SystemTime::now(),
flags: 0,
})
}
}
let mut server = LoginServerState::new(TestData {});
let send = server.handle(ClientId(1), &LOGIN_PACKET).unwrap().collect::<Vec<_>>();
assert!(send == vec![
(ClientId(1), SendLoginPacket::LoginResponse(LoginResponse {
status: AccountStatus::Banned,
tag: 65536,
guildcard: 0,
team_id: 0,
session: Session {
version: [69, 108, 115, 101, 119, 97, 114, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // utf8_to_array!("Elseware", 30),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
session_id: 0,
interserver_checksum: 0,
action: SessionAction::None,
character_slot: 0,
},
caps: 258
}))])
}
}
Loading…
Cancel
Save