25 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
27 #include "dbus-auth-script.h"
31 #include "dbus-auth.h"
32 #include "dbus-string.h"
33 #include "dbus-hash.h"
34 #include "dbus-credentials.h"
35 #include "dbus-internals.h"
37 #include "test/test-utils.h"
107 else if (b ==
' ' || b ==
'\n' || b ==
'\t')
126 int first_a_blank, first_b_blank;
131 if (first_a_blank != first_b_blank)
138 auth_state_from_string (
const DBusString *str)
141 return DBUS_AUTH_STATE_WAITING_FOR_INPUT;
143 return DBUS_AUTH_STATE_WAITING_FOR_MEMORY;
145 return DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND;
147 return DBUS_AUTH_STATE_NEED_DISCONNECT;
149 return DBUS_AUTH_STATE_AUTHENTICATED;
151 return DBUS_AUTH_STATE_INVALID;
155 auth_state_to_string (DBusAuthState state)
159 case DBUS_AUTH_STATE_WAITING_FOR_INPUT:
160 return "WAITING_FOR_INPUT";
161 case DBUS_AUTH_STATE_WAITING_FOR_MEMORY:
162 return "WAITING_FOR_MEMORY";
163 case DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND:
164 return "HAVE_BYTES_TO_SEND";
165 case DBUS_AUTH_STATE_NEED_DISCONNECT:
166 return "NEED_DISCONNECT";
167 case DBUS_AUTH_STATE_AUTHENTICATED:
168 return "AUTHENTICATED";
169 case DBUS_AUTH_STATE_INVALID:
181 int i, j, k, count, end;
188 for (count = 0; i < end; count++)
200 for (k = 0; k < count; k++)
205 if (array[k] ==
NULL)
212 array[k][j - i] =
'\0';
222 auth_set_unix_credentials(
DBusAuth *auth,
229 if (credentials ==
NULL)
258 _dbus_auth_script_run (
const DBusString *filename)
294 _dbus_warn (
"Getting contents of %s failed: %s",
300 state = DBUS_AUTH_STATE_NEED_DISCONNECT;
310 _dbus_string_delete_leading_blanks (&line);
315 DBUS_AUTH_STATE_HAVE_BYTES_TO_SEND)
351 fprintf (stderr,
"skipping unix only auth script\n");
367 fprintf (stderr,
"skipping windows only auth script\n");
379 _dbus_warn (
"already created a DBusAuth (CLIENT or SERVER given twice)");
405 _dbus_warn (
"no memory for setting credentials");
421 _dbus_warn (
"already created a DBusAuth (CLIENT or SERVER given twice)");
447 _dbus_warn (
"no memory for setting credentials");
458 else if (auth ==
NULL)
475 "SILLY_CREDENTIALS"))
484 _dbus_string_delete_first_word (&line);
485 mechs = split_string (&line);
494 _dbus_string_delete_first_word (&line);
502 if (!append_quoted_string (&to_send, &line))
504 _dbus_warn (
"failed to append quoted string line %d",
514 _dbus_warn (
"failed to append \\r\\n from line %d",
537 if (!_dbus_test_append_different_uid (&uid))
546 (
int) strlen (
"WRONG_USERID_HEX"));
550 _dbus_warn (
"no memory to subst WRONG_USERID_HEX");
559 "USERID_HEX", &where))
592 "WRONG_USERNAME_HEX", &where))
606 if (!_dbus_test_append_different_username (&username))
615 (
int) strlen (
"WRONG_USERNAME_HEX"));
620 _dbus_warn (
"no memory to subst WRONG_USERNAME_HEX");
631 _dbus_warn (
"WRONG_USERNAME_HEX cannot be used on Windows");
637 "USERNAME_HEX", &where))
661 _dbus_warn (
"no memory to subst USERNAME_HEX");
678 _dbus_warn (
"not enough memory to call bytes_received, or can't add bytes to auth object already in end state");
692 DBusAuthState expected;
694 _dbus_string_delete_first_word (&line);
696 expected = auth_state_from_string (&line);
699 _dbus_warn (
"bad auth state given to EXPECT_STATE");
703 if (expected != state)
705 _dbus_warn (
"expected auth state %s but got %s on line %d",
706 auth_state_to_string (expected),
707 auth_state_to_string (state),
717 _dbus_string_delete_first_word (&line);
721 _dbus_warn (
"no mem to allocate string received");
727 _dbus_warn (
"no line popped from the DBusAuth being tested, expected command %s on line %d",
733 if (!same_first_word (&received, &line))
735 _dbus_warn (
"line %d expected command '%s' and got '%s'",
751 _dbus_string_delete_first_word (&line);
755 _dbus_warn (
"no mem to allocate string expected");
759 if (!append_quoted_string (&expected, &line))
761 _dbus_warn (
"failed to append quoted string line %d",
776 _dbus_warn (
"Expected unused bytes '%s' and have '%s'",
784 "EXPECT_HAVE_NO_CREDENTIALS"))
791 _dbus_warn (
"Expected anonymous login or failed login, but some credentials were authorized");
796 "EXPECT_HAVE_SOME_CREDENTIALS"))
803 _dbus_warn (
"Expected to have some credentials, but we don't");
812 _dbus_string_delete_first_word (&line);
816 _dbus_warn (
"no mem to allocate string expected");
820 if (!append_quoted_string (&expected, &line))
822 _dbus_warn (
"failed to append quoted string line %d",
837 _dbus_warn (
"Expected exact string '%s' and have '%s'",
851 _dbus_warn (
"couldn't process line %d \"%s\"",
859 _dbus_warn (
"Auth script is bogus, did not even have CLIENT or SERVER");
862 else if (state == DBUS_AUTH_STATE_AUTHENTICATED)
870 _dbus_warn (
"did not expect unused bytes (scripts must specify explicitly if they are expected)");
877 _dbus_warn (
"script did not have EXPECT_ statements for all the data received from the DBusAuth");