@@ -38,6 +38,7 @@ func createTestConfiguration() *Configuration {
38
38
validation .NewTransportServerValidator (isTLSPassthroughEnabled , snippetsEnabled , isPlus ),
39
39
isTLSPassthroughEnabled ,
40
40
snippetsEnabled ,
41
+ certManagerEnabled ,
41
42
)
42
43
}
43
44
@@ -2676,6 +2677,88 @@ func TestPortCollisions(t *testing.T) {
2676
2677
}
2677
2678
}
2678
2679
2680
+ func TestChallengeIngressToVSR (t * testing.T ) {
2681
+ configuration := createTestConfiguration ()
2682
+
2683
+ var expectedProblems []ConfigurationProblem
2684
+
2685
+ // Add a new Ingress
2686
+
2687
+ vs := createTestVirtualServer ("virtualserver" , "foo.example.com" )
2688
+ vsr1 := createTestChallengeVirtualServerRoute ("challenge" , "foo.example.com" , "/.well-known/acme-challenge/test" )
2689
+
2690
+ ing := createTestChallengeIngress ("challenge" , "foo.example.com" , "/.well-known/acme-challenge/test" , "cm-acme-http-solver-test" )
2691
+
2692
+ expectedChanges := []ResourceChange {
2693
+ {
2694
+ Op : AddOrUpdate ,
2695
+ Resource : & VirtualServerConfiguration {
2696
+ VirtualServer : vs ,
2697
+ VirtualServerRoutes : []* conf_v1.VirtualServerRoute {vsr1 },
2698
+ Warnings : nil ,
2699
+ },
2700
+ },
2701
+ }
2702
+
2703
+ configuration .AddOrUpdateVirtualServer (vs )
2704
+ changes , problems := configuration .AddOrUpdateIngress (ing )
2705
+ if diff := cmp .Diff (expectedChanges , changes ); diff != "" {
2706
+ t .Errorf ("AddOrUpdateIngress() returned unexpected result (-want +got):\n %s" , diff )
2707
+ }
2708
+ if diff := cmp .Diff (expectedProblems , problems ); diff != "" {
2709
+ t .Errorf ("AddOrUpdateIngress() returned unexpected result (-want +got):\n %s" , diff )
2710
+ }
2711
+
2712
+ expectedChanges = nil
2713
+
2714
+ changes , problems = configuration .DeleteIngress (ing .Name )
2715
+ if diff := cmp .Diff (expectedChanges , changes ); diff != "" {
2716
+ t .Errorf ("DeleteIngress() returned unexpected result (-want +got):\n %s" , diff )
2717
+ }
2718
+ if diff := cmp .Diff (expectedProblems , problems ); diff != "" {
2719
+ t .Errorf ("DeleteIngress() returned unexpected result (-want +got):\n %s" , diff )
2720
+ }
2721
+
2722
+ expectedChanges = nil
2723
+ ing = createTestIngress ("wrong-challenge" , "foo.example.com" , "bar.example.com" )
2724
+ ing .Labels = map [string ]string {"acme.cert-manager.io/http01-solver" : "true" }
2725
+ expectedProblems = []ConfigurationProblem {
2726
+ {
2727
+ Object : ing ,
2728
+ IsError : true ,
2729
+ Reason : "Rejected" ,
2730
+ Message : "spec.rules: Forbidden: challenge Ingress must have exactly 1 rule defined" ,
2731
+ },
2732
+ }
2733
+
2734
+ changes , problems = configuration .AddOrUpdateIngress (ing )
2735
+ if diff := cmp .Diff (expectedChanges , changes ); diff != "" {
2736
+ t .Errorf ("AddOrUpdateIngress() returned unexpected result (-want +got):\n %s" , diff )
2737
+ }
2738
+ if diff := cmp .Diff (expectedProblems , problems ); diff != "" {
2739
+ t .Errorf ("AddOrUpdateIngress() returned unexpected result (-want +got):\n %s" , diff )
2740
+ }
2741
+
2742
+ ing = createTestIngress ("wrong-challenge" , "foo.example.com" )
2743
+ ing .Labels = map [string ]string {"acme.cert-manager.io/http01-solver" : "true" }
2744
+ expectedProblems = []ConfigurationProblem {
2745
+ {
2746
+ Object : ing ,
2747
+ IsError : true ,
2748
+ Reason : "Rejected" ,
2749
+ Message : "spec.rules.HTTP.Paths: Forbidden: challenge Ingress must have exactly 1 path defined" ,
2750
+ },
2751
+ }
2752
+
2753
+ changes , problems = configuration .AddOrUpdateIngress (ing )
2754
+ if diff := cmp .Diff (expectedChanges , changes ); diff != "" {
2755
+ t .Errorf ("AddOrUpdateIngress() returned unexpected result (-want +got):\n %s" , diff )
2756
+ }
2757
+ if diff := cmp .Diff (expectedProblems , problems ); diff != "" {
2758
+ t .Errorf ("AddOrUpdateIngress() returned unexpected result (-want +got):\n %s" , diff )
2759
+ }
2760
+ }
2761
+
2679
2762
func mustInitGlobalConfiguration (c * Configuration , gc * conf_v1alpha1.GlobalConfiguration ) {
2680
2763
changes , problems , err := c .AddOrUpdateGlobalConfiguration (gc )
2681
2764
@@ -2740,6 +2823,50 @@ func createTestIngress(name string, hosts ...string) *networking.Ingress {
2740
2823
}
2741
2824
}
2742
2825
2826
+ func createTestChallengeIngress (name string , host string , path string , serviceName string ) * networking.Ingress {
2827
+ var rules []networking.IngressRule
2828
+ backend := networking.IngressBackend {
2829
+ Service : & networking.IngressServiceBackend {
2830
+ Name : serviceName ,
2831
+ Port : networking.ServiceBackendPort {
2832
+ Number : 8089 ,
2833
+ },
2834
+ },
2835
+ }
2836
+
2837
+ rules = append (rules , networking.IngressRule {
2838
+ Host : host ,
2839
+ IngressRuleValue : networking.IngressRuleValue {
2840
+ HTTP : & networking.HTTPIngressRuleValue {
2841
+ Paths : []networking.HTTPIngressPath {
2842
+ {
2843
+ Path : path ,
2844
+ Backend : backend ,
2845
+ },
2846
+ },
2847
+ },
2848
+ },
2849
+ },
2850
+ )
2851
+
2852
+ return & networking.Ingress {
2853
+ ObjectMeta : metav1.ObjectMeta {
2854
+ Name : name ,
2855
+ Namespace : "default" ,
2856
+ CreationTimestamp : metav1 .Now (),
2857
+ Annotations : map [string ]string {
2858
+ "kubernetes.io/ingress.class" : "nginx" ,
2859
+ },
2860
+ Labels : map [string ]string {
2861
+ "acme.cert-manager.io/http01-solver" : "true" ,
2862
+ },
2863
+ },
2864
+ Spec : networking.IngressSpec {
2865
+ Rules : rules ,
2866
+ },
2867
+ }
2868
+ }
2869
+
2743
2870
func createTestVirtualServer (name string , host string ) * conf_v1.VirtualServer {
2744
2871
return & conf_v1.VirtualServer {
2745
2872
ObjectMeta : metav1.ObjectMeta {
@@ -2783,6 +2910,33 @@ func createTestVirtualServerRoute(name string, host string, path string) *conf_v
2783
2910
}
2784
2911
}
2785
2912
2913
+ func createTestChallengeVirtualServerRoute (name string , host string , path string ) * conf_v1.VirtualServerRoute {
2914
+ return & conf_v1.VirtualServerRoute {
2915
+ ObjectMeta : metav1.ObjectMeta {
2916
+ Namespace : "default" ,
2917
+ Name : name ,
2918
+ },
2919
+ Spec : conf_v1.VirtualServerRouteSpec {
2920
+ Host : host ,
2921
+ Upstreams : []conf_v1.Upstream {
2922
+ {
2923
+ Name : "challenge" ,
2924
+ Service : "cm-acme-http-solver-test" ,
2925
+ Port : 8089 ,
2926
+ },
2927
+ },
2928
+ Subroutes : []conf_v1.Route {
2929
+ {
2930
+ Path : path ,
2931
+ Action : & conf_v1.Action {
2932
+ Pass : "challenge" ,
2933
+ },
2934
+ },
2935
+ },
2936
+ },
2937
+ }
2938
+ }
2939
+
2786
2940
func createTestTransportServer (name string , listenerName string , listenerProtocol string ) * conf_v1alpha1.TransportServer {
2787
2941
return & conf_v1alpha1.TransportServer {
2788
2942
ObjectMeta : metav1.ObjectMeta {
0 commit comments