From 86038af323c008b73d6f76c65e679346705ffbf7 Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Tue, 15 Dec 2015 11:28:15 +0000 Subject: [PATCH] Added some checks for strange user-agents --- ripe/atlas/tools/commands/base.py | 2 +- tests/commands/report.py | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ripe/atlas/tools/commands/base.py b/ripe/atlas/tools/commands/base.py index 40adae4..94fd659 100644 --- a/ripe/atlas/tools/commands/base.py +++ b/ripe/atlas/tools/commands/base.py @@ -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 diff --git a/tests/commands/report.py b/tests/commands/report.py index 3926abb..638f98e 100644 --- a/tests/commands/report.py +++ b/tests/commands/report.py @@ -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)