@@ -65,6 +65,51 @@ func TestNginxProxyKubernetes(t *testing.T) {
65
65
}
66
66
}
67
67
68
+ func TestNginxProxyRewriteClientIP (t * testing.T ) {
69
+ t .Parallel ()
70
+ g := NewWithT (t )
71
+
72
+ k8sClient , err := getKubernetesClient (t )
73
+ g .Expect (err ).ToNot (HaveOccurred ())
74
+
75
+ tests := []struct {
76
+ policySpec ngfAPIv1alpha2.NginxProxySpec
77
+ name string
78
+ wantErrors []string
79
+ }{
80
+ {
81
+ name : "Validate NginxProxy is invalid when trustedAddresses is not set and mode is set" ,
82
+ wantErrors : []string {"if mode is set, trustedAddresses is a required field" },
83
+ policySpec : ngfAPIv1alpha2.NginxProxySpec {
84
+ RewriteClientIP : & ngfAPIv1alpha2.RewriteClientIP {
85
+ Mode : helpers.GetPointer [ngfAPIv1alpha2.RewriteClientIPModeType ]("XForwardedFor" ),
86
+ },
87
+ },
88
+ },
89
+ {
90
+ name : "Validate NginxProxy is valid when both mode and trustedAddresses are set" ,
91
+ policySpec : ngfAPIv1alpha2.NginxProxySpec {
92
+ RewriteClientIP : & ngfAPIv1alpha2.RewriteClientIP {
93
+ Mode : helpers.GetPointer [ngfAPIv1alpha2.RewriteClientIPModeType ]("XForwardedFor" ),
94
+ TrustedAddresses : []ngfAPIv1alpha2.RewriteClientIPAddress {
95
+ {
96
+ Type : ngfAPIv1alpha2 .RewriteClientIPAddressType ("CIDR" ),
97
+ Value : "10.0.0.0/8" ,
98
+ },
99
+ },
100
+ },
101
+ },
102
+ },
103
+ }
104
+
105
+ for _ , tt := range tests {
106
+ t .Run (tt .name , func (t * testing.T ) {
107
+ t .Parallel ()
108
+ validateNginxProxy (t , tt , g , k8sClient )
109
+ })
110
+ }
111
+ }
112
+
68
113
func validateNginxProxy (t * testing.T , tt struct {
69
114
policySpec ngfAPIv1alpha2.NginxProxySpec
70
115
name string
0 commit comments