-
Notifications
You must be signed in to change notification settings - Fork 2
/
serverTest.cpp
148 lines (125 loc) · 5.02 KB
/
serverTest.cpp
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
#include "server.h"
#include "minunit.h"
#include <string>
extern int tests_run;
//unsigned char TestCrypto::keySym[32] = "0123456789abcdef";
//unsigned char TestCrypto::iv[32] = {0};
//unsigned char TestCrypto::data[20] = "test crypto";
using namespace std;
static char* test_registration() {
Server* server = new Server();
const string login1 = "Lenka";
const string heslo1 = "Heslo1";
cert *certifikat1 = new cert();
User* user1 = new User(login1,heslo1,certifikat1);
//TEST correct registration
mu_assert("problem in correct registration",server->registration(login1,heslo1,certifikat1) == 0);
User* found = server->getUser(login1);
mu_assert("User is not found in the database",found!=NULL);
mu_assert("Login is not the same",found->login==user1->login);
mu_assert("Password is not the same",found->password==user1->password);
mu_assert("Certificate is not the same",found->certificate==user1->certificate);
//TEST registration without password
mu_assert("registration without password",server->registration("bez hesla","",certifikat1)!=0);
//TEST registration without without certificate
mu_assert("registration without certificate",server->registration("bez certifikatu","heslo",NULL)!=0);
//TEST registration without without login
mu_assert("registration without login",server->registration("","heslo",certifikat1)!=0);
//TEST
mu_assert("double registration of same login",server->registration("Lenka","heslo",certifikat1)!=0);
delete certifikat1;
delete user1;
}
static char* test_login()
{
Server* server = new Server();
cert *certifikat1 = new cert();
//TEST prihlasit zaregistrovaneho uzivatela
server->registration("Lenka","heslo",certifikat1);
server->registration("Zuzka","heslo",certifikat1);
mu_assert("login return non zero value",server->login("Lenka","heslo", 100)==0);
User* found = server->getOnlineUser("Lenka");
mu_assert("User is not found in the database",found!=NULL);
mu_assert("Login is not the same",found->login=="Lenka");
mu_assert("Password is not the same",found->password=="heslo");
mu_assert("Certificate is not the same",found->certificate==certifikat1);
//TEST pokus o login neregistrovaneho
mu_assert("login of unregistered user passed",server->login("neregistrovany","heslo", 100)!=0);
found = server->getOnlineUser("neregistrovany");
mu_assert("unregistered user is found in database of online users",found==NULL);
//TEST prihlasenie s nespravnym heslom
mu_assert("login with wrong password",server->login("Zuzka","nespravne", 100)!=0);
found = server->getOnlineUser("Zuzka");
mu_assert("after wrong password the user is found in list of online",found==NULL);
//TEST prihlasenie bez hesla
mu_assert("login without password",server->login("Zuzka","", 100)!=0);
found = server->getOnlineUser("Zuzka");
mu_assert("after login without password the user is found in list of online",found==NULL);
//TEST login without username
mu_assert("login without username",server->login("","heslo", 100)!=0);
delete server;
delete certifikat1;
}
static char* test_logout()
{
Server* server = new Server();
cert *certifikat1 = new cert();
server->registration("Lenka","heslo",certifikat1);
//TEST korektne odhlasenie
server->login("Lenka","heslo", 100);
mu_assert("correct logout didn't passed",server->logout("Lenka")==0);
User* found = server->getOnlineUser("Lenka");
mu_assert("user wasn't logout",found==NULL);
found = NULL;
found = server->getUser("Lenka");
mu_assert("after logout user was deleted from registrated",found!=NULL);
//TEST odhlasenie offline uzivatela
mu_assert("logout of offline user passed without error",server->logout("Lenka")!=0);
delete server;
delete certifikat1;
}
/*class TestCryptoClient{
public:
static unsigned char keySym[32];
static unsigned char keyPrivate[128];
static unsigned char keyPublic[128];
static unsigned char data[20];
static unsigned char output[20];
static unsigned char test[20];
static unsigned char iv[32];
static Server s1;
static char* test_cryptoSym(){
sl.cryptoSym(keySym, iv, data, output, 1);
sl.cryptoSym(keySym, iv, output, test, 0);
mu_assert("Error crypto", strcmp((const char*) test, (const char*)data) == 0);
return 0;
}
static char* test_cryptoAsym(){
sl.cryptoAsym(keyPublic, data, output, 1);
sl.cryptoAsym(keyPrivate, output, test, 0);
mu_assert("Error crypto asym", strcmp( (const char*) test, (const char*) data) == 0);
return 0;
}
static char* test_generAES()
{
keySym[0] = 0;
sl.randGenAES(keySym);
mu_assert("Wrong gener sym key", strlen( (const char*) keySym) != 0);
return 0;
}
static char* test_generRSA()
{
keyPrivate[0] = 0;
keyPublic[0] = 0;
sl.randGenRSA(keyPublic, keyPrivate);
mu_assert("Wrong gener asym key", (strlen((const char*)keySym) != 0 && strlen((const char*)keyPublic)!= 0 ));
return 0;
}
static char* all_run_tests(){
mu_run_test(test_cryptoAsym);
mu_run_test(test_cryptoSym);
mu_run_test(test_generAES);
mu_run_test(test_generRSA);
return 0;
}
};*/