use topcoat::router::request::Request; use topcoat::router::{Body, to_bytes}; use forge_web_app::views::NAV_SCRIPT_HREF; fn assert_no_inline_scripts(html: &str) { for (at, _) in html.match_indices("').expect("script tag closes"); assert!( tag[..end].contains(" src="), "inline script: {}", &tag[..=end] ); } } #[tokio::test] async fn shell_loads_the_deferred_nav_script_without_inline_scripts() { let dir = tempfile::tempdir().expect("tempdir"); let state = forge_web_app::test_support::test_state(dir.path()).await; let router = forge_web_app::test_support::app_router(state); let req = Request::builder() .method("GET") .uri("/login") .body(Body::empty()) .unwrap(); let res = router.handle(req).await; assert_eq!(res.status(), 200); let csp = res.headers()["content-security-policy"] .to_str() .unwrap() .to_owned(); assert!(csp.contains("default-src 'self'"), "{csp}"); assert!(!csp.contains("unsafe-inline"), "{csp}"); let html = String::from_utf8( to_bytes(res.into_body(), usize::MAX) .await .unwrap() .to_vec(), ) .unwrap(); let tag_at = html .find(&format!("