diff --git a/git_cl.py b/git_cl.py index e79a22df7..200fa0097 100755 --- a/git_cl.py +++ b/git_cl.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Copyright (c) 2013 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -3823,7 +3823,13 @@ class _GitCookiesChecker(object): @staticmethod def _parse_identity(identity): """Parses identity "git-.example.com" into and domain.""" - username, domain = identity.split('.', 1) + # Special case: users whose ldaps contain ".", which are generally not + # distinguishable from sub-domains. But we do know typical domains: + if identity.endswith('.chromium.org'): + domain = 'chromium.org' + username = identity[:-len('.chromium.org')] + else: + username, domain = identity.split('.', 1) if username.startswith('git-'): username = username[len('git-'):] return username, domain diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index 58a38a215..7ed3b2887 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -528,6 +528,18 @@ class GitCookiesCheckerTest(TestCase): self.c._all_hosts = [(ensure_googlesource(h), i, '.gitcookies') for h, i in subhost_identity_pairs] + def test_identity_parsing(self): + self.assertEqual(self.c._parse_identity('ldap.google.com'), + ('ldap', 'google.com')) + self.assertEqual(self.c._parse_identity('git-ldap.example.com'), + ('ldap', 'example.com')) + # Specical case because we know there are no subdomains in chromium.org. + self.assertEqual(self.c._parse_identity('git-note.period.chromium.org'), + ('note.period', 'chromium.org')) + # Pathological: .period. can be either ldap OR domain, more likely domain. + self.assertEqual(self.c._parse_identity('git-note.period.example.com'), + ('note', 'period.example.com')) + def test_analysis_nothing(self): self.c._all_hosts = [] self.assertFalse(self.c.has_generic_host())