Beispiel #1
0
    def test_server_credentials(self):
        root_certificates = b'Trust starts here. Really.'
        first_private_key = b'This is a really bad private key, yo.'
        first_certificate_chain = b'Trust me! Do I not look trustworty?'
        second_private_key = b'This is another bad private key, yo.'
        second_certificate_chain = b'Look into my eyes; you can totes trust me.'

        _c.init()

        server_credentials = _c.ServerCredentials(
            None, ((first_private_key, first_certificate_chain), ))
        del server_credentials
        server_credentials = _c.ServerCredentials(
            root_certificates,
            ((first_private_key, first_certificate_chain), ))
        del server_credentials
        server_credentials = _c.ServerCredentials(root_certificates, (
            (first_private_key, first_certificate_chain),
            (second_private_key, second_certificate_chain),
        ))
        del server_credentials
        with self.assertRaises(TypeError):
            _c.ServerCredentials(root_certificates, first_private_key,
                                 second_certificate_chain)

        _c.shut_down()
Beispiel #2
0
    def testChannel(self):
        _c.init()

        channel = _c.Channel('test host:12345', None)
        del channel

        _c.shut_down()
Beispiel #3
0
  def test_server_credentials(self):
    root_certificates = b'Trust starts here. Really.'
    first_private_key = b'This is a really bad private key, yo.'
    first_certificate_chain = b'Trust me! Do I not look trustworty?'
    second_private_key = b'This is another bad private key, yo.'
    second_certificate_chain = b'Look into my eyes; you can totes trust me.'

    _c.init()

    server_credentials = _c.ServerCredentials(
        None, ((first_private_key, first_certificate_chain),))
    del server_credentials
    server_credentials = _c.ServerCredentials(
        root_certificates, ((first_private_key, first_certificate_chain),))
    del server_credentials
    server_credentials = _c.ServerCredentials(
        root_certificates,
        ((first_private_key, first_certificate_chain),
         (second_private_key, second_certificate_chain),))
    del server_credentials
    with self.assertRaises(TypeError):
      _c.ServerCredentials(
          root_certificates, first_private_key, second_certificate_chain)

    _c.shut_down()
Beispiel #4
0
  def testChannel(self):
    _c.init()

    channel = _c.Channel('test host:12345', None)
    del channel

    _c.shut_down()
Beispiel #5
0
  def testChannel(self):
    _c.init()

    channel = _c.Channel(
        'test host:12345', None, server_host_override='ignored')
    del channel

    _c.shut_down()
Beispiel #6
0
  def testChannel(self):
    _c.init()

    channel = _c.Channel(
        'test host:12345', None, server_host_override='ignored')
    del channel

    _c.shut_down()
Beispiel #7
0
  def testCall(self):
    method = 'test method'
    host = 'test host'

    _c.init()

    channel = _c.Channel('%s:%d' % (host, 12345), None)
    call = _c.Call(channel, method, host, time.time() + _TIMEOUT)
    del call
    del channel

    _c.shut_down()
Beispiel #8
0
    def testServer(self):
        _c.init()

        completion_queue = _c.CompletionQueue()
        server = _c.Server(completion_queue)
        server.add_http2_addr('[::]:0')
        server.start()
        server.stop()
        completion_queue.stop()
        del server
        del completion_queue

        service_tag = object()
        completion_queue = _c.CompletionQueue()
        server = _c.Server(completion_queue)
        server.add_http2_addr('[::]:0')
        server.start()
        server.service(service_tag)
        server.stop()
        completion_queue.stop()
        event = completion_queue.get(time.time() + _TIMEOUT)
        self.assertIs(event.kind, _datatypes.Event.Kind.SERVICE_ACCEPTED)
        self.assertIs(event.tag, service_tag)
        self.assertIsNone(event.service_acceptance)
        for _ in range(_IDEMPOTENCE_DEMONSTRATION):
            event = completion_queue.get(time.time() + _TIMEOUT)
            self.assertIs(event.kind, _datatypes.Event.Kind.STOP)
        del server
        del completion_queue

        completion_queue = _c.CompletionQueue()
        server = _c.Server(completion_queue)
        server.add_http2_addr('[::]:0')
        server.start()
        thread = threading.Thread(target=completion_queue.get,
                                  args=(_FUTURE, ))
        thread.start()
        time.sleep(1)
        server.stop()
        completion_queue.stop()
        for _ in range(_IDEMPOTENCE_DEMONSTRATION):
            event = completion_queue.get(time.time() + _TIMEOUT)
            self.assertIs(event.kind, _datatypes.Event.Kind.STOP)
        thread.join()
        del server
        del completion_queue

        _c.shut_down()
Beispiel #9
0
  def testServer(self):
    _c.init()

    completion_queue = _c.CompletionQueue()
    server = _c.Server(completion_queue)
    server.add_http2_addr('[::]:0')
    server.start()
    server.stop()
    completion_queue.stop()
    del server
    del completion_queue

    service_tag = object()
    completion_queue = _c.CompletionQueue()
    server = _c.Server(completion_queue)
    server.add_http2_addr('[::]:0')
    server.start()
    server.service(service_tag)
    server.stop()
    completion_queue.stop()
    event = completion_queue.get(time.time() + _TIMEOUT)
    self.assertIs(event.kind, _datatypes.Event.Kind.SERVICE_ACCEPTED)
    self.assertIs(event.tag, service_tag)
    self.assertIsNone(event.service_acceptance)
    for _ in range(_IDEMPOTENCE_DEMONSTRATION):
      event = completion_queue.get(time.time() + _TIMEOUT)
      self.assertIs(event.kind, _datatypes.Event.Kind.STOP)
    del server
    del completion_queue

    completion_queue = _c.CompletionQueue()
    server = _c.Server(completion_queue)
    server.add_http2_addr('[::]:0')
    server.start()
    thread = threading.Thread(target=completion_queue.get, args=(_FUTURE,))
    thread.start()
    time.sleep(1)
    server.stop()
    completion_queue.stop()
    for _ in range(_IDEMPOTENCE_DEMONSTRATION):
      event = completion_queue.get(time.time() + _TIMEOUT)
      self.assertIs(event.kind, _datatypes.Event.Kind.STOP)
    thread.join()
    del server
    del completion_queue

    _c.shut_down()
Beispiel #10
0
  def testCompletionQueue(self):
    _c.init()

    completion_queue = _c.CompletionQueue()
    event = completion_queue.get(0)
    self.assertIsNone(event)
    event = completion_queue.get(time.time())
    self.assertIsNone(event)
    event = completion_queue.get(time.time() + _TIMEOUT)
    self.assertIsNone(event)
    completion_queue.stop()
    for _ in range(_IDEMPOTENCE_DEMONSTRATION):
      event = completion_queue.get(time.time() + _TIMEOUT)
      self.assertIs(event.kind, _datatypes.Event.Kind.STOP)

    del completion_queue
    del event

    _c.shut_down()
Beispiel #11
0
    def testCompletionQueue(self):
        _c.init()

        completion_queue = _c.CompletionQueue()
        event = completion_queue.get(0)
        self.assertIsNone(event)
        event = completion_queue.get(time.time())
        self.assertIsNone(event)
        event = completion_queue.get(time.time() + _TIMEOUT)
        self.assertIsNone(event)
        completion_queue.stop()
        for _ in range(_IDEMPOTENCE_DEMONSTRATION):
            event = completion_queue.get(time.time() + _TIMEOUT)
            self.assertIs(event.kind, _datatypes.Event.Kind.STOP)

        del completion_queue
        del event

        _c.shut_down()
Beispiel #12
0
    def test_client_credentials(self):
        root_certificates = b'Trust starts here. Really.'
        private_key = b'This is a really bad private key, yo.'
        certificate_chain = b'Trust me! Do I not look trustworty?'

        _c.init()

        client_credentials = _c.ClientCredentials(None, None, None)
        self.assertIsNotNone(client_credentials)
        client_credentials = _c.ClientCredentials(root_certificates, None,
                                                  None)
        self.assertIsNotNone(client_credentials)
        client_credentials = _c.ClientCredentials(None, private_key,
                                                  certificate_chain)
        self.assertIsNotNone(client_credentials)
        client_credentials = _c.ClientCredentials(root_certificates,
                                                  private_key,
                                                  certificate_chain)
        self.assertIsNotNone(client_credentials)
        del client_credentials

        _c.shut_down()
Beispiel #13
0
  def test_client_credentials(self):
    root_certificates = b'Trust starts here. Really.'
    private_key = b'This is a really bad private key, yo.'
    certificate_chain = b'Trust me! Do I not look trustworty?'

    _c.init()

    client_credentials = _c.ClientCredentials(
        None, None, None)
    self.assertIsNotNone(client_credentials)
    client_credentials = _c.ClientCredentials(
        root_certificates, None, None)
    self.assertIsNotNone(client_credentials)
    client_credentials = _c.ClientCredentials(
        None, private_key, certificate_chain)
    self.assertIsNotNone(client_credentials)
    client_credentials = _c.ClientCredentials(
        root_certificates, private_key, certificate_chain)
    self.assertIsNotNone(client_credentials)
    del client_credentials

    _c.shut_down()
Beispiel #14
0
  def test_secure_server(self):
    _c.init()

    server_credentials = _c.ServerCredentials(
        'root certificate', (('private key', 'certificate chain'),))

    completion_queue = _c.CompletionQueue()
    server = _c.Server(completion_queue, server_credentials)
    server.add_http2_addr('[::]:0')
    server.start()
    thread = threading.Thread(target=completion_queue.get, args=(_FUTURE,))
    thread.start()
    time.sleep(1)
    server.stop()
    completion_queue.stop()
    for _ in range(_IDEMPOTENCE_DEMONSTRATION):
      event = completion_queue.get(time.time() + _TIMEOUT)
      self.assertIs(event.kind, _datatypes.Event.Kind.STOP)
    thread.join()
    del server
    del completion_queue

    _c.shut_down()
Beispiel #15
0
  def test_secure_server(self):
    _c.init()

    server_credentials = _c.ServerCredentials(
        'root certificate', (('private key', 'certificate chain'),))

    completion_queue = _c.CompletionQueue()
    server = _c.Server(completion_queue, server_credentials)
    server.add_http2_addr('[::]:0')
    server.start()
    thread = threading.Thread(target=completion_queue.get, args=(_FUTURE,))
    thread.start()
    time.sleep(1)
    server.stop()
    completion_queue.stop()
    for _ in range(_IDEMPOTENCE_DEMONSTRATION):
      event = completion_queue.get(time.time() + _TIMEOUT)
      self.assertIs(event.kind, _datatypes.Event.Kind.STOP)
    thread.join()
    del server
    del completion_queue

    _c.shut_down()
Beispiel #16
0
 def testUpAndDown(self):
   _c.init()
   _c.shut_down()
Beispiel #17
0
 def testUpAndDown(self):
     _c.init()
     _c.shut_down()
Beispiel #18
0
def _shut_down():
  # force garbage collection before shutting down grpc, to ensure all grpc
  # objects are cleaned up
  gc.collect()
  _c.shut_down()