9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek/*
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek Authors:
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek Copyright (C) 2013 Red Hat
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek SSSD tests: Dynamic DNS tests
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek This program is free software; you can redistribute it and/or modify
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek it under the terms of the GNU General Public License as published by
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek (at your option) any later version.
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek This program is distributed in the hope that it will be useful,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek GNU General Public License for more details.
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek You should have received a copy of the GNU General Public License
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek*/
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek#include <talloc.h>
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek#include <tevent.h>
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek#include <errno.h>
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek#include <popt.h>
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek#include <unistd.h>
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek#include <sys/types.h>
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek#include <ifaddrs.h>
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek#include <arpa/inet.h>
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek/* In order to access opaque types */
0429e21a45aa26c133cb4d8285a60446a0611e44Pavel Březina#include "providers/be_dyndns.c"
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek#include "tests/cmocka/common_mock.h"
d43c9d18fb263b1ea4071b20e93ce4994583f62fJakub Hrozek#include "tests/cmocka/common_mock_be.h"
892ddeb5190dd5c1ffa26a95142a10a0034fc5e3Pavel Březina#include "src/providers/be_dyndns.h"
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
50c9d542e8bf641412debaa82a4dcf67ddb72258Lukas Slebodnik#define TESTS_PATH "tp_" BASE_FILE_STEM
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek#define TEST_CONF_DB "test_dyndns_conf.ldb"
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek#define TEST_DOM_NAME "dyndns_test"
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek#define TEST_ID_PROVIDER "ldap"
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekenum mock_nsupdate_states {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek MOCK_NSUPDATE_OK,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek MOCK_NSUPDATE_ERR,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek MOCK_NSUPDATE_TIMEOUT,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek};
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnikstatic TALLOC_CTX *global_mock_context = NULL;
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekstruct dyndns_test_ctx {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek struct sss_test_ctx *tctx;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek struct be_ctx *be_ctx;
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek struct be_nsupdate_ctx *update_ctx;
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek enum mock_nsupdate_states state;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek int child_status;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek int child_retval;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek};
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekstatic struct dyndns_test_ctx *dyndns_test_ctx;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekvoid __wrap_execv(const char *path, char *const argv[])
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek int err;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek switch (dyndns_test_ctx->state) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek case MOCK_NSUPDATE_OK:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "nsupdate success test case\n");
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek err = 0;
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz usleep(50000); /* 50 milliseconds */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek break;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek case MOCK_NSUPDATE_ERR:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "nsupdate error test case\n");
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek err = 1;
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz usleep(50000); /* 50 milliseconds */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek break;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek case MOCK_NSUPDATE_TIMEOUT:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FUNC_DATA, "nsupdate timeout test case\n");
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek err = 2;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek sleep(3);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek break;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek default:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "unknown test case\n");
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek err = 255;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek break;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek }
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Child exiting with status %d\n", err);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek _exit(err);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekint __wrap_getifaddrs(struct ifaddrs **_ifap)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
04868f1573f4b26ef34610b6d7069172f93bd8abJakub Hrozek struct ifaddrs *ifap = NULL;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek struct ifaddrs *ifap_prev = NULL;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek struct ifaddrs *ifap_head = NULL;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek char *name;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek char *straddr;
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl int ad_family;
4cae8609b513c267af11c0409bfe1d17d3a5da2fMichal Zidek struct sockaddr_in *sa;
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl void *dst;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek while ((name = sss_mock_ptr_type(char *)) != NULL) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek straddr = sss_mock_ptr_type(char *);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek if (straddr == NULL) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek errno = EINVAL;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek goto fail;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek }
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl ad_family = sss_mock_type(int);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik ifap = talloc_zero(global_mock_context, struct ifaddrs);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek if (ifap == NULL) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek errno = ENOMEM; /* getifaddrs sets errno, too */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek goto fail;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek }
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek if (ifap_prev) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ifap_prev->ifa_next = ifap;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek } else {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ifap_head = ifap;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek }
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ifap_prev = ifap;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ifap->ifa_name = talloc_strdup(ifap, name);
828cc04cd1ed9076faa6e1545055ae69a04f0f0fLukas Slebodnik if (ifap->ifa_name == NULL) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek errno = ENOMEM;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek goto fail;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek }
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Do not allocate directly on ifap->ifa_addr to
4cae8609b513c267af11c0409bfe1d17d3a5da2fMichal Zidek * avoid alignment warnings */
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl if (ad_family == AF_INET) {
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl sa = talloc(ifap, struct sockaddr_in);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl } else if (ad_family == AF_INET6) {
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl sa = (struct sockaddr_in *) talloc(ifap, struct sockaddr_in6);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl } else {
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl errno = EINVAL;
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl goto fail;
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl }
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl
4cae8609b513c267af11c0409bfe1d17d3a5da2fMichal Zidek if (sa == NULL) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek errno = ENOMEM;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek goto fail;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek }
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl sa->sin_family = ad_family;
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl if (ad_family == AF_INET) {
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl dst = &sa->sin_addr;
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl } else if (ad_family == AF_INET6) {
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl dst = &((struct sockaddr_in6 *)sa)->sin6_addr;
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl } else {
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl errno = EINVAL;
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl goto fail;
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl }
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* convert straddr into ifa_addr */
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl if (inet_pton(ad_family, straddr, dst) != 1) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek goto fail;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek }
4cae8609b513c267af11c0409bfe1d17d3a5da2fMichal Zidek
4cae8609b513c267af11c0409bfe1d17d3a5da2fMichal Zidek ifap->ifa_addr = (struct sockaddr *) sa;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek }
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek *_ifap = ifap_head;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek return 0;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekfail:
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek talloc_free(ifap);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek return -1;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekvoid __wrap_freeifaddrs(struct ifaddrs *ifap)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek talloc_free(ifap);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekstatic void dyndns_test_done(struct tevent_req *req)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek struct dyndns_test_ctx *ctx =
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tevent_req_callback_data(req, struct dyndns_test_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ctx->child_retval = -1;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ctx->tctx->error = be_nsupdate_recv(req, &ctx->child_status);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek talloc_zfree(req);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ctx->tctx->done = true;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichlvoid will_return_getifaddrs(const char *ifname, const char *straddr,
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl int af_family)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek will_return(__wrap_getifaddrs, ifname);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek if (ifname) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek will_return(__wrap_getifaddrs, straddr);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek }
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl if (straddr) {
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return(__wrap_getifaddrs, af_family);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl }
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichlvoid dyndns_test_sss_iface_addr_get_misc(void **state)
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl{
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl struct sss_iface_addr addrs[3];
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl struct sockaddr_storage ss[3];
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl addrs[0].prev = NULL;
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl addrs[0].next = &addrs[1];
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl addrs[0].addr = &ss[0];
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl addrs[1].prev = &addrs[0];
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl addrs[1].next = &addrs[2];
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl addrs[1].addr = &ss[1];
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl addrs[2].prev = &addrs[1];
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl addrs[2].next = NULL;
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl addrs[2].addr = &ss[2];
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_address(NULL), NULL);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_address(&addrs[0]), &ss[0]);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_address(&addrs[1]), &ss[1]);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_address(&addrs[2]), &ss[2]);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_next(NULL), NULL);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_next(&addrs[0]), &addrs[1]);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_next(&addrs[1]), &addrs[2]);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl assert_ptr_equal(sss_iface_addr_get_next(&addrs[2]), NULL);
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl}
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekvoid dyndns_test_get_ifaddr(void **state)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek errno_t ret;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek struct sss_iface_addr *addrlist;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek char straddr[128];
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek check_leaks_push(dyndns_test_ctx);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth1", "192.168.0.2", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ret = sss_iface_addr_list_get(dyndns_test_ctx, "eth0", &addrlist);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_int_equal(ret, EOK);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* There must be only one address with the correct value */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_non_null(addrlist);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_non_null(addrlist->addr);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_null(addrlist->next);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_null(addrlist->prev);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_non_null(inet_ntop(AF_INET,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek &((struct sockaddr_in *) addrlist->addr)->sin_addr,
e210ed5da220acebb6751db4466fe352de08eaebLukas Slebodnik straddr, INET_ADDRSTRLEN));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_string_equal(straddr, "192.168.0.1");
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek talloc_free(addrlist);
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_true(check_leaks_pop(dyndns_test_ctx) == true);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnikvoid dyndns_test_get_multi_ifaddr(void **state)
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik{
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik errno_t ret;
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik struct sss_iface_addr *addrlist;
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik struct sss_iface_addr *sss_if_addr;
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik char straddr[128];
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik check_leaks_push(dyndns_test_ctx);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik ret = sss_iface_addr_list_get(dyndns_test_ctx, "eth0", &addrlist);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_int_equal(ret, EOK);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik sss_if_addr = addrlist;
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_non_null(sss_if_addr);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_non_null(sss_if_addr->addr);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_non_null(sss_if_addr->next);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_null(sss_if_addr->prev);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_non_null(inet_ntop(AF_INET,
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik &((struct sockaddr_in *) sss_if_addr->addr)->sin_addr,
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik straddr, INET_ADDRSTRLEN));
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik /* ip addresses are returned in different order */
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_string_equal(straddr, "192.168.0.1");
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik sss_if_addr = addrlist->next;
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_non_null(sss_if_addr);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_non_null(sss_if_addr->addr);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_null(sss_if_addr->next);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_non_null(sss_if_addr->prev);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_non_null(inet_ntop(AF_INET,
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik &((struct sockaddr_in *) sss_if_addr->addr)->sin_addr,
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik straddr, INET_ADDRSTRLEN));
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik /* ip addresses are returned in different order */
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_string_equal(straddr, "192.168.0.2");
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik talloc_free(addrlist);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik assert_true(check_leaks_pop(dyndns_test_ctx) == true);
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik}
1a783fb0be9a48a0abdfe8b52fce551d530487ceLukas Slebodnik
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichlvoid dyndns_test_get_ifaddr_enoent(void **state)
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl{
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl errno_t ret;
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl struct sss_iface_addr *addrlist = NULL;
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl check_leaks_push(dyndns_test_ctx);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs("eth1", "192.168.0.2", AF_INET);
1112e84494bcfd0f658e073d25f15ed877d047aaPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl ret = sss_iface_addr_list_get(dyndns_test_ctx, "non_existing_interface",
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl &addrlist);
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl assert_int_equal(ret, ENOENT);
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl talloc_free(addrlist);
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl}
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichlvoid dyndns_test_addr_list_as_str_list(void **state)
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl{
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl int i;
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl char **output;
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl errno_t ret;
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl struct sss_iface_addr *addrlist;
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl struct {
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl const char* addr;
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl int af;
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl } input[] = {
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl {"2001:cdba::555", AF_INET6},
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl {"192.168.0.1", AF_INET},
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl {"192.168.0.2", AF_INET},
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl {"2001:cdba::444", AF_INET6}
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl };
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl int size = 4;
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl check_leaks_push(dyndns_test_ctx);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl for (i = 0; i < size; i++) {
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl will_return_getifaddrs("eth0", input[i].addr, input[i].af);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl }
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl ret = sss_iface_addr_list_get(dyndns_test_ctx, "eth0", &addrlist);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl assert_int_equal(ret, EOK);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl ret = sss_iface_addr_list_as_str_list(dyndns_test_ctx, addrlist, &output);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl assert_int_equal(ret, EOK);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl for (i = 0; i < size; i++) {
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl /* addresses are returned in reversed order */
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl assert_int_equal(strcmp(input[i].addr, output[size - 1 - i]), 0);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl }
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl talloc_free(addrlist);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl talloc_free(output);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl}
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichlvoid dyndns_test_create_fwd_msg(void **state)
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl{
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl errno_t ret;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl char *msg;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl struct sss_iface_addr *addrlist;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl int i;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl check_leaks_push(dyndns_test_ctx);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl for (i = 0; i < 2; i++) {
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth1", "192.168.0.1", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth1", "2001:cdba::444", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl }
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl struct sockaddr_in sin;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl memset(&sin, 0, sizeof (sin));
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl sin.sin_family = AF_INET;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.2");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl (struct sockaddr *) &sin,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl &addrlist);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl 1234, DYNDNS_REMOVE_A | DYNDNS_REMOVE_AAAA,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl addrlist, &msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_string_equal(msg,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_zfree(msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* fallback case realm and server */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, "North", "Winterfell",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl 1234, DYNDNS_REMOVE_A | DYNDNS_REMOVE_AAAA,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl addrlist, &msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_string_equal(msg,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "server Winterfell\n"
44996f2ea96ce75bf76f5155a6bdecf295593d97Lukas Slebodnik#ifdef HAVE_NSUPDATE_REALM
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "realm North\n"
44996f2ea96ce75bf76f5155a6bdecf295593d97Lukas Slebodnik#else
44996f2ea96ce75bf76f5155a6bdecf295593d97Lukas Slebodnik "\n"
44996f2ea96ce75bf76f5155a6bdecf295593d97Lukas Slebodnik#endif
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_zfree(msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* just realm */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, "North", NULL,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl 1234, DYNDNS_REMOVE_A | DYNDNS_REMOVE_AAAA,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl addrlist, &msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_string_equal(msg,
44996f2ea96ce75bf76f5155a6bdecf295593d97Lukas Slebodnik#ifdef HAVE_NSUPDATE_REALM
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "realm North\n"
44996f2ea96ce75bf76f5155a6bdecf295593d97Lukas Slebodnik#else
44996f2ea96ce75bf76f5155a6bdecf295593d97Lukas Slebodnik "\n"
44996f2ea96ce75bf76f5155a6bdecf295593d97Lukas Slebodnik#endif
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_zfree(msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* just server */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, "Winterfell",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl 1234, DYNDNS_REMOVE_A | DYNDNS_REMOVE_AAAA,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl addrlist, &msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_string_equal(msg,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "server Winterfell\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_zfree(msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* remove just A */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl 1234, DYNDNS_REMOVE_A,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl addrlist, &msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_string_equal(msg,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_zfree(msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* remove just AAAA */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl 1234, DYNDNS_REMOVE_AAAA,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl addrlist, &msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_string_equal(msg,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_zfree(msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_free(addrlist);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl}
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichlvoid dyndns_test_create_fwd_msg_mult(void **state)
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl{
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl errno_t ret;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl char *msg;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl struct sss_iface_addr *addrlist;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl int i;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl check_leaks_push(dyndns_test_ctx);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl for (i = 0; i < 2; i++) {
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "2001:cdba::444", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl }
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl struct sockaddr_in sin;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl memset(&sin, 0, sizeof (sin));
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl sin.sin_family = AF_INET;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.2");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl (struct sockaddr *) &sin,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl &addrlist);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl 1234, DYNDNS_REMOVE_A | DYNDNS_REMOVE_AAAA,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl addrlist, &msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_string_equal(msg,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.1\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::444\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_zfree(msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_free(addrlist);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl}
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichlvoid dyndns_test_create_fwd_msg_A(void **state)
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl{
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl errno_t ret;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl char *msg;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl struct sss_iface_addr *addrlist;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl int i;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl check_leaks_push(dyndns_test_ctx);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl for (i = 0; i < 2; i++) {
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl }
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl struct sockaddr_in sin;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl memset(&sin, 0, sizeof (sin));
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl sin.sin_family = AF_INET;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.2");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl (struct sockaddr *) &sin,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl &addrlist);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl 1234, DYNDNS_REMOVE_A | DYNDNS_REMOVE_AAAA,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl addrlist, &msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_string_equal(msg,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.1\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in A 192.168.0.2\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_zfree(msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_free(addrlist);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl}
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichlvoid dyndns_test_create_fwd_msg_AAAA(void **state)
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl{
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl errno_t ret;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl char *msg;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl struct sss_iface_addr *addrlist;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl int i;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl check_leaks_push(dyndns_test_ctx);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl for (i = 0; i < 2; i++) {
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs("eth0", "2001:cdba::444", AF_INET6);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl }
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl struct sockaddr_in6 sin;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl memset(&sin, 0, sizeof (sin));
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl sin.sin6_family = AF_INET6;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = inet_pton(AF_INET6, "2001:cdba::555", &sin.sin6_addr.s6_addr);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, 1);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl (struct sockaddr *) &sin,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl &addrlist);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl ret = be_nsupdate_create_fwd_msg(dyndns_test_ctx, NULL, NULL, "bran_stark",
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl 1234, DYNDNS_REMOVE_A | DYNDNS_REMOVE_AAAA,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl addrlist, &msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_int_equal(ret, EOK);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_string_equal(msg,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "\nupdate delete bran_stark. in A\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update delete bran_stark. in AAAA\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::444\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "update add bran_stark. 1234 in AAAA 2001:cdba::555\n"
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl "send\n");
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_zfree(msg);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl talloc_free(addrlist);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl}
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichlvoid dyndns_test_dualstack(void **state)
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl{
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl errno_t ret;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl struct sss_iface_addr *addrlist;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl struct sss_iface_addr *sss_if_addrs;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl char straddr[128];
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl int i;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl check_leaks_push(dyndns_test_ctx);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl for (i = 0; i < 2; i++) {
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth1", "192.168.0.1", AF_INET);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth1", "2001:cdba::444", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl }
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl struct sockaddr_in sin;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl memset(&sin, 0, sizeof (sin));
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sin.sin_family = AF_INET;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.2");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl (struct sockaddr *) &sin,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &addrlist);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_int_equal(ret, EOK);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sss_if_addrs = addrlist;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->addr);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->next);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_null(sss_if_addrs->prev);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(inet_ntop(AF_INET6,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in6 *) sss_if_addrs->addr)->sin6_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl straddr, INET6_ADDRSTRLEN));
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_string_equal(straddr, "2001:cdba::555");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sss_if_addrs = addrlist->next;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->addr);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_null(sss_if_addrs->next);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->prev);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(inet_ntop(AF_INET,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in *) sss_if_addrs->addr)->sin_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl straddr, INET_ADDRSTRLEN));
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_string_equal(straddr, "192.168.0.2");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl talloc_free(addrlist);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl}
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichlvoid dyndns_test_dualstack_multiple_addresses(void **state)
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl{
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl errno_t ret;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl struct sss_iface_addr *addrlist;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl struct sss_iface_addr *sss_if_addrs;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl char straddr[128];
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl int i;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl check_leaks_push(dyndns_test_ctx);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* getifaddrs is called twice in sss_get_dualstack_addresses() */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl for (i = 0; i < 2; i++) {
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* loopback - invalid for DNS (should be skipped) */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "::1", AF_INET6);
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* linklocal - invalid for DNS (should be skipped) */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "fe80::5054:ff:fe4a:65ae", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "2001:cdba::444", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl }
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl struct sockaddr_in sin;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl memset(&sin, 0, sizeof (sin));
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sin.sin_family = AF_INET;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.2");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl (struct sockaddr *) &sin,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &addrlist);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_int_equal(ret, EOK);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sss_if_addrs = addrlist;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->addr);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->next);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_null(sss_if_addrs->prev);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(inet_ntop(AF_INET6,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in6 *) sss_if_addrs->addr)->sin6_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl straddr, INET6_ADDRSTRLEN));
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_string_equal(straddr, "2001:cdba::444");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sss_if_addrs = sss_if_addrs->next;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->addr);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->prev);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->next);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(inet_ntop(AF_INET6,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in6 *) sss_if_addrs->addr)->sin6_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl straddr, INET6_ADDRSTRLEN));
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_string_equal(straddr, "2001:cdba::555");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sss_if_addrs = sss_if_addrs->next;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->addr);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->next);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->prev);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(inet_ntop(AF_INET,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in *) sss_if_addrs->addr)->sin_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl straddr, INET_ADDRSTRLEN));
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_string_equal(straddr, "192.168.0.1");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sss_if_addrs = sss_if_addrs->next;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->addr);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_null(sss_if_addrs->next);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(sss_if_addrs->prev);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_non_null(inet_ntop(AF_INET,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &((struct sockaddr_in *) sss_if_addrs->addr)->sin_addr,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl straddr, INET_ADDRSTRLEN));
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* ip addresses are returned in different order */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_string_equal(straddr, "192.168.0.2");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl talloc_free(addrlist);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl}
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichlvoid dyndns_test_dualstack_no_iface(void **state)
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl{
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl errno_t ret;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl struct sss_iface_addr *addrlist;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl check_leaks_push(dyndns_test_ctx);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth1", "192.168.0.1", AF_INET);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth0", "2001:cdba::555", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs("eth1", "2001:cdba::444", AF_INET6);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl struct sockaddr_in sin;
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl memset(&sin, 0, sizeof (sin));
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sin.sin_family = AF_INET;
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl sin.sin_addr.s_addr = inet_addr ("192.168.0.3");
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl ret = sss_get_dualstack_addresses(dyndns_test_ctx,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl (struct sockaddr *) &sin,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl &addrlist);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_int_equal(ret, ENOENT);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl assert_true(check_leaks_pop(dyndns_test_ctx) == true);
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl}
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekvoid dyndns_test_ok(void **state)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek struct tevent_req *req;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek errno_t ret;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek TALLOC_CTX *tmp_ctx;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tmp_ctx = talloc_new(global_talloc_context);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_non_null(tmp_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek check_leaks_push(tmp_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek dyndns_test_ctx->state = MOCK_NSUPDATE_OK;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek req = be_nsupdate_send(tmp_ctx, dyndns_test_ctx->tctx->ev,
e15a9f81eb33066937710d7dee6976a3646d119cJakub Hrozek BE_NSUPDATE_AUTH_GSS_TSIG,
e45b81abe0aafa8a04bd64ac31a2fac63ce675b7Jakub Hrozek discard_const("test message"), false);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_non_null(req);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tevent_req_set_callback(req, dyndns_test_done, dyndns_test_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Wait until the test finishes with EOK */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ret = test_ev_loop(dyndns_test_ctx->tctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Child request returned [%d]: %s\n", ret, strerror(ret));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_int_equal(ret, EOK);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_true(WIFEXITED(dyndns_test_ctx->child_status));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_int_equal(WEXITSTATUS(dyndns_test_ctx->child_status), 0);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_true(check_leaks_pop(tmp_ctx) == true);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek talloc_free(tmp_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekvoid dyndns_test_error(void **state)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek struct tevent_req *req;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek errno_t ret;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek TALLOC_CTX *tmp_ctx;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tmp_ctx = talloc_new(global_talloc_context);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_non_null(tmp_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek check_leaks_push(tmp_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek dyndns_test_ctx->state = MOCK_NSUPDATE_ERR;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek req = be_nsupdate_send(tmp_ctx, dyndns_test_ctx->tctx->ev,
e15a9f81eb33066937710d7dee6976a3646d119cJakub Hrozek BE_NSUPDATE_AUTH_GSS_TSIG,
e45b81abe0aafa8a04bd64ac31a2fac63ce675b7Jakub Hrozek discard_const("test message"), false);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_non_null(req);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tevent_req_set_callback(req, dyndns_test_done, dyndns_test_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Wait until the test finishes with EIO (child error) */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ret = test_ev_loop(dyndns_test_ctx->tctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Child request returned [%d]: %s\n", ret, strerror(ret));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_int_equal(ret, ERR_DYNDNS_FAILED);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_true(WIFEXITED(dyndns_test_ctx->child_status));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_int_equal(WEXITSTATUS(dyndns_test_ctx->child_status), 1);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_true(check_leaks_pop(tmp_ctx) == true);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek talloc_free(tmp_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekvoid dyndns_test_timeout(void **state)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek struct tevent_req *req;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek errno_t ret;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek TALLOC_CTX *tmp_ctx;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tmp_ctx = talloc_new(global_talloc_context);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_non_null(tmp_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek check_leaks_push(tmp_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek dyndns_test_ctx->state = MOCK_NSUPDATE_TIMEOUT;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek req = be_nsupdate_send(tmp_ctx, dyndns_test_ctx->tctx->ev,
e15a9f81eb33066937710d7dee6976a3646d119cJakub Hrozek BE_NSUPDATE_AUTH_GSS_TSIG,
e45b81abe0aafa8a04bd64ac31a2fac63ce675b7Jakub Hrozek discard_const("test message"), false);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_non_null(req);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tevent_req_set_callback(req, dyndns_test_done, dyndns_test_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Wait until the test finishes with EIO (child error) */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ret = test_ev_loop(dyndns_test_ctx->tctx);
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina /* The event queue may not be empty. We need to make sure that all events
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina * are processed. Unfortunately, tevent_loop_wait() contains a bug that
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina * prevents exiting the loop even if there are no remaining events, thus
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina * we have to use tevent_loop_once().
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina *
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina * FIXME: use tevent_loop_wait() when the bug is fixed
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina * https://bugzilla.samba.org/show_bug.cgi?id=10012
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina */
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina tevent_loop_once(dyndns_test_ctx->tctx->ev); /* SIGCHLD handler */
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina tevent_loop_once(dyndns_test_ctx->tctx->ev); /* nsupdate_child_handler */
a7401bf72db3a6eb62b1628f9dd141f7118e3510Pavel Březina
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Child request returned [%d]: %s\n", ret, strerror(ret));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_int_equal(ret, ERR_DYNDNS_TIMEOUT);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_true(check_leaks_pop(tmp_ctx) == true);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek talloc_free(tmp_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozekvoid dyndns_test_timer(void *pvt)
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek{
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek struct dyndns_test_ctx *ctx = talloc_get_type(pvt, struct dyndns_test_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek static int ncalls = 0;
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek ncalls++;
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek if (ncalls == 1) {
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek be_nsupdate_timer_schedule(ctx->tctx->ev, ctx->update_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek } else if (ncalls == 2) {
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek ctx->tctx->done = true;
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek }
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek ctx->tctx->error = ERR_OK;
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek}
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozekvoid dyndns_test_interval(void **state)
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek{
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek errno_t ret;
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek TALLOC_CTX *tmp_ctx;
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek tmp_ctx = talloc_new(global_talloc_context);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek assert_non_null(tmp_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek check_leaks_push(tmp_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek ret = be_nsupdate_init(tmp_ctx, dyndns_test_ctx->be_ctx, NULL,
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek &dyndns_test_ctx->update_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek assert_int_equal(ret, EOK);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek ret = be_nsupdate_init_timer(dyndns_test_ctx->update_ctx,
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek dyndns_test_ctx->be_ctx->ev,
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek dyndns_test_timer, dyndns_test_ctx);
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek assert_int_equal(ret, EOK);
3bd78eb2faf09635b8d307e4440ccb1420f80716Jakub Hrozek
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek /* Wait until the timer hits */
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek ret = test_ev_loop(dyndns_test_ctx->tctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Child request returned [%d]: %s\n", ret, strerror(ret));
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek assert_int_equal(ret, ERR_OK);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek talloc_free(dyndns_test_ctx->update_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek assert_true(check_leaks_pop(tmp_ctx) == true);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek talloc_free(tmp_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek}
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek/* Testsuite setup and teardown */
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int dyndns_test_setup(void **state)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek struct sss_test_conf_param params[] = {
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek { "dyndns_update", "true" },
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek { "dyndns_refresh_interval", "2" },
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek { NULL, NULL }, /* Sentinel */
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek };
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_true(leak_check_setup());
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik global_mock_context = talloc_new(global_talloc_context);
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik assert_non_null(global_mock_context);
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek dyndns_test_ctx = talloc_zero(global_talloc_context, struct dyndns_test_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_non_null(dyndns_test_ctx);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek dyndns_test_ctx->tctx = create_dom_test_ctx(dyndns_test_ctx, TESTS_PATH,
a95c006f748fa9df0dd81509b51974133d2786afLukas Slebodnik TEST_CONF_DB, TEST_DOM_NAME,
a95c006f748fa9df0dd81509b51974133d2786afLukas Slebodnik TEST_ID_PROVIDER, params);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_non_null(dyndns_test_ctx->tctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
d43c9d18fb263b1ea4071b20e93ce4994583f62fJakub Hrozek dyndns_test_ctx->be_ctx = mock_be_ctx(dyndns_test_ctx, dyndns_test_ctx->tctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek assert_non_null(dyndns_test_ctx->be_ctx);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int dyndns_test_simple_setup(void **state)
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik{
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik assert_true(leak_check_setup());
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik global_mock_context = talloc_new(global_talloc_context);
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik assert_non_null(global_mock_context);
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik dyndns_test_ctx = talloc_zero(global_talloc_context, struct dyndns_test_ctx);
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik assert_non_null(dyndns_test_ctx);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik}
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int dyndns_test_teardown(void **state)
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek talloc_free(dyndns_test_ctx);
12e7e87ccbae0d5c2f338cd019ca51556cbcd3aeLukas Slebodnik talloc_free(global_mock_context);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek assert_true(leak_check_teardown());
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozekint main(int argc, const char *argv[])
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek{
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek int rv;
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek int no_cleanup = 0;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek poptContext pc;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek int opt;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek struct poptOption long_options[] = {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek POPT_AUTOHELP
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek SSSD_DEBUG_OPTS
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek _("Do not delete the test database after a test run"), NULL },
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek POPT_TABLEEND
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek };
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Utility functions unit test */
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_sss_iface_addr_get_misc,
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl dyndns_test_simple_setup,
eeac17ebbe38f16deaa8599231cccfc97aaac85cPavel Reichl dyndns_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_get_ifaddr,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_simple_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_get_multi_ifaddr,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_simple_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_teardown),
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_get_ifaddr_enoent,
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl dyndns_test_simple_setup,
aa3fd6fde3888c0e333cad852ae5b4f671d55f58Pavel Reichl dyndns_test_teardown),
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_addr_list_as_str_list,
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl dyndns_test_simple_setup,
6fd5306145d98ea3bab7f32aa66475f610f388cePavel Reichl dyndns_test_teardown),
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek /* Dynamic DNS update unit tests*/
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_ok,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_error,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_timeout,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(dyndns_test_interval,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek dyndns_test_teardown),
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl /* Dynamic DNS dualstack unit tests*/
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_dualstack,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl dyndns_test_simple_setup,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl dyndns_test_teardown),
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_dualstack_multiple_addresses,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl dyndns_test_simple_setup,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl dyndns_test_teardown),
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_dualstack_no_iface,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl dyndns_test_simple_setup,
b0a8ed519554f8896e35812e0759862c33f157fePavel Reichl dyndns_test_teardown),
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl /* Messages for nsupdate */
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_create_fwd_msg,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl dyndns_test_setup,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl dyndns_test_teardown),
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_create_fwd_msg_mult,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl dyndns_test_setup,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl dyndns_test_teardown),
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_create_fwd_msg_A,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl dyndns_test_setup,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl dyndns_test_teardown),
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl cmocka_unit_test_setup_teardown(dyndns_test_create_fwd_msg_AAAA,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl dyndns_test_setup,
a741d0c4345dceb27dfbb20b81fd858a514b47cdPavel Reichl dyndns_test_teardown),
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek };
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek debug_level = SSSDBG_INVALID;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek switch(opt) {
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek default:
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek poptPrintUsage(pc, stderr, 0);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek return 1;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek }
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek }
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek poptFreeContext(pc);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
6b57784f0f175275fd900eca21c77415e3a5ea52Jakub Hrozek DEBUG_CLI_INIT(debug_level);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek /* Even though normally the tests should clean up after themselves
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * they might not after a failed run. Remove the old DB to be sure */
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek tests_set_cwd();
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek test_dom_suite_setup(TESTS_PATH);
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek if (rv == 0 && !no_cleanup) {
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
5a4239490c7fb7d732180a9d40f27f0247c56631Jakub Hrozek }
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek return rv;
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek}