Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
redapple committed Jan 17, 2017
1 parent 7d89eea commit 31dd441
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions scrapy/spidermiddlewares/referer.py
Expand Up @@ -159,7 +159,8 @@ class StrictOriginPolicy(ReferrerPolicy):
name = POLICY_STRICT_ORIGIN

def referrer(self, response, request):
if ((self.tls_protected(response) and self.potentially_trustworthy(request))
if ((self.tls_protected(response) and
self.potentially_trustworthy(request))
or not self.tls_protected(response)):
return self.origin_referrer(response)

Expand Down Expand Up @@ -208,9 +209,9 @@ def referrer(self, response, request):
origin = self.origin(response)
if origin == self.origin(request):
return self.stripped_referrer(response)
elif ((urlparse_cached(response).scheme in ('https', 'ftps') and
elif ((self.tls_protected(response) and
self.potentially_trustworthy(request))
or urlparse_cached(response).scheme == 'http'):
or not self.tls_protected(response)):
return self.origin_referrer(response)


Expand Down
8 changes: 7 additions & 1 deletion tests/test_spidermiddleware_referer.py
Expand Up @@ -232,7 +232,13 @@ class MixinStrictOriginWhenCrossOrigin(object):
# downgrade
('https://example4.com/page.html', 'http://example4.com/not-page.html', None),
('https://example4.com/page.html', 'http://not.example4.com/', None),
('ftp://example4.com/urls.zip', 'http://example4.com/not-page.html', None),

# non-TLS to non-TLS
('ftp://example4.com/urls.zip', 'http://example4.com/not-page.html', b'ftp://example4.com/'),

# upgrade
('http://example4.com/page.html', 'https://example4.com/not-page.html', b'http://example4.com/'),
('http://example4.com/page.html', 'https://not.example4.com/', b'http://example4.com/'),

# Different protocols: send origin as referrer
('ftps://example4.com/urls.zip', 'https://example4.com/not-page.html', b'ftps://example4.com/'),
Expand Down

0 comments on commit 31dd441

Please sign in to comment.