| 168 | _test_decoded_attr(treq(), "path") |
| 169 | |
| 170 | def test_authority(self): |
| 171 | request = treq() |
| 172 | assert request.authority == request.data.authority.decode("idna") |
| 173 | |
| 174 | # Test IDNA encoding |
| 175 | # Set str, get raw bytes |
| 176 | request.authority = "ídna.example" |
| 177 | assert request.data.authority == b"xn--dna-qma.example" |
| 178 | # Set raw bytes, get decoded |
| 179 | request.data.authority = b"xn--idn-gla.example" |
| 180 | assert request.authority == "idná.example" |
| 181 | # Set bytes, get raw bytes |
| 182 | request.authority = b"xn--dn-qia9b.example" |
| 183 | assert request.data.authority == b"xn--dn-qia9b.example" |
| 184 | # IDNA encoding is not bijective |
| 185 | request.authority = "fußball" |
| 186 | assert request.authority == "fussball" |
| 187 | |
| 188 | # Don't fail on garbage |
| 189 | request.data.authority = b"foo\xff\x00bar" |
| 190 | assert request.authority.startswith("foo") |
| 191 | assert request.authority.endswith("bar") |
| 192 | # foo.bar = foo.bar should not cause any side effects. |
| 193 | d = request.authority |
| 194 | request.authority = d |
| 195 | assert request.data.authority == b"foo\xff\x00bar" |
| 196 | |
| 197 | def test_host_update_also_updates_header(self): |
| 198 | request = treq() |