Skip to content

Commit

Permalink
Fix host check for counting views (#821)
Browse files Browse the repository at this point in the history
* Fix host check for counting views

* Fixing tests
  • Loading branch information
bradchoate authored Feb 21, 2025
1 parent 14581df commit 92c31bd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion handlers/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def on_finish(self):
"""
# only count views if we are on the s.mltshp.com host
if self.request.host == ("s.%s" % options.app_host):
if self.request.host != ("s.%s" % options.app_host):
return

# Abort if the s.mltshp.com/r/ABCD request didn't resolve to a file
Expand Down
8 changes: 4 additions & 4 deletions test/FileTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def test_raw_image_view_counts(self):

for i in range(0,10):
if i % 2 == 0:
response = self.fetch('/r/1', method='GET', headers={"Cookie":"sid=%s" % self.sid2})
response = self.fetch('/r/1', method='GET', headers={"Host": "s." + options.app_host, "Cookie":"sid=%s" % self.sid2})
else:
response = self.fetch('/r/1', method='GET')
response = self.fetch('/r/1', method='GET', headers={"Host": "s." + options.app_host})

imageviews = self.db.query("SELECT id, user_id, sharedfile_id, created_at from fileview")
self.assertEqual(len(imageviews), 10)
Expand All @@ -118,9 +118,9 @@ def test_raw_load_with_extension(self):

for i in range(0,10):
if i % 2 == 0:
response = self.fetch('/r/1.jpg', method='GET', headers={"Cookie":"sid=%s" % self.sid2})
response = self.fetch('/r/1.jpg', method='GET', headers={"Host": "s." + options.app_host, "Cookie":"sid=%s" % self.sid2})
else:
response = self.fetch('/r/1.jpg', method='GET')
response = self.fetch('/r/1.jpg', method='GET', headers={"Host": "s." + options.app_host})

imageviews = self.db.query("SELECT id, user_id, sharedfile_id, created_at from fileview")
self.assertEqual(len(imageviews), 10)
Expand Down
4 changes: 2 additions & 2 deletions test/SiteFunctionTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ def test_raw_image_view_counts(self):
if i % 2 == 0:
# views by owner aren't counted
response = self.fetch('/r/1', method='GET',
headers={"Cookie":"sid=%s" % self.sid2})
headers={"Host": "s." + options.app_host, "Cookie":"sid=%s" % self.sid2})
else:
# views by non-owner are counted
response = self.fetch('/r/1', method='GET')
response = self.fetch('/r/1', method='GET', headers={"Host": "s." + options.app_host})

imageviews = self.db.query("SELECT id, user_id, sharedfile_id, created_at from fileview")
self.assertEqual(len(imageviews), 10)
Expand Down

0 comments on commit 92c31bd

Please sign in to comment.