zwoop commented on code in PR #12948:
URL: https://github.com/apache/trafficserver/pull/12948#discussion_r2907421175
##########
plugins/header_rewrite/header_rewrite_test.cc:
##########
@@ -538,12 +544,120 @@ test_tokenizer()
return errors;
}
+#if TS_USE_HRW_MAXMINDDB
+static bool
+file_exists(const char *path)
+{
+ struct stat st;
+ return stat(path, &st) == 0;
+}
+
+static const char *
+find_country_mmdb()
+{
+ static const char *paths[] = {
+ "/usr/share/GeoIP/GeoLite2-Country.mmdb",
"/usr/local/share/GeoIP/GeoLite2-Country.mmdb",
+ "/var/lib/GeoIP/GeoLite2-Country.mmdb",
"/opt/geoip/GeoLite2-Country.mmdb",
+ "/usr/share/GeoIP/GeoIP2-Country.mmdb",
"/usr/share/GeoIP/dbip-country-lite.mmdb",
+ };
+ for (auto *p : paths) {
+ if (file_exists(p)) {
+ return p;
+ }
+ }
+ if (const char *env = getenv("MMDB_COUNTRY_PATH")) {
+ if (file_exists(env)) {
+ return env;
+ }
+ }
+ return nullptr;
+}
+
+int
+test_maxmind_geo()
+{
+ const char *db_path = find_country_mmdb();
+ if (db_path == nullptr) {
+ std::cout << "SKIP: No MaxMind country mmdb found (set MMDB_COUNTRY_PATH
to override)" << std::endl;
+ return 0;
+ }
+
+ std::cout << "Testing MaxMind geo lookups with: " << db_path << std::endl;
+
+ int errors = 0;
+ MMDB_s mmdb;
+ int status = MMDB_open(db_path, MMDB_MODE_MMAP, &mmdb);
+ if (MMDB_SUCCESS != status) {
+ std::cerr << "Cannot open " << db_path << ": " << MMDB_strerror(status) <<
std::endl;
+ return 1;
+ }
+
+ int gai_error, mmdb_error;
+ MMDB_lookup_result_s result = MMDB_lookup_string(&mmdb, "8.8.8.8",
&gai_error, &mmdb_error);
+
+ if (MMDB_SUCCESS != mmdb_error || !result.found_entry) {
Review Comment:
bike shed, but do we not want to use the gai_error here (and in the other
place) ? Should it be in the error message? I don't know what it contains, but
we collect it and never use it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]