示例#1
0
def test_load_secret():
    with patch('ssb.util.open', mock_open(read_data=CONFIG_FILE), create=True):
        secret = load_ssb_secret()

    priv_key = b'\xfd\xba\x83\x04\x8f\xef\x18\xb0\xf9\xab-\xc6\xc4\xcb \x1cX\x18"\xba\xd8\xd3\xc2_O5\x1a\t\x84\xfa\xc7A'

    assert secret[
        'id'] == '@rsYpBIcXsxjQAf0JNes+MHqT2DL+EfopWKAp4rGeEPQ=.ed25519'
    assert bytes(secret['keypair']) == priv_key
    assert bytes(secret['keypair'].verify_key) == b64decode(
        'rsYpBIcXsxjQAf0JNes+MHqT2DL+EfopWKAp4rGeEPQ=')
示例#2
0
    client = SHSClient('127.0.0.1', 8008, keypair, bytes(keypair.verify_key))
    packet_stream = PacketStream(client)
    await client.open()
    api.add_connection(packet_stream)
    await gather(ensure_future(api), test_client())


if __name__ == '__main__':
    # create console handler and set level to debug
    ch = logging.StreamHandler()
    ch.setLevel(logging.INFO)

    # create formatter
    formatter = ColoredFormatter(
        '%(log_color)s%(levelname)s%(reset)s:%(bold_white)s%(name)s%(reset)s - '
        '%(cyan)s%(message)s%(reset)s')

    # add formatter to ch
    ch.setFormatter(formatter)

    # add ch to logger
    logger = logging.getLogger('packet_stream')
    logger.setLevel(logging.INFO)
    logger.addHandler(ch)

    keypair = load_ssb_secret()['keypair']

    loop = get_event_loop()
    loop.run_until_complete(main())
    loop.close()
示例#3
0
async def main():
    server = SHSServer('127.0.0.1', 8008, load_ssb_secret()['keypair'])
    server.on_connect(on_connect)
    await server.listen()
示例#4
0
def test_load_exception():
    with pytest.raises(ConfigException):
        with patch('ssb.util.open',
                   mock_open(read_data=CONFIG_FILE_INVALID),
                   create=True):
            load_ssb_secret()