@@ -992,6 +992,36 @@ func TestGetCorazaDirectivesForTrafficProtectionPolicy(t *testing.T) {
992992 }
993993}
994994
995+ func TestGetCorazaDirectivesDoesNotAliasRouteBaseDirectives (t * testing.T ) {
996+ base := make ([]string , 2 , 8 )
997+ base [0 ] = "Include @crs-setup-conf"
998+ base [1 ] = "Include @recommended-conf"
999+
1000+ operatorConfig := config.NetworkServicesOperator {
1001+ Gateway : config.GatewayConfig {
1002+ Coraza : config.CorazaConfig {RouteBaseDirectives : base },
1003+ },
1004+ }
1005+ reconciler := & TrafficProtectionPolicyReconciler {Config : operatorConfig }
1006+
1007+ enforce := reconciler .getCorazaDirectivesForTrafficProtectionPolicy (& policyContext {ptr .To (
1008+ newTrafficProtectionPolicy ("default" , "tpp-enforce" , func (tpp * networkingv1alpha.TrafficProtectionPolicy ) {
1009+ tpp .Spec .Mode = networkingv1alpha .TrafficProtectionPolicyEnforce
1010+ }),
1011+ )})
1012+ assert .Contains (t , enforce , "SecRuleEngine On" )
1013+
1014+ reconciler .getCorazaDirectivesForTrafficProtectionPolicy (& policyContext {ptr .To (
1015+ newTrafficProtectionPolicy ("default" , "tpp-observe" ),
1016+ )})
1017+
1018+ assert .Contains (t , enforce , "SecRuleEngine On" ,
1019+ "second policy leaked into the first via a shared RouteBaseDirectives backing array" )
1020+ assert .EqualValues (t , []string {"Include @crs-setup-conf" , "Include @recommended-conf" },
1021+ reconciler .Config .Gateway .Coraza .RouteBaseDirectives ,
1022+ "shared base directives were mutated" )
1023+ }
1024+
9951025// nolint:unparam
9961026func newTrafficProtectionPolicy (
9971027 namespace ,
0 commit comments