Commit 0d2dea0a authored by Andrii Shyshkalov's avatar Andrii Shyshkalov Committed by Commit Bot

git cl creds-check: special case parsing of chromium.org emails.

R=phajdan.jr@chromium.org

Change-Id: Ia1380bc0cfff50e82f9a26d3c54e9dc34a38c7b5
Reviewed-on: https://chromium-review.googlesource.com/574528
Commit-Queue: Paweł Hajdan Jr. <phajdan.jr@chromium.org>
Reviewed-by: 's avatarPaweł Hajdan Jr. <phajdan.jr@chromium.org>
parent 9a289023
#!/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-<ldap>.example.com" into <ldap> 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
......
......@@ -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())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment