Return 400 for missing /api/serialize IDs (#1272)

This commit is contained in:
AK-Khan02
2026-06-10 21:48:33 -04:00
committed by GitHub
parent d12120bab6
commit 16633e3c65
4 changed files with 37 additions and 13 deletions

View File

@@ -228,11 +228,11 @@ impl TestServeSession {
}
}
pub fn get_api_serialize(
pub fn post_api_serialize(
&self,
ids: &[Ref],
session_id: SessionId,
) -> Result<SerializeResponse, reqwest::Error> {
) -> Result<reqwest::blocking::Response, reqwest::Error> {
let client = reqwest::blocking::Client::new();
let url = format!("http://localhost:{}/api/serialize", self.port);
let body = serialize_msgpack(&SerializeRequest {
@@ -241,9 +241,7 @@ impl TestServeSession {
})
.unwrap();
let body = client.post(url).body(body).send()?.bytes()?;
Ok(deserialize_msgpack(&body).expect("Server returned malformed response"))
client.post(url).body(body).send()
}
/// Sends a GET to `/api/rojo` with the given extra request headers and
@@ -291,7 +289,7 @@ fn serialize_msgpack<T: Serialize>(value: T) -> Result<Vec<u8>, rmp_serde::encod
Ok(serialized)
}
fn deserialize_msgpack<'a, T: Deserialize<'a>>(
pub fn deserialize_msgpack<'a, T: Deserialize<'a>>(
input: &'a [u8],
) -> Result<T, rmp_serde::decode::Error> {
let mut deserializer = rmp_serde::Deserializer::new(input).with_human_readable();

View File

@@ -1,14 +1,16 @@
use std::fs;
use insta::{assert_snapshot, assert_yaml_snapshot, with_settings};
use rbx_dom_weak::types::Ref;
use reqwest::StatusCode;
use tempfile::tempdir;
use crate::rojo_test::{
internable::InternAndRedact,
serve_util::{run_serve_test, serialize_to_xml_model},
serve_util::{deserialize_msgpack, run_serve_test, serialize_to_xml_model},
};
use librojo::web_api::SocketPacketType;
use librojo::web_api::{SerializeResponse, SocketPacketType};
#[test]
fn rejects_dns_rebinding_requests() {
@@ -713,9 +715,13 @@ fn meshpart_with_id() {
.find(|(_, inst)| inst.class_name == "ObjectValue")
.unwrap();
let serialize_response = session
.get_api_serialize(&[*meshpart, *objectvalue], info.session_id)
let body = session
.post_api_serialize(&[*meshpart, *objectvalue], info.session_id)
.unwrap()
.bytes()
.unwrap();
let serialize_response: SerializeResponse =
deserialize_msgpack(&body).expect("Server returned malformed response");
// We don't assert a snapshot on the SerializeResponse because the model includes the
// Refs from the DOM as names, which means it will obviously be different every time
@@ -727,6 +733,20 @@ fn meshpart_with_id() {
});
}
#[test]
fn serialize_missing_id() {
run_serve_test("empty", |session, _| {
let info = session.get_api_rojo().unwrap();
let missing_id = Ref::new();
let response = session
.post_api_serialize(&[missing_id], info.session_id)
.unwrap();
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
});
}
#[test]
fn forced_parent() {
run_serve_test("forced_parent", |session, mut redactions| {
@@ -741,9 +761,13 @@ fn forced_parent() {
read_response.intern_and_redact(&mut redactions, root_id)
);
let serialize_response = session
.get_api_serialize(&[root_id], info.session_id)
let body = session
.post_api_serialize(&[root_id], info.session_id)
.unwrap()
.bytes()
.unwrap();
let serialize_response: SerializeResponse =
deserialize_msgpack(&body).expect("Server returned malformed response");
assert_eq!(serialize_response.session_id, info.session_id);