Skip to content

Commit

Permalink
fix(IamPolicyStatement): don't serialize None condition (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
hffmnn authored Apr 23, 2024
1 parent aed8295 commit de822f9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lambda-events/src/event/iam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct IamPolicyStatement {
#[serde(deserialize_with = "deserialize_string_or_slice")]
pub resource: Vec<String>,
#[serde(default, deserialize_with = "deserialize_policy_condition")]
#[serde(skip_serializing_if = "Option::is_none")]
pub condition: Option<IamPolicyCondition>,
}

Expand Down Expand Up @@ -169,4 +170,24 @@ mod tests {

assert_eq!(vec!["janedoe/*"], condition["StringLike"]["s3:prefix"]);
}

#[test]
fn test_serialize_none_condition() {
let policy = IamPolicyStatement {
action: vec!["some:action".into()],
effect: IamPolicyEffect::Allow,
resource: vec!["some:resource".into()],
condition: None,
};
let policy_ser = serde_json::to_value(policy).unwrap();

assert_eq!(
policy_ser,
serde_json::json!({
"Action": ["some:action"],
"Effect": "Allow",
"Resource": ["some:resource"]
})
);
}
}

0 comments on commit de822f9

Please sign in to comment.