Skip to content

Commit

Permalink
fix(cloudformation-diff): cdk diff throws `toUpperCase is not a fun…
Browse files Browse the repository at this point in the history
…ction` when `ipProtocol` is a number (#28023)

Fix the describe protocol method when running a diff with a processed existing cloudformation template that has a security group rule with ipprotocol = -1

Closes #28021

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
gastonsilva committed Nov 21, 2023
1 parent 9ae9af2 commit 182bafc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class SecurityGroupRule {
public readonly peer?: RulePeer;

constructor(ruleObject: any, groupRef?: string) {
this.ipProtocol = ruleObject.IpProtocol || '*unknown*';
this.ipProtocol = ruleObject.IpProtocol?.toString() || '*unknown*';
this.fromPort = ruleObject.FromPort;
this.toPort = ruleObject.ToPort;
this.groupId = ruleObject.GroupId || groupRef || '*unknown*'; // In case of an inline rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ test('equality is symmetric', () => {
},
));
});

test('can describe protocol', () => {
expect(new SecurityGroupRule({ IpProtocol: -1 }).describeProtocol()).toEqual('Everything');
expect(new SecurityGroupRule({ IpProtocol: '-1' }).describeProtocol()).toEqual('Everything');
expect(new SecurityGroupRule({ FromPort: -1 }).describeProtocol()).toEqual('All *UNKNOWN*');
expect(new SecurityGroupRule({ IpProtocol: 'tcp', FromPort: -1, ToPort: -1 }).describeProtocol()).toEqual('All TCP');
expect(new SecurityGroupRule({ IpProtocol: 'tcp', FromPort: 10, ToPort: 20 }).describeProtocol()).toEqual('TCP 10-20');
expect(new SecurityGroupRule({ IpProtocol: 'tcp', FromPort: 10, ToPort: 10 }).describeProtocol()).toEqual('TCP 10');
});

0 comments on commit 182bafc

Please sign in to comment.