1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
4#[serde(rename_all = "snake_case")]
5pub struct NpmInstallPackageCapability {
6 pub package: String,
7}
8
9impl NpmInstallPackageCapability {
10 /// Returns whether the capability allows installing the given NPM package.
11 pub fn allows(&self, package: &str) -> bool {
12 self.package == "*" || self.package == package
13 }
14}
15
16#[cfg(test)]
17mod tests {
18 use pretty_assertions::assert_eq;
19
20 use super::*;
21
22 #[test]
23 fn test_allows() {
24 let capability = NpmInstallPackageCapability {
25 package: "*".to_string(),
26 };
27 assert_eq!(capability.allows("package"), true);
28
29 let capability = NpmInstallPackageCapability {
30 package: "react".to_string(),
31 };
32 assert_eq!(capability.allows("react"), true);
33
34 let capability = NpmInstallPackageCapability {
35 package: "react".to_string(),
36 };
37 assert_eq!(capability.allows("malicious-package"), false);
38 }
39}