Skip to content

Commit fa013b1

Browse files
committed
[Feature] Add support for shareable user resources.
1 parent 53e4b24 commit fa013b1

31 files changed

+2406
-137
lines changed

.sqlx/query-541804a2e0cf4aacb664c00738e83871ebb8cf4523a8ed9f136ce4a77469bfd6.json

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-bf66332e2ff3a8f98a2603cf8e28a4afe82accdb06626864268d67b6f8174319.json

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-f439499d9ce154a3cb6912bb907515fc6c38e687f94b79c7c8eb21b1fec42c23.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-f508c94cef60a0c2b707814ccfedf9c4bdfca11dedce461f780fb7b1dd457776.json

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Table to store user public shares (content security policies, certificate templates etc.).
2+
CREATE TABLE IF NOT EXISTS user_shares
3+
(
4+
id TEXT PRIMARY KEY NOT NULL COLLATE NOCASE,
5+
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
6+
resource BLOB NOT NULL,
7+
created_at INTEGER NOT NULL
8+
) STRICT;

src/main.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ mod tests {
240240
users::{User, UserId},
241241
utils::{WebPageResource, WebPageResourceContent, WebPageResourceContentData},
242242
};
243+
use anyhow::anyhow;
243244
use cron::Schedule;
244245
use lettre::transport::stub::AsyncStubTransport;
245246
use std::{
@@ -252,7 +253,7 @@ mod tests {
252253
use trust_dns_resolver::proto::rr::Record;
253254
use url::Url;
254255

255-
pub use crate::{network::tests::*, utils::tests::*};
256+
pub use crate::{network::tests::*, server::tests::*, utils::tests::*};
256257
use crate::{search::SearchIndex, templates::create_templates};
257258

258259
pub struct MockUserBuilder {
@@ -386,11 +387,20 @@ mod tests {
386387
Database::open(|| Ok("sqlite::memory:".to_string())).await
387388
}
388389

390+
pub fn mock_search_index() -> anyhow::Result<SearchIndex> {
391+
SearchIndex::open(|schema| Ok(Index::create_in_ram(schema)))
392+
}
393+
389394
pub fn mock_user() -> anyhow::Result<User> {
395+
mock_user_with_id(1)
396+
}
397+
398+
pub fn mock_user_with_id<I: TryInto<UserId>>(id: I) -> anyhow::Result<User> {
399+
let id = id.try_into().map_err(|_| anyhow!("err"))?;
390400
Ok(MockUserBuilder::new(
391-
1.try_into()?,
392-
393-
"dev-handle",
401+
id,
402+
&format!("dev-{}@secutils.dev", *id),
403+
&format!("dev-handle-{}", *id),
394404
StoredCredentials {
395405
password_hash: Some("hash".to_string()),
396406
..Default::default()
@@ -446,7 +456,7 @@ mod tests {
446456
Ok(Api::new(
447457
config,
448458
mock_db().await?,
449-
SearchIndex::open(|schema| Ok(Index::create_in_ram(schema)))?,
459+
mock_search_index()?,
450460
mock_network(),
451461
create_templates()?,
452462
))
@@ -458,7 +468,7 @@ mod tests {
458468
Ok(Api::new(
459469
mock_config()?,
460470
mock_db().await?,
461-
SearchIndex::open(|schema| Ok(Index::create_in_ram(schema)))?,
471+
mock_search_index()?,
462472
network,
463473
create_templates()?,
464474
))

src/notifications/api_ext.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ mod tests {
341341
Envelope {
342342
forward_path: [
343343
Address {
344-
serialized: "[email protected]",
345-
at_start: 3,
344+
serialized: "dev-1@secutils.dev",
345+
at_start: 5,
346346
},
347347
],
348348
reverse_path: Some(
@@ -352,7 +352,7 @@ mod tests {
352352
},
353353
),
354354
},
355-
"From: [email protected]\r\nReply-To: [email protected]\r\nTo: [email protected]\r\nSubject: [NO SUBJECT]\r\nDate: Sat, 01 Jan 2000 09:58:20 +0000\r\nContent-Transfer-Encoding: 7bit\r\n\r\nabc",
355+
"From: [email protected]\r\nReply-To: [email protected]\r\nTo: dev-1@secutils.dev\r\nSubject: [NO SUBJECT]\r\nDate: Sat, 01 Jan 2000 09:58:20 +0000\r\nContent-Transfer-Encoding: 7bit\r\n\r\nabc",
356356
),
357357
(
358358
Envelope {

src/notifications/notification_content.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ mod tests {
172172
.await?, @r###"
173173
EmailNotificationContent {
174174
subject: "Activate you Secutils.dev account",
175-
text: "To activate your Secutils.dev account, please click the following link: http://localhost:1234/activate?code=some-code&email=dev%40secutils.dev",
175+
text: "To activate your Secutils.dev account, please click the following link: http://localhost:1234/activate?code=some-code&email=dev-1%40secutils.dev",
176176
html: Some(
177-
"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <title>Activate your Secutils.dev account</title>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <style>\n body {\n font-family: Arial, sans-serif;\n background-color: #f1f1f1;\n margin: 0;\n padding: 0;\n }\n .container {\n max-width: 600px;\n margin: 0 auto;\n background-color: #fff;\n padding: 20px;\n border-radius: 5px;\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n }\n h1 {\n font-size: 24px;\n margin-top: 0;\n }\n p {\n font-size: 16px;\n line-height: 1.5;\n margin-bottom: 20px;\n }\n .button-link {\n color: #fff;\n background-color: #2196F3;\n padding: 10px 20px;\n text-decoration: none;\n border-radius: 5px;\n }\n </style>\n</head>\n<body>\n<div class=\"container\">\n <h1>Activate your Secutils.dev account</h1>\n <p>Thanks for signing up! To activate your account, please click the link below:</p>\n <a class=\"button-link\" href=\"http://localhost:1234/activate?code=some-code&email=dev%40secutils.dev\">Activate my account</a>\n <p>If the button above doesn't work, you can also copy and paste the following URL into your browser:</p>\n <p>http://localhost:1234/activate?code=some-code&email=dev%40secutils.dev</p>\n <p>If you have any trouble activating your account, please contact us at <a href=\"mailto: [email protected]\">[email protected]</a>.</p>\n</div>\n</body>\n</html>\n",
177+
"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <title>Activate your Secutils.dev account</title>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <style>\n body {\n font-family: Arial, sans-serif;\n background-color: #f1f1f1;\n margin: 0;\n padding: 0;\n }\n .container {\n max-width: 600px;\n margin: 0 auto;\n background-color: #fff;\n padding: 20px;\n border-radius: 5px;\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n }\n h1 {\n font-size: 24px;\n margin-top: 0;\n }\n p {\n font-size: 16px;\n line-height: 1.5;\n margin-bottom: 20px;\n }\n .button-link {\n color: #fff;\n background-color: #2196F3;\n padding: 10px 20px;\n text-decoration: none;\n border-radius: 5px;\n }\n </style>\n</head>\n<body>\n<div class=\"container\">\n <h1>Activate your Secutils.dev account</h1>\n <p>Thanks for signing up! To activate your account, please click the link below:</p>\n <a class=\"button-link\" href=\"http://localhost:1234/activate?code=some-code&email=dev-1%40secutils.dev\">Activate my account</a>\n <p>If the button above doesn't work, you can also copy and paste the following URL into your browser:</p>\n <p>http://localhost:1234/activate?code=some-code&email=dev-1%40secutils.dev</p>\n <p>If you have any trouble activating your account, please contact us at <a href=\"mailto: [email protected]\">[email protected]</a>.</p>\n</div>\n</body>\n</html>\n",
178178
),
179179
attachments: None,
180180
}

src/notifications/notification_content_template.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ mod tests {
8080
.await?, @r###"
8181
EmailNotificationContent {
8282
subject: "Activate you Secutils.dev account",
83-
text: "To activate your Secutils.dev account, please click the following link: http://localhost:1234/activate?code=some-code&email=dev%40secutils.dev",
83+
text: "To activate your Secutils.dev account, please click the following link: http://localhost:1234/activate?code=some-code&email=dev-1%40secutils.dev",
8484
html: Some(
85-
"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <title>Activate your Secutils.dev account</title>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <style>\n body {\n font-family: Arial, sans-serif;\n background-color: #f1f1f1;\n margin: 0;\n padding: 0;\n }\n .container {\n max-width: 600px;\n margin: 0 auto;\n background-color: #fff;\n padding: 20px;\n border-radius: 5px;\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n }\n h1 {\n font-size: 24px;\n margin-top: 0;\n }\n p {\n font-size: 16px;\n line-height: 1.5;\n margin-bottom: 20px;\n }\n .button-link {\n color: #fff;\n background-color: #2196F3;\n padding: 10px 20px;\n text-decoration: none;\n border-radius: 5px;\n }\n </style>\n</head>\n<body>\n<div class=\"container\">\n <h1>Activate your Secutils.dev account</h1>\n <p>Thanks for signing up! To activate your account, please click the link below:</p>\n <a class=\"button-link\" href=\"http://localhost:1234/activate?code=some-code&email=dev%40secutils.dev\">Activate my account</a>\n <p>If the button above doesn't work, you can also copy and paste the following URL into your browser:</p>\n <p>http://localhost:1234/activate?code=some-code&email=dev%40secutils.dev</p>\n <p>If you have any trouble activating your account, please contact us at <a href=\"mailto: [email protected]\">[email protected]</a>.</p>\n</div>\n</body>\n</html>\n",
85+
"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <title>Activate your Secutils.dev account</title>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <style>\n body {\n font-family: Arial, sans-serif;\n background-color: #f1f1f1;\n margin: 0;\n padding: 0;\n }\n .container {\n max-width: 600px;\n margin: 0 auto;\n background-color: #fff;\n padding: 20px;\n border-radius: 5px;\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n }\n h1 {\n font-size: 24px;\n margin-top: 0;\n }\n p {\n font-size: 16px;\n line-height: 1.5;\n margin-bottom: 20px;\n }\n .button-link {\n color: #fff;\n background-color: #2196F3;\n padding: 10px 20px;\n text-decoration: none;\n border-radius: 5px;\n }\n </style>\n</head>\n<body>\n<div class=\"container\">\n <h1>Activate your Secutils.dev account</h1>\n <p>Thanks for signing up! To activate your account, please click the link below:</p>\n <a class=\"button-link\" href=\"http://localhost:1234/activate?code=some-code&email=dev-1%40secutils.dev\">Activate my account</a>\n <p>If the button above doesn't work, you can also copy and paste the following URL into your browser:</p>\n <p>http://localhost:1234/activate?code=some-code&email=dev-1%40secutils.dev</p>\n <p>If you have any trouble activating your account, please contact us at <a href=\"mailto: [email protected]\">[email protected]</a>.</p>\n</div>\n</body>\n</html>\n",
8686
),
8787
attachments: None,
8888
}
@@ -115,9 +115,9 @@ mod tests {
115115
.await?, @r###"
116116
EmailNotificationContent {
117117
subject: "Reset password for your Secutils.dev account",
118-
text: "To reset your Secutils.dev password, please click the following link: http://localhost:1234/reset_credentials?code=some-code&email=dev%40secutils.dev",
118+
text: "To reset your Secutils.dev password, please click the following link: http://localhost:1234/reset_credentials?code=some-code&email=dev-1%40secutils.dev",
119119
html: Some(
120-
"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <title>Reset password for your Secutils.dev account</title>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <style>\n body {\n font-family: Arial, sans-serif;\n background-color: #f1f1f1;\n margin: 0;\n padding: 0;\n }\n .container {\n max-width: 600px;\n margin: 0 auto;\n background-color: #fff;\n padding: 20px;\n border-radius: 5px;\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n }\n h1 {\n font-size: 24px;\n margin-top: 0;\n }\n p {\n font-size: 16px;\n line-height: 1.5;\n margin-bottom: 20px;\n }\n .button-link {\n color: #fff;\n background-color: #2196F3;\n padding: 10px 20px;\n text-decoration: none;\n border-radius: 5px;\n }\n </style>\n</head>\n<body>\n<div class=\"container\">\n <h1>Reset password for your Secutils.dev account</h1>\n <p>You recently requested to reset your password. To reset your password, please click the link below:</p>\n <a class=\"button-link\" href=\"http://localhost:1234/reset_credentials?code=some-code&email=dev%40secutils.dev\">Reset your password</a>\n <p>If the button above doesn't work, you can also copy and paste the following URL into your browser:</p>\n <p>http://localhost:1234/reset_credentials?code=some-code&email=dev%40secutils.dev</p>\n <p>If you did not request to reset your password, please ignore this email and your password will not be changed.</p>\n <p>If you have any trouble resetting your password, please contact us at <a href=\"mailto: [email protected]\">[email protected]</a>.</p>\n</div>\n</body>\n</html>\n",
120+
"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <title>Reset password for your Secutils.dev account</title>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <style>\n body {\n font-family: Arial, sans-serif;\n background-color: #f1f1f1;\n margin: 0;\n padding: 0;\n }\n .container {\n max-width: 600px;\n margin: 0 auto;\n background-color: #fff;\n padding: 20px;\n border-radius: 5px;\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n }\n h1 {\n font-size: 24px;\n margin-top: 0;\n }\n p {\n font-size: 16px;\n line-height: 1.5;\n margin-bottom: 20px;\n }\n .button-link {\n color: #fff;\n background-color: #2196F3;\n padding: 10px 20px;\n text-decoration: none;\n border-radius: 5px;\n }\n </style>\n</head>\n<body>\n<div class=\"container\">\n <h1>Reset password for your Secutils.dev account</h1>\n <p>You recently requested to reset your password. To reset your password, please click the link below:</p>\n <a class=\"button-link\" href=\"http://localhost:1234/reset_credentials?code=some-code&email=dev-1%40secutils.dev\">Reset your password</a>\n <p>If the button above doesn't work, you can also copy and paste the following URL into your browser:</p>\n <p>http://localhost:1234/reset_credentials?code=some-code&email=dev-1%40secutils.dev</p>\n <p>If you did not request to reset your password, please ignore this email and your password will not be changed.</p>\n <p>If you have any trouble resetting your password, please contact us at <a href=\"mailto: [email protected]\">[email protected]</a>.</p>\n</div>\n</body>\n</html>\n",
121121
),
122122
attachments: None,
123123
}

src/scheduler/scheduler_jobs/notifications_send_job.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ mod tests {
272272
Envelope {
273273
forward_path: [
274274
Address {
275-
serialized: "[email protected]",
276-
at_start: 3,
275+
serialized: "dev-1@secutils.dev",
276+
at_start: 5,
277277
},
278278
],
279279
reverse_path: Some(
@@ -283,7 +283,7 @@ mod tests {
283283
},
284284
),
285285
},
286-
"From: [email protected]\r\nReply-To: [email protected]\r\nTo: [email protected]\r\nSubject: [NO SUBJECT]\r\nDate: Sat, 01 Jan 2000 10:00:00 +0000\r\nContent-Transfer-Encoding: 7bit\r\n\r\nmessage 0",
286+
"From: [email protected]\r\nReply-To: [email protected]\r\nTo: dev-1@secutils.dev\r\nSubject: [NO SUBJECT]\r\nDate: Sat, 01 Jan 2000 10:00:00 +0000\r\nContent-Transfer-Encoding: 7bit\r\n\r\nmessage 0",
287287
)
288288
"###);
289289

0 commit comments

Comments
 (0)