Ejemplo n.º 1
0
 def finish(self):
     """Overwrite the finish() to include the killing of the web_server"""
     ProxyHandler.finish(self)
     if self.current_destination:
         TestController.instance(self.client_address,
                                 self.current_destination.host,
                                 self.current_destination.port).cleanup()
Ejemplo n.º 2
0
    def main(self):
        parser = optparse.OptionParser()
        parser.add_option("-d", "--domain", dest="domains_arg", action="append",
                          help="Domain to be monitored, might be used multiple times and supports regular expressions")
        parser.add_option("-v", "--verbose", dest="verbose_arg", default=False,
                          action="store_true", help="Verbose mode")
        (options, args) = parser.parse_args()
        if not options.domains_arg or len(options.domains_arg) <1:   # if domains_arg is not given
            parser.error('Domain not given')

        Configuration().fake_server_address = ("127.0.0.1", 0)
        Configuration().verbose_mode = options.verbose_arg
        Configuration().testcase_list = [CertificateInvalidCASignature,
                                         CertificateUnknownCA,
                                         CertificateSignedWithCA,
                                         CertificateSelfSigned,
                                         CertificateWrongCN,
                                         CertificateSignWithMD5,
                                         CertificateSignWithMD4,
                                         CertificateExpired,
                                         CertificateNotYetValid
                                         ]
        TestController.set_monitored_domains(options.domains_arg)
        proxy = ProxyServer(proxy_handler=ProxyHandlerCertificateTest)
        proxy.start()
Ejemplo n.º 3
0
    def main(self):
        parser = optparse.OptionParser()
        parser.add_option("-d", "--domains", dest="domains_arg",
                          help="Set a list of comma-separated domains")
        parser.add_option("-v", "--verbose", dest="verbose_arg", default=False,
                          action="store_true", help="Verbose mode")
        (options, args) = parser.parse_args()
        if not options.domains_arg:   # if domains_arg is not given
            parser.error('Domain not given')

        domain_list = options.domains_arg.split(",")

        Configuration().fake_server_address = ("127.0.0.1", 0)
        Configuration().verbose_mode = options.verbose_arg
        Configuration().testcase_list = [CertificateInvalidCASignature,
                                         CertificateUnknownCA,
                                         CertificateSignedWithCA,
                                         CertificateSelfSigned,
                                         CertificateWrongCN,
                                         CertificateSignWithMD5,
                                         CertificateSignWithMD4,
                                         CertificateExpired,
                                         CertificateNotYetValid
                                         ]
        TestController.set_monitored_domains(domain_list)
        proxy = ProxyServer(proxy_handler=ProxyHandlerCertificateTest)
        proxy.start()
Ejemplo n.º 4
0
 def getParticipantID(self):
     pid, ok = QtGui.QInputDialog.getInt(self,
                                         "Setup",
                                         "Participant ID",
                                         minValue=0)
     if ok:
         self.ctrl = TestController(participant_id=pid)
     return ok
Ejemplo n.º 5
0
    def process_connect(self):
        # Set keep_alive if necessary
        if self.http_data.has_keepalive():
            self.keep_alive = True

        self.current_destination = self.get_destination_from_data()

        if TestController.match_monitored_domains(self.current_destination.host):
            self.redirect_destination()

        # Else Reply 200 Connection Established and forward data
        self.send_data(socket_to=self.request, data="HTTP/1.0 200 Connection established\r\n\r\n")
        # Forward data
        self.forward_https_channel()
Ejemplo n.º 6
0
 def redirect_destination(self):
     try:
         server_address = TestController.instance(self.client_address,
                                                  self.current_destination.host,
                                                  self.current_destination.port).configure_fake_server()
         if Configuration().verbose_mode:
             print "Web Server for host %s listening at %s on port %d" % (self.current_destination.host, server_address[0], server_address[1])
     except TestControllerException:
         # This means the TestSuite finished, do not redirect anymore
         return
     address, port = server_address
     # Remove the created connection to the original destination
     self.readable_sockets.remove(self.current_destination.socket_connection)
     # Create the new connection to our fake server
     try:
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.connect(server_address)
         self.readable_sockets.append(s)
         self.current_destination.socket_connection = s
     except Exception as e:
         Logger().log_error("## FakeServer connection error - While trying to connect to {1} at port {2}".format(address, port))
Ejemplo n.º 7
0
class MainInterfaceQt(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.setWindowTitle('Speech Intelligibility Test')
        self.resize(800, 100)
        self.media = Phonon.MediaObject(self)
        self.audio = Phonon.AudioOutput(Phonon.MusicCategory, self)
        Phonon.createPath(self.media, self.audio)
        self.buttonStart = QtGui.QPushButton('Start', self)
        self.slider = Phonon.VolumeSlider(self)
        self.slider.setAudioOutput(self.audio)
        self.entry = QtGui.QLineEdit()
        self.entry.setEnabled(False)
        entryFont = QtGui.QFont("Times", 18)
        self.entry.setFont(entryFont)
        layout = QtGui.QGridLayout(self)
        layout.addWidget(self.entry, 0, 0, 1, 2)
        layout.addWidget(self.buttonStart, 1, 1)
        layout.addWidget(self.slider, 1, 0)
        layout.setRowStretch(0, 1)
        self.media.stateChanged.connect(self.handleStateChanged)
        self.media.finished.connect(self.handleSampleFinished)
        self.buttonStart.clicked.connect(self.handleButtonStart)
        self.entry.returnPressed.connect(self.handleSaveEntry)

    def getParticipantID(self):
        pid, ok = QtGui.QInputDialog.getInt(self,
                                            "Setup",
                                            "Participant ID",
                                            minValue=0)
        if ok:
            self.ctrl = TestController(participant_id=pid)
        return ok

    def updateAndPlayNext(self):
        try:
            path, n = self.ctrl.next_sample()
            self.media.setCurrentSource(Phonon.MediaSource(path))
            self.setWindowTitle('Sample %s' % n)
            if not self.ctrl.is_training_sample():
                self.slider.setEnabled(False)
            self.media.play()
        except IndexError:
            self.entry.setText("This was the last sample.")
            self.entry.setEnabled(False)
            self.buttonStart.setEnabled(False)

    def handleButtonStart(self):
        self.updateAndPlayNext()
        self.buttonStart.setText("Next")
        self.buttonStart.clicked.disconnect(self.handleButtonStart)
        self.buttonStart.clicked.connect(self.handleSaveEntry)

    def handleStateChanged(self, newstate, oldstate):
        if newstate == Phonon.PlayingState:
            self.entry.setText('')
            self.entry.setEnabled(False)
            self.buttonStart.setEnabled(False)
        elif (newstate != Phonon.LoadingState
              and newstate != Phonon.BufferingState):
            if newstate == Phonon.ErrorState:
                source = self.media.currentSource().fileName()
                print('ERROR: could not play: %s' % source)
                print('  %s' % self.media.errorString())

    def handleSampleFinished(self):
        self.entry.setEnabled(True)
        self.buttonStart.setEnabled(True)
        self.entry.setFocus()

    def handleSaveEntry(self):
        self.ctrl.save_result(self.entry.text())
        self.updateAndPlayNext()
Ejemplo n.º 8
0
 def Initialize(self, server, cacheManager, controllerComponentManager):
     Module.Initialize(self, server, cacheManager,
                       controllerComponentManager)
     self.AddController(lambda: TestController())
     self.AddPacket("ITestPacket", lambda: TestPacket())