コード例 #1
0
ファイル: test_pop3.py プロジェクト: adarshdinesh/beeswarm
    def test_initial_session(self):
        """Tests if the basic parts of the session is filled correctly"""

        sessions = {}

        #provide valid login/pass to authenticator
        authenticator = Authenticator({'james': 'bond'})
        Session.authenticator = authenticator

        sut = pop3.pop3(sessions, {'port': 110, 'max_attempts': 3})

        #dont really care about the socket at this point (None...)
        #TODO: mock the socket!
        try:
            sut.handle_session(None, ['192.168.1.200', 12000])
        except AttributeError:
            #because socket is not set
            pass

        #expect a single entry in the sessions dict
        self.assertEqual(1, len(sessions))
        session = sessions.values()[0]
        self.assertEqual(110, session.honey_port)
        self.assertEqual('pop3', session.protocol)
        self.assertEquals('192.168.1.200', session.attacker_ip)
        self.assertEqual(12000, session.attacker_source_port)
コード例 #2
0
ファイル: test_pop3.py プロジェクト: adarshdinesh/beeswarm
    def test_login(self):
        """Testing different login combinations"""

        #provide valid login/pass to authenticator
        authenticator = Authenticator({'james': 'bond'})
        Session.authenticator = authenticator

        login_sequences = [
            #valid login. valid password
            (('USER james', '+OK User accepted'), ('PASS bond', '+OK Pass accepted')),
            #valid login, invalid password, try to run TRANSACTION state command
            (('USER james', '+OK User accepted'), ('PASS wakkawakka', '-ERR Authentication failed.'),
             ('RETR', '-ERR Unknown command')),
            #invalid login, invalid password
            (('USER wakkwakk', '+OK User accepted'), ('PASS wakkwakk', '-ERR Authentication failed.')),
            #PASS without user
            (('PASS bond', '-ERR No username given.'),),
            #Try to run a TRANSACITON state command in AUTHORIZATION state
            (('RETR', '-ERR Unknown command'),),
        ]

        sessions = {}

        sut = pop3.pop3(sessions, {'port': 110, 'max_attempts': 3})

        server = StreamServer(('127.0.0.1', 0), sut.handle_session)
        server.start()

        for sequence in login_sequences:
            client = gevent.socket.create_connection(('127.0.0.1', server.server_port))

            fileobj = client.makefile()

            #skip banner
            fileobj.readline()

            for pair in sequence:
                client.sendall(pair[0] + "\r\n")
                response = fileobj.readline().rstrip()
                self.assertEqual(response, pair[1])

        server.stop()