Skip to content

Commit 04e85bd

Browse files
committed
Temporarily revert get_install_id() in nmhproxy
This is to get the x86 version building. i686 Rust9x hates this commit for some reason. It will either be here until a fix is found either for Rust9x or to use a different function, or if I decide to just remove nmhproxy.
1 parent e8f6670 commit 04e85bd

File tree

4 files changed

+3
-172
lines changed

4 files changed

+3
-172
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

browser/app/nmhproxy/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ name = "nmhproxy"
1010
path = "src/main.rs"
1111

1212
[dependencies]
13-
dirs = "4"
1413
mozbuild = "0.1"
1514
mozilla-central-workspace-hack = { version = "0.1", features = ["nmhproxy"], optional = true }
1615
serde = { version = "1", features = ["derive", "rc"] }
1716
serde_json = "1.0"
18-
tempfile = "3"
1917
url = "2.4"

browser/app/nmhproxy/src/commands.rs

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use serde::{Deserialize, Serialize};
66
use std::io::{self, Read, Write};
7-
use std::path::PathBuf;
87
use std::process::Command;
98
use url::Url;
109

@@ -24,7 +23,6 @@ pub enum FirefoxCommand {
2423
LaunchFirefox { url: String },
2524
LaunchFirefoxPrivate { url: String },
2625
GetVersion {},
27-
GetInstallId {},
2826
}
2927
#[derive(Serialize, Deserialize)]
3028
// {
@@ -36,14 +34,6 @@ pub struct Response {
3634
pub result_code: u32,
3735
}
3836

39-
#[derive(Serialize, Deserialize)]
40-
// {
41-
// "installation_id": "123ABC456",
42-
// }
43-
pub struct InstallationId {
44-
pub installation_id: String,
45-
}
46-
4737
#[repr(u32)]
4838
pub enum ResultCode {
4939
Success = 0,
@@ -162,28 +152,6 @@ pub fn process_command(command: &FirefoxCommand) -> std::io::Result<bool> {
162152
Ok(true)
163153
}
164154
FirefoxCommand::GetVersion {} => generate_response("1", ResultCode::Success.into()),
165-
FirefoxCommand::GetInstallId {} => {
166-
// config_dir() evaluates to ~/Library/Application Support on macOS
167-
// and %RoamingAppData% on Windows.
168-
let mut json_path = match dirs::config_dir() {
169-
Some(path) => path,
170-
None => {
171-
return generate_response(
172-
"Config dir could not be found",
173-
ResultCode::Error.into(),
174-
)
175-
}
176-
};
177-
#[cfg(target_os = "windows")]
178-
json_path.push("Mozilla\\Firefox");
179-
#[cfg(target_os = "macos")]
180-
json_path.push("Firefox");
181-
182-
json_path.push("install_id");
183-
json_path.set_extension("json");
184-
let mut install_id = String::new();
185-
get_install_id(&mut json_path, &mut install_id)
186-
}
187155
}
188156
}
189157

@@ -260,54 +228,10 @@ fn launch_firefox<C: CommandRunner>(
260228
command.to_string()
261229
}
262230

263-
fn get_install_id(json_path: &mut PathBuf, install_id: &mut String) -> std::io::Result<bool> {
264-
if !json_path.exists() {
265-
return Err(std::io::Error::new(
266-
std::io::ErrorKind::NotFound,
267-
"Install ID file does not exist",
268-
));
269-
}
270-
let json_size = std::fs::metadata(&json_path)
271-
.map_err(|e| std::io::Error::new(std::io::ErrorKind::NotFound, e))?
272-
.len();
273-
// Set a 1 KB limit for the file size.
274-
if json_size <= 0 || json_size > 1024 {
275-
return Err(std::io::Error::new(
276-
std::io::ErrorKind::InvalidData,
277-
"Install ID file has invalid size",
278-
));
279-
}
280-
let mut file =
281-
std::fs::File::open(json_path).or_else(|_| -> std::io::Result<std::fs::File> {
282-
return Err(std::io::Error::new(
283-
std::io::ErrorKind::NotFound,
284-
"Failed to open file",
285-
));
286-
})?;
287-
let mut contents = String::new();
288-
match file.read_to_string(&mut contents) {
289-
Ok(_) => match serde_json::from_str::<InstallationId>(&contents) {
290-
Ok(id) => {
291-
*install_id = id.installation_id.clone();
292-
generate_response(&id.installation_id, ResultCode::Success.into())
293-
}
294-
Err(_) => {
295-
return Err(std::io::Error::new(
296-
std::io::ErrorKind::InvalidData,
297-
"Failed to read installation ID",
298-
))
299-
}
300-
},
301-
Err(_) => generate_response("Failed to read file", ResultCode::Error.into()),
302-
}?;
303-
Ok(true)
304-
}
305-
306231
#[cfg(test)]
307232
mod tests {
308233
use super::*;
309234
use std::io::Cursor;
310-
use tempfile::NamedTempFile;
311235
#[test]
312236
fn test_validate_url() {
313237
let valid_test_cases = vec![
@@ -423,90 +347,4 @@ mod tests {
423347
let correct_url_format = format!("-osint -private-window {}", url);
424348
assert!(command_line.contains(correct_url_format.as_str()));
425349
}
426-
427-
#[test]
428-
fn test_get_install_id_valid() -> std::io::Result<()> {
429-
let mut tempfile = NamedTempFile::new().unwrap();
430-
let installation_id = InstallationId {
431-
installation_id: "123ABC456".to_string(),
432-
};
433-
let json_string = serde_json::to_string(&installation_id);
434-
let _ = tempfile.write_all(json_string?.as_bytes());
435-
let mut install_id = String::new();
436-
let result = get_install_id(&mut tempfile.path().to_path_buf(), &mut install_id);
437-
assert!(result.is_ok());
438-
assert_eq!(install_id, "123ABC456");
439-
Ok(())
440-
}
441-
442-
#[test]
443-
fn test_get_install_id_incorrect_var() -> std::io::Result<()> {
444-
#[derive(Serialize, Deserialize)]
445-
pub struct IncorrectJSON {
446-
pub incorrect_var: String,
447-
}
448-
let mut tempfile = NamedTempFile::new().unwrap();
449-
let incorrect_json = IncorrectJSON {
450-
incorrect_var: "incorrect_val".to_string(),
451-
};
452-
let json_string = serde_json::to_string(&incorrect_json);
453-
let _ = tempfile.write_all(json_string?.as_bytes());
454-
let mut install_id = String::new();
455-
let result = get_install_id(&mut tempfile.path().to_path_buf(), &mut install_id);
456-
assert!(result.is_err());
457-
let error = result.err().unwrap();
458-
assert_eq!(error.kind(), std::io::ErrorKind::InvalidData);
459-
Ok(())
460-
}
461-
462-
#[test]
463-
fn test_get_install_id_partially_correct_vars() -> std::io::Result<()> {
464-
#[derive(Serialize, Deserialize)]
465-
pub struct IncorrectJSON {
466-
pub installation_id: String,
467-
pub incorrect_var: String,
468-
}
469-
let mut tempfile = NamedTempFile::new().unwrap();
470-
let incorrect_json = IncorrectJSON {
471-
installation_id: "123ABC456".to_string(),
472-
incorrect_var: "incorrect_val".to_string(),
473-
};
474-
let json_string = serde_json::to_string(&incorrect_json);
475-
let _ = tempfile.write_all(json_string?.as_bytes());
476-
let mut install_id = String::new();
477-
let result = get_install_id(&mut tempfile.path().to_path_buf(), &mut install_id);
478-
// This still succeeds as the installation_id field is present
479-
assert!(result.is_ok());
480-
Ok(())
481-
}
482-
483-
#[test]
484-
fn test_get_install_id_file_does_not_exist() -> std::io::Result<()> {
485-
let tempfile = NamedTempFile::new().unwrap();
486-
let mut path = tempfile.path().to_path_buf();
487-
tempfile.close()?;
488-
let mut install_id = String::new();
489-
let result = get_install_id(&mut path, &mut install_id);
490-
assert!(result.is_err());
491-
let error = result.err().unwrap();
492-
assert_eq!(error.kind(), std::io::ErrorKind::NotFound);
493-
Ok(())
494-
}
495-
496-
#[test]
497-
fn test_get_install_id_file_too_large() -> std::io::Result<()> {
498-
let mut tempfile = NamedTempFile::new().unwrap();
499-
let installation_id = InstallationId {
500-
// Create a ~10 KB file
501-
installation_id: String::from_utf8(vec![b'X'; 10000]).unwrap(),
502-
};
503-
let json_string = serde_json::to_string(&installation_id);
504-
let _ = tempfile.write_all(json_string?.as_bytes());
505-
let mut install_id = String::new();
506-
let result = get_install_id(&mut tempfile.path().to_path_buf(), &mut install_id);
507-
assert!(result.is_err());
508-
let error = result.err().unwrap();
509-
assert_eq!(error.kind(), std::io::ErrorKind::InvalidData);
510-
Ok(())
511-
}
512350
}

browser/app/nmhproxy/src/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,9 @@ fn main() -> Result<(), Error> {
4343
"Failed to deserialize message JSON",
4444
));
4545
})?;
46-
commands::process_command(&native_messaging_json).or_else(|e| -> Result<bool, _> {
47-
commands::generate_response(
48-
format!("Failed to process command: {}", e).as_str(),
49-
ResultCode::Error.into(),
50-
)
51-
.expect("JSON error");
46+
commands::process_command(&native_messaging_json).or_else(|_| -> Result<bool, _> {
47+
commands::generate_response("Failed to process command", ResultCode::Error.into())
48+
.expect("JSON error");
5249
return Err(Error::new(
5350
ErrorKind::InvalidInput,
5451
"Failed to process command",

0 commit comments

Comments
 (0)