fix: preserve account data and validate CLI operations
This commit is contained in:
1 parent
22a3eebe78
commit
2b6750a971
11 files changed
+300
-119
No files matched your search
@@ -20,7 +20,7 @@ fn microsoft_account() -> Account {
|
||||
fn creates_offline_account_after_microsoft_account_exists() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let mut store = AccountStore::empty_for_test(temp.path().join("accounts.json"));
|
||||
store.add(microsoft_account());
|
||||
store.add(microsoft_account()).unwrap();
|
||||
add_offline_account(&mut store, "Steve").expect("offline account should be added");
|
||||
|
||||
assert_eq!(store.accounts.len(), 2);
|
||||
@@ -45,3 +45,36 @@ fn rejects_empty_offline_username() {
|
||||
let mut store = AccountStore::empty_for_test(temp.path().join("accounts.json"));
|
||||
assert!(add_offline_account(&mut store, " ").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_usernames_require_a_unique_account_selector() {
|
||||
let mut microsoft = microsoft_account();
|
||||
microsoft.username = "Steve".to_owned();
|
||||
let offline = crate::auth::create_offline_account("Steve");
|
||||
let accounts = vec![microsoft, offline.clone()];
|
||||
|
||||
assert!(super::find_account_index(&accounts, "Steve").is_err());
|
||||
assert_eq!(
|
||||
super::find_account_index(&accounts, &offline.uuid).unwrap(),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn device_code_failure_does_not_wait_for_a_code() {
|
||||
let _guard = crate::tests::TEST_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(|error| error.into_inner());
|
||||
*crate::auth::DEVICE_CODE_DISPLAY.lock().unwrap() = None;
|
||||
let result = std::sync::Arc::new(std::sync::Mutex::new(Some(crate::auth::AuthResult::Error(
|
||||
"device code failed".to_owned(),
|
||||
))));
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_time()
|
||||
.build()
|
||||
.unwrap();
|
||||
let error = runtime
|
||||
.block_on(super::wait_for_device_code(&result))
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("device code failed"));
|
||||
}
|
||||
@@ -17,3 +17,15 @@ fn rejects_invalid_resolution_format() {
|
||||
assert!(parse_resolution("1920xa").is_err());
|
||||
assert!(parse_resolution("0x1080").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_memory_update_keeps_existing_setting() {
|
||||
let mut config: crate::instance::InstanceConfig = serde_json::from_value(serde_json::json!({
|
||||
"name": "test", "game_version": "1.21.1", "loader": "vanilla",
|
||||
"loader_version": null, "created": "2026-01-01T00:00:00Z", "memory_max": "8G"
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
assert!(super::apply_config_update(&mut config, "memory-max", "garbage").is_err());
|
||||
assert_eq!(config.memory_max.as_deref(), Some("8G"));
|
||||
}
|
||||
@@ -32,3 +32,21 @@ fn resolves_named_log_file() {
|
||||
Some("latest.log")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_log_paths_outside_the_instance() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let dir = tmp.path().join("demo/minecraft/logs/launches");
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let outside = tmp.path().join("outside.txt");
|
||||
std::fs::write(&outside, "private").unwrap();
|
||||
|
||||
assert!(resolve_log_path(tmp.path(), "demo", Some(outside.to_str().unwrap())).is_err());
|
||||
assert!(resolve_log_path(tmp.path(), "demo", Some("../../outside.txt")).is_err());
|
||||
#[cfg(unix)]
|
||||
{
|
||||
std::os::unix::fs::symlink(&outside, dir.join("escape.log")).unwrap();
|
||||
assert!(resolve_log_path(tmp.path(), "demo", Some("escape.log")).is_err());
|
||||
assert!(resolve_log_path(tmp.path(), "demo", None).is_err());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user