Commit 1b98c432 authored by dpranke@chromium.org's avatar dpranke@chromium.org

Check for a missing scheme in the input_api.host.

R=chase@chromium.org,maruel@chromium.org
Review URL: http://codereview.chromium.org/6712007

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@78599 0039d316-1c4b-4281-b951-d872f2087c98
parent 82e5f28e
...@@ -655,8 +655,12 @@ def _Approvers(input_api, email_regexp): ...@@ -655,8 +655,12 @@ def _Approvers(input_api, email_regexp):
if not input_api.change.issue: if not input_api.change.issue:
return [] return []
path = '/api/%s?messages=true' # TODO(dpranke): Should figure out if input_api.host_url is supposed to
url = (input_api.host_url + path) % input_api.change.issue # be a host or a scheme+host and normalize it there.
host = input_api.host_url
if not host.startswith('http://') and not host.startswith('https://'):
host = 'http://' + host
url = '%s/api/%s?messages=true' % (host, input_api.change.issue)
f = input_api.urllib2.urlopen(url) f = input_api.urllib2.urlopen(url)
issue_props = input_api.json.load(f) issue_props = input_api.json.load(f)
......
...@@ -1867,13 +1867,19 @@ mac|success|blew ...@@ -1867,13 +1867,19 @@ mac|success|blew
def OwnersTest(self, is_committing, tbr=False, change_tags=None, def OwnersTest(self, is_committing, tbr=False, change_tags=None,
suggested_reviewers=None, approvers=None, suggested_reviewers=None, approvers=None,
uncovered_files=None, expected_reviewers=None, expected_output=''): uncovered_files=None, expected_reviewers=None, expected_output='',
host_url=None):
affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
affected_file.LocalPath().AndReturn('foo.cc') affected_file.LocalPath().AndReturn('foo.cc')
change = self.mox.CreateMock(presubmit.Change) change = self.mox.CreateMock(presubmit.Change)
change.AffectedFiles(None).AndReturn([affected_file]) change.AffectedFiles(None).AndReturn([affected_file])
input_api = self.MockInputApi(change, False) input_api = self.MockInputApi(change, False)
expected_host = 'http://localhost'
if host_url:
input_api.host_url = host_url
if host_url.startswith('https'):
expected_host = host_url
fake_db = self.mox.CreateMock(owners.Database) fake_db = self.mox.CreateMock(owners.Database)
fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP)
input_api.owners_db = fake_db input_api.owners_db = fake_db
...@@ -1887,7 +1893,7 @@ mac|success|blew ...@@ -1887,7 +1893,7 @@ mac|success|blew
rietveld_response = ('{"owner": "john@example.com",' rietveld_response = ('{"owner": "john@example.com",'
'"messages": [' + ','.join(messages) + ']}') '"messages": [' + ','.join(messages) + ']}')
input_api.urllib2.urlopen( input_api.urllib2.urlopen(
input_api.host_url + '/api/1?messages=true').AndReturn( expected_host + '/api/1?messages=true').AndReturn(
StringIO.StringIO(rietveld_response)) StringIO.StringIO(rietveld_response))
input_api.json = presubmit.json input_api.json = presubmit.json
fake_db.files_not_covered_by(set(['foo.cc']), approvers).AndReturn( fake_db.files_not_covered_by(set(['foo.cc']), approvers).AndReturn(
...@@ -1937,6 +1943,17 @@ mac|success|blew ...@@ -1937,6 +1943,17 @@ mac|success|blew
uncovered_files=set(), uncovered_files=set(),
expected_output='--tbr was specified, skipping OWNERS check\n') expected_output='--tbr was specified, skipping OWNERS check\n')
def testCannedCheckOwners_MissingSchemeInHostURL(self):
self.OwnersTest(is_committing=True,
approvers=set(['ben@example.com']),
uncovered_files=set(), host_url='localhost')
def testCannedCheckOwners_HTTPS_HostURL(self):
self.OwnersTest(is_committing=True,
approvers=set(['ben@example.com']),
uncovered_files=set(), host_url='https://localhost')
if __name__ == '__main__': if __name__ == '__main__':
import unittest import unittest
unittest.main() unittest.main()
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