From b4b3bc7b8bc220b617bdc59329d278fab8e05e13 Mon Sep 17 00:00:00 2001 From: k22036 <131113333+k22036@users.noreply.github.com> Date: Wed, 28 Aug 2024 20:33:49 +0900 Subject: [PATCH] =?UTF-8?q?change:=20=E4=BB=95=E6=A7=98=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/DB.py | 6 --- server/src/Pairing/routes.py | 41 ++-------------- server/tests/test_pairing.py | 84 +++++---------------------------- server/tests/test_streetpass.py | 25 +--------- 4 files changed, 16 insertions(+), 140 deletions(-) diff --git a/server/src/DB.py b/server/src/DB.py index 60b57d8..24291ce 100644 --- a/server/src/DB.py +++ b/server/src/DB.py @@ -8,7 +8,6 @@ def __init__(self): db = client["db"] self.__users = db["users"] self.__device_keys = db["device_keys"] - self.__pre_pairings = db["pre_pairings"] self.__pairings = db["pairings"] self.__pre_passes = db["pre_passes"] self.__now_passes = db["now_passes"] @@ -25,11 +24,6 @@ def users(self): def device_keys(self): return self.__device_keys - # pre_pairings - @property - def pre_pairings(self): - return self.__pre_pairings - # pairings @property def pairings(self): diff --git a/server/src/Pairing/routes.py b/server/src/Pairing/routes.py index 88ae5f1..55d3eb6 100644 --- a/server/src/Pairing/routes.py +++ b/server/src/Pairing/routes.py @@ -10,7 +10,6 @@ db = DB() users = db.users device_keys = db.device_keys -pre_pairings = db.pre_pairings pairings = db.pairings @@ -51,51 +50,17 @@ def register_pairing(): if not device_key: return jsonify({'error': 'Invalid public_key'}), 400 - pre_pairings.insert_one({ - 'uid': user['uid'], - 'public_key': public_key - }) - - return jsonify({'done': 'pre_pairing'}), 200 - - -@PAIRING_BP.route('/check_pairing', methods=['POST']) -def check_pairing(): - token = request.json['token'] - if not token: - return jsonify({'error': 'Missing token'}), 400 - private_key = request.json['private_key'] - if not private_key: - return jsonify({'error': 'Missing private_key'}), 400 - - user = users.find_one({'token': token}) - if not user: - return jsonify({'error': 'Invalid token'}), 400 - - device_key = device_keys.find_one({'private_key': private_key}) - if not device_key: - return jsonify({'error': 'Invalid private_key'}), 400 - - pre_pairing = pre_pairings.find_one( - {'uid': user['uid'], 'public_key': device_key['public_key']}) - - if not pre_pairing: - return jsonify({'error': 'Invalid pairing'}), 400 - - pre_pairings.delete_many( - {'uid': user['uid'], 'public_key': device_key['public_key']}) - pairings.delete_many({'uid': user['uid']}) pairings.delete_many({'public_key': device_key['public_key']}) - pairings.delete_many({'private_key': private_key}) + pairings.delete_many({'private_key': device_key['private_key']}) pairings.insert_one({ 'uid': user['uid'], 'public_key': device_key['public_key'], - 'private_key': private_key + 'private_key': device_key['private_key'] }) - return jsonify({'done': 'success'}), 200 + return jsonify({'done': 'pairing'}), 200 @PAIRING_BP.route('/auth_check', methods=['POST']) diff --git a/server/tests/test_pairing.py b/server/tests/test_pairing.py index e78320d..1335937 100644 --- a/server/tests/test_pairing.py +++ b/server/tests/test_pairing.py @@ -64,7 +64,17 @@ def test_register_pairing_success(baseurl): 'public_key': public_key }) assert res.status_code == 200 - assert res.json()['done'] == 'pre_pairing' + assert res.json()['done'] == 'pairing' + + client = MongoClient('localhost', 27017) + db = client['db'] + pairings = db['pairings'] + users = db['users'] + + user = users.find_one({'token': token}) + pairing = pairings.find_one( + {'uid': user['uid'], 'public_key': public_key, 'private_key': private_key}) + assert pairing def test_register_pairing_missing_token(baseurl): @@ -111,74 +121,6 @@ def test_register_pairing_invalid_public_key(baseurl): assert res.json()['error'] == 'Invalid public_key' -def test_check_pairing_missing_token(baseurl): - global private_key - url = baseurl+'/pairing/check_pairing' - res = requests.post(url, json={ - 'token': '', - 'private_key': private_key - }) - assert res.status_code == 400 - assert res.json()['error'] == 'Missing token' - - -def test_check_pairing_missing_private_key(baseurl): - global token - url = baseurl+'/pairing/check_pairing' - res = requests.post(url, json={ - 'token': token, - 'private_key': '' - }) - assert res.status_code == 400 - assert res.json()['error'] == 'Missing private_key' - - -def test_check_pairing_invalid_token(baseurl): - global private_key - url = baseurl+'/pairing/check_pairing' - res = requests.post(url, json={ - 'token': 'invalidToken', - 'private_key': private_key - }) - assert res.status_code == 400 - assert res.json()['error'] == 'Invalid token' - - -def test_check_pairing_invalid_private_key(baseurl): - global token - url = baseurl+'/pairing/check_pairing' - res = requests.post(url, json={ - 'token': token, - 'private_key': 'invalidPrivateKey' - }) - assert res.status_code == 400 - assert res.json()['error'] == 'Invalid private_key' - - -def test_check_pairing_success(baseurl): - global token - global private_key - url = baseurl+'/pairing/check_pairing' - res = requests.post(url, json={ - 'token': token, - 'private_key': private_key - }) - assert res.status_code == 200 - assert res.json()['done'] == 'success' - - -def test_check_pairing_invalid_pairing(baseurl): - global token - global private_key - url = baseurl+'/pairing/check_pairing' - res = requests.post(url, json={ - 'token': token, - 'private_key': private_key - }) - assert res.status_code == 400 - assert res.json()['error'] == 'Invalid pairing' - - def test_auth_check_success(baseurl): global token url = baseurl+'/pairing/auth_check' @@ -220,10 +162,6 @@ def test_done(baseurl): users = db['users'] user = users.find_one({'token': token}) - pre_pairings = db['pre_pairings'] - pre_pairings.delete_many({'uid': user['uid']}) - assert not pre_pairings.find_one({'uid': user['uid']}) - pairings = db['pairings'] pairings.delete_many({'uid': user['uid']}) assert not pairings.find_one({'uid': user['uid']}) diff --git a/server/tests/test_streetpass.py b/server/tests/test_streetpass.py index 3348647..5bff9c0 100644 --- a/server/tests/test_streetpass.py +++ b/server/tests/test_streetpass.py @@ -82,7 +82,7 @@ def test_pairing_success(baseurl): 'public_key': public_key1 }) assert res.status_code == 200 - assert res.json()['done'] == 'pre_pairing' + assert res.json()['done'] == 'pairing' global token2 global private_key2 @@ -92,23 +92,7 @@ def test_pairing_success(baseurl): 'public_key': public_key2 }) assert res.status_code == 200 - assert res.json()['done'] == 'pre_pairing' - - url = baseurl+'/pairing/check_pairing' - res = requests.post(url, json={ - 'token': token1, - 'private_key': private_key1 - }) - assert res.status_code == 200 - assert res.json()['done'] == 'success' - - url = baseurl+'/pairing/check_pairing' - res = requests.post(url, json={ - 'token': token2, - 'private_key': private_key2 - }) - assert res.status_code == 200 - assert res.json()['done'] == 'success' + assert res.json()['done'] == 'pairing' url = baseurl+'/pairing/auth_check' res = requests.post(url, json={ @@ -232,11 +216,6 @@ def test_done(): users = db['users'] user1 = users.find_one({'token': token1}) user2 = users.find_one({'token': token2}) - pre_pairings = db['pre_pairings'] - pre_pairings.delete_many({'uid': user1['uid']}) - assert not pre_pairings.find_one({'uid': user1['uid']}) - pre_pairings.delete_many({'uid': user2['uid']}) - assert not pre_pairings.find_one({'uid': user2['uid']}) pairings = db['pairings'] pairings.delete_many({'uid': user1['uid']})