geoip_test.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id$ */
/*! \file */
#include <config.h>
#include <atf-c.h>
#include <unistd.h>
#include "dnstest.h"
#ifdef HAVE_GEOIP
#include <GeoIP.h>
/* We use GeoIP databases from the 'geoip' system test */
/*
* Helper functions
*/
static dns_geoip_databases_t geoip = {
};
static void
{
char *info;
}
if (! GeoIP_db_avail(edition)) {
goto fail;
}
"failed to initialize GeoIP %s (type %d) DB%s\n",
? "; geoip matches using this database will fail"
: "");
goto fail;
}
return;
fail:
if (fallback != 0)
}
static void
load_geoip(const char *dir) {
#ifdef _WIN32
#else
#endif
char *p;
}
method, "Country (IPv4)");
#ifdef HAVE_GEOIP_V6
method, "Country (IPv6)");
#endif
#if defined(HAVE_GEOIP_V6) && defined(HAVE_GEOIP_CITY_V6)
#endif
method, "ISP");
method, "Org");
method, "AS");
method, "Domain");
method, "NetSpeed");
}
static isc_boolean_t
{
}
static isc_boolean_t
{
}
static isc_boolean_t
{
}
/*
* Individual unit tests
*/
/* GeoIP country matching */
}
/* Use databases from the geoip system test */
dns_test_end();
atf_tc_skip("Database not available");
}
dns_geoip_country_code, "AU");
dns_geoip_country_code3, "AUS");
dns_geoip_country_name, "Australia");
dns_geoip_country_code, "O1");
dns_geoip_country_name, "Other");
dns_test_end();
}
/* GeoIP country (ipv6) matching */
}
/* Use databases from the geoip system test */
dns_test_end();
atf_tc_skip("Database not available");
}
dns_geoip_country_code, "AU");
dns_geoip_country_code3, "AUS");
dns_geoip_country_name, "Australia");
dns_test_end();
}
/* GeoIP city (ipv4) matching */
}
/* Use databases from the geoip system test */
dns_test_end();
atf_tc_skip("Database not available");
}
dns_geoip_city_continentcode, "NA");
dns_geoip_city_countrycode, "US");
dns_geoip_city_countrycode3, "USA");
dns_geoip_city_countryname, "United States");
dns_geoip_city_region, "CA");
dns_geoip_city_regionname, "California");
dns_geoip_city_name, "Redwood City");
dns_geoip_city_postalcode, "94063");
dns_test_end();
}
/* GeoIP city (ipv6) matching */
}
/* Use databases from the geoip system test */
dns_test_end();
atf_tc_skip("Database not available");
}
dns_geoip_city_continentcode, "NA");
dns_geoip_city_countrycode, "US");
dns_geoip_city_countrycode3, "USA");
"United States");
dns_geoip_city_region, "CA");
dns_geoip_city_regionname, "California");
dns_geoip_city_name, "Redwood City");
dns_geoip_city_postalcode, "94063");
dns_test_end();
}
/* GeoIP region matching */
}
/* Use databases from the geoip system test */
dns_test_end();
atf_tc_skip("Database not available");
}
dns_geoip_region_code, "CA");
dns_geoip_region_name, "California");
dns_geoip_region_countrycode, "US");
dns_test_end();
}
/*
* GeoIP best-database matching
* (With no specified databse and a city database available, answers
* should come from city database. With city database unavailable, region
* database. Region database unavailable, country database.)
*/
}
/* Use databases from the geoip system test */
dns_test_end();
atf_tc_skip("Database not available");
}
dns_geoip_countrycode, "US");
dns_geoip_countrycode3, "USA");
dns_geoip_countryname, "United States");
dns_geoip_regionname, "Virginia");
dns_geoip_region, "VA");
dns_geoip_countrycode, "AU");
/*
* Note, region doesn't support code3 or countryname, so
* the next two would be answered from the country database instead
*/
dns_geoip_countrycode3, "CAN");
dns_geoip_countryname, "Canada");
dns_geoip_countrycode, "CA");
dns_geoip_countrycode3, "CAN");
dns_geoip_countryname, "Canada");
dns_test_end();
}
/* GeoIP asnum matching */
}
/* Use databases from the geoip system test */
dns_test_end();
atf_tc_skip("Database not available");
}
"AS100003 Three Network Labs");
dns_test_end();
}
/* GeoIP isp matching */
}
/* Use databases from the geoip system test */
dns_test_end();
atf_tc_skip("Database not available");
}
"One Systems, Inc.");
dns_test_end();
}
/* GeoIP org matching */
}
/* Use databases from the geoip system test */
dns_test_end();
atf_tc_skip("Database not available");
}
"Two Technology Ltd.");
dns_test_end();
}
/* GeoIP domain matching */
}
/* Use databases from the geoip system test */
dns_test_end();
atf_tc_skip("Database not available");
}
dns_geoip_domain_name, "four.com");
dns_test_end();
}
/* GeoIP netspeed matching */
}
/* Use databases from the geoip system test */
dns_test_end();
atf_tc_skip("Database not available");
}
dns_test_end();
}
#else
}
atf_tc_skip("GeoIP not available");
}
#endif
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
#ifdef HAVE_GEOIP
#else
#endif
return (atf_no_error());
}