Skip to content

Commit

Permalink
fix: fixes get_file test
Browse files Browse the repository at this point in the history
  • Loading branch information
tuddman committed Apr 3, 2024
1 parent 908f3f0 commit a2676ef
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ async fn main() -> std::io::Result<()> {
#[cfg(test)]
mod tests {
use super::*;
use actix_web::dev::Service;
use actix_web::test;
use tempfile::tempdir;

Expand Down Expand Up @@ -225,7 +226,7 @@ mod tests {
// Cleanup: TempDir will automatically remove the temporary directory once it goes out of scope
}

#[actix_rt::test]
#[actix_web::test]
async fn test_get_file() {
let data = web::Data::new(AppState {
secret_key: std::str::from_utf8(SECRET_KEY).unwrap().to_string(),
Expand All @@ -234,7 +235,7 @@ mod tests {

let file_contents = b"this too shall pass!"; // Simulated file contents
let correct_hmac = create_hmac_signature(SECRET_KEY, file_contents);
let incorrect_hmac = "nope".to_string();
let incorrect_hmac = String::from("none shall pass");

let temp_dir = tempdir().unwrap();
let upload_path = temp_dir.path().join("uploads");
Expand All @@ -252,25 +253,17 @@ mod tests {
.unwrap()
.insert(file_id, file_name.display().to_string());

dbg!(&data.file_map);

let app = test::init_service(
App::new()
.app_data(data)
.route(&format!("/files/{file_id}"), web::get().to(get_file)),
)
.await;
let app = test::init_service(App::new()
.app_data(data.clone())
.service(web::resource("/files/{id}").route(web::get().to(get_file)))).await;

// Test with correct HMAC
let req = test::TestRequest::get()
.uri(&format!("/files/{file_id}"))
.insert_header(("X-HMAC", correct_hmac))
.to_request();
dbg!(&req);

let resp = test::call_service(&app, req).await;
dbg!(&file_id);
dbg!(&file_name);
dbg!(&resp);
assert!(
resp.status().is_success(),
"Should succeed with correct HMAC"
Expand Down

0 comments on commit a2676ef

Please sign in to comment.