Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster.joinSeedNodes(...) does not throw warnings when seed hostname contains underscores #25287 #27222

Merged
merged 3 commits into from Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 22 additions & 4 deletions akka-actor-tests/src/test/scala/akka/actor/ActorPathSpec.scala
Expand Up @@ -89,15 +89,33 @@ class ActorPathSpec extends WordSpec with Matchers {
ActorPath.fromString("akka://mysys/user/boom/*")
}

"detect invalid chars in host names when not using AddressFromURIString, e.g. docker host given name" in {
Address("akka", "sys", Some("valid"), Some(0)).hasInvalidHostCharacters shouldBe false
Address("akka", "sys", Some("in_valid"), Some(0)).hasInvalidHostCharacters shouldBe true
"detect valid and invalid chars in host names when not using AddressFromURIString, e.g. docker host given name" in {
Seq(
Address("akka", "sys", Some("valid"), Some(0)),
Address("akka", "sys", Some("is_valid.org"), Some(0)),
Address("akka", "sys", Some("fu.is_valid.org"), Some(0))).forall(_.hasInvalidHostCharacters) shouldBe false

Seq(Address("akka", "sys", Some("in_valid"), Some(0)), Address("akka", "sys", Some("invalid._org"), Some(0)))
.forall(_.hasInvalidHostCharacters) shouldBe true

intercept[MalformedURLException](AddressFromURIString("akka://sys@in_valid:5001"))
}
johanandren marked this conversation as resolved.
Show resolved Hide resolved

"not fail fast if the check is called on valid chars in host names" in {
Seq(
Address("akka", "sys", Some("localhost"), Some(0)),
Address("akka", "sys", Some("is_valid.org"), Some(0)),
Address("akka", "sys", Some("fu.is_valid.org"), Some(0))).foreach(_.checkHostCharacters())
}

"fail fast if the check is called when invalid chars are in host names" in {
Address("akka", "sys", Some("localhost"), Some(0)).checkHostCharacters()
Seq(
Address("akka", "sys", Some("localhost"), Some(0)),
Address("akka", "sys", Some("is_valid.org"), Some(0)),
Address("akka", "sys", Some("fu.is_valid.org"), Some(0))).foreach(_.checkHostCharacters())

intercept[IllegalArgumentException](Address("akka", "sys", Some("in_valid"), Some(0)).checkHostCharacters())
intercept[IllegalArgumentException](Address("akka", "sys", Some("invalid._org"), Some(0)).checkHostCharacters())
}
}
}
6 changes: 5 additions & 1 deletion akka-actor/src/main/scala/akka/actor/Address.scala
Expand Up @@ -74,7 +74,8 @@ final case class Address private (protocol: String, system: String, host: Option
* are any unusual characters in the host string.
*/
@InternalApi
private[akka] def hasInvalidHostCharacters: Boolean = host.exists(_.contains("_"))
private[akka] def hasInvalidHostCharacters: Boolean =
host.exists(Address.InvalidHostRegex.findFirstIn(_).nonEmpty)

/** INTERNAL API */
@InternalApi
Expand All @@ -85,6 +86,9 @@ final case class Address private (protocol: String, system: String, host: Option

object Address {

// if underscore and no dot after, then invalid
val InvalidHostRegex = "_[^.]*$".r

/**
* Constructs a new Address with the specified protocol and system name
*/
Expand Down
19 changes: 16 additions & 3 deletions akka-cluster/src/test/scala/akka/cluster/ClusterSpec.scala
Expand Up @@ -73,9 +73,22 @@ class ClusterSpec extends AkkaSpec(ClusterSpec.config) with ImplicitSender {
}

"fail fast in a join if invalid chars in host names, e.g. docker host given name" in {
val address = Address("akka", "sys", Some("in_valid"), Some(0))
intercept[IllegalArgumentException](cluster.join(address))
intercept[IllegalArgumentException](cluster.joinSeedNodes(scala.collection.immutable.Seq(address)))
val addresses = scala.collection.immutable
.Seq(Address("akka", "sys", Some("in_valid"), Some(0)), Address("akka", "sys", Some("invalid._org"), Some(0)))

addresses.foreach(a => intercept[IllegalArgumentException](cluster.join(a)))
intercept[IllegalArgumentException](cluster.joinSeedNodes(addresses))
}

"not fail fast to attempt a join with valid chars in host names" in {
val addresses = scala.collection.immutable.Seq(
Address("akka", "sys", Some("localhost"), Some(0)),
Address("akka", "sys", Some("is_valid.org"), Some(0)),
Address("akka", "sys", Some("fu.is_valid.org"), Some(0)),
Address("akka", "sys", Some("fu_.is_valid.org"), Some(0)))
johanandren marked this conversation as resolved.
Show resolved Hide resolved

addresses.foreach(cluster.join)
cluster.joinSeedNodes(addresses)
}

"initially become singleton cluster when joining itself and reach convergence" in {
Expand Down