]> git.ipfire.org Git - thirdparty/pdns.git/blame - modules/remotebackend/test-remotebackend-json.cc
auth: Use smart pointers in the remote backend unit tests
[thirdparty/pdns.git] / modules / remotebackend / test-remotebackend-json.cc
CommitLineData
12471842
PL
1/*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
870a0fe4
AT
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
b26e91bb 25#include "pdns/namespaces.hh"
21e99384
RK
26#include "pdns/dns.hh"
27#include "pdns/dnsbackend.hh"
28#include "pdns/dnspacket.hh"
21e99384
RK
29#include "pdns/pdnsexception.hh"
30#include "pdns/logger.hh"
31#include "pdns/arguments.hh"
93278d2a 32#include "pdns/json.hh"
b26e91bb 33#include "pdns/statbag.hh"
bf269e28
RG
34#include "pdns/auth-packetcache.hh"
35#include "pdns/auth-querycache.hh"
1f0fb39a 36#include "pdns/auth-zonecache.hh"
b26e91bb
AT
37
38StatBag S;
bf269e28
RG
39AuthPacketCache PC;
40AuthQueryCache QC;
1f0fb39a 41AuthZoneCache g_zoneCache;
ff05c7e1 42ArgvMap& arg()
b26e91bb
AT
43{
44 static ArgvMap arg;
45 return arg;
46};
47
48class RemoteLoader
49{
ff05c7e1
O
50public:
51 RemoteLoader();
b26e91bb
AT
52};
53
ccd73bec 54std::unique_ptr<DNSBackend> backendUnderTest;
b26e91bb 55
1c2d079d 56#ifndef BOOST_TEST_DYN_LINK
b26e91bb 57#define BOOST_TEST_DYN_LINK
1c2d079d
FM
58#endif
59
b26e91bb
AT
60#define BOOST_TEST_MAIN
61#define BOOST_TEST_MODULE unit
62
63#include <boost/test/unit_test.hpp>
64#include <boost/assign/list_of.hpp>
fa8fd4d2 65
b26e91bb
AT
66#include <boost/tuple/tuple.hpp>
67
ff05c7e1
O
68struct RemotebackendSetup
69{
70 RemotebackendSetup()
71 {
ccd73bec 72 backendUnderTest = nullptr;
ff05c7e1
O
73 try {
74 // setup minimum arguments
75 ::arg().set("module-dir") = "./.libs";
dea9553f 76 auto loader = std::make_unique<RemoteLoader>();
ff05c7e1
O
77 BackendMakers().launch("remote");
78 // then get us a instance of it
79 ::arg().set("remote-connection-string") = "http:url=http://localhost:62434/dns/endpoint.json,post=1,post_json=1";
80 ::arg().set("remote-dnssec") = "yes";
ccd73bec 81 backendUnderTest = std::move(BackendMakers().all()[0]);
b26e91bb 82 }
ff05c7e1
O
83 catch (PDNSException& ex) {
84 BOOST_TEST_MESSAGE("Cannot start remotebackend: " << ex.reason);
85 };
86 }
645d66cf 87 ~RemotebackendSetup() = default;
b26e91bb
AT
88};
89
ff05c7e1 90BOOST_GLOBAL_FIXTURE(RemotebackendSetup);