Skip to content

Commit

Permalink
Added some checks for strange user-agents
Browse files Browse the repository at this point in the history
  • Loading branch information
danielquinn committed Dec 15, 2015
1 parent 11885f2 commit 86038af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ripe/atlas/tools/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _get_user_agent():
try:
custom = os.path.join(os.path.dirname(__file__), "..", "user-agent")
with open(custom) as f:
return f.read().strip()
return f.readline().strip()[:128]
except IOError:
pass # We go with the default

Expand Down
20 changes: 11 additions & 9 deletions tests/commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,17 @@ def test_asns_filter(self):

def test_user_agent(self):
standard = "RIPE Atlas Tools (Magellan) {}".format(__version__)
tests = [
standard,
"Some custom agent",
"Αυτό είναι ένας παράγοντας δοκιμή",
"이것은 테스트 요원",
]
tests = {
standard: standard,
"Some custom agent": "Some custom agent",
"Some custom agent\nwith a second line": "Some custom agent",
"x" * 3000: "x" * 128,
"Πράκτορας χρήστη": "Πράκτορας χρήστη",
"이것은 테스트 요원": "이것은 테스트 요원",
}
self.assertEqual(self.cmd.user_agent, standard)
for agent in tests:
for in_string, out_string in tests.items():
path = "ripe.atlas.tools.commands.base.open"
content = mock.mock_open(read_data=agent)
content = mock.mock_open(read_data=in_string)
with mock.patch(path, content):
self.assertEqual(Command().user_agent, agent)
self.assertEqual(Command().user_agent, out_string)

0 comments on commit 86038af

Please sign in to comment.