def test_logging(monkeypatch, config_stub, filter_request, caplog, enabled): monkeypatch.setattr(cookies.objects, 'debug_flags', ['log-cookies'] if enabled else []) config_stub.val.content.cookies.accept = 'all' caplog.clear() cookies._accept_cookie(filter_request) if enabled: expected = ("Cookie from origin <unknown> on https://example.com " "(third party: False) -> applying setting all") assert caplog.messages == [expected] else: assert not caplog.messages
def test_third_party_workaround(monkeypatch, config_stub, filter_request): monkeypatch.setattr(cookies.qtutils, 'version_check', lambda ver, compiled: False) config_stub.val.content.cookies.accept = 'no-3rdparty' filter_request.thirdParty = True filter_request.firstPartyUrl = QUrl() assert cookies._accept_cookie(filter_request)
def test_accept_cookie_with_pattern(config_stub, filter_request, setting, pattern_setting, third_party, accepted): """Test that _accept_cookie matches firstPartyUrl with the UrlPattern.""" filter_request.thirdParty = third_party config_stub.set_str('content.cookies.accept', setting) config_stub.set_str('content.cookies.accept', pattern_setting, pattern=urlmatch.UrlPattern('https://*.example.com')) assert cookies._accept_cookie(filter_request) == accepted
def test_invalid_url(config_stub, filter_request, global_value): """Make sure we fall back to the global value with invalid URLs. This can happen when there's a cookie request from an iframe, e.g. here: https://developers.google.com/youtube/youtube_player_demo """ config_stub.val.content.cookies.accept = global_value filter_request.firstPartyUrl = QUrl() accepted = global_value == 'all' assert cookies._accept_cookie(filter_request) == accepted
def test_accept_cookie(config_stub, filter_request, setting, third_party, accepted): """Test that _accept_cookie respects content.cookies.accept.""" config_stub.val.content.cookies.accept = setting filter_request.thirdParty = third_party assert cookies._accept_cookie(filter_request) == accepted