|
@ -194,4 +194,104 @@ mod test { |
|
|
padding: 0,
|
|
|
padding: 0,
|
|
|
}))])
|
|
|
}))])
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_login_bad_username() {
|
|
|
|
|
|
struct TestData {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl DataAccess for TestData {
|
|
|
|
|
|
fn get_user_by_name(&self, _name: String) -> Option<UserAccount> {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut server = LoginServerState::new(TestData {});
|
|
|
|
|
|
|
|
|
|
|
|
let send = server.handle(ClientId(1), &RecvLoginPacket::Login(Login {
|
|
|
|
|
|
flag: 0,
|
|
|
|
|
|
tag: 65536,
|
|
|
|
|
|
guildcard: 0,
|
|
|
|
|
|
version: 65,
|
|
|
|
|
|
unknown1: [0, 0, 0, 255, 0, 14],
|
|
|
|
|
|
team: 0,
|
|
|
|
|
|
username: utf8_to_array!("testuser", 16),
|
|
|
|
|
|
unknown2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
|
password: utf8_to_array!("mypassword", 16),
|
|
|
|
|
|
unknown3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
|
hwinfo: [129, 1, 1, 1, 1, 1, 1, 1],
|
|
|
|
|
|
security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0,
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
|
|
|
|
|
|
|
})).unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
assert!(send == vec![
|
|
|
|
|
|
(ClientId(1), SendLoginPacket::LoginResponse(LoginResponse {
|
|
|
|
|
|
flag: 0,
|
|
|
|
|
|
status: AccountStatus::InvalidUser,
|
|
|
|
|
|
tag: 65536,
|
|
|
|
|
|
guildcard: 0,
|
|
|
|
|
|
team_id: 0,
|
|
|
|
|
|
security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0,
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
|
caps: 258
|
|
|
|
|
|
}))])
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_login_bad_password() {
|
|
|
|
|
|
struct TestData {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl DataAccess 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("notpassword", 5).unwrap(),
|
|
|
|
|
|
guildcard: None,
|
|
|
|
|
|
team_id: None,
|
|
|
|
|
|
banned: false,
|
|
|
|
|
|
muted_until: SystemTime::now(),
|
|
|
|
|
|
created_at: SystemTime::now(),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut server = LoginServerState::new(TestData {});
|
|
|
|
|
|
|
|
|
|
|
|
let send = server.handle(ClientId(1), &RecvLoginPacket::Login(Login {
|
|
|
|
|
|
flag: 0,
|
|
|
|
|
|
tag: 65536,
|
|
|
|
|
|
guildcard: 0,
|
|
|
|
|
|
version: 65,
|
|
|
|
|
|
unknown1: [0, 0, 0, 255, 0, 14],
|
|
|
|
|
|
team: 0,
|
|
|
|
|
|
username: utf8_to_array!("testuser", 16),
|
|
|
|
|
|
unknown2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
|
password: utf8_to_array!("mypassword", 16),
|
|
|
|
|
|
unknown3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
|
hwinfo: [129, 1, 1, 1, 1, 1, 1, 1],
|
|
|
|
|
|
security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0,
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
|
|
|
|
|
|
|
})).unwrap().collect::<Vec<_>>();
|
|
|
|
|
|
assert!(send == vec![
|
|
|
|
|
|
(ClientId(1), SendLoginPacket::LoginResponse(LoginResponse {
|
|
|
|
|
|
flag: 0,
|
|
|
|
|
|
status: AccountStatus::InvalidPassword,
|
|
|
|
|
|
tag: 65536,
|
|
|
|
|
|
guildcard: 0,
|
|
|
|
|
|
team_id: 0,
|
|
|
|
|
|
security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0,
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
|
caps: 258
|
|
|
|
|
|
}))])
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|