Skip to content

feature/us-04-private-test-cases#15

Open
juanjo36 wants to merge 2 commits into
mainfrom
feature/us-04-private-test-cases
Open

feature/us-04-private-test-cases#15
juanjo36 wants to merge 2 commits into
mainfrom
feature/us-04-private-test-cases

Conversation

@juanjo36

Copy link
Copy Markdown
Member

Se implementa el módulo de test cases para gestionar casos de prueba desde un file server.

Se crea el módulo src/modules/test-cases/ con dos endpoints GET:

  • GET /test-cases/:problemId retorna todos los casos, para el juez interno.
  • GET /test-cases/public/:problemId retorna solo casos públicos, para el usuario.

El servicio lee archivos JSON desde src/files/test-cases/, separa casos públicos (is_sample=true) de privados (is_sample=false) y mantiene el orden mediante sort_order.

Se añadieron pruebas básicas que validan la separación público/privado y el orden correcto.

Se agregan 3 ejemplos en src/files/test-cases/.

@juanjo36 juanjo36 linked an issue Jul 11, 2026 that may be closed by this pull request
5 tasks
@juanjo36 juanjo36 moved this from To do to In review PR in Judge Back Jul 11, 2026
@juanjo36 juanjo36 removed this from Judge Back Jul 11, 2026
@JGaviria0

Copy link
Copy Markdown
Member

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6835b1f472

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
});

router.get('/:problemId', async (req, res, next) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Protect the private test case endpoint

This route is mounted directly as GET /test-cases/:problemId without any middleware, so any API client can fetch the full payload returned by getAllTestCases, including cases where is_sample is false. The commit describes this endpoint as intended for the internal judge, while the existing repo protects authenticated routes with authGuard in src/modules/auth/auth.controller.js; without an internal credential or similar guard here, students can retrieve hidden inputs and expected outputs and bypass the private-test mechanism.

Useful? React with 👍 / 👎.

Comment on lines +29 to +31
const notFoundError = new Error('Test cases file not found');
notFoundError.statusCode = 404;
throw notFoundError;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return the not-found status from test case errors

Setting notFoundError.statusCode = 404 here does not affect the HTTP response because the app-level error middleware in src/main.js ignores error.statusCode and maps everything except two Google auth messages to 500. As a result, GET /test-cases/<missing problem> reports an internal server error instead of a normal not-found condition, which will mislead clients and monitoring for absent problem files unless the controller returns 404 directly or the shared error handler honors this status.

Useful? React with 👍 / 👎.

const TEST_CASES_DIR = path.resolve(__dirname, '../../files/test-cases');

async function getAllTestCases(problemId) {
const filePath = path.join(TEST_CASES_DIR, `problema-${problemId}.json`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Constrain problemId before building file paths

Because Express decodes route parameters, a request can supply an encoded slash in problemId (for example %2F..%2F) and this path.join will normalize the resulting ../ segments before reading the file. In that case the endpoint is no longer confined to src/files/test-cases, so it can disclose any readable JSON array file whose normalized name fits the problema-*.json pattern, or at least expose file-existence/format differences through the error messages; restrict IDs to the expected numeric form or verify the resolved path stays under TEST_CASES_DIR before reading.

Useful? React with 👍 / 👎.

Comment on lines +19 to +20

const allCases = await testCasesService.getAllTestCases('1', tempDir);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Make the test read the temporary fixture

These calls pass tempDir, but getAllTestCases and getPublicTestCases only accept problemId, so the extra argument is ignored and the test reads the committed src/files/test-cases/problema-1.json fixture instead of the file created above. This lets the test keep passing even if the service is not reading the intended fixture contents, and it also means the claimed ordering/separation behavior is only checked against whatever happens to be in the production sample file.

Useful? React with 👍 / 👎.

throw notFoundError;
}

if (error.message === 'Unexpected token') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Detect JSON parse errors reliably

For a malformed test-case file, JSON.parse does not throw an error whose message is exactly Unexpected token (it includes the token/position or other details), so this branch is skipped and clients receive the raw parser message instead of the intended generic Invalid JSON in test cases file. If a fixture is corrupted, especially one containing hidden cases, matching on SyntaxError (or wrapping only the parse call) avoids exposing parser snippets and keeps the error contract consistent.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

US-04: Modelar test cases privados por problema

2 participants