Skip to content

Commit

Permalink
fix cors test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tguntenaar committed Dec 29, 2024
1 parent bdd1a79 commit c96bc3e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,26 +312,35 @@ fn test_cors_configuration() {
let client = Client::tracked(super::rocket()).expect("valid Rocket instance");

// Test allowed origin
let response = client
.options("/")
let res = client
.get("/")
.header(Header::new("Origin", "http://localhost:3000"))
.header(Header::new("Access-Control-Request-Method", "GET"))
.dispatch();
assert_eq!(response.status(), Status::Ok);
assert!(response
assert_eq!(
res.status(),
Status::Ok,
"Response should be Ok 200 but is {:?}",
res.status()
);
assert!(res
.headers()
.get("Access-Control-Allow-Origin")
.next()
.is_some());

// Test disallowed origin
let response = client
.options("/")
.get("/")
.header(Header::new("Origin", "http://disallowed-origin.com"))
.header(Header::new("Access-Control-Request-Method", "GET"))
.dispatch();

assert_eq!(response.status(), Status::NoContent);
assert_eq!(
response.status(),
Status::Forbidden,
"Response should be Forbidden 403 but is {:?}",
response.status()
);
}

#[test]
Expand Down

0 comments on commit c96bc3e

Please sign in to comment.