Skip to content

Commit

Permalink
Merge branch 'CA-150404'
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>

GitHub: closes #230 on xapi-project/sm
  • Loading branch information
siddharthv committed Feb 13, 2015
2 parents 9a60cd3 + cf744dc commit 90b1c7a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/ISCSISR.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,26 @@ def load(self, sr_uuid):
self.chappassword = ""
if self.dconf.has_key('chapuser') \
and (self.dconf.has_key('chappassword') or self.dconf.has_key('chappassword_secret')):
self.chapuser = self.dconf['chapuser']
self.chapuser = self.dconf['chapuser'].encode('utf-8')
if self.dconf.has_key('chappassword_secret'):
self.chappassword = util.get_secret(self.session, self.dconf['chappassword_secret'])
else:
self.chappassword = self.dconf['chappassword']

self.chappassword = self.chappassword.encode('utf-8')

self.incoming_chapuser = ""
self.incoming_chappassword = ""
if self.dconf.has_key('incoming_chapuser') \
and (self.dconf.has_key('incoming_chappassword') or self.dconf.has_key('incoming_chappassword_secret')):
self.incoming_chapuser = self.dconf['incoming_chapuser']
self.incoming_chapuser = self.dconf['incoming_chapuser'].encode('utf-8')
if self.dconf.has_key('incoming_chappassword_secret'):
self.incoming_chappassword = util.get_secret(self.session, self.dconf['incoming_chappassword_secret'])
else:
self.incoming_chappassword = self.dconf['incoming_chappassword']

self.incoming_chappassword = self.incoming_chappassword.encode('utf-8')

self.port = DEFAULT_PORT
if self.dconf.has_key('port') and self.dconf['port']:
try:
Expand Down
45 changes: 45 additions & 0 deletions tests/test_ISCSISR.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,48 @@ def fake_exists(path):
iscsi_sr._initPaths()

self.assertActiveNodeEquals(self.node2, iscsi_sr)


class TestISCSISR(TestBase):

@mock.patch('ISCSISR.util._convertDNS')
def test_load_assert_utf_8_chap_credencials(
self,
mock__convertDNS):

""" Asserts that CHAP credentials are always encoded in UTF-8.
Xapi passes CHAP credentials to ISCSISR as strings of type 'str',
if they strictly contain ASCII characters, or as strings of type
'unicode' if they contain at least one non-ASCII character.
"""

s1 = 'ascii'
s2 = u'\u03bc\u03b9x\u03b5d' # == 'mixed' in Greek and Latin chars
s3 = u'\u03c4\u03bf\u03c0\u03b9\u03ba\u03cc' # == 'local' in Greek
s4 = u'\u6c5fw\u6708\u03c2\xfc\xe4\xd6' # gibberish var char len str

# These are the sizes of the 4 strings
# in bytes when encoded in UTF-8
s1_size = 5
s2_size = 8
s3_size = 12
s4_size = 15

iscsi_sr = NonInitingISCSISR({
'chapuser': s1,
'chappassword': s2,
'incoming_chapuser': s3,
'incoming_chappassword': s4
})

iscsi_sr.load(None)

self.assertEqual(iscsi_sr.chapuser, s1.encode('utf-8'))
self.assertEqual(iscsi_sr.chappassword, s2.encode('utf-8'))
self.assertEqual(iscsi_sr.incoming_chapuser, s3.encode('utf-8'))
self.assertEqual(iscsi_sr.incoming_chappassword, s4.encode('utf-8'))
self.assertEqual(len(iscsi_sr.chapuser), s1_size)
self.assertEqual(len(iscsi_sr.chappassword), s2_size)
self.assertEqual(len(iscsi_sr.incoming_chapuser), s3_size)
self.assertEqual(len(iscsi_sr.incoming_chappassword), s4_size)

0 comments on commit 90b1c7a

Please sign in to comment.