@@ -2883,6 +2883,7 @@ func Test_isUnconditionalRedirect(t *testing.T) {
2883
2883
name string
2884
2884
listener elbv2.Listener
2885
2885
rule elbv2.Rule
2886
+ ruleHost string
2886
2887
2887
2888
expected bool
2888
2889
}{
@@ -2920,11 +2921,12 @@ func Test_isUnconditionalRedirect(t *testing.T) {
2920
2921
{
2921
2922
Field : aws .String (conditions .FieldHostHeader ),
2922
2923
HostHeaderConfig : & elbv2.HostHeaderConditionConfig {
2923
- Values : aws .StringSlice ([]string {"www.example.com" , "anno.example.com" }),
2924
+ Values : aws .StringSlice ([]string {"www.example.com" }),
2924
2925
},
2925
2926
},
2926
2927
},
2927
2928
},
2929
+ ruleHost : "www.example.com" ,
2928
2930
expected : true ,
2929
2931
},
2930
2932
{
@@ -3012,7 +3014,7 @@ func Test_isUnconditionalRedirect(t *testing.T) {
3012
3014
expected : false ,
3013
3015
},
3014
3016
{
3015
- name : "Path condition set to /* and Host condition is set " ,
3017
+ name : "Path condition set to /* and Host condition is set to same as ruleHost " ,
3016
3018
listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
3017
3019
rule : elbv2.Rule {
3018
3020
Actions : []* elbv2.Action {
@@ -3031,13 +3033,42 @@ func Test_isUnconditionalRedirect(t *testing.T) {
3031
3033
{
3032
3034
Field : aws .String (conditions .FieldHostHeader ),
3033
3035
HostHeaderConfig : & elbv2.HostHeaderConditionConfig {
3034
- Values : aws .StringSlice ([]string {"www.example.com" , "anno.example.com" }),
3036
+ Values : aws .StringSlice ([]string {"www.example.com" }),
3035
3037
},
3036
3038
},
3037
3039
},
3038
3040
},
3041
+ ruleHost : "www.example.com" ,
3039
3042
expected : true ,
3040
3043
},
3044
+ {
3045
+ name : "Path condition set to /* and Host condition is set to more than ruleHost" ,
3046
+ listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
3047
+ rule : elbv2.Rule {
3048
+ Actions : []* elbv2.Action {
3049
+ {
3050
+ Type : aws .String (elbv2 .ActionTypeEnumRedirect ),
3051
+ RedirectConfig : redirectActionConfig (& elbv2.RedirectActionConfig {Path : aws .String ("/#{path}" )}),
3052
+ },
3053
+ },
3054
+ Conditions : []* elbv2.RuleCondition {
3055
+ {
3056
+ Field : aws .String (conditions .FieldPathPattern ),
3057
+ PathPatternConfig : & elbv2.PathPatternConditionConfig {
3058
+ Values : aws .StringSlice ([]string {"/*" }),
3059
+ },
3060
+ },
3061
+ {
3062
+ Field : aws .String (conditions .FieldHostHeader ),
3063
+ HostHeaderConfig : & elbv2.HostHeaderConditionConfig {
3064
+ Values : aws .StringSlice ([]string {"www.example.com" , "annos.example.com" }),
3065
+ },
3066
+ },
3067
+ },
3068
+ },
3069
+ ruleHost : "www.example.com" ,
3070
+ expected : false ,
3071
+ },
3041
3072
{
3042
3073
name : "Path condition set to /* but a SourceIP condition is also set" ,
3043
3074
listener : elbv2.Listener {Protocol : aws .String ("HTTP" ), Port : aws .Int64 (80 )},
@@ -3067,7 +3098,7 @@ func Test_isUnconditionalRedirect(t *testing.T) {
3067
3098
},
3068
3099
} {
3069
3100
t .Run (tc .name , func (t * testing.T ) {
3070
- assert .Equal (t , tc .expected , isUnconditionalRedirect (& tc .listener , tc .rule ))
3101
+ assert .Equal (t , tc .expected , isUnconditionalRedirect (& tc .listener , tc .rule , tc . ruleHost ))
3071
3102
})
3072
3103
}
3073
3104
}
0 commit comments