mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-15 12:50:47 +02:00
Use default name when empty (#774)
* Disallow empty name for contact profile * Disallow empty name for signing profile * Disallow empty name for peer
This commit is contained in:
parent
9312e5f23b
commit
7a6a9477ee
4 changed files with 59 additions and 2 deletions
|
|
@ -134,6 +134,7 @@ def peer_id(server_stub, admin_stub):
|
|||
# Create a new peer
|
||||
create_peer_response = admin_stub.CreatePeer(
|
||||
squeak_admin_pb2.CreatePeerRequest(
|
||||
peer_name="fake_peer_name",
|
||||
host="fake_host",
|
||||
port=1234,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -481,6 +481,31 @@ def test_make_contact_profile(server_stub, admin_stub):
|
|||
assert contact_profile_id in contact_profile_ids
|
||||
|
||||
|
||||
def test_make_signing_profile_empty_name(server_stub, admin_stub):
|
||||
# Try to create a new signing profile with an empty name
|
||||
with pytest.raises(Exception) as excinfo:
|
||||
admin_stub.CreateSigningProfile(
|
||||
squeak_admin_pb2.CreateSigningProfileRequest(
|
||||
profile_name="",
|
||||
)
|
||||
)
|
||||
assert "Profile name cannot be empty." in str(excinfo.value)
|
||||
|
||||
|
||||
def test_make_contact_profile_empty_name(server_stub, admin_stub):
|
||||
# Try to create a new contact profile with an empty name
|
||||
contact_signing_key = generate_signing_key()
|
||||
contact_address = get_address(contact_signing_key)
|
||||
with pytest.raises(Exception) as excinfo:
|
||||
admin_stub.CreateContactProfile(
|
||||
squeak_admin_pb2.CreateContactProfileRequest(
|
||||
profile_name="",
|
||||
address=contact_address,
|
||||
)
|
||||
)
|
||||
assert "Profile name cannot be empty." in str(excinfo.value)
|
||||
|
||||
|
||||
def test_set_profile_following(server_stub, admin_stub, contact_profile_id):
|
||||
# Set the profile to be following
|
||||
admin_stub.SetSqueakProfileFollowing(
|
||||
|
|
@ -683,6 +708,7 @@ def test_create_peer(server_stub, admin_stub):
|
|||
# Add a new peer
|
||||
create_peer_response = admin_stub.CreatePeer(
|
||||
squeak_admin_pb2.CreatePeerRequest(
|
||||
peer_name="fake_peer_name",
|
||||
host="fake_host",
|
||||
port=1234,
|
||||
)
|
||||
|
|
@ -706,6 +732,19 @@ def test_create_peer(server_stub, admin_stub):
|
|||
assert "fake_host" in peer_hosts
|
||||
|
||||
|
||||
def test_create_peer_empty_name(server_stub, admin_stub):
|
||||
# Try to create a new signing profile with an empty name
|
||||
with pytest.raises(Exception) as excinfo:
|
||||
admin_stub.CreatePeer(
|
||||
squeak_admin_pb2.CreatePeerRequest(
|
||||
peer_name="",
|
||||
host="another_fake_host",
|
||||
port=1234,
|
||||
)
|
||||
)
|
||||
assert "Peer name cannot be empty." in str(excinfo.value)
|
||||
|
||||
|
||||
def test_set_peer_downloading(server_stub, admin_stub, peer_id):
|
||||
# Get the peer
|
||||
get_peer_response = admin_stub.GetPeer(
|
||||
|
|
@ -999,6 +1038,7 @@ def test_connect_other_node(
|
|||
# Add the main node as a peer
|
||||
create_peer_response = other_admin_stub.CreatePeer(
|
||||
squeak_admin_pb2.CreatePeerRequest(
|
||||
peer_name="test_peer",
|
||||
host="squeaknode",
|
||||
port=8774,
|
||||
)
|
||||
|
|
@ -1200,6 +1240,7 @@ def test_download_single_squeak(
|
|||
# Add the main node as a peer
|
||||
create_peer_response = other_admin_stub.CreatePeer(
|
||||
squeak_admin_pb2.CreatePeerRequest(
|
||||
peer_name="test_peer",
|
||||
host="squeaknode",
|
||||
port=8774,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -388,7 +388,7 @@ class SqueakAdminServerHandler(object):
|
|||
return squeak_admin_pb2.DeleteSqueakReply()
|
||||
|
||||
def handle_create_peer(self, request):
|
||||
peer_name = request.peer_name if request.peer_name else None
|
||||
peer_name = request.peer_name
|
||||
host = request.host
|
||||
port = request.port
|
||||
logger.info(
|
||||
|
|
|
|||
|
|
@ -120,6 +120,10 @@ class SqueakController:
|
|||
return sent_offer
|
||||
|
||||
def create_signing_profile(self, profile_name: str):
|
||||
if len(profile_name) == 0:
|
||||
raise Exception(
|
||||
"Profile name cannot be empty.",
|
||||
)
|
||||
signing_key = CSigningKey.generate()
|
||||
verifying_key = signing_key.get_verifying_key()
|
||||
address = CSqueakAddress.from_verifying_key(verifying_key)
|
||||
|
|
@ -154,9 +158,16 @@ class SqueakController:
|
|||
return self.squeak_db.insert_profile(squeak_profile)
|
||||
|
||||
def create_contact_profile(self, profile_name: str, squeak_address: str):
|
||||
if len(profile_name) == 0:
|
||||
raise Exception(
|
||||
"Profile name cannot be empty.",
|
||||
)
|
||||
if not is_address_valid(squeak_address):
|
||||
raise Exception(
|
||||
"Invalid squeak address: {}".format(squeak_address))
|
||||
"Invalid squeak address: {}".format(
|
||||
squeak_address
|
||||
),
|
||||
)
|
||||
squeak_profile = SqueakProfile(
|
||||
profile_id=None,
|
||||
profile_name=profile_name,
|
||||
|
|
@ -226,6 +237,10 @@ class SqueakController:
|
|||
return self.squeak_db.delete_squeak(squeak_hash)
|
||||
|
||||
def create_peer(self, peer_name: str, host: str, port: int):
|
||||
if len(peer_name) == 0:
|
||||
raise Exception(
|
||||
"Peer name cannot be empty.",
|
||||
)
|
||||
port = port or self.config.core.default_peer_rpc_port
|
||||
squeak_peer = SqueakPeer(
|
||||
peer_id=None,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue