Răsfoiți Sursa

use first ip passed though in string for ip lookup

Henry Oswald 12 ani în urmă
părinte
comite
e78e4d46b0

+ 5 - 0
services/web/app/coffee/infrastructure/GeoIpLookup.coffee

@@ -18,6 +18,11 @@ _.each EuroCountries, (country)-> currencyMappings[country] = "EUR"
 module.exports = GeoIpLookup =
 
 	getDetails : (ip, callback)->
+		if !ip?
+			e = new Error("no ip passed")
+			return callback(e)
+		ip = ip.trim().split(" ")[0]
+
 		opts = 
 			url: "#{settings.apis.geoIpLookup.url}/#{ip}"
 		request.get opts, (err, ipDetails)->

+ 5 - 0
services/web/test/UnitTests/coffee/infrastructure/GeoIpLookupTests.coffee

@@ -49,6 +49,11 @@ describe "GeoIpLookup", ->
 				assert.deepEqual returnedDetails, @stubbedResponse
 				done()
 
+		it "should take the first ip in the string", (done)->
+			@GeoIpLookup.getDetails " #{@ipAddress} 456.312.452.102 432.433.888.234", (err)=>
+				@request.get.calledWith(url:@settings.apis.geoIpLookup.url+"/"+@ipAddress).should.equal true
+				done()
+
 	describe "getCurrencyCode", ->
 
 		it "should return GBP for GB country", (done)->