@@ -471,6 +471,34 @@ var basicsTests = [...]jarTest{
471
471
"a=1" ,
472
472
[]query {{"http://www.bbc.co.uk" , "a=1" }},
473
473
},
474
+ {
475
+ "Host cookie on IP." ,
476
+ "http://192.168.0.10" ,
477
+ []string {"a=1" },
478
+ "a=1" ,
479
+ []query {{"http://192.168.0.10" , "a=1" }},
480
+ },
481
+ {
482
+ "Port is ignored #1." ,
483
+ "http://www.host.test/" ,
484
+ []string {"a=1" },
485
+ "a=1" ,
486
+ []query {
487
+ {"http://www.host.test" , "a=1" },
488
+ {"http://www.host.test:8080/" , "a=1" },
489
+ },
490
+ },
491
+ {
492
+ "Port is ignored #2." ,
493
+ "http://www.host.test:8080/" ,
494
+ []string {"a=1" },
495
+ "a=1" ,
496
+ []query {
497
+ {"http://www.host.test" , "a=1" },
498
+ {"http://www.host.test:8080/" , "a=1" },
499
+ {"http://www.host.test:1234/" , "a=1" },
500
+ },
501
+ },
474
502
}
475
503
476
504
func TestBasics (t * testing.T ) {
@@ -989,3 +1017,177 @@ func TestChromiumDeletion(t *testing.T) {
989
1017
test .run (t , jar )
990
1018
}
991
1019
}
1020
+
1021
+ // domainHandlingTests tests and documents the rules for domain handling.
1022
+ // Each test must be performed on an empty new Jar.
1023
+ var domainHandlingTests = [... ]jarTest {
1024
+ {
1025
+ "Host cookie" ,
1026
+ "http://www.host.test" ,
1027
+ []string {"a=1" },
1028
+ "a=1" ,
1029
+ []query {
1030
+ {"http://www.host.test" , "a=1" },
1031
+ {"http://host.test" , "" },
1032
+ {"http://bar.host.test" , "" },
1033
+ {"http://foo.www.host.test" , "" },
1034
+ {"http://other.test" , "" },
1035
+ {"http://test" , "" },
1036
+ },
1037
+ },
1038
+ {
1039
+ "Domain cookie #1" ,
1040
+ "http://www.host.test" ,
1041
+ []string {"a=1; domain=host.test" },
1042
+ "a=1" ,
1043
+ []query {
1044
+ {"http://www.host.test" , "a=1" },
1045
+ {"http://host.test" , "a=1" },
1046
+ {"http://bar.host.test" , "a=1" },
1047
+ {"http://foo.www.host.test" , "a=1" },
1048
+ {"http://other.test" , "" },
1049
+ {"http://test" , "" },
1050
+ },
1051
+ },
1052
+ {
1053
+ "Domain cookie #2" ,
1054
+ "http://www.host.test" ,
1055
+ []string {"a=1; domain=.host.test" },
1056
+ "a=1" ,
1057
+ []query {
1058
+ {"http://www.host.test" , "a=1" },
1059
+ {"http://host.test" , "a=1" },
1060
+ {"http://bar.host.test" , "a=1" },
1061
+ {"http://foo.www.host.test" , "a=1" },
1062
+ {"http://other.test" , "" },
1063
+ {"http://test" , "" },
1064
+ },
1065
+ },
1066
+ {
1067
+ "Host cookie on IDNA domain #1" ,
1068
+ "http://www.bücher.test" ,
1069
+ []string {"a=1" },
1070
+ "a=1" ,
1071
+ []query {
1072
+ {"http://www.bücher.test" , "a=1" },
1073
+ {"http://www.xn--bcher-kva.test" , "a=1" },
1074
+ {"http://bücher.test" , "" },
1075
+ {"http://xn--bcher-kva.test" , "" },
1076
+ {"http://bar.bücher.test" , "" },
1077
+ {"http://bar.xn--bcher-kva.test" , "" },
1078
+ {"http://foo.www.bücher.test" , "" },
1079
+ {"http://foo.www.xn--bcher-kva.test" , "" },
1080
+ {"http://other.test" , "" },
1081
+ {"http://test" , "" },
1082
+ },
1083
+ },
1084
+ {
1085
+ "Host cookie on IDNA domain #2" ,
1086
+ "http://www.xn--bcher-kva.test" ,
1087
+ []string {"a=1" },
1088
+ "a=1" ,
1089
+ []query {
1090
+ {"http://www.bücher.test" , "a=1" },
1091
+ {"http://www.xn--bcher-kva.test" , "a=1" },
1092
+ {"http://bücher.test" , "" },
1093
+ {"http://xn--bcher-kva.test" , "" },
1094
+ {"http://bar.bücher.test" , "" },
1095
+ {"http://bar.xn--bcher-kva.test" , "" },
1096
+ {"http://foo.www.bücher.test" , "" },
1097
+ {"http://foo.www.xn--bcher-kva.test" , "" },
1098
+ {"http://other.test" , "" },
1099
+ {"http://test" , "" },
1100
+ },
1101
+ },
1102
+ {
1103
+ "Domain cookie on IDNA domain #1" ,
1104
+ "http://www.bücher.test" ,
1105
+ []string {"a=1; domain=xn--bcher-kva.test" },
1106
+ "a=1" ,
1107
+ []query {
1108
+ {"http://www.bücher.test" , "a=1" },
1109
+ {"http://www.xn--bcher-kva.test" , "a=1" },
1110
+ {"http://bücher.test" , "a=1" },
1111
+ {"http://xn--bcher-kva.test" , "a=1" },
1112
+ {"http://bar.bücher.test" , "a=1" },
1113
+ {"http://bar.xn--bcher-kva.test" , "a=1" },
1114
+ {"http://foo.www.bücher.test" , "a=1" },
1115
+ {"http://foo.www.xn--bcher-kva.test" , "a=1" },
1116
+ {"http://other.test" , "" },
1117
+ {"http://test" , "" },
1118
+ },
1119
+ },
1120
+ {
1121
+ "Domain cookie on IDNA domain #2" ,
1122
+ "http://www.xn--bcher-kva.test" ,
1123
+ []string {"a=1; domain=xn--bcher-kva.test" },
1124
+ "a=1" ,
1125
+ []query {
1126
+ {"http://www.bücher.test" , "a=1" },
1127
+ {"http://www.xn--bcher-kva.test" , "a=1" },
1128
+ {"http://bücher.test" , "a=1" },
1129
+ {"http://xn--bcher-kva.test" , "a=1" },
1130
+ {"http://bar.bücher.test" , "a=1" },
1131
+ {"http://bar.xn--bcher-kva.test" , "a=1" },
1132
+ {"http://foo.www.bücher.test" , "a=1" },
1133
+ {"http://foo.www.xn--bcher-kva.test" , "a=1" },
1134
+ {"http://other.test" , "" },
1135
+ {"http://test" , "" },
1136
+ },
1137
+ },
1138
+ {
1139
+ "Host cookie on TLD." ,
1140
+ "http://com" ,
1141
+ []string {"a=1" },
1142
+ "a=1" ,
1143
+ []query {
1144
+ {"http://com" , "a=1" },
1145
+ {"http://any.com" , "" },
1146
+ {"http://any.test" , "" },
1147
+ },
1148
+ },
1149
+ {
1150
+ "Domain cookie on TLD becomes a host cookie." ,
1151
+ "http://com" ,
1152
+ []string {"a=1; domain=com" },
1153
+ "a=1" ,
1154
+ []query {
1155
+ {"http://com" , "a=1" },
1156
+ {"http://any.com" , "" },
1157
+ {"http://any.test" , "" },
1158
+ },
1159
+ },
1160
+ {
1161
+ "Host cookie on public suffix." ,
1162
+ "http://co.uk" ,
1163
+ []string {"a=1" },
1164
+ "a=1" ,
1165
+ []query {
1166
+ {"http://co.uk" , "a=1" },
1167
+ {"http://uk" , "" },
1168
+ {"http://some.co.uk" , "" },
1169
+ {"http://foo.some.co.uk" , "" },
1170
+ {"http://any.uk" , "" },
1171
+ },
1172
+ },
1173
+ {
1174
+ "Domain cookie on public suffix is ignored." ,
1175
+ "http://some.co.uk" ,
1176
+ []string {"a=1; domain=co.uk" },
1177
+ "" ,
1178
+ []query {
1179
+ {"http://co.uk" , "" },
1180
+ {"http://uk" , "" },
1181
+ {"http://some.co.uk" , "" },
1182
+ {"http://foo.some.co.uk" , "" },
1183
+ {"http://any.uk" , "" },
1184
+ },
1185
+ },
1186
+ }
1187
+
1188
+ func TestDomainHandling (t * testing.T ) {
1189
+ for _ , test := range domainHandlingTests {
1190
+ jar := newTestJar ()
1191
+ test .run (t , jar )
1192
+ }
1193
+ }
0 commit comments