2 #include <gtest/gtest.h> 3 #include <openssl/sha.h> 5 #include <rosauth/Authentication.h> 14 TEST(RosHashAuthentication, validAuthentication)
16 string secret =
"abcdefghijklmnop";
17 string client_ip =
"192.168.1.101";
18 string dest_ip =
"192.168.1.111";
19 string rand =
"xyzabc";
20 Time now = Time::now();
21 string user_level =
"admin";
22 Time end = Time::now();
27 ss << secret << client_ip << dest_ip << rand << now.
sec << user_level << end.
sec;
28 string local_hash = ss.str();
29 unsigned char sha512_hash[SHA512_DIGEST_LENGTH];
30 SHA512((
unsigned char *)local_hash.c_str(), local_hash.length(), sha512_hash);
33 char hex[SHA512_DIGEST_LENGTH * 2];
34 for (
int i = 0; i < SHA512_DIGEST_LENGTH; i++)
35 sprintf(&hex[i * 2],
"%02x", sha512_hash[i]);
38 rosauth::Authentication srv;
39 srv.request.mac = string(hex);
40 srv.request.client = client_ip;
41 srv.request.dest = dest_ip;
42 srv.request.rand = rand;
44 srv.request.level = user_level;
45 srv.request.end = end;
47 EXPECT_TRUE(client.
call(srv));
48 EXPECT_TRUE(srv.response.authenticated);
52 int main(
int argc,
char **argv)
54 testing::InitGoogleTest(&argc, argv);
57 init(argc, argv,
"ros_hash_authentication_test");
61 client = node.
serviceClient<rosauth::Authentication>(
"authenticate");
63 return RUN_ALL_TESTS();
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
TEST(RosHashAuthentication, validAuthentication)
void init(const M_string &remappings)
bool call(MReq &req, MRes &res)
int main(int argc, char **argv)