@@ -17,15 +17,23 @@ limitations under the License.
17
17
package settings
18
18
19
19
import (
20
+ "context"
21
+ "fmt"
22
+ "path/filepath"
20
23
"strings"
21
24
22
25
"net/http"
23
26
24
27
"github.com/onsi/ginkgo"
28
+ "github.com/stretchr/testify/assert"
25
29
30
+ appsv1 "k8s.io/api/apps/v1"
31
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
32
"k8s.io/ingress-nginx/test/e2e/framework"
27
33
)
28
34
35
+ const testdataURL = "https://github.com/maxmind/MaxMind-DB/blob/5a0be1c0320490b8e4379dbd5295a18a648ff156/test-data/GeoLite2-Country-Test.mmdb?raw=true"
36
+
29
37
var _ = framework .DescribeSetting ("Geoip2" , func () {
30
38
f := framework .NewDefaultFramework ("geoip2" )
31
39
@@ -35,6 +43,30 @@ var _ = framework.DescribeSetting("Geoip2", func() {
35
43
f .NewEchoDeployment ()
36
44
})
37
45
46
+ ginkgo .It ("should include geoip2 line in config when enabled and db file exists" , func () {
47
+ edition := "GeoLite2-Country"
48
+
49
+ err := f .UpdateIngressControllerDeployment (func (deployment * appsv1.Deployment ) error {
50
+ args := deployment .Spec .Template .Spec .Containers [0 ].Args
51
+ args = append (args , "--maxmind-edition-ids=" + edition )
52
+ deployment .Spec .Template .Spec .Containers [0 ].Args = args
53
+ _ , err := f .KubeClientSet .AppsV1 ().Deployments (f .Namespace ).Update (context .TODO (), deployment , metav1.UpdateOptions {})
54
+ return err
55
+ })
56
+ assert .Nil (ginkgo .GinkgoT (), err , "updating ingress controller deployment flags" )
57
+
58
+ filename := fmt .Sprintf ("/etc/nginx/geoip/%s.mmdb" , edition )
59
+ exec , err := f .ExecIngressPod (fmt .Sprintf (`sh -c "mkdir -p '%s' && wget -O '%s' '%s' 2>&1"` , filepath .Dir (filename ), filename , testdataURL ))
60
+ framework .Logf (exec )
61
+ assert .Nil (ginkgo .GinkgoT (), err , fmt .Sprintln ("error downloading test geoip2 db" , filename ))
62
+
63
+ f .UpdateNginxConfigMapData ("use-geoip2" , "true" )
64
+ f .WaitForNginxConfiguration (
65
+ func (cfg string ) bool {
66
+ return strings .Contains (cfg , fmt .Sprintf ("geoip2 %s" , filename ))
67
+ })
68
+ })
69
+
38
70
ginkgo .It ("should only allow requests from specific countries" , func () {
39
71
ginkgo .Skip ("GeoIP test are temporarily disabled" )
40
72
0 commit comments