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. format. The allowed elements are described below.
.Bl -tag .Bl -tag
.It Ic account .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 .Bl -tag
.It Ic contacts Ar array .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: 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 .It
rsa4096 rsa4096
.El .El
.It Ic name Ar string
The name the account is registered under. Must be unique.
.It Cm signature_algorithm Ar string .It Cm signature_algorithm Ar string
Name of the signature algorithm used to sign the messages sent to the endpoint as defined in Name of the signature algorithm used to sign the messages sent to the endpoint as defined in
.Em RFC 7518 . .Em RFC 7518 .

8
src/config.rs

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

28
src/config/account.rs

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

3
tests/config/override/00_initial.toml

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

3
tests/config/simple/simple.toml

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

Loading…
Cancel
Save