Phase 4: documents, encrypted on the server
Scans and photos of a person's papers, and a company's documents for the extension packs, uploaded on a dashed strip that takes dropped files: up to 10 files of 20 MB each, 64 MB in all; PDF, JPEG, PNG and WebP, told by their first bytes. - src/files.rs: one file per document as <id>.vdoc, AES-256-GCM under a key per file (HKDF-SHA256 from the file key and a random salt in the header); the document's id is authenticated with it. The key comes from VISA_FILES_KEY_FILE or the credential files-key; with the login on, the app does not start without it and VISA_FILES_DIR. - migrations/0003: documents (a person's or a company's, the record it belongs to, kind, date on it, note, file name, type, size, SHA-256); audit_log gets company_id and the action download. - A Documents tab per person, the documents on the company's page, and each record's documents next to its Edit link with "+ Document". - An upload's form token is its first field and is checked before any file is read; the guard lets multipart through only to the two upload addresses. - Files open under their own CSP and are never cached; a download is named after the person or company, the kind and the date. Every upload, view, download, change and deletion is in the audit log. - visa files-check; demo documents in seed-demo; scripts/dev.sh keeps the local documents and their key in .dev/; /favicon.ico for image and PDF pages. Tests: 57 unit and 33 integration (8 new for documents). Edge check of the strip (choose, drop, too large), an upload, the PDF and image viewers under the file policy: no problems, no console errors.
This commit is contained in:
1 parent
d543c929e9
commit
2061e3a024
35 files changed
+4256
-58
No files matched your search
+37
-1
@@ -65,6 +65,26 @@ async fn every_page_renders_with_demo_data(pool: PgPool) {
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
let store = app.st.files.as_ref().unwrap();
|
||||
assert!(
|
||||
visa::seed::demo_documents(&pool, store, visa::dates::today())
|
||||
.await
|
||||
.unwrap()
|
||||
> 0
|
||||
);
|
||||
let doc: i64 = sqlx::query_scalar(
|
||||
"SELECT id FROM documents WHERE person_id = $1 AND kind = 'passport-photo-page'",
|
||||
)
|
||||
.bind(erika)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
let company_doc: i64 =
|
||||
sqlx::query_scalar("SELECT id FROM documents WHERE company_id = $1 ORDER BY id LIMIT 1")
|
||||
.bind(company)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut pages = vec![
|
||||
("/".to_string(), "90-day report".to_string()),
|
||||
@@ -97,12 +117,24 @@ async fn every_page_renders_with_demo_data(pool: PgPool) {
|
||||
("/companies/new".to_string(), "New company".to_string()),
|
||||
(
|
||||
format!("/companies/{company}"),
|
||||
"People employed".to_string(),
|
||||
"Company certificate".to_string(),
|
||||
),
|
||||
(
|
||||
format!("/companies/{company}/edit"),
|
||||
"0999999000004".to_string(),
|
||||
),
|
||||
(
|
||||
format!("/people/{erika}/documents"),
|
||||
"Passport photo page".to_string(),
|
||||
),
|
||||
(
|
||||
format!("/people/{erika}/documents/{doc}/edit"),
|
||||
"passport-photo-page.png".to_string(),
|
||||
),
|
||||
(
|
||||
format!("/companies/{company}/documents/{company_doc}/edit"),
|
||||
"About the document".to_string(),
|
||||
),
|
||||
];
|
||||
for kind in visa::records::STAY {
|
||||
pages.push((
|
||||
@@ -187,6 +219,10 @@ async fn open_paths_headers_and_not_found(pool: PgPool) {
|
||||
app.get("/static/nope.css").await.status,
|
||||
StatusCode::NOT_FOUND
|
||||
);
|
||||
// an image or a PDF opened in the browser asks for the icon here
|
||||
let icon = app.get("/favicon.ico").await;
|
||||
assert_eq!(icon.status, StatusCode::OK);
|
||||
assert_eq!(icon.headers["content-type"], "image/svg+xml");
|
||||
|
||||
let r = app.get("/").await;
|
||||
assert_eq!(r.status, StatusCode::OK);
|
||||
|
||||
Reference in new issue
Block a user