|
17 | 17 | from webcompat.issues import filter_new
|
18 | 18 | from webcompat.helpers import format_link_header
|
19 | 19 | from webcompat.helpers import parse_link_header
|
| 20 | +from webcompat.helpers import rewrite_links |
20 | 21 |
|
21 | 22 | # Any request that depends on parsing HTTP Headers (basically anything
|
22 | 23 | # on the index route, will need to include the following: environ_base=headers
|
@@ -119,5 +120,17 @@ def test_format_http_link_headers(self):
|
119 | 120 | link_header = '<https://api.github.com/repositories/17914657/issues?page=2>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11>; rel="last"'
|
120 | 121 | self.assertEqual(format_link_header(parsed_headers), link_header)
|
121 | 122 |
|
| 123 | + def test_rewrite_links(self): |
| 124 | + '''Test the rewriting is correct.''' |
| 125 | + link_header_1 = '<https://api.github.com/repositories/17914657/issues?page=2>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11>; rel="last"' |
| 126 | + rewritten_header_1 = '</api/issues?page=2>; rel="next", </api/issues?page=11>; rel="last"' |
| 127 | + self.assertEqual(rewrite_links(link_header_1), rewritten_header_1) |
| 128 | + |
| 129 | + def test_sanitize_link(self): |
| 130 | + '''Test the sanitization.''' |
| 131 | + link_header = '<https://api.github.com/repositories/17914657/issues?page=2&access_token=abc123>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11&access_token=abc123>; rel="last"' |
| 132 | + rewritten_header = '<https://api.github.com/repositories/17914657/issues?page=2>; rel="next", <https://api.github.com/repositories/17914657/issues?page=11>; rel="last"' |
| 133 | + self.assertEqual(sanitize_link(link_header), rewritten_header) |
| 134 | + |
122 | 135 | if __name__ == '__main__':
|
123 | 136 | unittest.main()
|
0 commit comments