Skip to content

Commit 25e1799

Browse files
committed
test(mgmt): Add statefull NAT tests with VpcExpose with excludes only
Make sure that we process expose objects containing exclusion prefixes only as we expect. Signed-off-by: Quentin Monnet <[email protected]>
1 parent 5766706 commit 25e1799

File tree

2 files changed

+59
-9
lines changed

2 files changed

+59
-9
lines changed

mgmt/src/models/internal/natconfig/table_extend.rs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,6 @@ mod tests {
355355
expected
356356
);
357357

358-
// Empty prefixes, non-empty excludes
359-
let prefixes = BTreeSet::new();
360-
let excludes = btree_from(vec!["1.0.0.0/16", "2.0.0.0/24"]);
361-
let expected = prefixes.clone();
362-
assert_eq!(
363-
collapse_prefix_lists(&prefixes, &excludes).unwrap(),
364-
expected
365-
);
366-
367358
// Excludes outside prefix
368359
let prefixes = btree_from(vec!["10.0.0.0/16"]);
369360
let excludes = btree_from(vec!["1.0.0.0/16", "2.0.0.0/24"]);
@@ -547,6 +538,48 @@ mod tests {
547538
expected
548539
);
549540

541+
// Empty prefixes, non-empty excludes
542+
let prefixes = BTreeSet::new();
543+
let excludes = btree_from(vec!["1.0.0.0/16", "2.0.0.0/24"]);
544+
let expected = btree_from(vec![
545+
"0.0.0.0/8",
546+
"1.1.0.0/16",
547+
"1.2.0.0/15",
548+
"1.4.0.0/14",
549+
"1.8.0.0/13",
550+
"1.16.0.0/12",
551+
"1.32.0.0/11",
552+
"1.64.0.0/10",
553+
"1.128.0.0/9",
554+
"2.0.1.0/24",
555+
"2.0.2.0/23",
556+
"2.0.4.0/22",
557+
"2.0.8.0/21",
558+
"2.0.16.0/20",
559+
"2.0.32.0/19",
560+
"2.0.64.0/18",
561+
"2.0.128.0/17",
562+
"2.1.0.0/16",
563+
"2.2.0.0/15",
564+
"2.4.0.0/14",
565+
"2.8.0.0/13",
566+
"2.16.0.0/12",
567+
"2.32.0.0/11",
568+
"2.64.0.0/10",
569+
"2.128.0.0/9",
570+
"3.0.0.0/8",
571+
"4.0.0.0/6",
572+
"8.0.0.0/5",
573+
"16.0.0.0/4",
574+
"32.0.0.0/3",
575+
"64.0.0.0/2",
576+
"128.0.0.0/1",
577+
]);
578+
assert_eq!(
579+
collapse_prefix_lists(&prefixes, &excludes).unwrap(),
580+
expected
581+
);
582+
550583
// Full peering
551584
let expose = VpcExpose::empty()
552585
.ip("1.0.0.0/16".into())

mgmt/src/models/internal/natconfig/test.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ mod tests {
313313
.ip("192.168.100.0/24".into())
314314
.as_range("34.34.34.0/24".into());
315315
let expose431 = VpcExpose::empty().ip("4.4.0.0/24".into());
316+
let expose432 = VpcExpose::empty()
317+
.not("192.0.0.0/2".into())
318+
.not("4.0.0.0/8".into())
319+
.not_as("0.0.0.0/2".into())
320+
.not_as("255.0.0.0/8".into());
316321

317322
// VPC1 <-> VPC2
318323
let mut manifest12 = VpcManifest::new("VPC-1");
@@ -349,6 +354,7 @@ mod tests {
349354
add_expose(&mut manifest34, expose341);
350355
let mut manifest43 = VpcManifest::new("VPC-4");
351356
add_expose(&mut manifest43, expose431);
357+
add_expose(&mut manifest43, expose432);
352358

353359
let peering12 = VpcPeering::new("VPC-1--VPC-2", manifest12, manifest21);
354360
let peering31 = VpcPeering::new("VPC-3--VPC-1", manifest31, manifest13);
@@ -540,5 +546,16 @@ mod tests {
540546
let (output_src, output_dst) = check_packet(&mut nat, vni(400), target_dst, target_src);
541547
assert_eq!(output_src, orig_dst);
542548
assert_eq!(output_dst, orig_src);
549+
550+
// expose341 <-> expose432 (exclusion prefixes only)
551+
let (orig_src, orig_dst) = (addr_v4("192.168.100.34"), addr_v4("65.1.1.1"));
552+
let (target_src, target_dst) = (addr_v4("34.34.34.34"), addr_v4("1.1.1.1"));
553+
let (output_src, output_dst) = check_packet(&mut nat, vni(300), orig_src, orig_dst);
554+
assert_eq!(output_src, target_src);
555+
assert_eq!(output_dst, target_dst);
556+
// Reverse path
557+
let (output_src, output_dst) = check_packet(&mut nat, vni(400), target_dst, target_src);
558+
assert_eq!(output_src, orig_dst);
559+
assert_eq!(output_dst, orig_src);
543560
}
544561
}

0 commit comments

Comments
 (0)