Repository: actix/actix-web
File: src/json.rs (Rust)

Code before:
        .finish();
        assert!(handler.handle(&req).as_err().is_none())
    }

    #[test]
    fn test_with_json_and_custom_content_type() {
        let mut cfg = JsonConfig::default();
        cfg.limit(4096);
        cfg.content_type(|mime: mime::Mime| {
            mime.type_() == mime::TEXT && mime.subtype() == mime::PLAIN
        });
        let handler = With::new(|data: Json<MyObject>| data, cfg);

        let req = TestRequest::with_header(
            header::CONTENT_TYPE,
            header::HeaderValue::from_static("text/plain"),
        ).header(
            header::CONTENT_LENGTH,
            header::HeaderValue::from_static("16"),
        ).set_payload(Bytes::from_static(b"{\"name\": \"test\"}"))
        .finish();
        assert!(handler.handle(&req).as_err().is_none())
    }

    #[test]
    fn test_with_json_and_bad_content_type() {
        let mut cfg = JsonConfig::default();
        cfg.limit(4096);
        let handler = With::new(|data: Json<MyObject>| data, cfg);

        let req = TestRequest::with_header(
            header::CONTENT_TYPE,
            header::HeaderValue::from_static("text/plain"),
        ).header(
            header::CONTENT_LENGTH,
            header::HeaderValue::from_static("16"),
        ).set_payload(Bytes::from_static(b"{\"name\": \"test\"}"))
        .finish();
        assert!(handler.handle(&req).as_err().is_some())
    }
}


Review comment (suggestion):
Please add test case to verify that `cfg.content_type(...)` works correctly.
For example, it maps text/plain as json, but pass request with html

Code after:
        .finish();
        assert!(handler.handle(&req).as_err().is_none())
    }

    #[test]
    fn test_with_json_and_bad_content_type() {
        let mut cfg = JsonConfig::default();
        cfg.limit(4096);
        let handler = With::new(|data: Json<MyObject>| data, cfg);

        let req = TestRequest::with_header(
            header::CONTENT_TYPE,
            header::HeaderValue::from_static("text/plain"),
        ).header(
            header::CONTENT_LENGTH,
            header::HeaderValue::from_static("16"),
        ).set_payload(Bytes::from_static(b"{\"name\": \"test\"}"))
        .finish();
        assert!(handler.handle(&req).as_err().is_some())
    }

    #[test]
    fn test_with_json_and_good_custom_content_type() {
        let mut cfg = JsonConfig::default();
        cfg.limit(4096);
        cfg.content_type(|mime: mime::Mime| {
            mime.type_() == mime::TEXT && mime.subtype() == mime::PLAIN
        });
        let handler = With::new(|data: Json<MyObject>| data, cfg);

        let req = TestRequest::with_header(
            header::CONTENT_TYPE,
            header::HeaderValue::from_static("text/plain"),
        ).header(
            header::CONTENT_LENGTH,
            header::HeaderValue::from_static("16"),
        ).set_payload(Bytes::from_static(b"{\"name\": \"test\"}"))
        .finish();
        assert!(handler.handle(&req).as_err().is_none())
    }

    #[test]
    fn test_with_json_and_bad_custom_content_type() {
        let mut cfg = JsonConfig::default();
        cfg.limit(4096);
        cfg.content_type(|mime: mime::Mime| {
            mime.type_() == mime::TEXT && mime.subtype() == mime::PLAIN
        });
        let handler = With::new(|data: Json<MyObject>| data, cfg);

        let req = TestRequest::with_header(