|
1 | 1 | import { expect, haveResource } from '@aws-cdk/assert';
|
2 |
| -import { Lazy, Stack } from '@aws-cdk/core'; |
| 2 | +import { Intrinsic, Lazy, Stack, Token } from '@aws-cdk/core'; |
3 | 3 | import { Test } from 'nodeunit';
|
4 | 4 | import { Peer, Port, SecurityGroup, Vpc } from "../lib";
|
5 | 5 |
|
@@ -182,5 +182,81 @@ export = {
|
182 | 182 | }
|
183 | 183 |
|
184 | 184 | test.done();
|
| 185 | + }, |
| 186 | + |
| 187 | + 'Peer IP CIDR validation': { |
| 188 | + 'passes with valid IPv4 CIDR block'(test: Test) { |
| 189 | + // GIVEN |
| 190 | + const cidrIps = ['0.0.0.0/0', '192.168.255.255/24']; |
| 191 | + |
| 192 | + // THEN |
| 193 | + for (const cidrIp of cidrIps) { |
| 194 | + test.equal(Peer.ipv4(cidrIp).uniqueId, cidrIp); |
| 195 | + } |
| 196 | + |
| 197 | + test.done(); |
| 198 | + }, |
| 199 | + |
| 200 | + 'passes with unresolved IP CIDR token'(test: Test) { |
| 201 | + // GIVEN |
| 202 | + const cidrIp = Token.asString(new Intrinsic('ip')); |
| 203 | + |
| 204 | + // THEN |
| 205 | + test.equal(Peer.ipv4(cidrIp).uniqueId, '${Token[TOKEN.1385]}'); |
| 206 | + test.equal(Peer.ipv6(cidrIp).uniqueId, '${Token[TOKEN.1385]}'); |
| 207 | + |
| 208 | + test.done(); |
| 209 | + }, |
| 210 | + |
| 211 | + 'throws if invalid IPv4 CIDR block'(test: Test) { |
| 212 | + // THEN |
| 213 | + test.throws(() => { |
| 214 | + Peer.ipv4('invalid'); |
| 215 | + }, /Invalid IPv4 CIDR/); |
| 216 | + |
| 217 | + test.done(); |
| 218 | + }, |
| 219 | + |
| 220 | + 'throws if missing mask in IPv4 CIDR block'(test: Test) { |
| 221 | + test.throws(() => { |
| 222 | + Peer.ipv4('0.0.0.0'); |
| 223 | + }, /CIDR mask is missing in IPv4/); |
| 224 | + |
| 225 | + test.done(); |
| 226 | + }, |
| 227 | + |
| 228 | + 'passes with valid IPv6 CIDR block'(test: Test) { |
| 229 | + // GIVEN |
| 230 | + const cidrIps = [ |
| 231 | + '::/0', |
| 232 | + '2001:db8::/32', |
| 233 | + '2001:0db8:0000:0000:0000:8a2e:0370:7334/32', |
| 234 | + '2001:db8::8a2e:370:7334/32', |
| 235 | + ]; |
| 236 | + |
| 237 | + // THEN |
| 238 | + for (const cidrIp of cidrIps) { |
| 239 | + test.equal(Peer.ipv6(cidrIp).uniqueId, cidrIp); |
| 240 | + } |
| 241 | + |
| 242 | + test.done(); |
| 243 | + }, |
| 244 | + |
| 245 | + 'throws if invalid IPv6 CIDR block'(test: Test) { |
| 246 | + // THEN |
| 247 | + test.throws(() => { |
| 248 | + Peer.ipv6('invalid'); |
| 249 | + }, /Invalid IPv6 CIDR/); |
| 250 | + |
| 251 | + test.done(); |
| 252 | + }, |
| 253 | + |
| 254 | + 'throws if missing mask in IPv6 CIDR block'(test: Test) { |
| 255 | + test.throws(() => { |
| 256 | + Peer.ipv6('::'); |
| 257 | + }, /IDR mask is missing in IPv6/); |
| 258 | + |
| 259 | + test.done(); |
| 260 | + } |
185 | 261 | }
|
186 | 262 | };
|
0 commit comments