From 650e2fab9968e23bf90baf6a5818d603525bbda1 Mon Sep 17 00:00:00 2001
From: Evann DREUMONT <evann@grifon.fr>
Date: Sat, 7 Feb 2026 23:59:12 +0100
Subject: ASPA: Finish official test case coverage

This commit implements missing test cases based on the official ASPA
path verification examples to expand coverage.

Also, one of the custom test was incorrect, because while there is no valid
ASPA this could be seen, from a downstream perspective, as peering.

This commit was originally a complete fix of the ASPA verification.
Reduced significantly by committer.

diff --git a/filter/test.conf b/filter/test.conf
index 18a531ada..c21d74614 100644
--- a/filter/test.conf
+++ b/filter/test.conf
@@ -2447,7 +2447,7 @@ function t_aspa_check()
 	bgppath p3 = +empty+;
 	p3.prepend(65541);
 	p3.prepend(65544);
-	bt_assert(aspa_check(at, p3, false) = ASPA_INVALID);
+	bt_assert(aspa_check(at, p3, false) = ASPA_VALID);
 	bt_assert(aspa_check(at, p3, true) = ASPA_INVALID);
 
 	bgppath p4 = +empty+;
@@ -2484,6 +2484,13 @@ protocol static
 	route aspa 65543 providers 65546;
 	route aspa 65544 providers 65546, 65547;
 	route aspa 65547 transit;
+	route aspa 65548 transit;
+	route aspa 65550 transit;
+	route aspa 65551 providers 65550;
+	route aspa 65552 transit;
+	route aspa 65553 transit;
+	route aspa 65554 providers 65553;
+	route aspa 65555 providers 65554;
 }
 
 function t_aspa_check_official()
@@ -2493,6 +2500,7 @@ function t_aspa_check_official()
 	bool UP = true; bool DOWN = false;
 	bgppath p;
 
+	# Examples of Upstream Path Verification
 	# F-G is a lateral peer, we do not prepend
 	p = +empty+.prepend(A).prepend(C).prepend(F);
 	bt_assert(aspa_check(at_official, p, UP) = ASPA_VALID);
@@ -2528,6 +2536,50 @@ function t_aspa_check_official()
 	# E-D is a lateral peer, we do not prepend
 	p = +empty+.prepend(B).prepend(E);
 	bt_assert(aspa_check(at_official, p, UP) = ASPA_VALID);
+
+	# Examples of Downstream Path Verification
+	p = +empty+.prepend(A).prepend(C).prepend(F).prepend(G).prepend(E);
+	bt_assert(aspa_check(at_official, p, DOWN) = ASPA_UNKNOWN);
+
+	p = +empty+.prepend(A).prepend(D).prepend(G).prepend(E);
+	bt_assert(aspa_check(at_official, p, DOWN) = ASPA_VALID);
+
+	p = +empty+.prepend(A).prepend(C).prepend(D).prepend(E);
+	bt_assert(aspa_check(at_official, p, DOWN) = ASPA_UNKNOWN);
+
+	p = +empty+.prepend(A).prepend(C).prepend(D).prepend(G).prepend(E);
+	bt_assert(aspa_check(at_official, p, DOWN) = ASPA_INVALID);
+
+	p = +empty+.prepend(G).prepend(D).prepend(F).prepend(C);
+	bt_assert(aspa_check(at_official, p, DOWN) = ASPA_UNKNOWN);
+
+	p = +empty+.prepend(B).prepend(E).prepend(G).prepend(D);
+	bt_assert(aspa_check(at_official, p, DOWN) = ASPA_VALID);
+
+	p = +empty+.prepend(B).prepend(E).prepend(G).prepend(D).prepend(C);
+	bt_assert(aspa_check(at_official, p, DOWN) = ASPA_INVALID);
+
+	p = +empty+.prepend(A).prepend(C).prepend(F);
+	bt_assert(aspa_check(at_official, p, DOWN) = ASPA_VALID);
+
+	# Topology Contains Complex BGP Relationships
+	int H = 65548; int J = 65549; int K = 65550; int L = 65551;
+	int P = 65552; int Q = 65553; int R = 65554; int S = 65555;
+
+	p = +empty+.prepend(H).prepend(J);
+	bt_assert(aspa_check(at_official, p, UP) = ASPA_INVALID);
+
+	p = +empty+.prepend(H).prepend(J).prepend(K);
+	bt_assert(aspa_check(at_official, p, DOWN) = ASPA_INVALID);
+
+	p = +empty+.prepend(P).prepend(Q);
+	bt_assert(aspa_check(at_official, p, UP) = ASPA_INVALID);
+
+	p = +empty+.prepend(P).prepend(Q);
+	bt_assert(aspa_check(at_official, p, DOWN) = ASPA_VALID);
+
+	p = +empty+.prepend(P).prepend(Q).prepend(R);
+	bt_assert(aspa_check(at_official, p, DOWN) = ASPA_VALID);
 }
 
 bt_test_suite(t_aspa_check_official, "Testing ASPA (official tests)");
