test: Fix a warning about unsued arguments in the online test
[libisds.git] / test / online / login.c
blob8322a8e5d9c57c441c20eef10273f3731f3bbf2b
1 #include "../test.h"
2 #include "isds.h"
3 #include "common.h"
5 static int test_login(const isds_error error, struct isds_ctx *context,
6 const char *url, const char *username, const char *password,
7 const struct isds_pki_credentials *pki_credentials,
8 struct isds_otp *otp) {
9 isds_error err;
11 err = isds_login(context, url, username, password, pki_credentials, otp);
12 if (error != err)
13 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
14 isds_strerror(error), isds_strerror(err),
15 isds_long_message(context));
17 isds_logout(context);
18 PASS_TEST;
21 static int test_login2(const isds_error error1, const isds_error error2,
22 struct isds_ctx *context,
23 const char *url, const char *username, const char *password,
24 const struct isds_pki_credentials *pki_credentials,
25 struct isds_otp *otp) {
27 isds_error err =
28 isds_login(context, url, username, password, pki_credentials, otp);
29 if (err != error1 && err != error2)
30 FAIL_TEST("Wrong return code: must_differ=%s, must_differ=%s, "
31 "returned=%s (%s)",
32 isds_strerror(error1), isds_strerror(error2),
33 isds_strerror(err), isds_long_message(context));
35 isds_logout(context);
36 PASS_TEST;
40 int main(void) {
41 INIT_TEST("login");
43 struct isds_ctx *context = NULL;
44 const char *url = isds_testing_locator;
46 if (isds_init())
47 ABORT_UNIT("isds_init() failed\n");
48 context = isds_ctx_create();
49 if (!context)
50 ABORT_UNIT("isds_ctx_create() failed\n");
53 TEST("invalid context", test_login, IE_INVALID_CONTEXT, NULL,
54 url, username(), password(), NULL, NULL);
55 TEST("NULL url with invalid credentials", test_login, IE_NOT_LOGGED_IN,
56 context, NULL, username(), password(), NULL, NULL);
57 TEST("NULL username", test_login, IE_INVAL, context,
58 url, NULL, password(), NULL, NULL);
59 TEST("NULL password", test_login, IE_INVAL, context,
60 url, username(), NULL, NULL, NULL);
62 TEST("invalid URL", test_login, IE_NETWORK, context,
63 "invalid://", username(), password(), NULL, NULL);
64 /* Direct connection fails on local resolution, connection trough proxy
65 * failes on HTTP code */
66 TEST("unresolvable host name", test_login2, IE_NETWORK, IE_HTTP, context,
67 "http://unresolvable.example.com/", username(), password(),
68 NULL, NULL);
70 TEST("invalid credentials", test_login, IE_NOT_LOGGED_IN, context,
71 url, "7777777", "nbuusr1", NULL, NULL);
73 TEST("valid login", test_login, IE_SUCCESS, context,
74 url, username(), password(), NULL, NULL);
76 isds_ctx_free(&context);
77 isds_cleanup();
79 SUM_TEST();