Exemple #1
0
 def test_constructor(self):
     """
     Test the with passing auth store in constructor.
     """
     auth = SimpleAuthenticator({'user': '******'})
     assert auth.authenticate('user', 'pass') == True
     assert auth.authenticate('user1', 'pass') == False
     assert auth.authenticate('user', 'pass2') == False
Exemple #2
0
 def test_constructor(self):
     """
     Test the with passing auth store in constructor.
     """
     auth = SimpleAuthenticator({'user': '******'})
     assert auth.authenticate('user', 'pass') == True
     assert auth.authenticate('user1', 'pass') == False
     assert auth.authenticate('user', 'pass2') == False
Exemple #3
0
 def test_from_configfile_fp_invalid(self):
     """
     Test loading store with missing section in config.
     """
     fp = StringIO(u"[invalid]\nusername=password")
     auth = SimpleAuthenticator()
     try:
         auth.from_configfile(fp)
         self.fail("Expected error with missing section.")
     except ValueError as e:
         pass
Exemple #4
0
 def test_from_configfile_invalid(self):
     """
     Test loading store with invalid file path.
     """
     filename = resource_filename('tests.resources', 'auth-invlaid.ini')
     auth = SimpleAuthenticator()
     try:
         auth.from_configfile(filename)
         self.fail("Expected error with invalid filename.")
     except ValueError as e:
         pass
Exemple #5
0
 def test_from_configfile_fp_invalid(self):
     """
     Test loading store with missing section in config.
     """
     fp = StringIO(u"[invalid]\nusername=password")
     auth = SimpleAuthenticator()
     try:
         auth.from_configfile(fp)
         self.fail("Expected error with missing section.")
     except ValueError as e:
         pass
Exemple #6
0
 def test_from_configfile_invalid(self):
     """
     Test loading store with invalid file path.
     """
     filename = resource_filename('tests.resources', 'auth-invlaid.ini')
     auth = SimpleAuthenticator()
     try:
         auth.from_configfile(filename)
         self.fail("Expected error with invalid filename.")
     except ValueError as e:
         pass
Exemple #7
0
 def test_from_configfile(self):
     """
     Test the loading store from config file path.
     """
     filename = resource_filename('tests.resources', 'auth.ini')
     auth = SimpleAuthenticator()
     auth.from_configfile(filename)
     assert auth.authenticate('juniper', 'b3rr1es') == True
     assert auth.authenticate('oak', 'ac$rrubrum') == True
     assert auth.authenticate('pinetree', 'str0bus') == True
     assert auth.authenticate('foo', 'bar') == False
Exemple #8
0
    def test_from_configfile_fp(self):
        """
        Test loading store from file-like object.
        """
        with open(resource_filename('tests.resources', 'auth.ini'), 'r') as fp:
            auth = SimpleAuthenticator()
            auth.from_configfile(fp)

        assert auth.authenticate('juniper', 'b3rr1es') == True
        assert auth.authenticate('oak', 'ac$rrubrum') == True
        assert auth.authenticate('pinetree', 'str0bus') == True
        assert auth.authenticate('foo', 'bar') == False
Exemple #9
0
 def test_from_configfile(self):
     """
     Test the loading store from config file path.
     """
     filename = resource_filename('tests.resources', 'auth.ini')
     auth = SimpleAuthenticator()
     auth.from_configfile(filename)
     assert auth.authenticate('juniper', 'b3rr1es') == True
     assert auth.authenticate('oak', 'ac$rrubrum') == True
     assert auth.authenticate('pinetree', 'str0bus') == True
     assert auth.authenticate('foo', 'bar') == False
Exemple #10
0
    def test_from_configfile_fp(self):
        """
        Test loading store from file-like object.
        """
        with open(resource_filename('tests.resources', 'auth.ini'), 'r') as fp:
            auth = SimpleAuthenticator()
            auth.from_configfile(fp)

        assert auth.authenticate('juniper', 'b3rr1es') == True
        assert auth.authenticate('oak', 'ac$rrubrum') == True
        assert auth.authenticate('pinetree', 'str0bus') == True
        assert auth.authenticate('foo', 'bar') == False
Exemple #11
0
    def test_connect_auth(self):
        """ Test connecting when auth is required. """
        self.server.authenticator = SimpleAuthenticator(store={'user': '******'})

        c1 = self._new_client(connect=False)
        c1.connect()
        r = c1.received_frames.get(timeout=1)
        self.assertEqual(r.cmd, 'error')
        self.assertIn(b'Auth', r.body)

        c2 = self._new_client(connect=False)
        c2.connect(headers={'login': '******', 'passcode': 'pass'})
        r2 = c2.received_frames.get(timeout=1)

        self.assertEqual(r2.cmd.lower(), 'connected')

        c3 = self._new_client(connect=False)
        c3.connect(headers={'login': '******', 'passcode': 'pass-invalid'})
        r3 = c3.received_frames.get(timeout=1)

        self.assertEqual(r3.cmd, 'error')
Exemple #12
0
    def test_connect_auth(self):
        """ Test connecting when auth is required. """
        self.server.authenticator = SimpleAuthenticator(store={'user': '******'})

        c1 = self._new_client(connect=False)
        c1.connect()
        r = c1.received_frames.get(timeout=1)
        assert r.command == 'ERROR'
        assert 'Auth' in r.body

        c2 = self._new_client(connect=False)
        c2.connect(headers={'login': '******', 'passcode': 'pass'})
        r2 = c2.received_frames.get(timeout=1)
        print r2

        assert r2.command == 'CONNECTED'

        c3 = self._new_client(connect=False)
        c3.connect(headers={'login': '******', 'passcode': 'pass-invalid'})
        r3 = c3.received_frames.get(timeout=1)
        print r3

        assert r3.command == 'ERROR'