2007-07-14 02:44:01 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2005-01-17 03:53:40 +00:00
|
|
|
/* dbus-auth-util.c Would be in dbus-auth.c, but only used for tests/bus
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2002, 2003, 2004 Red Hat Inc.
|
|
|
|
|
*
|
2023-01-02 15:31:43 +01:00
|
|
|
* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
|
|
|
|
|
*
|
2005-01-17 03:53:40 +00:00
|
|
|
* Licensed under the Academic Free License version 2.1
|
2018-12-17 10:56:38 +00:00
|
|
|
*
|
2005-01-17 03:53:40 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
2018-12-17 10:56:38 +00:00
|
|
|
*
|
2005-01-17 03:53:40 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2009-07-10 19:32:38 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-01-17 03:53:40 +00:00
|
|
|
*
|
|
|
|
|
*/
|
2010-03-19 12:36:49 +01:00
|
|
|
|
|
|
|
|
#include <config.h>
|
2018-09-28 16:27:42 +01:00
|
|
|
|
|
|
|
|
#include "misc-internals.h"
|
|
|
|
|
|
|
|
|
|
#include "dbus/dbus-auth.h"
|
|
|
|
|
#include "dbus/dbus-internals.h"
|
|
|
|
|
#include "dbus/dbus-test-tap.h"
|
|
|
|
|
#include "dbus/dbus-test.h"
|
2005-01-17 03:53:40 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @addtogroup DBusAuth
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
2013-06-28 16:25:54 +08:00
|
|
|
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
|
2005-01-17 03:53:40 +00:00
|
|
|
#include "dbus-auth-script.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
process_test_subdir (const DBusString *test_base_dir,
|
|
|
|
|
const char *subdir)
|
|
|
|
|
{
|
|
|
|
|
DBusString test_directory;
|
|
|
|
|
DBusString filename;
|
|
|
|
|
DBusDirIter *dir;
|
|
|
|
|
dbus_bool_t retval;
|
2007-10-10 11:41:57 +01:00
|
|
|
DBusError error = DBUS_ERROR_INIT;
|
2005-01-17 03:53:40 +00:00
|
|
|
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
dir = NULL;
|
2018-12-17 11:30:00 +00:00
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
if (!_dbus_string_init (&test_directory))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("didn't allocate test_directory");
|
2005-01-17 03:53:40 +00:00
|
|
|
|
|
|
|
|
_dbus_string_init_const (&filename, subdir);
|
2018-12-17 11:30:00 +00:00
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
if (!_dbus_string_copy (test_base_dir, 0,
|
|
|
|
|
&test_directory, 0))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("couldn't copy test_base_dir to test_directory");
|
|
|
|
|
|
2018-12-17 11:30:00 +00:00
|
|
|
if (!_dbus_concat_dir_and_file (&test_directory, &filename))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("couldn't allocate full path");
|
2005-01-17 03:53:40 +00:00
|
|
|
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
if (!_dbus_string_init (&filename))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("didn't allocate filename string");
|
2005-01-17 03:53:40 +00:00
|
|
|
|
|
|
|
|
dir = _dbus_directory_open (&test_directory, &error);
|
|
|
|
|
if (dir == NULL)
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Could not open %s: %s",
|
2005-01-17 03:53:40 +00:00
|
|
|
_dbus_string_get_const_data (&test_directory),
|
|
|
|
|
error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 14:09:59 +00:00
|
|
|
_dbus_test_diag ("Testing %s:", subdir);
|
|
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
while (_dbus_directory_get_next_file (dir, &filename, &error))
|
|
|
|
|
{
|
|
|
|
|
DBusString full_path;
|
2018-12-17 11:30:00 +00:00
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
if (!_dbus_string_init (&full_path))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("couldn't init string");
|
2005-01-17 03:53:40 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("couldn't copy dir to full_path");
|
2005-01-17 03:53:40 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_concat_dir_and_file (&full_path, &filename))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("couldn't concat file to dir");
|
2005-01-17 03:53:40 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_string_ends_with_c_str (&filename, ".auth-script"))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose ("Skipping non-.auth-script file %s\n",
|
|
|
|
|
_dbus_string_get_const_data (&filename));
|
|
|
|
|
_dbus_string_free (&full_path);
|
2022-09-09 16:21:43 +01:00
|
|
|
continue;
|
2005-01-17 03:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-14 14:09:59 +00:00
|
|
|
_dbus_test_diag (" %s", _dbus_string_get_const_data (&filename));
|
|
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
if (!_dbus_auth_script_run (&full_path))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_dbus_string_free (&full_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set (&error))
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("Could not get next file in %s: %s",
|
2005-01-17 03:53:40 +00:00
|
|
|
_dbus_string_get_const_data (&test_directory), error.message);
|
|
|
|
|
dbus_error_free (&error);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
2018-12-17 11:30:00 +00:00
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
retval = TRUE;
|
2018-12-17 11:30:00 +00:00
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
failed:
|
|
|
|
|
|
|
|
|
|
if (dir)
|
|
|
|
|
_dbus_directory_close (dir);
|
|
|
|
|
_dbus_string_free (&test_directory);
|
|
|
|
|
_dbus_string_free (&filename);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_bool_t
|
|
|
|
|
process_test_dirs (const char *test_data_dir)
|
|
|
|
|
{
|
|
|
|
|
DBusString test_directory;
|
|
|
|
|
dbus_bool_t retval;
|
|
|
|
|
|
|
|
|
|
retval = FALSE;
|
2018-12-17 11:30:00 +00:00
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
_dbus_string_init_const (&test_directory, test_data_dir);
|
|
|
|
|
|
|
|
|
|
if (!process_test_subdir (&test_directory, "auth"))
|
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
|
|
retval = TRUE;
|
2018-12-17 11:30:00 +00:00
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
failed:
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&test_directory);
|
2018-12-17 11:30:00 +00:00
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
|
|
|
|
_dbus_auth_test (const char *test_data_dir)
|
|
|
|
|
{
|
2018-12-17 11:30:00 +00:00
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
if (test_data_dir == NULL)
|
|
|
|
|
return TRUE;
|
2018-12-17 11:30:00 +00:00
|
|
|
|
2005-01-17 03:53:40 +00:00
|
|
|
if (!process_test_dirs (test_data_dir))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 16:25:54 +08:00
|
|
|
#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
|