Let a query login say that its address is on the server's allowlist
The engine's own query connections used the query crate's default line options, which keep a client-side limit of nine commands in three seconds. The live tests passed voelin_query::Connect with that limit off, because the development servers allowlist their clients, and with the limit on the channel relay of ts3_engine and ts6_engine did not connect within the two seconds the test waits before it speaks. QueryLogin gets the one bit the tests had: allowlisted, off for the application (which cannot know), on for the tests, and the UI's login says false, as it always effectively did. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d70a3582f2
commit
ca34f84610
3 files changed
+27
-2
No files matched your search
@@ -37,6 +37,13 @@ pub struct QueryLogin {
|
||||
pub server_port: Option<u16>,
|
||||
/// ...or by id (the first server when neither is given).
|
||||
pub server_id: Option<u32>,
|
||||
/// This machine's address is on the server's query allowlist, which the
|
||||
/// server's flood protection skips: the engine then sends its commands
|
||||
/// without the limit it keeps for a server that has not said so (a command
|
||||
/// the server refuses as a flood slows the connection down all the same).
|
||||
/// The application usually cannot know, and says `false`; the development
|
||||
/// servers of the tests allowlist their clients.
|
||||
pub allowlisted: bool,
|
||||
}
|
||||
|
||||
impl fmt::Debug for QueryLogin {
|
||||
@@ -49,6 +56,7 @@ impl fmt::Debug for QueryLogin {
|
||||
.field("secret", &self.secret.as_ref().map(|_| "[secret]"))
|
||||
.field("server_port", &self.server_port)
|
||||
.field("server_id", &self.server_id)
|
||||
.field("allowlisted", &self.allowlisted)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
@@ -67,7 +75,15 @@ impl QueryLogin {
|
||||
secret: self.secret.clone(),
|
||||
server_port: self.server_port,
|
||||
server_id: self.server_id,
|
||||
line: Default::default(),
|
||||
line: voelin_query::LineOptions {
|
||||
// Off the client-side limit only where the server skips it.
|
||||
rate_limit: if self.allowlisted {
|
||||
None
|
||||
} else {
|
||||
voelin_query::LineOptions::default().rate_limit
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,6 +185,7 @@ mod tests {
|
||||
secret: Some("hunter2".into()),
|
||||
server_port: Some(9987),
|
||||
server_id: Some(3),
|
||||
allowlisted: false,
|
||||
};
|
||||
let connect = login.connect();
|
||||
assert_eq!(connect.transport, voelin_query::Transport::Ssh);
|
||||
@@ -185,10 +202,14 @@ mod tests {
|
||||
assert_eq!(connect.transport, theirs);
|
||||
}
|
||||
// The line options are the query crate's defaults, as the UI always
|
||||
// gave them.
|
||||
// gave them, unless the server allowlists the client.
|
||||
let line = voelin_query::LineOptions::default();
|
||||
assert!(line.rate_limit.is_some());
|
||||
assert_eq!(connect.line.rate_limit, line.rate_limit);
|
||||
assert_eq!(connect.line.timeout, line.timeout);
|
||||
let allowlisted = QueryLogin { allowlisted: true, ..login.clone() }.connect();
|
||||
assert_eq!(allowlisted.line.rate_limit, None);
|
||||
assert_eq!(allowlisted.line.timeout, line.timeout);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -200,6 +221,7 @@ mod tests {
|
||||
secret: Some("hunter2".into()),
|
||||
server_port: None,
|
||||
server_id: None,
|
||||
allowlisted: false,
|
||||
};
|
||||
let text = format!("{login:?}");
|
||||
assert!(!text.contains("hunter2") && text.contains("[secret]"), "{text}");
|
||||
|
||||
@@ -109,6 +109,8 @@ fn login(connect: &voelin_query::Connect) -> QueryLogin {
|
||||
secret: connect.secret.clone(),
|
||||
server_port: connect.server_port,
|
||||
server_id: connect.server_id,
|
||||
// The development servers allowlist their clients.
|
||||
allowlisted: connect.line.rate_limit.is_none(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -313,6 +313,7 @@ impl App {
|
||||
secret,
|
||||
server_port: q.server_port,
|
||||
server_id: None,
|
||||
allowlisted: false,
|
||||
};
|
||||
self.engine.send(Command::ObserveQuery { session, connect: Box::new(connect) });
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user