Newer
Older
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
// Tests for auth_client.c.
#include <stdlib.h>
#include "gtest/gtest.h"
extern "C" {
#include "auth_client.h"
}
static const char *server = NULL;
static const char *ssl_ca = "../authserv/test/testca/public/ca.pem";
static const char *ssl_cert = "../authserv/test/testca/public/certs/client.pem";
static const char *ssl_key = "../authserv/test/testca/private/client.key";
TEST(AuthClientCurlInterface, ErrorConversion) {
int curl_err = 35;
int err = auth_client_err_from_curl(curl_err);
int translated = auth_client_err_to_curl(err);
EXPECT_EQ(curl_err, translated);
}
TEST(AuthClient, NewAndFree) {
auth_client_t ac;
ac = auth_client_new("service", server);
EXPECT_TRUE(ac != NULL);
auth_client_free(ac);
}
TEST(AuthClient, AuthOK) {
auth_client_t ac;
int result;
printf("Connecting to %s...\n", server);
ac = auth_client_new("service", server);
EXPECT_TRUE(ac != NULL);
auth_client_set_certificate(ac, ssl_ca, ssl_cert, ssl_key);
result = auth_client_authenticate(ac, "user", "pass", NULL, "127.0.0.1");
EXPECT_EQ(AC_OK, result) << "Got error: " << auth_client_strerror(result);
auth_client_free(ac);
}
int main(int argc, char **argv) {
server = getenv("AUTH_SERVER");
if (server == NULL) {
server = "localhost:1617";
}
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}