Skip to content

Commit

Permalink
Merge pull request #135 from ngrok/bob/policy-default
Browse files Browse the repository at this point in the history
Add serde(default) back to policy parent struct
  • Loading branch information
bobzilladev authored Jan 31, 2024
2 parents 49b1575 + a987e3c commit 0115806
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ngrok/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ngrok"
version = "0.14.0-pre.10"
version = "0.14.0-pre.11"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "The ngrok agent SDK"
Expand Down
15 changes: 15 additions & 0 deletions ngrok/assets/policy-inbound.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"inbound": [
{
"name": "test_in",
"expressions": [
"req.Method == 'PUT'"
],
"actions": [
{
"type": "deny"
}
]
}
]
}
15 changes: 15 additions & 0 deletions ngrok/src/config/policies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::internals::proto;
/// A policy that defines rules that should be applied to incoming or outgoing
/// connections to the edge.
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
#[serde(default)]
pub struct Policy {
inbound: Vec<Rule>,
outbound: Vec<Rule>,
Expand Down Expand Up @@ -241,6 +242,13 @@ pub(crate) mod test {
);
}

#[test]
fn test_empty_json_to_policy() {
let policy: Policy = Policy::from_json("{}").unwrap();
assert_eq!(0, policy.inbound.len());
assert_eq!(0, policy.outbound.len());
}

#[test]
fn test_policy_to_json() {
let policy = Policy::from_json(POLICY_JSON).unwrap();
Expand Down Expand Up @@ -317,6 +325,13 @@ pub(crate) mod test {
assert_eq!(policy, policy2);
}

#[test]
fn test_load_inbound_file() {
let policy = Policy::from_file("assets/policy-inbound.json").unwrap();
assert_eq!("test_in", policy.inbound[0].name);
assert_eq!(0, policy.outbound.len());
}

#[test]
fn test_load_file_error() {
let error = Policy::from_file("assets/absent.json").err().unwrap();
Expand Down

0 comments on commit 0115806

Please sign in to comment.