Browse Source

Use a table of table for the accounts

ng
Rodolphe Bréard 4 weeks ago
parent
commit
e3bffef123
Failed to extract signature
  1. 4
      man/en/acmed.toml.5
  2. 8
      src/config.rs
  3. 28
      src/config/account.rs
  4. 3
      tests/config/override/00_initial.toml
  5. 3
      tests/config/simple/simple.toml

4
man/en/acmed.toml.5

@ -18,7 +18,7 @@ are written in the
format. The allowed elements are described below.
.Bl -tag
.It Ic account
Array of table representing an account on one or several endpoint.
Table of table representing an account on one or several endpoint.
.Bl -tag
.It Ic contacts Ar array
Array of tables describing describing the account holder's contact information. Each table must have one and only one key-value pair. Possible keys and their associated values are:
@ -78,8 +78,6 @@ rsa2048
.It
rsa4096
.El
.It Ic name Ar string
The name the account is registered under. Must be unique.
.It Cm signature_algorithm Ar string
Name of the signature algorithm used to sign the messages sent to the endpoint as defined in
.Em RFC 7518 .

8
src/config.rs

@ -36,7 +36,7 @@ pub struct AcmedConfig {
#[serde(default)]
pub(in crate::config) group: Vec<Group>,
#[serde(default)]
pub(in crate::config) account: Vec<Account>,
pub(in crate::config) account: HashMap<String, Account>,
#[serde(default)]
pub(in crate::config) certificate: Vec<Certificate>,
}
@ -119,13 +119,12 @@ mod tests {
assert!(cfg.hook.is_empty());
assert!(cfg.group.is_empty());
assert_eq!(cfg.account.len(), 1);
let account = cfg.account.first().unwrap();
let account = cfg.account.get("example").unwrap();
assert_eq!(account.contacts.len(), 1);
assert!(account.env.is_empty());
assert!(account.external_account.is_none());
assert!(account.hooks.is_empty());
assert_eq!(account.key_type, AccountKeyType::EcDsaP256);
assert_eq!(account.name, "example");
assert_eq!(
account.signature_algorithm,
Some(AccountSignatureAlgorithm::Hs384)
@ -162,13 +161,12 @@ mod tests {
assert!(cfg.hook.is_empty());
assert!(cfg.group.is_empty());
assert_eq!(cfg.account.len(), 1);
let account = cfg.account.first().unwrap();
let account = cfg.account.get("example").unwrap();
assert_eq!(account.contacts.len(), 1);
assert!(account.env.is_empty());
assert!(account.external_account.is_none());
assert!(account.hooks.is_empty());
assert_eq!(account.key_type, AccountKeyType::EcDsaP256);
assert_eq!(account.name, "example");
assert!(account.signature_algorithm.is_none());
assert!(cfg.certificate.is_empty());
}

28
src/config/account.rs

@ -14,7 +14,6 @@ pub struct Account {
pub(in crate::config) hooks: Vec<String>,
#[serde(default)]
pub(in crate::config) key_type: AccountKeyType,
pub(in crate::config) name: String,
#[serde(default)]
pub(in crate::config) signature_algorithm: Option<AccountSignatureAlgorithm>,
}
@ -89,7 +88,6 @@ mod tests {
#[test]
fn account_minimal() {
let cfg = r#"
name = "test"
contacts = [
{ mailto = "acme@example.org" }
]
@ -106,14 +104,12 @@ contacts = [
assert!(a.external_account.is_none());
assert!(a.hooks.is_empty());
assert_eq!(a.key_type, AccountKeyType::EcDsaP256);
assert_eq!(a.name, "test");
assert!(a.signature_algorithm.is_none());
}
#[test]
fn account_full() {
let cfg = r#"
name = "test"
contacts = [
{ mailto = "acme@example.org" }
]
@ -142,37 +138,15 @@ signature_algorithm = "HS512"
assert_eq!(a.external_account, Some(ea));
assert_eq!(a.hooks, vec!["hook name".to_string()]);
assert_eq!(a.key_type, AccountKeyType::Rsa2048);
assert_eq!(a.name, "test");
assert_eq!(
a.signature_algorithm,
Some(AccountSignatureAlgorithm::Hs512)
);
}
#[test]
fn account_missing_name() {
let cfg = r#"
contacts = [
{ mailto = "acme@example.org" }
]
"#;
let res = load_str::<Account>(cfg);
assert!(res.is_err());
}
#[test]
fn account_missing_contact() {
let cfg = r#"name = "test""#;
let res = load_str::<Account>(cfg);
assert!(res.is_err());
}
#[test]
fn account_empty_contact() {
let cfg = r#"
name = "test"
contacts = []
"#;
let cfg = r#"contacts = []"#;
let res = load_str::<Account>(cfg);
assert!(res.is_err());
}

3
tests/config/override/00_initial.toml

@ -9,8 +9,7 @@ tos_agreed = false
[endpoint."test AC 2"]
url = "https://acme-v02.ac2.example.org/directory"
[[account]]
name = "example"
[account."example"]
contacts = [
{ mailto = "acme@example.org" },
]

3
tests/config/simple/simple.toml

@ -2,8 +2,7 @@
accounts_directory = "/tmp/example/account/dir"
certificates_directory = "/tmp/example/cert/dir/"
[[account]]
name = "example"
[account."example"]
contacts = [
{ mailto = "acme@example.org" },
]

Loading…
Cancel
Save