Skip to content

Commit

Permalink
Common: switch to HostName.asInetAddress to validate IP addresses (close
Browse files Browse the repository at this point in the history
  • Loading branch information
chuwy committed Sep 17, 2020
1 parent bdde15c commit 453ead4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -476,5 +476,5 @@ object ConversionUtils {

/** Extract valid IP (v4 or v6) address from a string */
def extractInetAddress(arg: String): Option[InetAddress] =
Either.catchNonFatal(new HostName(arg).toInetAddress).toOption
Option(new HostName(arg).asInetAddress)
}
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,22 @@ class EnrichmentManagerSpec extends Specification with EitherMatchers {
EnrichmentManager.getIabContext(input, iabEnrichment) must beRight(None)
}

"return None if user_ipaddress in invalid" >> {
"return None if user_ipaddress is invalid" >> {
val input = new EnrichedEvent()
input.setUser_ipaddress("invalid")
input.setUseragent("Firefox")
input.setDerived_tstamp("2010-06-30 01:20:01.000")
EnrichmentManager.getIabContext(input, iabEnrichment) must beRight(None)
}

"return None if user_ipaddress is hostname (don't try to resovle it)" >> {
val input = new EnrichedEvent()
input.setUser_ipaddress("localhost")
input.setUseragent("Firefox")
input.setDerived_tstamp("2010-06-30 01:20:01.000")
EnrichmentManager.getIabContext(input, iabEnrichment) must beRight(None)
}

"return Some if all arguments are valid" >> {
val input = new EnrichedEvent()
input.setUser_ipaddress("127.0.0.1")
Expand Down

0 comments on commit 453ead4

Please sign in to comment.