Skip to content

Commit

Permalink
SaslTestCase: Change config instead of messing with irc.sasl_next_mec…
Browse files Browse the repository at this point in the history
…hanisms

Changing the internal state will break in the next commit, which
reorganizes SASL state initialization
  • Loading branch information
progval committed Sep 5, 2023
1 parent eb31ed3 commit fed8d52
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions test/test_irclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1494,29 +1494,41 @@ def testBatchInterleaved(self):

class SaslTestCase(SupyTestCase, CapNegMixin):
def setUp(self):
pass
self._default_mechanisms = conf.supybot.networks.test.sasl.mechanisms()

def tearDown(self):
conf.supybot.networks.test.sasl.mechanisms.setValue(self._default_mechanisms)
conf.supybot.networks.test.sasl.username.setValue('')
conf.supybot.networks.test.sasl.password.setValue('')
conf.supybot.networks.test.certfile.setValue('')

def testPlain(self):
conf.supybot.networks.test.sasl.username.setValue('jilles')
conf.supybot.networks.test.sasl.password.setValue('sesame')
conf.supybot.networks.test.sasl.mechanisms.setValue(
['scram-sha-256', 'plain'])

self.irc = irclib.Irc('test')

self.assertEqual(self.irc.sasl_current_mechanism, None)
self.irc.sasl_next_mechanisms = ['scram-sha-256', 'plain']

self.startCapNegociation()
if irclib.scram:
self.assertEqual(self.irc.sasl_next_mechanisms,
['scram-sha-256', 'plain'])

self.startCapNegociation()

m = self.irc.takeMsg()
self.assertEqual(m, ircmsgs.IrcMsg(command='AUTHENTICATE',
args=('SCRAM-SHA-256',)))
self.irc.feedMsg(ircmsgs.IrcMsg(command='904',
args=('mechanism not available',)))
else:
self.assertEqual(self.irc.sasl_next_mechanisms,
['plain'])

self.startCapNegociation()

m = self.irc.takeMsg()
self.assertEqual(m, ircmsgs.IrcMsg(command='AUTHENTICATE',
args=('SCRAM-SHA-256',)))
self.irc.feedMsg(ircmsgs.IrcMsg(command='904',
args=('mechanism not available',)))

m = self.irc.takeMsg()
self.assertEqual(m, ircmsgs.IrcMsg(command='AUTHENTICATE',
Expand All @@ -1537,11 +1549,14 @@ def testExternalFallbackToPlain(self):
conf.supybot.networks.test.sasl.username.setValue('jilles')
conf.supybot.networks.test.sasl.password.setValue('sesame')
conf.supybot.networks.test.certfile.setValue('foo')
conf.supybot.networks.test.sasl.mechanisms.setValue(
['external', 'plain'])

self.irc = irclib.Irc('test')

self.assertEqual(self.irc.sasl_current_mechanism, None)
self.irc.sasl_next_mechanisms = ['external', 'plain']
self.assertEqual(self.irc.sasl_next_mechanisms,
['external', 'plain'])

self.startCapNegociation()

Expand Down Expand Up @@ -1570,11 +1585,14 @@ def testFilter(self):
conf.supybot.networks.test.sasl.username.setValue('jilles')
conf.supybot.networks.test.sasl.password.setValue('sesame')
conf.supybot.networks.test.certfile.setValue('foo')
conf.supybot.networks.test.sasl.mechanisms.setValue(
['external', 'plain'])

self.irc = irclib.Irc('test')

self.assertEqual(self.irc.sasl_current_mechanism, None)
self.irc.sasl_next_mechanisms = ['external', 'plain']
self.assertEqual(self.irc.sasl_next_mechanisms,
['external', 'plain'])

self.startCapNegociation(caps='sasl=foo,plain,bar')

Expand All @@ -1596,11 +1614,14 @@ def testFilter(self):
def testReauthenticate(self):
conf.supybot.networks.test.sasl.username.setValue('jilles')
conf.supybot.networks.test.sasl.password.setValue('sesame')
conf.supybot.networks.test.sasl.mechanisms.setValue(
['external', 'plain'])

self.irc = irclib.Irc('test')

self.assertEqual(self.irc.sasl_current_mechanism, None)
self.irc.sasl_next_mechanisms = ['plain']
self.assertEqual(self.irc.sasl_next_mechanisms,
['plain'])

self.startCapNegociation(caps='')

Expand Down

0 comments on commit fed8d52

Please sign in to comment.