feat: disallow dans IFF random is used; regardless (#1050)

* feat: disallow dans IFF random is used; regardless

* blegh
This commit is contained in:
zkldi
2024-04-25 01:12:14 +01:00
committed by GitHub
parent e7051d82f9
commit ea70e36d83
2 changed files with 23 additions and 104 deletions
@@ -552,30 +552,6 @@ t.test("POST /ir/beatoraja/submit-course", (t) => {
t.end();
});
t.test("Should reject too few constraints", async (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-course")
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(
deepmerge(
courseScore,
{
course: {
constraint: ["GAUGE_LR2"],
},
},
{ arrayMerge: (d, s) => s }
)
);
t.equal(res.status, 400);
t.equal(res.body.success, false);
t.equal(res.body.description, "Invalid Constraints.");
t.end();
});
t.test("Should reject non-array constraints", async (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-course")
@@ -600,7 +576,7 @@ t.test("POST /ir/beatoraja/submit-course", (t) => {
t.end();
});
t.test("Should reject too many constraints", async (t) => {
t.test("Should reject invalid non lr2 gauge", async (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-course")
.set("X-TachiIR-Version", "v2.0.0")
@@ -610,7 +586,7 @@ t.test("POST /ir/beatoraja/submit-course", (t) => {
courseScore,
{
course: {
constraint: ["LN", "MIRROR", "GAUGE_LR2", "LN"],
constraint: ["GAUGE_5KEY", "MIRROR"],
},
},
{ arrayMerge: (d, s) => s }
@@ -619,61 +595,7 @@ t.test("POST /ir/beatoraja/submit-course", (t) => {
t.equal(res.status, 400);
t.equal(res.body.success, false);
t.equal(res.body.description, "Invalid Constraints.");
t.end();
});
t.test("Should reject invalid constraints", async (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-course")
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(
deepmerge(
courseScore,
{
course: {
constraint: ["foo", "bar"],
},
},
{ arrayMerge: (d, s) => s }
)
);
t.equal(res.status, 400);
t.equal(res.body.success, false);
t.equal(
res.body.description,
"[course.constraint[0]] Expected any of LN, MIRROR, GAUGE_LR2. (Received foo)"
);
t.end();
});
t.test("Should reject invalid constraints for 3", async (t) => {
const res = await mockApi
.post("/ir/beatoraja/submit-course")
.set("X-TachiIR-Version", "v2.0.0")
.set("Authorization", "Bearer mock_token")
.send(
deepmerge(
courseScore,
{
course: {
constraint: ["GAUGE_LR2", "MIRROR", "CHEAT_MODE"],
},
},
{ arrayMerge: (d, s) => s }
)
);
t.equal(res.status, 400);
t.equal(res.body.success, false);
t.equal(
res.body.description,
"[course.constraint[2]] Expected any of LN, MIRROR, GAUGE_LR2. (Received CHEAT_MODE)"
);
t.equal(res.body.description, "Dan GAUGE mode must be GAUGE_LR2.");
t.end();
});
+20 -23
View File
@@ -188,7 +188,7 @@ router.post(
"Expected an array of 4 objects with MD5 properties."
);
},
constraint: [p.isIn("LN", "MIRROR", "GAUGE_LR2")],
constraint: ["string"],
},
score: {
// For some reason, a course can have any of these lamps.
@@ -207,6 +207,7 @@ router.post(
"Perfect",
"Max"
),
option: p.isInteger,
lntype: p.isIn(0, 1, 2),
},
},
@@ -218,10 +219,11 @@ router.post(
const body = req.safeBody as {
course: {
charts: Array<{ md5: string }>;
constraint: Array<"GAUGE_LR2" | "LN" | "MIRROR">;
constraint: Array<string>;
};
score: {
clear: BeatorajaScore["clear"];
option: integer;
lntype: 0 | 1 | 2;
};
};
@@ -249,37 +251,32 @@ router.post(
});
}
// Constraints are a bit complicated.
// We only want to accept dans with the following
// beatoraja constraints - ["MIRROR","GAUGE_LR2"] or
// ["MIRROR", "GAUGE_LR2", "LN"].
const constraint = body.course.constraint;
if (constraint.length !== 2 && constraint.length !== 3) {
if (body.course.constraint.includes("CN")) {
return res.status(400).json({
success: false,
description: `Invalid Constraints.`,
description: `CN mode is not allowed in dans.`,
});
}
// If there are two constraints, check that they are
// MIRROR and GAUGE_LR2.
if (!constraint.includes("MIRROR") || !constraint.includes("GAUGE_LR2")) {
if (body.course.constraint.includes("HCN")) {
return res.status(400).json({
success: false,
description: `Invalid Constraints.`,
description: `HCN mode is not allowed in dans.`,
});
}
// If there are three constraints, check that the third
// is LN
if (constraint.length === 3) {
if (!constraint.includes("LN")) {
return res.status(400).json({
success: false,
description: `Invalid Constraints.`,
});
}
if (body.course.constraint.some((f) => f.startsWith("GAUGE_") && f !== "GAUGE_LR2")) {
return res.status(400).json({
success: false,
description: `Dan GAUGE mode must be GAUGE_LR2.`,
});
}
if (body.score.option !== 0 && body.score.option !== 1) {
return res.status(400).json({
success: false,
description: `RANDOM is not allowed in courses.`,
});
}
// Combine the md5s into one string in their order.