Validate connection text and identity arguments before dispatch
This commit is contained in:
1 parent
c12cf2123f
commit
f41e064ea6
5 files changed
+74
-16
No files matched your search
@@ -290,6 +290,33 @@ fn client_menu_commands_are_validated_and_never_fake_success_offline() {
|
||||
core.shutdown();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn connect_and_disconnect_validate_arguments_before_network_io() {
|
||||
let dir = TempDir::new("connection-args");
|
||||
let mut core = Core::start(&dir.0);
|
||||
for (field, value) in [
|
||||
("address", json!("x".repeat(256))), ("address", json!("localhost\n")),
|
||||
("channel", json!("")), ("channel", json!("x".repeat(513))),
|
||||
("nickname", json!("x".repeat(65))), ("identity_id", Value::Null), ("identity_id", json!("other")),
|
||||
("server_password", json!("x".repeat(256))), ("channel_password", json!("bad\tpassword")),
|
||||
] {
|
||||
let mut args = json!({"address":"127.0.0.1"}); args[field] = value;
|
||||
let (reply, events) = core.request("invalid-connect", "connect", args);
|
||||
assert_eq!(reply["error"]["code"], "bad_request", "{field}: {reply}");
|
||||
assert!(!events.iter().any(|e| e["state"] == "connecting"));
|
||||
}
|
||||
let limit = "\u{10000}".repeat(40);
|
||||
for args in [json!({"message":format!("{limit}x")}), json!({"message":"\r"}), json!({"message":null})] {
|
||||
let (reply, _) = core.request("invalid-disconnect", "disconnect", args);
|
||||
assert_eq!(reply["error"]["code"], "bad_request", "{reply}");
|
||||
}
|
||||
for valid in [json!({}), json!({"message":""}), json!({"message":limit})] {
|
||||
let (reply, _) = core.request("valid-disconnect", "disconnect", valid);
|
||||
assert_eq!(reply["error"]["code"], "not_connected", "{reply}");
|
||||
}
|
||||
core.shutdown();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn channel_queries_validate_arguments_before_connection_lookup() {
|
||||
let dir = TempDir::new("channel-query-args");
|
||||
|
||||
Reference in new issue
Block a user