mirror of
https://github.com/veeso/termscp.git
synced 2026-07-27 18:11:06 +02:00
Panic if bookmark name is empty
This commit is contained in:
@@ -137,6 +137,9 @@ impl BookmarksClient {
|
|||||||
username: String,
|
username: String,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
) {
|
) {
|
||||||
|
if name.is_empty() {
|
||||||
|
panic!("Bookmark name can't be empty");
|
||||||
|
}
|
||||||
// Make bookmark
|
// Make bookmark
|
||||||
let host: Bookmark = self.make_bookmark(addr, port, protocol, username, password);
|
let host: Bookmark = self.make_bookmark(addr, port, protocol, username, password);
|
||||||
self.hosts.bookmarks.insert(name, host);
|
self.hosts.bookmarks.insert(name, host);
|
||||||
@@ -520,6 +523,25 @@ mod tests {
|
|||||||
assert!(client.write_bookmarks().is_ok());
|
assert!(client.write_bookmarks().is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn test_system_bookmarks_add_bookmark_empty() {
|
||||||
|
let tmp_dir: tempfile::TempDir = create_tmp_dir();
|
||||||
|
let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path());
|
||||||
|
// Initialize a new bookmarks client
|
||||||
|
let mut client: BookmarksClient =
|
||||||
|
BookmarksClient::new(cfg_path.as_path(), key_path.as_path()).unwrap();
|
||||||
|
// Add bookmark
|
||||||
|
client.add_bookmark(
|
||||||
|
String::from(""),
|
||||||
|
String::from("192.168.1.31"),
|
||||||
|
22,
|
||||||
|
FileTransferProtocol::Sftp,
|
||||||
|
String::from("pi"),
|
||||||
|
Some(String::from("mypassword")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// ### get_paths
|
/// ### get_paths
|
||||||
///
|
///
|
||||||
/// Get paths for configuration and key for bookmarks
|
/// Get paths for configuration and key for bookmarks
|
||||||
|
|||||||
Reference in New Issue
Block a user