/*
Authors:
Jakub Hrozek <jhrozek@redhat.com>
Copyright (C) 2013 Red Hat
SSSD tests: Dynamic DNS tests
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <talloc.h>
#include <tevent.h>
#include <errno.h>
#include <popt.h>
#include <unistd.h>
#include <ifaddrs.h>
/* In order to access opaque types */
#include "providers/be_dyndns.c"
#include "tests/cmocka/common_mock.h"
#include "tests/cmocka/common_mock_be.h"
#include "src/providers/be_dyndns.h"
enum mock_nsupdate_states {
};
struct dyndns_test_ctx {
int child_status;
int child_retval;
};
{
int err;
switch (dyndns_test_ctx->state) {
case MOCK_NSUPDATE_OK:
err = 0;
break;
case MOCK_NSUPDATE_ERR:
err = 1;
break;
case MOCK_NSUPDATE_TIMEOUT:
err = 2;
sleep(3);
break;
default:
err = 255;
break;
}
}
{
char *name;
char *straddr;
int ad_family;
void *dst;
straddr = sss_mock_ptr_type(char *);
goto fail;
}
ad_family = sss_mock_type(int);
goto fail;
}
if (ifap_prev) {
} else {
}
goto fail;
}
/* Do not alocate directly on ifap->ifa_addr to
* avoid alignment warnings */
} else {
goto fail;
}
goto fail;
}
} else {
goto fail;
}
/* convert straddr into ifa_addr */
goto fail;
}
}
return 0;
fail:
return -1;
}
{
}
{
}
int af_family)
{
if (ifname) {
}
if (straddr) {
}
}
{
}
{
/* There must be only one address with the correct value */
}
{
/* ip addresses are returned in different order */
/* ip addresses are returned in different order */
}
{
&addrlist);
}
{
int i;
char **output;
struct {
const char* addr;
int af;
} input[] = {
{"2001:cdba::555", AF_INET6},
{"192.168.0.1", AF_INET},
{"192.168.0.2", AF_INET},
{"2001:cdba::444", AF_INET6}
};
for (i = 0; i < size; i++) {
}
for (i = 0; i < size; i++) {
/* addresses are returned in reversed order */
}
}
{
char *msg;
int i;
/* getifaddrs is called twice in sss_get_dualstack_addresses() */
for (i = 0; i < 2; i++) {
}
&addrlist);
"\nupdate delete bran_stark. in A\n"
"update add bran_stark. 1234 in A 192.168.0.2\n"
"send\n"
"update delete bran_stark. in AAAA\n"
"update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
"send\n");
/* fallback case realm and server */
"bran_stark",
"server Winterfell\n"
"realm North\n"
"update delete bran_stark. in A\n"
"update add bran_stark. 1234 in A 192.168.0.2\n"
"send\n"
"update delete bran_stark. in AAAA\n"
"update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
"send\n");
/* just realm */
"bran_stark",
"realm North\n"
"update delete bran_stark. in A\n"
"update add bran_stark. 1234 in A 192.168.0.2\n"
"send\n"
"update delete bran_stark. in AAAA\n"
"update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
"send\n");
/* just server */
"bran_stark",
"server Winterfell\n"
"\n"
"update delete bran_stark. in A\n"
"update add bran_stark. 1234 in A 192.168.0.2\n"
"send\n"
"update delete bran_stark. in AAAA\n"
"update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
"send\n");
/* remove just A */
1234, DYNDNS_REMOVE_A,
"\nupdate delete bran_stark. in A\n"
"update add bran_stark. 1234 in A 192.168.0.2\n"
"send\n"
"update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
"send\n");
/* remove just AAAA */
1234, DYNDNS_REMOVE_AAAA,
"\nupdate add bran_stark. 1234 in A 192.168.0.2\n"
"send\n"
"update delete bran_stark. in AAAA\n"
"update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
"send\n");
}
{
char *msg;
int i;
/* getifaddrs is called twice in sss_get_dualstack_addresses() */
for (i = 0; i < 2; i++) {
}
&addrlist);
"\nupdate delete bran_stark. in A\n"
"update add bran_stark. 1234 in A 192.168.0.1\n"
"update add bran_stark. 1234 in A 192.168.0.2\n"
"send\n"
"update delete bran_stark. in AAAA\n"
"update add bran_stark. 1234 in AAAA 2001:cdba::444\n"
"update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
"send\n");
}
{
char *msg;
int i;
/* getifaddrs is called twice in sss_get_dualstack_addresses() */
for (i = 0; i < 2; i++) {
}
&addrlist);
"\nupdate delete bran_stark. in A\n"
"update add bran_stark. 1234 in A 192.168.0.1\n"
"update add bran_stark. 1234 in A 192.168.0.2\n"
"send\n"
"update delete bran_stark. in AAAA\n"
"send\n");
}
{
char *msg;
int i;
/* getifaddrs is called twice in sss_get_dualstack_addresses() */
for (i = 0; i < 2; i++) {
}
&addrlist);
"\nupdate delete bran_stark. in A\n"
"send\n"
"update delete bran_stark. in AAAA\n"
"update add bran_stark. 1234 in AAAA 2001:cdba::444\n"
"update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
"send\n");
}
{
int i;
/* getifaddrs is called twice in sss_get_dualstack_addresses() */
for (i = 0; i < 2; i++) {
}
&addrlist);
/* ip addresses are returned in different order */
/* ip addresses are returned in different order */
}
{
int i;
/* getifaddrs is called twice in sss_get_dualstack_addresses() */
for (i = 0; i < 2; i++) {
/* loopback - invalid for dns (should be skipped) */
/* linklocal - invalid for dns (should be skipped) */
}
&addrlist);
/* ip addresses are returned in different order */
/* ip addresses are returned in different order */
/* ip addresses are returned in different order */
/* ip addresses are returned in different order */
}
{
&addrlist);
}
{
discard_const("test message"), false);
/* Wait until the test finishes with EOK */
}
{
discard_const("test message"), false);
/* Wait until the test finishes with EIO (child error) */
}
{
discard_const("test message"), false);
/* Wait until the test finishes with EIO (child error) */
/* The event queue may not be empty. We need to make sure that all events
* are processed. Unfortunately, tevent_loop_wait() contains a bug that
* prevents exiting the loop even if there are no remaining events, thus
* we have to use tevent_loop_once().
*
* FIXME: use tevent_loop_wait() when the bug is fixed
*/
}
{
static int ncalls = 0;
ncalls++;
if (ncalls == 1) {
} else if (ncalls == 2) {
}
}
{
/* Wait until the timer hits */
}
/* Testsuite setup and teardown */
{
{ "dyndns_update", "true" },
{ "dyndns_refresh_interval", "2" },
};
return 0;
}
{
return 0;
}
{
return 0;
}
{
int rv;
int no_cleanup = 0;
int opt;
_("Do not delete the test database after a test run"), NULL },
};
/* Utility functions unit test */
/* Dynamic DNS update unit tests*/
/* Dynamic DNS dualstack unit tests*/
/* Messages for nsupdate */
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
default:
return 1;
}
}
/* Even though normally the tests should clean up after themselves
* they might not after a failed run. Remove the old db to be sure */
if (rv == 0 && !no_cleanup) {
}
return rv;
}