Skip to content

Commit

Permalink
feat(core): validate duplicated capability identifier (#10858)
Browse files Browse the repository at this point in the history
having duplicate capability identifier lead to unexpected behavior because one of the capabilities gets ignored.
With this change the build script now fails when this happens.
  • Loading branch information
lucasfernog authored Sep 2, 2024
1 parent ecc5362 commit f0acf50
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/capability-id-already-exists.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-utils": patch:enhance
---

Validate duplicate capability identifier.
10 changes: 10 additions & 0 deletions crates/tauri-utils/src/acl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,20 @@ pub fn parse_capabilities(
{
match CapabilityFile::load(&path)? {
CapabilityFile::Capability(capability) => {
if capabilities_map.contains_key(&capability.identifier) {
return Err(Error::CapabilityAlreadyExists {
identifier: capability.identifier,
});
}
capabilities_map.insert(capability.identifier.clone(), capability);
}
CapabilityFile::List(capabilities) | CapabilityFile::NamedList { capabilities } => {
for capability in capabilities {
if capabilities_map.contains_key(&capability.identifier) {
return Err(Error::CapabilityAlreadyExists {
identifier: capability.identifier,
});
}
capabilities_map.insert(capability.identifier.clone(), capability);
}
}
Expand Down
7 changes: 7 additions & 0 deletions crates/tauri-utils/src/acl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ pub enum Error {
/// Permission identifier.
permission: String,
},

/// Capability with the given identifier already exists.
#[error("capability with identifier `{identifier}` already exists")]
CapabilityAlreadyExists {
/// Capability identifier.
identifier: String,
},
}

/// Allowed and denied commands inside a permission.
Expand Down

0 comments on commit f0acf50

Please sign in to comment.