Various corrections for the MEP login feature
[libisds.git] / test / online / login_mep.c
blobf314df94762b9c4fde5cb0e94301cf30e43e7de2
1 #include <unistd.h> /* sleep() */
3 #include "../test.h"
4 #include "isds.h"
5 #include "common.h"
7 /*
8 * The test requires MEP credentials to be stored in ../../test_credentials_mep.
9 * The file must contain the username on the first line and the communication
10 * key on the second line. The key and line must be related to a working account
11 * in the ISDS testing environment.
14 static int test_login_mep(const isds_error error, struct isds_ctx *context,
15 const char *url, const char *username, const char *code,
16 struct isds_mep *mep) {
18 isds_error err = isds_login_mep(context, url, username, code, mep);
19 if (error != err) {
20 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
21 isds_strerror(error), isds_strerror(err),
22 isds_long_message(context));
25 isds_logout(context);
26 PASS_TEST;
29 static int test_login_mep2(const isds_error error1, const isds_error error2,
30 struct isds_ctx *context, const char *url, const char *username,
31 const char *code, struct isds_mep *mep) {
33 isds_error err = isds_login_mep(context, url, username, code, mep);
34 if ((error1 != err) && (error2 != err)) {
35 FAIL_TEST("Wrong return code: must_differ=%s, must_differ=%s, "
36 "returned=%s (%s)",
37 isds_strerror(error1), isds_strerror(error2),
38 isds_strerror(err), isds_long_message(context));
41 isds_logout(context);
42 PASS_TEST;
45 /* Complete login procedure. */
46 static int test_login_mep_cycle(const isds_error error,
47 struct isds_ctx *context, const char *url, const char *username,
48 const char *code, struct isds_mep *mep) {
49 isds_set_timeout(context, 60000);
51 isds_error err = isds_login_mep(context, url, username, code, mep);
52 while (err == IE_PARTIAL_SUCCESS) {
53 sleep(1);
54 err = isds_login_mep(context, url, username, code, mep);
56 if (error != err) {
57 FAIL_TEST("Wrong return code: expected=%s, returned=%s (%s)",
58 isds_strerror(error), isds_strerror(err),
59 isds_long_message(context));
62 isds_logout(context);
63 PASS_TEST;
66 int main(void) {
67 INIT_TEST("login_mep");
69 struct isds_ctx *context = NULL;
70 const char *url = isds_mep_testing_locator;
72 if (IE_SUCCESS != isds_init()) {
73 ABORT_UNIT("isds_init() failed\n");
75 context = isds_ctx_create();
76 if (NULL == context) {
77 ABORT_UNIT("isds_ctx_create() failed\n");
80 struct isds_mep mep = {
81 .app_name = "libisds-test",
82 .intermediate_uri = NULL,
83 .resolution = MEP_RESOLUTION_SUCCESS
86 TEST("invalid context", test_login_mep, IE_INVALID_CONTEXT, NULL,
87 url, username_mep(), code_mep(), &mep);
88 TEST("NULL URL with invalid credentials", test_login_mep, IE_NOT_LOGGED_IN,
89 context, NULL, username_mep(), code_mep(), &mep);
90 TEST("NULL username", test_login_mep, IE_INVAL, context, url, NULL,
91 code_mep(), &mep);
92 TEST("NULL communication code", test_login_mep, IE_INVAL, context, url,
93 username_mep(), NULL, &mep);
94 TEST("NULL MEP context", test_login_mep, IE_INVAL, context, url,
95 username_mep(), code_mep(), NULL);
97 TEST("invalid URL", test_login_mep, IE_NETWORK, context,
98 "invalid://", username_mep(), code_mep(), &mep);
99 /* Direct connection fails on local resolution, connection trough proxy
100 * fails on HTTP code. */
101 TEST("unresolvable host name", test_login_mep2, IE_NETWORK, IE_HTTP,
102 context, "http://unresolvable.example.com/", username_mep(),
103 code_mep(), &mep);
105 TEST("invalid credentials", test_login_mep, IE_NOT_LOGGED_IN, context,
106 url, "7777777", "nbuusr1", &mep);
108 TEST("valid MEP login", test_login_mep_cycle, IE_SUCCESS, context, url,
109 username_mep(), code_mep(), &mep);
111 isds_ctx_free(&context);
112 isds_cleanup();
114 SUM_TEST();