From 0278e364ece20aca847c4084c24c7253e695ebb0 Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Wed, 7 Mar 2018 18:42:21 +0100 Subject: [PATCH] add tests for csrf upgrade filter --- src/middleware/csrf.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/middleware/csrf.rs b/src/middleware/csrf.rs index d9d4692b4..dfdb538d9 100644 --- a/src/middleware/csrf.rs +++ b/src/middleware/csrf.rs @@ -274,4 +274,25 @@ mod tests { assert!(csrf.start(&mut req).is_ok()); } + + #[test] + fn test_upgrade() { + let strict_csrf = CsrfFilter::build() + .allowed_origin("https://www.example.com") + .finish(); + + let lax_csrf = CsrfFilter::build() + .allowed_origin("https://www.example.com") + .allow_upgrade() + .finish(); + + let mut req = TestRequest::with_header("Origin", "https://cswsh.com") + .header("Connection", "Upgrade") + .header("Upgrade", "websocket") + .method(Method::GET) + .finish(); + + assert!(strict_csrf.start(&mut req).is_err()); + assert!(lax_csrf.start(&mut req).is_ok()); + } }