2020-06-26 22:19:44 +02:00
|
|
|
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
|
|
|
|
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
|
|
|
|
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
|
|
|
|
// ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║
|
|
|
|
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod passing {
|
2021-10-17 09:16:37 +02:00
|
|
|
use monolith::html;
|
|
|
|
use monolith::opts::Options;
|
2020-06-26 22:19:44 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn isolated() {
|
2020-06-28 07:36:41 +02:00
|
|
|
let mut options = Options::default();
|
|
|
|
options.isolate = true;
|
2020-11-23 06:12:26 +01:00
|
|
|
let csp_content = html::compose_csp(&options);
|
2020-06-26 22:19:44 +02:00
|
|
|
|
|
|
|
assert_eq!(csp_content, "default-src 'unsafe-inline' data:;");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_css() {
|
2020-06-28 07:36:41 +02:00
|
|
|
let mut options = Options::default();
|
|
|
|
options.no_css = true;
|
2020-11-23 06:12:26 +01:00
|
|
|
let csp_content = html::compose_csp(&options);
|
2020-06-26 22:19:44 +02:00
|
|
|
|
|
|
|
assert_eq!(csp_content, "style-src 'none';");
|
|
|
|
}
|
|
|
|
|
2020-06-27 00:14:46 +02:00
|
|
|
#[test]
|
|
|
|
fn no_fonts() {
|
2020-06-28 07:36:41 +02:00
|
|
|
let mut options = Options::default();
|
|
|
|
options.no_fonts = true;
|
2020-11-23 06:12:26 +01:00
|
|
|
let csp_content = html::compose_csp(&options);
|
2020-06-27 00:14:46 +02:00
|
|
|
|
|
|
|
assert_eq!(csp_content, "font-src 'none';");
|
|
|
|
}
|
|
|
|
|
2020-06-26 22:19:44 +02:00
|
|
|
#[test]
|
|
|
|
fn no_frames() {
|
2020-06-28 07:36:41 +02:00
|
|
|
let mut options = Options::default();
|
|
|
|
options.no_frames = true;
|
2020-11-23 06:12:26 +01:00
|
|
|
let csp_content = html::compose_csp(&options);
|
2020-06-26 22:19:44 +02:00
|
|
|
|
|
|
|
assert_eq!(csp_content, "frame-src 'none'; child-src 'none';");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_js() {
|
2020-06-28 07:36:41 +02:00
|
|
|
let mut options = Options::default();
|
|
|
|
options.no_js = true;
|
2020-11-23 06:12:26 +01:00
|
|
|
let csp_content = html::compose_csp(&options);
|
2020-06-26 22:19:44 +02:00
|
|
|
|
|
|
|
assert_eq!(csp_content, "script-src 'none';");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-06-28 07:36:41 +02:00
|
|
|
fn no_images() {
|
|
|
|
let mut options = Options::default();
|
|
|
|
options.no_images = true;
|
2020-11-23 06:12:26 +01:00
|
|
|
let csp_content = html::compose_csp(&options);
|
2020-06-26 22:19:44 +02:00
|
|
|
|
|
|
|
assert_eq!(csp_content, "img-src data:;");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn all() {
|
2020-06-28 07:36:41 +02:00
|
|
|
let mut options = Options::default();
|
|
|
|
options.isolate = true;
|
|
|
|
options.no_css = true;
|
|
|
|
options.no_fonts = true;
|
|
|
|
options.no_frames = true;
|
|
|
|
options.no_js = true;
|
|
|
|
options.no_images = true;
|
2020-11-23 06:12:26 +01:00
|
|
|
let csp_content = html::compose_csp(&options);
|
2020-06-26 22:19:44 +02:00
|
|
|
|
2020-06-27 00:14:46 +02:00
|
|
|
assert_eq!(csp_content, "default-src 'unsafe-inline' data:; style-src 'none'; font-src 'none'; frame-src 'none'; child-src 'none'; script-src 'none'; img-src data:;");
|
2020-06-26 22:19:44 +02:00
|
|
|
}
|
|
|
|
}
|