Our Personal Data Server from scratch! tranquil.farm
pds rust database fun oauth atproto
238
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(tranquil-comms): prework for email #6

open opened by oyster.cafe targeting main from feat/inline-emailing
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:3fwecdnvtcscjnrx2p4n7alz/sh.tangled.repo.pull/3mkuoecyrw422
+87 -9
Interdiff #0 #1
Cargo.lock

This file has not been changed.

Cargo.toml

This file has not been changed.

crates/tranquil-comms/Cargo.toml

This file has not been changed.

+2 -9
crates/tranquil-comms/src/email/types.rs
··· 12 12 InvalidTlsMode(String), 13 13 } 14 14 15 - fn parse_token( 16 - raw: &str, 17 - lowercase: bool, 18 - strip_trailing_dot: bool, 19 - ) -> Result<String, ParseError> { 15 + fn parse_token(raw: &str, lowercase: bool, strip_trailing_dot: bool) -> Result<String, ParseError> { 20 16 let mut s = raw.trim(); 21 17 if strip_trailing_dot { 22 18 s = s.trim_end_matches('.'); ··· 260 256 261 257 #[test] 262 258 fn email_domain_strips_trailing_dot() { 263 - assert_eq!( 264 - EmailDomain::parse("Nel.pet.").unwrap().as_str(), 265 - "nel.pet" 266 - ); 259 + assert_eq!(EmailDomain::parse("Nel.pet.").unwrap().as_str(), "nel.pet"); 267 260 } 268 261 269 262 #[test]
+77
crates/tranquil-config/src/lib.rs
··· 5 5 6 6 static CONFIG: OnceLock<TranquilConfig> = OnceLock::new(); 7 7 8 + const REMOVED_ENV_VARS: &[(&str, &str)] = &[( 9 + "SENDMAIL_PATH", 10 + "the sendmail-binary transport was replaced with native SMTP. \ 11 + Configure MAIL_SMARTHOST_HOST for relay delivery, or leave it unset to \ 12 + deliver directly via recipient MX records. See example.toml for the full \ 13 + MAIL_* surface.", 14 + )]; 15 + 8 16 /// Errors discovered during configuration validation. 9 17 #[derive(Debug)] 10 18 pub struct ConfigError { ··· 162 170 pub fn validate(&self, ignore_secrets: bool) -> Result<(), ConfigError> { 163 171 let mut errors = Vec::new(); 164 172 173 + // -- removed config --------------------------------------------------- 174 + errors.extend( 175 + REMOVED_ENV_VARS 176 + .iter() 177 + .filter(|(var, _)| std::env::var_os(var).is_some()) 178 + .map(|(var, guidance)| format!("{var} is no longer supported: {guidance}")), 179 + ); 180 + 165 181 // -- secrets ---------------------------------------------------------- 166 182 if !ignore_secrets && !self.secrets.allow_insecure && !cfg!(test) { 167 183 if let Some(ref s) = self.secrets.jwt_secret { ··· 1364 1380 pub fn template() -> String { 1365 1381 confique::toml::template::<TranquilConfig>(confique::toml::FormatOptions::default()) 1366 1382 } 1383 + 1384 + #[cfg(test)] 1385 + mod tests { 1386 + use super::*; 1387 + 1388 + fn seed_required_env() { 1389 + let required = [ 1390 + ("PDS_HOSTNAME", "test.local"), 1391 + ("DATABASE_URL", "postgres://localhost/test"), 1392 + ("TRANQUIL_PDS_ALLOW_INSECURE_SECRETS", "1"), 1393 + ("INVITE_CODE_REQUIRED", "false"), 1394 + ("ENABLE_PDS_HOSTED_DID_WEB", "true"), 1395 + ("TRANQUIL_LEXICON_OFFLINE", "1"), 1396 + ]; 1397 + required 1398 + .iter() 1399 + .filter(|(k, _)| std::env::var_os(k).is_none()) 1400 + .for_each(|(k, v)| unsafe { std::env::set_var(k, v) }); 1401 + } 1402 + 1403 + #[test] 1404 + fn serial_validate_rejects_legacy_sendmail_path() { 1405 + seed_required_env(); 1406 + unsafe { std::env::set_var("SENDMAIL_PATH", "/usr/sbin/sendmail") }; 1407 + let config = TranquilConfig::builder() 1408 + .env() 1409 + .load() 1410 + .expect("load fresh config"); 1411 + let result = config.validate(true); 1412 + unsafe { std::env::remove_var("SENDMAIL_PATH") }; 1413 + 1414 + let err = result.expect_err("validate must reject SENDMAIL_PATH"); 1415 + let mentions_sendmail = err.errors.iter().any(|e| e.contains("SENDMAIL_PATH")); 1416 + assert!( 1417 + mentions_sendmail, 1418 + "errors did not mention SENDMAIL_PATH: {:?}", 1419 + err.errors 1420 + ); 1421 + } 1422 + 1423 + #[test] 1424 + fn serial_validate_passes_when_no_legacy_env_set() { 1425 + seed_required_env(); 1426 + unsafe { std::env::remove_var("SENDMAIL_PATH") }; 1427 + let config = TranquilConfig::builder() 1428 + .env() 1429 + .load() 1430 + .expect("load fresh config"); 1431 + let result = config.validate(true); 1432 + let leaked_legacy = result 1433 + .as_ref() 1434 + .err() 1435 + .map(|e| e.errors.iter().any(|s| s.contains("SENDMAIL_PATH"))) 1436 + .unwrap_or(false); 1437 + assert!( 1438 + !leaked_legacy, 1439 + "validate spuriously flagged SENDMAIL_PATH when unset: {:?}", 1440 + result 1441 + ); 1442 + } 1443 + }
example.toml

This file has not been changed.

+8
.config/nextest.toml
··· 68 68 filter = "package(tranquil-signal)" 69 69 test-group = "serial-env-tests" 70 70 71 + [[profile.default.overrides]] 72 + filter = "package(tranquil-config)" 73 + test-group = "serial-env-tests" 74 + 71 75 [[profile.default.overrides]] 72 76 filter = "binary(whole_story)" 73 77 test-group = "heavy-load-tests" ··· 118 122 filter = "package(tranquil-signal)" 119 123 test-group = "serial-env-tests" 120 124 125 + [[profile.ci.overrides]] 126 + filter = "package(tranquil-config)" 127 + test-group = "serial-env-tests" 128 + 121 129 [[profile.ci.overrides]] 122 130 filter = "binary(whole_story)" 123 131 test-group = "heavy-load-tests"

History

4 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
feat(tranquil-comms): prework for email
merge conflicts detected
expand
  • .config/nextest.toml:68
  • Cargo.lock:9
  • Cargo.toml:26
  • crates/tranquil-comms/Cargo.toml:10
  • crates/tranquil-config/src/lib.rs:5
  • example.toml:373
expand 0 comments
1 commit
expand
feat(tranquil-comms): prework for email
expand 0 comments
1 commit
expand
feat(tranquil-comms): prework for email
expand 0 comments
1 commit
expand
feat(tranquil-comms): prework for email
expand 0 comments