static void test_sc_initialize_ns_groups() { if (geteuid() != 0) { g_test_skip("this test needs to run as root"); return; } // NOTE: this is g_test_subprocess aware! const char *ns_dir = sc_test_use_fake_ns_dir(); g_test_queue_destroy(unmount_dir, (char *)ns_dir); if (g_test_subprocess()) { // Initialize namespace groups using a fake directory. sc_initialize_ns_groups(); // Check that the fake directory is now a private mount. g_assert_true(sc_is_ns_group_dir_private()); // Check that the lock file did not leak unclosed. // Construct the name of the lock file char *lock_file __attribute__ ((cleanup(sc_cleanup_string))) = NULL; lock_file = g_strdup_printf("%s/%s", sc_ns_dir, SC_NS_LOCK_FILE); // Attempt to open and lock the lock file. int lock_fd __attribute__ ((cleanup(sc_cleanup_close))) = -1; lock_fd = open(lock_file, O_RDWR | O_CLOEXEC | O_NOFOLLOW); g_assert_cmpint(lock_fd, !=, -1); // The non-blocking lock operation should not fail int err = flock(lock_fd, LOCK_EX | LOCK_NB); g_assert_cmpint(err, ==, 0); return; } g_test_trap_subprocess(NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDERR); g_test_trap_assert_passed(); }
static void setup (Fixture *f, gconstpointer context) { const Config *config = context; gchar *address; f->ctx = test_main_context_get (); f->ge = NULL; dbus_error_init (&f->e); address = test_get_dbus_daemon (config ? config->config_file : NULL, TEST_USER_MESSAGEBUS, NULL, &f->daemon_pid); if (address == NULL) { f->skip = TRUE; return; } f->conn = test_try_connect_to_bus_as_user (f->ctx, address, config ? config->user : TEST_USER_ME, &f->ge); if (f->conn == NULL && g_error_matches (f->ge, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) { g_test_skip (f->ge->message); g_clear_error (&f->ge); f->skip = TRUE; } g_assert_no_error (f->ge); g_free (address); }
static void test_sc_is_ns_group_dir_private() { if (geteuid() != 0) { g_test_skip("this test needs to run as root"); return; } const char *ns_dir = sc_test_use_fake_ns_dir(); g_test_queue_destroy(unmount_dir, (char *)ns_dir); if (g_test_subprocess()) { // The temporary directory should not be private initially g_assert_false(sc_is_ns_group_dir_private()); /// do what "mount --bind /foo /foo; mount --make-private /foo" does. int err; err = mount(ns_dir, ns_dir, NULL, MS_BIND, NULL); g_assert_cmpint(err, ==, 0); err = mount(NULL, ns_dir, NULL, MS_PRIVATE, NULL); g_assert_cmpint(err, ==, 0); // The temporary directory should now be private g_assert_true(sc_is_ns_group_dir_private()); return; } g_test_trap_subprocess(NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDERR); g_test_trap_assert_passed(); }
GRAPHENE_TEST_UNIT_END GRAPHENE_TEST_UNIT_BEGIN (frustum_matrix_contains_point) { #if defined(GRAPHENE_USE_GCC) # if GLIB_CHECK_VERSION (2, 38, 0) g_test_skip ("Disabled when using GCC vectors"); # else if (g_test_verbose ()) g_test_message ("Disabled when using GCC vectors"); # endif #else graphene_matrix_t m; graphene_frustum_t f; graphene_point3d_t p; graphene_matrix_init_frustum (&m, -1.f, 1.f, -1.f, 1.f, 1.f, 100.f); graphene_frustum_init_from_matrix (&f, &m); g_assert_false (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, 0.f, 0.f, 0.f))); g_assert_true (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, 0.f, 0.f, -50.f))); g_assert_true (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, 0.f, 0.f, -1.001f))); g_assert_true (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, -1.f, -1.f, -1.001f))); g_assert_false (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, -1.1f, -1.1f, -1.001f))); g_assert_true (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, 1.f, 1.f, -1.001f))); g_assert_false (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, 1.1f, 1.1f, -1.001f))); #endif }
static int test_common_start(test_t * test, x11spice_server_t * server, xdummy_t *xserver, gconstpointer user_data) { int rc; if (!xserver->running) { g_test_skip("No server"); return -1; } test->xserver = xserver; test->name = user_data; test->logfile = g_test_build_filename(G_TEST_BUILT, "run", test->name, "test.log", NULL); if (!test->logfile) { g_warning("Failed to create logfile"); g_test_fail(); return -1; } memset(server, 0, sizeof(*server)); rc = x11spice_start(server, test); if (rc) { g_warning("Failed to start x11spice"); g_test_fail(); return rc; } return 0; }
static void test_xattr_races (void) { /* If for some reason we're built in a VM which only has one vcpu, let's still * at least make the test do something. */ /* FIXME - this deadlocks for me on 4.9.4-201.fc25.x86_64, whether * using overlayfs or xfs as source/dest. */ const guint nprocs = MAX (4, g_get_num_processors ()); struct XattrWorker wdata[nprocs]; GThread *threads[nprocs]; g_autoptr(GError) local_error = NULL; GError **error = &local_error; g_auto(GLnxTmpDir) tmpdir = { 0, }; g_autofree char *tmpdir_path = g_strdup_printf ("%s/libglnx-xattrs-XXXXXX", getenv ("TMPDIR") ?: "/var/tmp"); guint nread = 0; if (!glnx_mkdtempat (AT_FDCWD, tmpdir_path, 0700, &tmpdir, error)) goto out; /* Support people building/testing on tmpfs https://github.com/flatpak/flatpak/issues/686 */ if (fsetxattr (tmpdir.fd, "user.test", "novalue", strlen ("novalue"), 0) < 0) { if (errno == EOPNOTSUPP) { g_test_skip ("no xattr support"); return; } else { glnx_set_error_from_errno (error); goto out; } } for (guint i = 0; i < nprocs; i++) { struct XattrWorker *worker = &wdata[i]; worker->dfd = tmpdir.fd; worker->is_writer = i % 2 == 0; threads[i] = g_thread_new (NULL, xattr_thread, worker); } for (guint i = 0; i < nprocs; i++) { if (wdata[i].is_writer) (void) g_thread_join (threads[i]); else nread += GPOINTER_TO_UINT (g_thread_join (threads[i])); } g_print ("Read %u xattrs race free!\n", nread); out: g_assert_no_error (local_error); }
gboolean test_check_tcp_works (void) { #ifdef DBUS_UNIX /* In pathological container environments, we might not have a * working 127.0.0.1 */ int res; struct addrinfo *addrs = NULL; struct addrinfo hints; int saved_errno; _DBUS_ZERO (hints); #ifdef AI_ADDRCONFIG hints.ai_flags |= AI_ADDRCONFIG; #endif hints.ai_flags = AI_ADDRCONFIG; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; res = getaddrinfo ("127.0.0.1", "0", &hints, &addrs); saved_errno = errno; if (res != 0) { const gchar *system_message; gchar *skip_message; #ifdef EAI_SYSTEM if (res == EAI_SYSTEM) system_message = g_strerror (saved_errno); else #endif system_message = gai_strerror (res); skip_message = g_strdup_printf ("Name resolution does not work here: " "getaddrinfo(\"127.0.0.1\", \"0\", " "{flags=ADDRCONFIG, family=INET," "socktype=STREAM, protocol=TCP}): " "%s", system_message); g_test_skip (skip_message); free (skip_message); } if (addrs != NULL) freeaddrinfo (addrs); return (res == 0); #else /* Assume that on Windows, TCP always works */ return TRUE; #endif }
static void fu_wac_firmware_parse_func (void) { DfuElement *element; DfuImage *image; gboolean ret; g_autofree gchar *fn = NULL; g_autoptr(DfuFirmware) firmware = dfu_firmware_new (); g_autoptr(GBytes) blob_block = NULL; g_autoptr(GBytes) bytes = NULL; g_autoptr(GError) error = NULL; /* parse the test file */ fn = fu_test_get_filename (TESTDATADIR, "test.wac"); if (fn == NULL) { g_test_skip ("no data file found"); return; } bytes = fu_common_get_contents_bytes (fn, &error); g_assert_no_error (error); g_assert_nonnull (bytes); ret = fu_wac_firmware_parse_data (firmware, bytes, DFU_FIRMWARE_PARSE_FLAG_NONE, &error); g_assert_no_error (error); g_assert_true (ret); /* get image data */ image = dfu_firmware_get_image (firmware, 0); g_assert_nonnull (image); element = dfu_image_get_element_default (image); g_assert_nonnull (element); /* get block */ blob_block = dfu_element_get_contents_chunk (element, 0x8008000, 1024, &error); g_assert_no_error (error); g_assert_nonnull (blob_block); fu_wac_buffer_dump ("IMG", FU_WAC_REPORT_ID_MODULE, g_bytes_get_data (blob_block, NULL), g_bytes_get_size (blob_block)); }
// Sanity check, ensure that the namespace filesystem identifier is what we // expect, aka NSFS_MAGIC. static void test_nsfs_fs_id() { struct utsname uts; if (uname(&uts) < 0) { g_test_message("cannot use uname(2)"); g_test_fail(); return; } int major, minor; if (sscanf(uts.release, "%d.%d", &major, &minor) != 2) { g_test_message("cannot use sscanf(2) to parse kernel release"); g_test_fail(); return; } if (major < 3 || (major == 3 && minor < 19)) { g_test_skip("this test needs kernel 3.19+"); return; } struct statfs buf; int err = statfs("/proc/self/ns/mnt", &buf); g_assert_cmpint(err, ==, 0); g_assert_cmpint(buf.f_type, ==, NSFS_MAGIC); }
static void clutter_test_func_wrapper (gconstpointer data_) { const ClutterTestData *data = data_; /* ensure that the previous test state has been cleaned up */ g_assert_null (test_environ->stage); if (test_environ->no_display) { g_test_skip ("No DISPLAY set"); goto out; } if (data->test_data != NULL) { GTestDataFunc test_func = data->test_func; test_func (data->test_data); } else { GTestFunc test_func = data->test_func; test_func (); } out: if (data->test_notify != NULL) data->test_notify (data->test_data); if (test_environ->stage != NULL) { clutter_actor_destroy (test_environ->stage); g_assert_null (test_environ->stage); } }
static bool wait_for_fds(TestServer *s) { gint64 end_time; bool got_region; int i; g_mutex_lock(&s->data_mutex); end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; while (!s->fds_num) { if (!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) { /* timeout has passed */ g_assert(s->fds_num); break; } } /* check for sanity */ g_assert_cmpint(s->fds_num, >, 0); g_assert_cmpint(s->fds_num, ==, s->memory.nregions); g_mutex_unlock(&s->data_mutex); got_region = false; for (i = 0; i < s->memory.nregions; ++i) { VhostUserMemoryRegion *reg = &s->memory.regions[i]; if (reg->guest_phys_addr == 0) { got_region = true; break; } } if (!got_region) { g_test_skip("No memory at address 0x0"); } return got_region; }
static gchar * spawn_dbus_daemon (const gchar *binary, const gchar *configuration, const gchar *listen_address, TestUser user, const gchar *runtime_dir, GPid *daemon_pid) { GError *error = NULL; GString *address; gint address_fd; GPtrArray *argv; gchar **envp; #ifdef DBUS_UNIX const struct passwd *pwd = NULL; #endif if (user != TEST_USER_ME) { #ifdef DBUS_UNIX if (getuid () != 0) { g_test_skip ("cannot use alternative uid when not uid 0"); return NULL; } switch (user) { case TEST_USER_ROOT: break; case TEST_USER_MESSAGEBUS: pwd = getpwnam (DBUS_USER); if (pwd == NULL) { gchar *message = g_strdup_printf ("user '%s' does not exist", DBUS_USER); g_test_skip (message); g_free (message); return NULL; } break; case TEST_USER_OTHER: pwd = getpwnam (DBUS_TEST_USER); if (pwd == NULL) { gchar *message = g_strdup_printf ("user '%s' does not exist", DBUS_TEST_USER); g_test_skip (message); g_free (message); return NULL; } break; case TEST_USER_ME: /* cannot get here, fall through */ default: g_assert_not_reached (); } #else g_test_skip ("cannot use alternative uid on Windows"); return NULL; #endif } envp = g_get_environ (); if (runtime_dir != NULL) envp = g_environ_setenv (envp, "XDG_RUNTIME_DIR", runtime_dir, TRUE); argv = g_ptr_array_new_with_free_func (g_free); g_ptr_array_add (argv, g_strdup (binary)); g_ptr_array_add (argv, g_strdup (configuration)); g_ptr_array_add (argv, g_strdup ("--nofork")); g_ptr_array_add (argv, g_strdup ("--print-address=1")); /* stdout */ if (listen_address != NULL) g_ptr_array_add (argv, g_strdup (listen_address)); #ifdef DBUS_UNIX g_ptr_array_add (argv, g_strdup ("--systemd-activation")); #endif g_ptr_array_add (argv, NULL); g_spawn_async_with_pipes (NULL, /* working directory */ (gchar **) argv->pdata, envp, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, #ifdef DBUS_UNIX child_setup, (gpointer) pwd, #else NULL, NULL, #endif daemon_pid, NULL, /* child's stdin = /dev/null */ &address_fd, NULL, /* child's stderr = our stderr */ &error); g_assert_no_error (error); g_ptr_array_free (argv, TRUE); g_strfreev (envp); address = g_string_new (NULL); /* polling until the dbus-daemon writes out its address is a bit stupid, * but at least it's simple, unlike dbus-launch... in principle we could * use select() here, but life's too short */ while (1) { gssize bytes; gchar buf[4096]; gchar *newline; bytes = read (address_fd, buf, sizeof (buf)); if (bytes > 0) g_string_append_len (address, buf, bytes); newline = strchr (address->str, '\n'); if (newline != NULL) { if ((newline > address->str) && ('\r' == newline[-1])) newline -= 1; g_string_truncate (address, newline - address->str); break; } g_usleep (G_USEC_PER_SEC / 10); } g_close (address_fd, NULL); return g_string_free (address, FALSE); }
gchar * test_get_dbus_daemon (const gchar *config_file, TestUser user, const gchar *runtime_dir, GPid *daemon_pid) { gchar *dbus_daemon; gchar *arg; const gchar *listen_address = NULL; gchar *address; /* we often have to override this because on Windows, the default may be * autolaunch:, which is globally-scoped and hence unsuitable for * regression tests */ listen_address = "--address=" TEST_LISTEN; if (config_file != NULL) { if (g_getenv ("DBUS_TEST_DATA") == NULL) { g_test_message ("set DBUS_TEST_DATA to a directory containing %s", config_file); g_test_skip ("DBUS_TEST_DATA not set"); return NULL; } arg = g_strdup_printf ( "--config-file=%s/%s", g_getenv ("DBUS_TEST_DATA"), config_file); /* The configuration file is expected to give a suitable address, * do not override it */ listen_address = NULL; } else if (g_getenv ("DBUS_TEST_DATADIR") != NULL) { arg = g_strdup_printf ("--config-file=%s/dbus-1/session.conf", g_getenv ("DBUS_TEST_DATADIR")); } else if (g_getenv ("DBUS_TEST_DATA") != NULL) { arg = g_strdup_printf ( "--config-file=%s/valid-config-files/session.conf", g_getenv ("DBUS_TEST_DATA")); } else { arg = g_strdup ("--session"); } dbus_daemon = g_strdup (g_getenv ("DBUS_TEST_DAEMON")); if (dbus_daemon == NULL) dbus_daemon = g_strdup ("dbus-daemon"); if (g_getenv ("DBUS_TEST_DAEMON_ADDRESS") != NULL) { if (config_file != NULL || user != TEST_USER_ME) { g_test_skip ("cannot use DBUS_TEST_DAEMON_ADDRESS for " "unusally-configured dbus-daemon"); address = NULL; } else { address = g_strdup (g_getenv ("DBUS_TEST_DAEMON_ADDRESS")); } } else { address = spawn_dbus_daemon (dbus_daemon, arg, listen_address, user, runtime_dir, daemon_pid); } g_free (dbus_daemon); g_free (arg); return address; }
static void test_hash_func(const struct hash_func_s *func) { if (!func->supported) { g_test_skip("not supported"); return; } bool tested = false; #define t(FUNC, TEXT, DIGEST) \ if (func->id == G_PASTE(HASH_FUNC_, FUNC)) { \ select_func(func->id, true); \ test_hash_func_digest(func->id, TEXT, NULL, DIGEST); \ tested = true; \ } t(ADLER32, "", "00000001"); t(BLAKE2B, "", "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce"); t(BLAKE2S, "", "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9"); t(BLAKE2BP, "", "b5ef811a8038f70b628fa8b294daae7492b1ebe343a80eaabbf1f6ae664dd67b9d90b0120791eab81dc96985f28849f6a305186a85501b405114bfa678df9380"); t(BLAKE2SP, "", "dd0e891776933f43c7d032b08a917e25741f8aa9a12c12e1cac8801500f2ca4f"); t(CRC32, "", "00000000"); t(GOST, "", "ce85b99cc46752fffee35cab9a7b0278abb4c2d2055cff685af4912c49490f8d"); t(HAVAL128_3, "", "c68f39913f901f3ddf44c707357a7d70"); t(HAVAL160_3, "", "d353c3ae22a25401d257643836d7231a9a95f953"); t(HAVAL192_3, "", "e9c48d7903eaf2a91c5b350151efcb175c0fc82de2289a4e"); t(HAVAL224_3, "", "c5aae9d47bffcaaf84a8c6e7ccacd60a0dd1932be7b1a192b9214b6d"); t(HAVAL256_3, "", "4f6938531f0bc8991f62da7bbd6f7de3fad44562b8c6f4ebf146d5b4e46f7c17"); t(MD2, "", "8350e5a3e24c153df2275c9f80692773"); t(MD4, "", "31d6cfe0d16ae931b73c59d7e0c089c0"); t(MD5, "", "d41d8cd98f00b204e9800998ecf8427e"); t(MD6_224, "", "d2091aa2ad17f38c51ade2697f24cafc3894c617c77ffe10fdc7abcb"); t(MD6_256, "", "bca38b24a804aa37d821d31af00f5598230122c5bbfc4c4ad5ed40e4258f04ca"); t(MD6_384, "", "b0bafffceebe856c1eff7e1ba2f539693f828b532ebf60ae9c16cbc3499020401b942ac25b310b2227b2954ccacc2f1f"); t(MD6_512, "", "6b7f33821a2c060ecdd81aefddea2fd3c4720270e18654f4cb08ece49ccb469f8beeee7c831206bd577f9f2630d9177979203a9489e47e04df4e6deaa0f8e0c0"); t(RIPEMD128, "", "cdf26213a150dc3ecb610f18f6b38b46"); t(RIPEMD160, "", "9c1185a5c5e9fc54612808977ee8f548b2258d31"); t(RIPEMD256, "", "02ba4c4e5f8ecd1877fc52d64d30e37a2d9774fb1e5d026380ae0168e3c5522d"); t(RIPEMD320, "", "22d65d5661536cdc75c1fdf5c6de7b41b9f27325ebc61e8557177d705a0ec880151c3a32a00899b8"); t(SHA1, "", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); t(SHA224, "", "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f"); t(SHA256, "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); t(SHA384, "", "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"); t(SHA512, "", "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"); t(SHA3_224, "", "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7"); t(SHA3_256, "", "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a"); t(SHA3_384, "", "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004"); t(SHA3_512, "", "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26"); t(SNEFRU128, "", "8617f366566a011837f4fb4ba5bedea2"); t(SNEFRU256, "", "8617f366566a011837f4fb4ba5bedea2b892f3ed8b894023d16ae344b2be5881"); t(TIGER192, "", "24f0130c63ac933216166e76b1bb925ff373de2d49584e7a"); t(WHIRLPOOL, "", "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3"); t(CRC32, "The quick brown fox jumps over the lazy dog", "414fa339"); t(BLAKE2B, "The quick brown fox jumps over the lazy dog", "a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918"); t(GOST, "The quick brown fox jumps over the lazy dog", "77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294"); t(MD2, "The quick brown fox jumps over the lazy dog", "03d85a0d629d2c442e987525319fc471"); t(MD4, "The quick brown fox jumps over the lazy dog", "1bee69a46ba811185c194762abaeae90"); t(MD5, "The quick brown fox jumps over the lazy dog", "9e107d9d372bb6826bd81d3542a419d6"); t(RIPEMD160, "The quick brown fox jumps over the lazy dog", "37f332f68db77bd9d7edd4969571ad671cf9dd3b"); t(SHA1, "The quick brown fox jumps over the lazy dog", "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"); t(SHA224, "The quick brown fox jumps over the lazy dog", "730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525"); t(SHA256, "The quick brown fox jumps over the lazy dog", "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"); t(SHA384, "The quick brown fox jumps over the lazy dog", "ca737f1014a48f4c0b6dd43cb177b0afd9e5169367544c494011e3317dbf9a509cb1e5dc1e85a941bbee3d7f2afbc9b1"); t(SHA512, "The quick brown fox jumps over the lazy dog", "07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb642e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6"); t(SHA3_224, "The quick brown fox jumps over the lazy dog", "d15dadceaa4d5d7bb3b48f446421d542e08ad8887305e28d58335795"); t(SHA3_256, "The quick brown fox jumps over the lazy dog", "69070dda01975c8c120c3aada1b282394e7f032fa9cf32f4cb2259a0897dfc04"); t(SHA3_384, "The quick brown fox jumps over the lazy dog", "7063465e08a93bce31cd89d2e3ca8f602498696e253592ed26f07bf7e703cf328581e1471a7ba7ab119b1a9ebdf8be41"); t(SHA3_512, "The quick brown fox jumps over the lazy dog", "01dedd5de4ef14642445ba5f5b97c15e47b9ad931326e4b0727cd94cefc44fff23f07bf543139939b49128caf436dc1bdee54fcb24023a08d9403f9b4bf0d450"); t(SNEFRU128, "The quick brown fox jumps over the lazy dog", "59d9539d0dd96d635b5bdbd1395bb86c"); t(SNEFRU256, "The quick brown fox jumps over the lazy dog", "674caa75f9d8fd2089856b95e93a4fb42fa6c8702f8980e11d97a142d76cb358"); t(WHIRLPOOL, "The quick brown fox jumps over the lazy dog", "b97de512e91e3828b40d2b0fdce9ceb3c4a71f9bea8d88e75c4fa854df36725fd2b52eb6544edcacd6f8beddfea403cb55ae31f03ad62a5ef54e42ee82c3fb35"); t(RIPEMD128, "message digest", "9e327b3d6e523062afc1132d7df9d1b8"); t(RIPEMD160, "message digest", "5d0689ef49d2fae572b881b123a85ffa21595f36"); t(RIPEMD256, "message digest", "87e971759a1ce47a514d5c914c392c9018c7c46bc14465554afcdf54a5070c0e"); t(RIPEMD320, "message digest", "3a8e28502ed45d422f68844f9dd316e7b98533fa3f2a91d29f84d425c88d6b4eff727df66a7c0197"); t(WHIRLPOOL, "message digest", "378c84a4126e2dc6e56dcc7458377aac838d00032230f53ce1f5700c0ffb4d3b8421557659ef55c106b4b52ac5a4aaa692ed920052838f3362e86dbd37a8903e"); t(ADLER32, "abc", "024d0127"); t(CRC32, "abc", "352441c2"); t(TIGER192, "abc", "f258c1e88414ab2a527ab541ffc5b8bf935f7b951c132951"); #undef t if (!tested) g_test_incomplete("not implemented"); select_func(func->id, false); }
DBusConnection * test_connect_to_bus_as_user (TestMainContext *ctx, const char *address, TestUser user) { /* For now we only do tests like this on Linux, because I don't know how * safe this use of setresuid() is on other platforms */ #if defined(HAVE_GETRESUID) && defined(HAVE_SETRESUID) && defined(__linux__) uid_t ruid, euid, suid; const struct passwd *pwd; DBusConnection *conn; const char *username; switch (user) { case TEST_USER_ME: return test_connect_to_bus (ctx, address); case TEST_USER_ROOT: username = "******"; break; case TEST_USER_MESSAGEBUS: username = DBUS_USER; break; case TEST_USER_OTHER: username = DBUS_TEST_USER; break; default: g_return_val_if_reached (NULL); } if (getresuid (&ruid, &euid, &suid) != 0) g_error ("getresuid: %s", g_strerror (errno)); if (ruid != 0 || euid != 0 || suid != 0) { g_test_message ("not uid 0 (ruid=%ld euid=%ld suid=%ld)", (unsigned long) ruid, (unsigned long) euid, (unsigned long) suid); g_test_skip ("not uid 0"); return NULL; } pwd = getpwnam (username); if (pwd == NULL) { g_test_message ("getpwnam(\"%s\"): %s", username, g_strerror (errno)); g_test_skip ("not uid 0"); return NULL; } /* Impersonate the desired user while we connect to the bus. * This should work, because we're root. */ if (setresuid (pwd->pw_uid, pwd->pw_uid, 0) != 0) g_error ("setresuid(%ld, (same), 0): %s", (unsigned long) pwd->pw_uid, g_strerror (errno)); conn = test_connect_to_bus (ctx, address); /* go back to our saved uid */ if (setresuid (0, 0, 0) != 0) g_error ("setresuid(0, 0, 0): %s", g_strerror (errno)); return conn; #else switch (user) { case TEST_USER_ME: return test_connect_to_bus (ctx, address); default: g_test_skip ("setresuid() not available, or unsure about " "credentials-passing semantics on this platform"); return NULL; } #endif }