-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample_auditor.py
85 lines (73 loc) · 2.87 KB
/
example_auditor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#/usr/bin/python
import time
import random
import string
import datetime
import json
import os
import sys
# not provided here!
import swarm
from libs import earth
import swarm
from auditor import Auditor
import auditor_constants as const
import random
DEVICE_ID1 = 'aaaaaaaaaaaaaaaaaaaaaaaa'
DEVICE_ID2 = 'bbbbbbbbbbbbbbbbbbbbbbbb'
def _repr_coords(coords):
return repr(coords[0]) + "," + repr(coords[1])
users= [
['test_email1', 'password1'],
['test_email2', 'password2']
]
brng = 180
travel_dist = 0
center_coords = [40.807849, -73.962121]
class Tester(Auditor):
def auditor_get_distance(self, user_a, user_b, user_loc):
usera_crdnt = swarm.sw_login(users[user_a][0],
users[user_a][1],
_repr_coords(center_coords),
30 + random.uniform(-20, 10),
DEVICE_ID1)
usera_acc_token = usera_crdnt['access_token']
userb_crdnt = swarm.sw_login(users[user_b][0],
users[user_b][1],
_repr_coords(center_coords),
30 + random.uniform(-20, 10),
DEVICE_ID2)
userb_acc_token = usera_crdnt['access_token']
userb = swarm.sw_get_friend_info(usera_acc_token, users[user_b][0])
userb_id = str(userb['id'])
rspn = swarm.sw_get_user_location(usera_acc_token,
_repr_coords(user_loc),
str(30 + random.uniform(-20, 10)),
userb_id)
if rspn is None:
return (None, 1)
else:
return (float(rspn[2]) / 1000, 1)
def auditor_set_location(self, user, lat, lon):
user_crdnt = swarm.sw_login(users[user][0],
users[user][1],
_repr_coords(center_coords),
30 + random.uniform(-20, 10),
DEVICE_ID1)
user_acc_token = user_crdnt['access_token']
update = swarm.update_location(user_acc_token,
DEVICE_ID1,
_repr_coords([lat, lon]),
str(30 + random.uniform(-20, 10)),
_repr_coords([lat, lon]),
str(30 + random.uniform(-20, 10)), '')
if update is False:
return (False, 1)
else:
return (True, 1)
t = Tester("swarm", [0, 1])
t.test_speed_limit()
t.test_location_verification()
t.test_query_limit()
t.test_dudp_attack([0.321869, 1.60934, 8.04672, 32.1869, 64.3738])
t.test_rudp_attack([[[0.1, float('inf')], 0.03, const.ROUNDING.BOTH]])