aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test/java
Commit message (Collapse)AuthorAgeFilesLines
* server: accept event file uploads held entirely in memory Kostya2026-10-102-1/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | Add POST /api/upload: a logged-in user sends a Schema v3 file as a multipart part, its events join the market for everyone, and the uploader becomes their Market Maker. It uses the Servlet API's own multipart support, as the spec asks, and hands the part's stream to the v3 loader, so validation errors (bad XML, broken Exercise 1 rules, a name already in the market) come back as 400 with their reason. As in Exercise 1, a file whose name does not end in .xml is refused before it is read, since a request need not come from our client. The spec warns that the grading server cannot write files, and Tomcat writes any multipart part larger than @MultipartConfig's fileSizeThreshold to a temp file. That threshold defaults to 0, so a plain upload servlet always touches the disk. Cap uploads at 1 MB and put the threshold above the whole request limit, so every upload stays in memory. Bigger files get 413, requests without a session 401, and non-multipart bodies 400. Tomcat deletes spooled parts once the request ends, so comparing the files before and after an upload cannot catch spooling. The test instead watches the webapp's temp directory for any file being created while a near-limit upload runs. It fails if the threshold is set back to 0.
* server: add username login and logout endpoints Kostya2026-10-093-37/+159
| | | | | | | | | | | | | | | | | | | | | | The spec asks for a login by unique name only, with no passwords or sign-up, and an error that lets the user try again if the name exists. Add POST /api/login (form field "username") and POST /api/logout. Sessions maps each name, ignoring case, to the one HTTP session holding it. A second session asking for a held name gets 409 NAME_TAKEN, and a blank name gets 400. When a session ends, by logout or by Tomcat timing it out after a client quits without logging out, an HttpSessionListener frees the name. The account itself (ledger, Market Maker roles) stays, and logging in with that name again resumes it rather than locking the user out for the life of the server. New accounts start with a zero balance and are funded through deposits. Json gives every endpoint the same response shape, with errors as {"error": CODE, "message": text} built from a failed Result. Tomcat setup for the tests moves into a shared TestServer helper, whose clients each keep their own cookie jar and so act as separate users.
* server: add Tomcat webapp module with shared engine and CORS Kostya2026-10-091-0/+97
Exercise 3 moves the market behind a Tomcat server that the desktop and browser clients share. Add a server module, registered in the build scripts, holding the pieces every later endpoint builds on: - ServerEngine wires one in-memory market (repositories, ledger, trading pipeline, v3 upload loader) and lives in the servlet context for the webapp's lifetime. Its catalog refuses path-based loading, so events can only arrive through uploaded streams and the server never reads or writes files. - EngineBootstrap builds that engine when the webapp deploys. - CorsFilter answers preflights and echoes the caller's Origin with Allow-Credentials, which the browser client needs to send its session cookie from another origin. With usernames as the only login, echoing any origin exposes nothing a page couldn't get by logging in itself. - /api/health reports that the engine is up. Vendor tomcat-juli 10.1.26 next to the other Tomcat jars. It ships in Tomcat's bin/ rather than lib/, and embedded Tomcat cannot start without it. A test deploys the module into embedded Tomcat, so annotation scanning, the health check and CORS are checked against a real container.