Skip to content

Commit 7ee4e4a

Browse files
committed
Improve test_shares_on_hubs
1 parent 809441c commit 7ee4e4a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

hub/hub.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ async def get_share_requested_by_client(
140140
share = self.get_share(key_id)
141141
share.check_master_sae(master_sae_id)
142142
share.check_slave_sae(slave_sae_id)
143+
del self._shares[key_id]
143144
encryption_key = EncryptionKey.from_pool(peer_client.local_pool, share.size)
144145
encrypted_share_value = encryption_key.encrypt(share.value)
145146
response = APIGetShareResponse(

system_tests/test_share_storage.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test share storage at hubs.
33
"""
44

5+
import httpx
56
import pytest
67
from . import system_test_common
78

@@ -16,17 +17,41 @@ def setup_and_teardown():
1617
system_test_common.stop_topology()
1718

1819

19-
def test_get_key_creates_shares_on_hubs():
20+
def test_shares_on_hubs():
2021
"""
2122
Test that getting a key on the master client results in shares being created on the hubs.
2223
"""
23-
key_id = system_test_common.get_key("sam", "sofia")
24+
# Get key on master client
25+
key_id = system_test_common.get_key("sam", "sunny")
26+
# There should be a share stored one each hub (we only check hank)
2427
status = system_test_common.status_node("hub", "hank")
2528
assert "shares" in status
2629
shares = status["shares"]
2730
assert len(shares) == 1
2831
share = shares[0]
2932
assert share["key_id"] == key_id
3033
assert share["master_sae_id"] == "sam"
31-
assert share["slave_sae_id"] == "sofia"
34+
assert share["slave_sae_id"] == "sunny"
3235
assert share["share_index"] == 0
36+
# Incorrect get key with key IDS on slave client (wrong master SAE ID)
37+
curtis_port = 8109
38+
url = (
39+
f"http://127.0.0.1:{curtis_port}"
40+
f"/client/curtis/etsi/api/v1/keys/sam/dec_keys?" # All correct
41+
f"key_ID={key_id}"
42+
)
43+
result = httpx.get(url, headers={"Authorization": "susan"}) # Wrong slave SAE ID
44+
assert result.status_code == 400
45+
assert "Slave SAE ID does not match" in result.text
46+
# Share was not removed
47+
status = system_test_common.status_node("hub", "hank")
48+
assert "shares" in status
49+
shares = status["shares"]
50+
assert len(shares) == 1
51+
# Correct get key with key IDS on slave client
52+
system_test_common.get_key_with_key_ids("sam", "sunny", key_id)
53+
# The share should be removed from the hub
54+
status = system_test_common.status_node("hub", "hank")
55+
assert "shares" in status
56+
shares = status["shares"]
57+
assert len(shares) == 0

0 commit comments

Comments
 (0)