#!/usr/bin/env python2 from bithordetest import message, BithordeD, Cache, TestConnection, TigerId if __name__ == '__main__': ASSET = "A" * 87234 ASSET_TTH = "5V7AM5PT6PVGTCWITETZUFPBTCDK2DPHBJMTFWI" bithorded = BithordeD(config={ 'cache': { 'dir': Cache() }, 'client.tester.addr': '', }) conn = TestConnection(bithorded, name='tester') # Open an invalid handle conn.send( message.BindRead(handle=1, ids=[TigerId("IDONOTEXISTO")], timeout=500)) conn.expect(message.AssetStatus(handle=1, status=message.NOTFOUND)) # Create small asset conn.send(message.BindWrite(handle=1, size=len(ASSET))) conn.expect(message.AssetStatus(handle=1, status=message.SUCCESS)) conn.send(message.DataSegment(handle=1, offset=0, content=ASSET)) conn.expect( message.AssetStatus(handle=1, status=message.SUCCESS, ids=[TigerId(ASSET_TTH)]))
#!/usr/bin/env python2 from bithordetest import message, BithordeD, TestConnection if __name__ == '__main__': bithorded = BithordeD(config={ 'friend.evilservant.addr': '', }) conn = TestConnection(bithorded, name='tester') server = TestConnection(bithorded, name='evilservant') # Open a valid handle conn.send(message.BindRead(handle=1, ids=[message.Identifier(type=message.TREE_TIGER, id='NON-EXISTANT')], timeout=500)) assetReq = server.expect(message.BindRead) server.send(message.AssetStatus(handle=assetReq.handle, ids=assetReq.ids, status=message.SUCCESS, size=1024)) conn.expect(message.AssetStatus(handle=1, ids=assetReq.ids, status=message.SUCCESS)) # Send a pending read-request. conn.send(message.Read.Request(reqId=1, handle=1, offset=0, size=1024, timeout=500)) server.expect(message.Read.Request(handle=assetReq.handle, offset=0, size=1024)) # Close upstream server server.close() bithorded.wait_for("Disconnected: evilservant") conn.expect([ message.Read.Response(reqId=1, status=message.NOTFOUND, offset=0), message.AssetStatus(handle=1, status=message.NOTFOUND), ]) # Reconnect upstream server server = TestConnection(bithorded, name='evilservant')
conn.encryptor = setupCipher(cipher, key, sendIv).encrypt conn.decryptor = setupCipher(authentication.cipher, key, authentication.cipheriv).decrypt except (socket.error, StopIteration): return None return greeting.name if __name__ == '__main__': import base64, hashlib, hmac from Crypto.Cipher import AES, ARC4 key = os.urandom(16) bithorded = BithordeD(config={ 'server.name': 'test_server', 'client.tester1': { 'cipher': 'RC4', 'key': base64.b64encode(key), }, 'client.tester2': { 'cipher': 'AES', 'key': base64.b64encode(key), }, }) # Test auth failure for unknown key conn = EncryptedConnection(bithorded) assert secure_auth_and_encryption(conn, name="anonymous", key=key, cipher=message.RC4) == None # Test auth failure for wrong key conn = EncryptedConnection(bithorded) secure_auth_and_encryption(conn, name="tester1", key='0'*len(key), cipher=message.RC4, validate_auth=False) try:
#!/usr/bin/env python2 from bithordetest import message, BithordeD, TestConnection if __name__ == '__main__': bithorded = BithordeD(config={ 'friend.evilservant.addr': '', }) conn = TestConnection(bithorded, name='tester') server = TestConnection(bithorded, name='evilservant') # Open a valid handle conn.send( message.BindRead(handle=1, ids=[ message.Identifier(type=message.TREE_TIGER, id='NON-EXISTANT') ], timeout=500)) assetReq = server.expect(message.BindRead) server.send( message.AssetStatus(handle=assetReq.handle, ids=assetReq.ids, status=message.SUCCESS, size=1024)) conn.expect( message.AssetStatus(handle=1, ids=assetReq.ids, status=message.SUCCESS)) # Send a pending read-request. conn.send(
#!/usr/bin/env python2 from bithordetest import message, BithordeD, TestConnection if __name__ == '__main__': bithorded = BithordeD(config={ 'friend.deadservant.addr': '' }) server = TestConnection(bithorded, name='deadservant') conn = TestConnection(bithorded, name='tester') dummy_ids = [message.Identifier(type=message.TREE_TIGER, id='NON-EXISTANT')] # Send request, and wait for it to arrive at server and time out conn.send(message.BindRead(handle=1, ids=dummy_ids, timeout=50)) req = server.expect(message.BindRead) bithorded.wait_for("Failed upstream deadservant") conn.expect(message.AssetStatus(handle=1, status=message.NOTFOUND)) # BithordeD should now have closed the connection. Hold the confirmation. req = server.expect(message.BindRead(handle=req.handle, ids=[])) # Re-bind, now with responding source conn.send(message.BindRead(handle=1, ids=dummy_ids, timeout=5000)) req2 = server.expect(message.BindRead(ids=dummy_ids)) assert req.handle != req2.handle # Since we did not confirm the close before, bithorde should not yet have re-used the handle. server.send(message.AssetStatus(handle=req2.handle, ids=req2.ids, status=message.SUCCESS)) conn.expect(message.AssetStatus(handle=1, status=message.SUCCESS)) # Now close both handles and confirm the closing server.send(message.AssetStatus(handle=req.handle, status=message.NOTFOUND))
except Exception as err: print err if __name__ == '__main__': import os import random import shutil try: shutil.rmtree('cache') except OSError: pass bithorded = BithordeD(config={ 'friend.server.addr': '', 'cache': { 'dir': 'cache', 'size': 8192, }, }) server = TestConnection(bithorded, name='server') client = TestConnection(bithorded, name='client') dummy_ids = [ message.Identifier(type=message.TREE_TIGER, id='NON-EXISTANT') ] # Send request, and wait for it to arrive at server and time out client.send(message.BindRead(handle=1, ids=dummy_ids, timeout=50)) server_asset = server.expect(message.BindRead) server.send( message.AssetStatus(handle=server_asset.handle,
#!/usr/bin/env python2 from bithordetest import message, BithordeD, TestConnection from random import randint ASSET_IDS = [ message.Identifier(type=message.TREE_TIGER, id='GIS3CRGMSBT7CKRBLQFXFAL3K4YIO5P5E3AMC2A') ] INITIAL_REQUEST = randint(0, (2**64) - 1) if __name__ == '__main__': bithorded = BithordeD(config={ 'friend.upstream1.addr': '', 'friend.upstream2.addr': '', }) upstream1 = TestConnection(bithorded, name='upstream1') upstream2 = TestConnection(bithorded, name='upstream2') downstream1 = TestConnection(bithorded, name='downstream1') downstream2 = TestConnection(bithorded, name='downstream2') # Request an asset-session downstream1.send( message.BindRead(handle=1, ids=ASSET_IDS, timeout=500, requesters=[INITIAL_REQUEST])) req1 = upstream1.expect(message.BindRead) assert len(req1.requesters) > 1 assert INITIAL_REQUEST in req1.requesters assert INITIAL_REQUEST == req1.requesters[
return None return greeting.name if __name__ == '__main__': import base64 import hashlib import hmac from Crypto.Cipher import AES, ARC4 key = os.urandom(16) bithorded = BithordeD( config={ 'server.name': 'test_server', 'client.tester1': { 'cipher': 'RC4', 'key': base64.b64encode(key), }, 'client.tester2': { 'cipher': 'AES', 'key': base64.b64encode(key), }, }) # Test auth failure for unknown key conn = EncryptedConnection(bithorded) assert secure_auth_and_encryption( conn, name="anonymous", key=key, cipher=message.RC4) is None # Test auth failure for wrong key conn = EncryptedConnection(bithorded) secure_auth_and_encryption(conn, name="tester1",