mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-24 19:25:56 +00:00
feat(phase15): release and security hardening, DPAPI key store, probe & protocol hardening, secret redaction, audit and readiness report
This commit is contained in:
1 parent
b69fa6b867
commit
51e0f136d6
207 files changed
+38235
-7770
No files matched your search
@@ -1,7 +1,7 @@
|
||||
//! A player's client connection, independent of any local server installation.
|
||||
use std::path::{Path, PathBuf};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::{client, fsx, Error, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct Profile {
|
||||
@@ -19,7 +19,9 @@ pub fn load(dir: &Path) -> Result<Profile> {
|
||||
|
||||
pub fn save(dir: &Path, profile: &Profile) -> Result<()> {
|
||||
if !profile.host.is_empty() && !client::host_ok(&profile.host) {
|
||||
return Err(Error::Invalid("Enter a server IP address or hostname, without a URL or port.".into()));
|
||||
return Err(Error::Invalid(
|
||||
"Enter a server IP address or hostname, without a URL or port.".into(),
|
||||
));
|
||||
}
|
||||
if let Some(path) = &profile.client_path {
|
||||
let client = PathBuf::from(path);
|
||||
@@ -27,9 +29,13 @@ pub fn save(dir: &Path, profile: &Profile) -> Result<()> {
|
||||
return Err(Error::Invalid("This folder does not look like a game client (it needs Data and the game executable).".into()));
|
||||
}
|
||||
if client::is_running(&client) {
|
||||
return Err(Error::Invalid("Close the game before changing its connection.".into()));
|
||||
return Err(Error::Invalid(
|
||||
"Close the game before changing its connection.".into(),
|
||||
));
|
||||
}
|
||||
if !profile.host.is_empty() {
|
||||
client::set_realmlist(&client, dir, &profile.host)?;
|
||||
}
|
||||
if !profile.host.is_empty() { client::set_realmlist(&client, dir, &profile.host)?; }
|
||||
}
|
||||
fsx::atomic_write_json(&dir.join("connection.json"), profile)
|
||||
}
|
||||
@@ -40,7 +46,10 @@ mod tests {
|
||||
#[test]
|
||||
fn connection_needs_no_server_and_survives_restart() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let profile = Profile { host: "192.168.1.10".into(), client_path: None };
|
||||
let profile = Profile {
|
||||
host: "192.168.1.10".into(),
|
||||
client_path: None,
|
||||
};
|
||||
save(dir.path(), &profile).unwrap();
|
||||
assert_eq!(load(dir.path()).unwrap().host, profile.host);
|
||||
assert!(!dir.path().join("install.json").exists());
|
||||
@@ -51,14 +60,35 @@ mod tests {
|
||||
let game = dir.path().join("game");
|
||||
std::fs::create_dir_all(game.join("Data/enUS")).unwrap();
|
||||
std::fs::write(game.join("Wow.exe"), b"fixture").unwrap();
|
||||
std::fs::write(game.join("Data/enUS/realmlist.wtf"), "set realmlist 127.0.0.1\n").unwrap();
|
||||
std::fs::write(
|
||||
game.join("Data/enUS/realmlist.wtf"),
|
||||
"set realmlist 127.0.0.1\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::create_dir_all(game.join("WTF")).unwrap();
|
||||
std::fs::write(game.join("WTF/Config.wtf"), "SET realmName \"My realm\"\n").unwrap();
|
||||
let profile = Profile { host: "192.168.1.10".into(), client_path: Some(game.to_string_lossy().into()) };
|
||||
let profile = Profile {
|
||||
host: "192.168.1.10".into(),
|
||||
client_path: Some(game.to_string_lossy().into()),
|
||||
};
|
||||
save(dir.path(), &profile).unwrap();
|
||||
assert!(std::fs::read_to_string(game.join("Data/enUS/realmlist.wtf")).unwrap().contains(&profile.host));
|
||||
assert_eq!(std::fs::read_to_string(game.join("WTF/Config.wtf")).unwrap(), "SET realmName \"My realm\"\n");
|
||||
assert!(save(dir.path(), &Profile { host: "bad\nset realmlist other".into(), ..profile }).is_err());
|
||||
assert!(
|
||||
std::fs::read_to_string(game.join("Data/enUS/realmlist.wtf"))
|
||||
.unwrap()
|
||||
.contains(&profile.host)
|
||||
);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(game.join("WTF/Config.wtf")).unwrap(),
|
||||
"SET realmName \"My realm\"\n"
|
||||
);
|
||||
assert!(save(
|
||||
dir.path(),
|
||||
&Profile {
|
||||
host: "bad\nset realmlist other".into(),
|
||||
..profile
|
||||
}
|
||||
)
|
||||
.is_err());
|
||||
assert_eq!(load(dir.path()).unwrap().host, "192.168.1.10");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user