Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct RawCryptifyConfig {
staging_mode: Option<bool>,
metrics_token: Option<String>,
usage_db: Option<String>,
email_attribute: Option<String>,
}

#[derive(Debug, Deserialize)]
Expand All @@ -43,6 +44,11 @@ pub struct CryptifyConfig {
/// (the in-memory map in `Store` is only a cache). `None` keeps usage
/// entirely in memory, as it was before persistence was added.
usage_db: Option<String>,
/// Attribute type carrying the sender's email in the signing identity
/// (postguard#236). Finalize requires this attribute to be present.
/// Test environments override it with a test-scheme type (e.g.
/// `irma-demo.sidn-pbdf.email.email`); production keeps the default.
email_attribute: String,
}

impl From<RawCryptifyConfig> for CryptifyConfig {
Expand All @@ -67,6 +73,9 @@ impl From<RawCryptifyConfig> for CryptifyConfig {
staging_mode: config.staging_mode.unwrap_or(false),
metrics_token: config.metrics_token,
usage_db: config.usage_db,
email_attribute: config
.email_attribute
.unwrap_or_else(|| "pbdf.sidn-pbdf.email.email".to_owned()),
}
}
}
Expand Down Expand Up @@ -141,6 +150,12 @@ impl CryptifyConfig {
self.usage_db.as_deref()
}

/// The attribute type carrying the sender's email in the signing
/// identity. Defaults to the production `pbdf.sidn-pbdf.email.email`.
pub fn email_attribute(&self) -> &str {
&self.email_attribute
}

#[cfg(test)]
pub(crate) fn for_test(server_url: &str, staging_mode: bool) -> Self {
CryptifyConfig {
Expand All @@ -160,6 +175,7 @@ impl CryptifyConfig {
staging_mode,
metrics_token: None,
usage_db: None,
email_attribute: "pbdf.sidn-pbdf.email.email".to_owned(),
}
}
}
Expand Down Expand Up @@ -196,4 +212,20 @@ mod tests {
.unwrap();
assert_eq!(config.usage_db(), None);
}

#[test]
fn email_attribute_defaults_to_production_type() {
let config: CryptifyConfig = Figment::from(Serialized::defaults(base_config()))
.extract()
.unwrap();
assert_eq!(config.email_attribute(), "pbdf.sidn-pbdf.email.email");
}

#[test]
fn email_attribute_is_overridable() {
let mut raw = base_config();
raw["email_attribute"] = serde_json::json!("irma-demo.sidn-pbdf.email.email");
let config: CryptifyConfig = Figment::from(Serialized::defaults(raw)).extract().unwrap();
assert_eq!(config.email_attribute(), "irma-demo.sidn-pbdf.email.email");
}
}
12 changes: 9 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,19 +933,25 @@ async fn upload_finalize(
.pub_id
.con;

// The attribute type carrying the sender's email is configurable
// (postguard#236): test environments use a test-scheme type since pbdf
// credentials cannot be issued outside production.
let email_attribute = config.email_attribute();
let sender = attributes
.iter()
.find(|x| x.atype == "pbdf.sidn-pbdf.email.email")
.find(|x| x.atype == email_attribute)
.ok_or_else(|| {
log::error!("finalized upload has no email attribute in postguard metadata");
log::error!(
"finalized upload has no email attribute ({email_attribute}) in postguard metadata"
);
Error::InternalServerError(Some(GENERIC_INTERNAL_ERROR_MSG.to_owned()))
})?
.value
.clone();

let sender_attributes: Vec<(String, String)> = attributes
.into_iter()
.filter(|x| x.atype != "pbdf.sidn-pbdf.email.email")
.filter(|x| x.atype != email_attribute)
.filter_map(|x| {
let atype = x.atype;
x.value.map(|v| (atype, v))
Expand Down