forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ec2-alpha): do not use string comparison in
rangesOverlap
(aws#…
…32269) ### Issue aws#32145 Closes aws#32145. ### Reason for this change The rangesOverlap method was using string comparison to check if IP ranges overlapped. ### Description of changes The rangesOverlap method was updated to compare IP ranges using the ip-num library ### Description of how you validated changes Added two unit tests to verify correct behavior ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
7 changed files
with
103 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ws-cdk/aws-ec2-alpha/test/integ.subnet-v2.js.snapshot/aws-cdk-vpcv2-alpha-new.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 49 additions & 24 deletions
73
packages/@aws-cdk/aws-ec2-alpha/test/integ.subnet-v2.js.snapshot/manifest.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 5 additions & 5 deletions
10
packages/@aws-cdk/aws-ec2-alpha/test/integ.subnet-v2.js.snapshot/tree.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { CidrBlock } from '../lib/util'; | ||
|
||
describe('Tests for the CidrBlock.rangesOverlap method to check if IPv4 ranges overlap', () =>{ | ||
test('Should return false for non-overlapping IP ranges', () => { | ||
const testCidr = new CidrBlock('10.0.0.0/16'); | ||
const range1 = ['10.0.0.0', '10.0.15.255'] as [string, string]; | ||
const range2 = ['10.0.128.0', '10.0.143.255'] as [string, string]; | ||
expect(testCidr.rangesOverlap(range1, range2)).toBe(false); | ||
}); | ||
|
||
test('Should return true for overlapping IP ranges', () => { | ||
const testCidr = new CidrBlock('54.0.0.0/17'); | ||
const range1 = ['54.0.0.0', '54.0.127.255'] as [string, string]; | ||
const range2 = ['54.0.100.0', '54.0.192.255'] as [string, string]; | ||
expect(testCidr.rangesOverlap(range1, range2)).toBe(true); | ||
}); | ||
|
||
test('Should return true for overlapping IP ranges where one range is completely inside the other', () => { | ||
const testCidr = new CidrBlock('10.0.0.0/16'); | ||
const range1 = ['10.0.0.0', '10.0.127.255'] as [string, string]; | ||
const range2 = ['10.0.64.0', '10.0.65.255'] as [string, string]; | ||
expect(testCidr.rangesOverlap(range1, range2)).toBe(true); | ||
}); | ||
|
||
test('Should return true for overlapping IP ranges where the last IP of one range is the first IP of the other', () => { | ||
const testCidr = new CidrBlock('10.0.0.0/16'); | ||
const range1 = ['10.0.0.0', '10.0.15.255'] as [string, string]; | ||
const range2 = ['10.0.15.255', '10.0.255.255'] as [string, string]; | ||
expect(testCidr.rangesOverlap(range1, range2)).toBe(true); | ||
}); | ||
|
||
test('Should return false for non-overlapping IP ranges where one range starts immediately after the other ends', () => { | ||
const testCidr = new CidrBlock('10.0.0.0/16'); | ||
const range1 = ['10.0.0.0', '10.0.15.255'] as [string, string]; | ||
const range2 = ['10.0.16.0', '10.0.19.255'] as [string, string]; | ||
expect(testCidr.rangesOverlap(range1, range2)).toBe(false); | ||
}); | ||
}); |