Ejemplo n.º 1
0
def test_crt_missmatch():
    '''
    Forged certificate should raise napalm_logs.exceptions.SSLMismatchException.
    '''
    nlap = NapalmLogsAuthProc('tests/auth/forged.crt', 'tests/auth/forged.key',
                              'fake_pk', 'fake_hex')
    with pytest.raises(napalm_logs.exceptions.SSLMismatchException):
        nlap.start()
Ejemplo n.º 2
0
def test_invalid_cert():
    '''
    Testing if the auth process dies when
    unable to open the SSL certificate or keyfile.
    '''
    nlap = NapalmLogsAuthProc('fake_cert', 'fake_keyfile', 'fake_pk',
                              'fake_hex')
    with pytest.raises(IOError):
        nlap.start()
Ejemplo n.º 3
0
 def _start_auth_proc(self, auth_skt):
     '''
     Start the authenticator process.
     '''
     log.debug('Computing the signing key hex')
     verify_key = self.__signing_key.verify_key
     sgn_verify_hex = verify_key.encode(encoder=nacl.encoding.HexEncoder)
     log.debug('Starting the authenticator subprocess')
     auth = NapalmLogsAuthProc(self.certificate, self.keyfile,
                               self.__priv_key, sgn_verify_hex, auth_skt)
     auth.verify_cert()
     proc = Process(target=auth.start)
     proc.start()
     log.debug('Started auth process as {pname} with PID {pid}'.format(
         pname=proc._name, pid=proc.pid))
     return proc
Ejemplo n.º 4
0
def test_successful_start():
    '''
    Test that the auth process can start properly
    when valid certificate and key are configured.
    '''
    global AUTH_PROC
    pk, sgn_key = _generate_test_keys()
    nlap = NapalmLogsAuthProc('tests/auth/server.crt', 'tests/auth/server.key',
                              pk, sgn_key)
    AUTH_PROC = Process(target=nlap.start)
    AUTH_PROC.start()
Ejemplo n.º 5
0
def _get_proc_class(port):
    '''
    Return the testing napalm-logs authenticator class.
    '''
    pk, sgn_key = _generate_test_keys()
    nlap = NapalmLogsAuthProc('tests/auth/server.crt',
                              'tests/auth/server.key',
                              pk,
                              sgn_key,
                              auth_port=port)
    return nlap
Ejemplo n.º 6
0
 def _start_auth_proc(self):
     '''
     Start the authenticator process.
     '''
     log.debug('Computing the signing key hex')
     verify_key = self.__signing_key.verify_key
     sgn_verify_hex = verify_key.encode(encoder=nacl.encoding.HexEncoder)
     log.debug('Starting the authenticator subprocess')
     auth = NapalmLogsAuthProc(self.certificate, self.keyfile,
                               self.__priv_key, sgn_verify_hex,
                               self.auth_address, self.auth_port)
     proc = Process(target=auth.start)
     proc.start()
     proc.description = 'Auth process'
     log.debug('Started auth process as %s with PID %s', proc._name,
               proc.pid)
     return proc
Ejemplo n.º 7
0
def test_twice_bind():
    '''
    Test that binding twice on the same host/port fails,
    and raises napalm_logs.exceptions.BindException.
    '''
    pk, sgn_key = _generate_test_keys()
    nlap = NapalmLogsAuthProc('tests/auth/server.crt', 'tests/auth/server.key',
                              pk, sgn_key)
    assert AUTH_PROC.is_alive()
    time.sleep(.1)  # waiting for the auth socket
    with pytest.raises(napalm_logs.exceptions.BindException):
        nlap.start()
    nlap.stop()