commit c36ddbe3f069f0ab7d2a6b91badf0d6d71d40069 Author: Karsten Loesing karsten.loesing@gmx.net Date: Wed Jun 15 16:11:59 2016 +0200
Parse ASN database lines without AS names.
Fixes #19420. --- .../java/org/torproject/onionoo/updater/LookupService.java | 5 ++--- .../org/torproject/onionoo/updater/LookupServiceTest.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/updater/LookupService.java b/src/main/java/org/torproject/onionoo/updater/LookupService.java index e800926..57a0885 100644 --- a/src/main/java/org/torproject/onionoo/updater/LookupService.java +++ b/src/main/java/org/torproject/onionoo/updater/LookupService.java @@ -252,8 +252,7 @@ public class LookupService { long endIpNum = Long.parseLong(parts[1]); while (firstAddressNumber <= endIpNum && firstAddressNumber != -1L) { - if (parts[2].startsWith("AS") && - parts[2].split(" ", 2).length == 2) { + if (parts[2].startsWith("AS")) { addressNumberASN.put(firstAddressNumber, parts[2]); } sortedAddressNumbers.remove(firstAddressNumber); @@ -319,7 +318,7 @@ public class LookupService { String[] parts = addressNumberASN.get(addressNumber).split(" ", 2); lookupResult.setAsNumber(parts[0]); - lookupResult.setAsName(parts[1]); + lookupResult.setAsName(parts.length == 2 ? parts[1] : ""); } lookupResults.put(addressString, lookupResult); } diff --git a/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java b/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java index 7ba3462..7faab7c 100644 --- a/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java +++ b/src/test/java/org/torproject/onionoo/updater/LookupServiceTest.java @@ -416,6 +416,17 @@ public class LookupServiceTest { }
@Test() + public void testLookupGeoipASNum2NoASName() { + List<String> geoipASNum2Lines = new ArrayList<String>(); + geoipASNum2Lines.add("134743296,134744063,AS3356"); + geoipASNum2Lines.add("134744064,134744319,AS15169"); + geoipASNum2Lines.add("134744320,134750463,AS3356"); + this.assertLookupResult(null, null, geoipASNum2Lines, "8.8.8.8", "us", + "United States", "California", "Mountain View", 37.3860f, + -122.0838f, "AS15169", ""); + } + + @Test() public void testLookupLocationTurkey() { List<String> geoLite2CityBlocksIPv4Lines = new ArrayList<String>(); geoLite2CityBlocksIPv4Lines.add("network,geoname_id,"