@@ -2878,6 +2878,200 @@ func Test_createsRedirectLoop(t *testing.T) {
2878
2878
}
2879
2879
}
2880
2880
2881
+ func Test_isUnconditionalRedirect (t * testing.T ) {
2882
+ for _ , tc := range []struct {
2883
+ name string
2884
+ listener elbv2.Listener
2885
+ rule elbv2.Rule
2886
+
2887
+ expected bool
2888
+ }{
2889
+ {
2890
+ name : "No RedirectConfig" ,
2891
+ listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
2892
+ rule : elbv2.Rule {},
2893
+ expected : false ,
2894
+ },
2895
+ {
2896
+ name : "No conditions" ,
2897
+ listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
2898
+ rule : elbv2.Rule {
2899
+ Actions : []* elbv2.Action {
2900
+ {
2901
+ Type : aws .String (elbv2 .ActionTypeEnumRedirect ),
2902
+ RedirectConfig : redirectActionConfig (& elbv2.RedirectActionConfig {Path : aws .String ("/#{path}" )}),
2903
+ },
2904
+ },
2905
+ Conditions : nil ,
2906
+ },
2907
+ expected : true ,
2908
+ },
2909
+ {
2910
+ name : "No Path conditions" ,
2911
+ listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
2912
+ rule : elbv2.Rule {
2913
+ Actions : []* elbv2.Action {
2914
+ {
2915
+ Type : aws .String (elbv2 .ActionTypeEnumRedirect ),
2916
+ RedirectConfig : redirectActionConfig (& elbv2.RedirectActionConfig {Path : aws .String ("/#{path}" )}),
2917
+ },
2918
+ },
2919
+ Conditions : []* elbv2.RuleCondition {
2920
+ {
2921
+ Field : aws .String (conditions .FieldHostHeader ),
2922
+ HostHeaderConfig : & elbv2.HostHeaderConditionConfig {
2923
+ Values : aws .StringSlice ([]string {"www.example.com" , "anno.example.com" }),
2924
+ },
2925
+ },
2926
+ },
2927
+ },
2928
+ expected : true ,
2929
+ },
2930
+ {
2931
+ name : "Path condition set to /*" ,
2932
+ listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
2933
+ rule : elbv2.Rule {
2934
+ Actions : []* elbv2.Action {
2935
+ {
2936
+ Type : aws .String (elbv2 .ActionTypeEnumRedirect ),
2937
+ RedirectConfig : redirectActionConfig (& elbv2.RedirectActionConfig {Path : aws .String ("/#{path}" )}),
2938
+ },
2939
+ },
2940
+ Conditions : []* elbv2.RuleCondition {
2941
+ {
2942
+ Field : aws .String (conditions .FieldPathPattern ),
2943
+ PathPatternConfig : & elbv2.PathPatternConditionConfig {
2944
+ Values : aws .StringSlice ([]string {"/*" }),
2945
+ },
2946
+ },
2947
+ },
2948
+ },
2949
+ expected : true ,
2950
+ },
2951
+ {
2952
+ name : "Multiple Path conditions, one of which is /*" ,
2953
+ listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
2954
+ rule : elbv2.Rule {
2955
+ Actions : []* elbv2.Action {
2956
+ {
2957
+ Type : aws .String (elbv2 .ActionTypeEnumRedirect ),
2958
+ RedirectConfig : redirectActionConfig (& elbv2.RedirectActionConfig {Path : aws .String ("/#{path}" )}),
2959
+ },
2960
+ },
2961
+ Conditions : []* elbv2.RuleCondition {
2962
+ {
2963
+ Field : aws .String (conditions .FieldPathPattern ),
2964
+ PathPatternConfig : & elbv2.PathPatternConditionConfig {
2965
+ Values : aws .StringSlice ([]string {"/*" , "/test" , "/annothertest" }),
2966
+ },
2967
+ },
2968
+ },
2969
+ },
2970
+ expected : true ,
2971
+ },
2972
+ {
2973
+ name : "Multiple Path conditions, one of which is /*, different ordering" ,
2974
+ listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
2975
+ rule : elbv2.Rule {
2976
+ Actions : []* elbv2.Action {
2977
+ {
2978
+ Type : aws .String (elbv2 .ActionTypeEnumRedirect ),
2979
+ RedirectConfig : redirectActionConfig (& elbv2.RedirectActionConfig {Path : aws .String ("/#{path}" )}),
2980
+ },
2981
+ },
2982
+ Conditions : []* elbv2.RuleCondition {
2983
+ {
2984
+ Field : aws .String (conditions .FieldPathPattern ),
2985
+ PathPatternConfig : & elbv2.PathPatternConditionConfig {
2986
+ Values : aws .StringSlice ([]string {"/test" , "/anothertest" , "/*" }),
2987
+ },
2988
+ },
2989
+ },
2990
+ },
2991
+ expected : true ,
2992
+ },
2993
+ {
2994
+ name : "Multiple Path conditions, none of which is /*" ,
2995
+ listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
2996
+ rule : elbv2.Rule {
2997
+ Actions : []* elbv2.Action {
2998
+ {
2999
+ Type : aws .String (elbv2 .ActionTypeEnumRedirect ),
3000
+ RedirectConfig : redirectActionConfig (& elbv2.RedirectActionConfig {Path : aws .String ("/#{path}" )}),
3001
+ },
3002
+ },
3003
+ Conditions : []* elbv2.RuleCondition {
3004
+ {
3005
+ Field : aws .String (conditions .FieldPathPattern ),
3006
+ PathPatternConfig : & elbv2.PathPatternConditionConfig {
3007
+ Values : aws .StringSlice ([]string {"/test" , "/anothertest" , "anothertest2" }),
3008
+ },
3009
+ },
3010
+ },
3011
+ },
3012
+ expected : false ,
3013
+ },
3014
+ {
3015
+ name : "Path condition set to /* and Host condition is set " ,
3016
+ listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
3017
+ rule : elbv2.Rule {
3018
+ Actions : []* elbv2.Action {
3019
+ {
3020
+ Type : aws .String (elbv2 .ActionTypeEnumRedirect ),
3021
+ RedirectConfig : redirectActionConfig (& elbv2.RedirectActionConfig {Path : aws .String ("/#{path}" )}),
3022
+ },
3023
+ },
3024
+ Conditions : []* elbv2.RuleCondition {
3025
+ {
3026
+ Field : aws .String (conditions .FieldPathPattern ),
3027
+ PathPatternConfig : & elbv2.PathPatternConditionConfig {
3028
+ Values : aws .StringSlice ([]string {"/*" }),
3029
+ },
3030
+ },
3031
+ {
3032
+ Field : aws .String (conditions .FieldHostHeader ),
3033
+ HostHeaderConfig : & elbv2.HostHeaderConditionConfig {
3034
+ Values : aws .StringSlice ([]string {"www.example.com" , "anno.example.com" }),
3035
+ },
3036
+ },
3037
+ },
3038
+ },
3039
+ expected : true ,
3040
+ },
3041
+ {
3042
+ name : "Path condition set to /* but a SourceIP condition is also set" ,
3043
+ listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
3044
+ rule : elbv2.Rule {
3045
+ Actions : []* elbv2.Action {
3046
+ {
3047
+ Type : aws .String (elbv2 .ActionTypeEnumRedirect ),
3048
+ RedirectConfig : redirectActionConfig (& elbv2.RedirectActionConfig {Path : aws .String ("/#{path}" )}),
3049
+ },
3050
+ },
3051
+ Conditions : []* elbv2.RuleCondition {
3052
+ {
3053
+ Field : aws .String (conditions .FieldPathPattern ),
3054
+ PathPatternConfig : & elbv2.PathPatternConditionConfig {
3055
+ Values : aws .StringSlice ([]string {"/*" }),
3056
+ },
3057
+ },
3058
+ {
3059
+ Field : aws .String (conditions .FieldSourceIP ),
3060
+ SourceIpConfig : & elbv2.SourceIpConditionConfig {
3061
+ Values : aws .StringSlice ([]string {"192.168.0.0/16" }),
3062
+ },
3063
+ },
3064
+ },
3065
+ },
3066
+ expected : false ,
3067
+ },
3068
+ } {
3069
+ t .Run (tc .name , func (t * testing.T ) {
3070
+ assert .Equal (t , tc .expected , isUnconditionalRedirect (& tc .listener , tc .rule ))
3071
+ })
3072
+ }
3073
+ }
3074
+
2881
3075
func redirectActionConfig (override * elbv2.RedirectActionConfig ) * elbv2.RedirectActionConfig {
2882
3076
r := & elbv2.RedirectActionConfig {
2883
3077
Host : aws .String ("#{host}" ),
0 commit comments