forked from VirgilSecurity/virgil-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
185 lines (144 loc) · 7.09 KB
/
tests.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
from VirgilSDK import virgilhub
import VirgilSDK.virgil_crypto.cryptolib as cryptolib
import VirgilSDK.helper as helper
import mailinator
import time
from config import *
import random
def test_search_app(value):
app_card = virgil_hub.virgilcard.search_app(value)
# print(app_card)
assert app_card[0]['identity']['value'] == value, 'We`ve got a problem'
def test_search_card(value):
card = virgil_hub.virgilcard.search_card(value)
# print(card)
assert card[0]['identity']['value'] == value, 'We`ve got a problem'
def test_verify_identity(type, value):
ver_res = virgil_hub.identity.verify(type, value)
# print(ver_res)
assert ver_res['action_id'], 'We`ve got a problem'
def test_confirm_identity(type, value):
ver_res = virgil_hub.identity.verify(type, value)
mailinator_token = MAILINATOR_TOKEN
code = ''
for i in range(3):
try:
code = mailinator.receive_code(mailinator_token, value)
if code != '':
break
time.sleep(10)
except:
pass
conf_res = virgil_hub.identity.confirm(code, ver_res['action_id'], 3)
# print(conf_res)
assert conf_res['validation_token'], 'We`ve got a problem'
return conf_res['validation_token']
def test_create_card(type, value, keys, private_key_pswd, val_token):
data = {'name': 'Test', 'Organization': 'Test'}
card = virgil_hub.virgilcard.create_card(type, value, data, val_token,
keys['private_key'], private_key_pswd, keys['public_key'])
# print(card)
assert card['id'], 'We`ve got a problem'
return card
def test_get_card(card_id):
card = virgil_hub.virgilcard.get_virgil_card(card_id)
# print(card)
assert card['id'] == card_id, 'We`ve got a problem'
def test_sign_card(signed_card, signer_card, private_key, password):
sign = virgil_hub.virgilcard.sign_card(signed_card, signer_card, private_key, password)
# print(sign)
assert sign['signed_digest'], 'We`ve got a problem'
def test_unsign_card(signed_card, signer_card, private_key, password):
unsign = virgil_hub.virgilcard.unsign_card(signed_card, signer_card, private_key, password)
# print(unsign)
assert unsign == 'Unsigned!', 'We`ve got a problem'
def test_load_private_key(private_key, card_id, password):
recipient_card = virgil_hub.virgilcard.search_app(('com.virgilsecurity.private-keys'))
response = virgil_hub.privatekey.load_private_key(recipient_card[0]['public_key']['public_key'], recipient_card[0]['id'],
private_key, card_id, password)
assert response == '[]', 'We`ve got a problem'
def test_grab_private_key(type, value, password, card_id, val_token):
recipient_card = virgil_hub.virgilcard.search_app(('com.virgilsecurity.private-keys'))
response = virgil_hub.privatekey.grab_private_key(recipient_card[0]['public_key']['public_key'],
recipient_card[0]['id'], type, value,
val_token, password,
card_id)
assert response['private_key'], 'We`ve got a problem'
def test_delete_private_key(private_key, card_id, password):
recipient_card = virgil_hub.virgilcard.search_app(('com.virgilsecurity.private-keys'))
response = virgil_hub.privatekey.delete_private_key(recipient_card[0]['public_key']['public_key'], recipient_card[0]['id'],
private_key, card_id, password)
assert response == '[]', 'We`ve got a problem'
def test_get_public_key(key_id, signer_card_id, private_key, password):
response = virgil_hub.virgilcard.get_public_key(key_id, True, signer_card_id, private_key, password)
# print(response)
assert response['id'] == key_id, 'We`ve got a problem'
def test_delete_card(type, value, card_id, private_key, password, val_token):
response = virgil_hub.virgilcard.delete_card(type, value, val_token, card_id, private_key,
password)
assert response == '', 'We`ve got a problem'
if __name__ == '__main__':
token = VIRGIL_APPLICATION_TOKEN
ident_link = 'https://identity-stg.virgilsecurity.com/v1'
virgil_card_link = 'https://keys-stg.virgilsecurity.com/v3'
private_key_link = 'https://keys-private-stg.virgilsecurity.com/v3'
virgil_hub = virgilhub.VirgilHub(token, ident_link, virgil_card_link, private_key_link)
# Search application
print('Trying to search Virgil application..')
application_value = APPLICATION_VALUE
test_search_app(application_value)
print('Result: Successful')
# Confirmation and validation identity
print('Trying to confirm identity..')
type = virgilhub.IdentityType.email
value = IDENTITY_VALUE + str(random.randint(0, 100)) + '@mailinator.com'
print(value)
val_token = test_confirm_identity(type, value)
print('Result: Successful')
# Create new test card
print('Trying to create Virgil card..')
Passwd = NEW_CARD_PASSWORD
keys = cryptolib.CryptoWrapper.generate_keys(cryptolib.crypto_helper.VirgilKeyPair.Type_Default, Passwd)
my_new_card = test_create_card(type, value, keys, Passwd, val_token)
print('Result: Successful')
# Search card
print('Trying to search Virgil card..')
test_search_card(value)
print('Result: Successful')
# Get card by id
print('Trying to get Virgil card by ID..')
test_get_card(my_new_card['id'])
print('Result: Successful')
"""
# Sign virgil card
print('Trying to sign Virgil card..')
prkey = PRIVATE_KEY
passw = PRIVATE_KEY_PASSWORD
signer_card_id = APPLICATION_CARD_ID
test_sign_card(my_new_card['id'], signer_card_id, prkey, passw)
print('Result: Successful')
# Unsign virgil card
print('Trying to unsign Virgil card..')
test_unsign_card(my_new_card['id'], signer_card_id, prkey, passw)
print('Result: Successful')
"""
# Load private key
print('Trying to upload private key..')
test_load_private_key(keys['private_key'], my_new_card['id'], Passwd)
print('Result: Successful')
# Get private key
print('Trying to download private key..')
test_grab_private_key(type, value, Passwd, my_new_card['id'], val_token)
print('Result: Successful')
# Delete private key
print('Trying to delete prvate key..')
test_delete_private_key(keys['private_key'], my_new_card['id'], Passwd)
print('Result: Successful')
# Get public key
print('Trying to get public key by ID..')
test_get_public_key(my_new_card['public_key']['id'], my_new_card['id'], keys['private_key'], Passwd)
print('Result: Successful')
# Delete card
print('Trying to delete Virgil card..')
test_delete_card(type, value, my_new_card['id'], keys['private_key'], Passwd, val_token)
print('Result: Successful')