bitbake: fetch2.URI: Set username/password should not change the other

When setting the username after already having set the password, the password
was unexpectedly reset. This change fixes this issue and introduces unit tests
to make sure it doesn't happen again.

(Bitbake rev: 25faef3a047f9c7564089463d7c96f6910b640cb)

Signed-off-by: Olof Johansson <olof.johansson@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Olof Johansson 2014-01-20 12:03:24 +01:00 committed by Richard Purdie
parent 57484d68df
commit 7dd4bf6310
2 changed files with 17 additions and 2 deletions

View File

@ -321,9 +321,10 @@ class URI(object):
@username.setter
def username(self, username):
password = self.password
self.userinfo = username
if self.password:
self.userinfo += ":%s" % self.password
if password:
self.userinfo += ":%s" % password
@property
def password(self):

View File

@ -274,6 +274,20 @@ class URITest(unittest.TestCase):
self.assertEqual(uri.username, test['username'])
self.assertEqual(uri.password, test['password'])
# make sure changing the values doesn't do anything unexpected
uri.username = 'changeme'
self.assertEqual(uri.username, 'changeme')
self.assertEqual(uri.password, test['password'])
uri.password = 'insecure'
self.assertEqual(uri.username, 'changeme')
self.assertEqual(uri.password, 'insecure')
# reset back after our trickery
uri.userinfo = test['userinfo']
self.assertEqual(uri.userinfo, test['userinfo'])
self.assertEqual(uri.username, test['username'])
self.assertEqual(uri.password, test['password'])
uri.hostname = test['hostname']
self.assertEqual(uri.hostname, test['hostname'])
self.assertEqual(uri.hostport, test['hostname'])