Skip to content

Commit 85656c4

Browse files
committed
chore: migrate to rust 2024 by fixing implicit borrows and unsafe env modifications
1 parent 3f2d6cf commit 85656c4

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/app_config.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ mod test {
774774
let _lock = ENV_LOCK
775775
.lock()
776776
.expect("Another test panicked while holding the lock");
777-
env::set_var("SQLPAGE_CONFIGURATION_DIRECTORY", "/path/to/config");
777+
unsafe { env::set_var("SQLPAGE_CONFIGURATION_DIRECTORY", "/path/to/config"); }
778778

779779
let config = load_from_env().unwrap();
780780

@@ -784,41 +784,41 @@ mod test {
784784
"Configuration directory should match the SQLPAGE_CONFIGURATION_DIRECTORY env var"
785785
);
786786

787-
env::remove_var("SQLPAGE_CONFIGURATION_DIRECTORY");
787+
unsafe { env::remove_var("SQLPAGE_CONFIGURATION_DIRECTORY"); }
788788
}
789789

790790
#[test]
791791
fn test_k8s_env_var_ignored() {
792792
let _lock = ENV_LOCK
793793
.lock()
794794
.expect("Another test panicked while holding the lock");
795-
env::set_var("SQLPAGE_PORT", "tcp://10.0.0.1:8080");
795+
unsafe { env::set_var("SQLPAGE_PORT", "tcp://10.0.0.1:8080"); }
796796

797797
let config = load_from_env().unwrap();
798798
assert_eq!(config.port, None);
799799

800-
env::remove_var("SQLPAGE_PORT");
800+
unsafe { env::remove_var("SQLPAGE_PORT"); }
801801
}
802802

803803
#[test]
804804
fn test_valid_port_env_var() {
805805
let _lock = ENV_LOCK
806806
.lock()
807807
.expect("Another test panicked while holding the lock");
808-
env::set_var("SQLPAGE_PORT", "9000");
808+
unsafe { env::set_var("SQLPAGE_PORT", "9000"); }
809809

810810
let config = load_from_env().unwrap();
811811
assert_eq!(config.port, Some(9000));
812812

813-
env::remove_var("SQLPAGE_PORT");
813+
unsafe { env::remove_var("SQLPAGE_PORT"); }
814814
}
815815

816816
#[test]
817817
fn test_config_priority() {
818818
let _lock = ENV_LOCK
819819
.lock()
820820
.expect("Another test panicked while holding the lock");
821-
env::set_var("SQLPAGE_WEB_ROOT", "/");
821+
unsafe { env::set_var("SQLPAGE_WEB_ROOT", "/"); }
822822

823823
let cli = Cli {
824824
web_root: Some(PathBuf::from(".")),
@@ -835,7 +835,7 @@ mod test {
835835
"CLI argument should take precedence over environment variable"
836836
);
837837

838-
env::remove_var("SQLPAGE_WEB_ROOT");
838+
unsafe { env::remove_var("SQLPAGE_WEB_ROOT"); }
839839
}
840840

841841
#[test]
@@ -859,7 +859,7 @@ mod test {
859859
.to_string();
860860
std::fs::write(&config_file_path, config_content).unwrap();
861861

862-
env::set_var("SQLPAGE_WEB_ROOT", env_web_dir.to_str().unwrap());
862+
unsafe { env::set_var("SQLPAGE_WEB_ROOT", env_web_dir.to_str().unwrap()); }
863863

864864
let cli = Cli {
865865
web_root: None,
@@ -898,7 +898,7 @@ mod test {
898898
"Configuration directory should remain unchanged"
899899
);
900900

901-
env::remove_var("SQLPAGE_WEB_ROOT");
901+
unsafe { env::remove_var("SQLPAGE_WEB_ROOT"); }
902902
std::fs::remove_dir_all(&temp_dir).unwrap();
903903
}
904904

@@ -907,8 +907,8 @@ mod test {
907907
let _lock = ENV_LOCK
908908
.lock()
909909
.expect("Another test panicked while holding the lock");
910-
env::remove_var("SQLPAGE_CONFIGURATION_DIRECTORY");
911-
env::remove_var("SQLPAGE_WEB_ROOT");
910+
unsafe { env::remove_var("SQLPAGE_CONFIGURATION_DIRECTORY"); }
911+
unsafe { env::remove_var("SQLPAGE_WEB_ROOT"); }
912912

913913
let cli = Cli {
914914
web_root: None,

src/webserver/database/execute_queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ async fn apply_delayed_functions(
610610
) -> anyhow::Result<()> {
611611
// We need to open new connections for each delayed function call, because we are still fetching the results of the current query in the main connection.
612612
let mut db_conn = None;
613-
if let DbItem::Row(serde_json::Value::Object(ref mut results)) = item {
613+
if let DbItem::Row(serde_json::Value::Object(results)) = item {
614614
for f in delayed_functions {
615615
log::trace!("Applying delayed function {} to {:?}", f.function, results);
616616
apply_single_delayed_function(request, &mut db_conn, f, results).await?;
@@ -654,7 +654,7 @@ fn json_to_fn_param(json: serde_json::Value) -> Option<Cow<'static, str>> {
654654
}
655655

656656
fn apply_json_columns(item: &mut DbItem, json_columns: &[String]) {
657-
if let DbItem::Row(Value::Object(ref mut row)) = item {
657+
if let DbItem::Row(Value::Object(row)) = item {
658658
for column in json_columns {
659659
if let Some(value) = row.get_mut(column) {
660660
if let Value::String(json_str) = value {

tests/requests/webhook_hmac.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::common::get_request_to;
66
#[actix_web::test]
77
async fn test_webhook_hmac_invalid_signature() -> actix_web::Result<()> {
88
// Set up environment variable for webhook secret
9-
std::env::set_var("WEBHOOK_SECRET", "test-secret-key");
9+
unsafe { std::env::set_var("WEBHOOK_SECRET", "test-secret-key"); }
1010

1111
let webhook_body = r#"{"order_id":12345,"total":"99.99"}"#;
1212
let invalid_signature = "96a5f6f65c85a2d4d1f3a37813ab2c0b44041bdc17691fbb0884e3eb52b7c54b";
@@ -40,7 +40,7 @@ async fn test_webhook_hmac_invalid_signature() -> actix_web::Result<()> {
4040
#[actix_web::test]
4141
async fn test_webhook_hmac_valid_signature() -> actix_web::Result<()> {
4242
// Set up environment variable for webhook secret
43-
std::env::set_var("WEBHOOK_SECRET", "test-secret-key");
43+
unsafe { std::env::set_var("WEBHOOK_SECRET", "test-secret-key"); }
4444

4545
let webhook_body = r#"{"order_id":12345,"total":"99.99"}"#;
4646
let valid_signature = "260b3b5ead84843645588af82d5d2c3fe24c598a950d36c45438c3a5f5bb941c";
@@ -68,7 +68,7 @@ async fn test_webhook_hmac_valid_signature() -> actix_web::Result<()> {
6868
#[actix_web::test]
6969
async fn test_webhook_hmac_missing_signature() -> actix_web::Result<()> {
7070
// Set up environment variable for webhook secret
71-
std::env::set_var("WEBHOOK_SECRET", "test-secret-key");
71+
unsafe { std::env::set_var("WEBHOOK_SECRET", "test-secret-key"); }
7272

7373
let webhook_body = r#"{"order_id":12345,"total":"99.99"}"#;
7474

0 commit comments

Comments
 (0)