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

Fixes #14770: Invalid comparision of String and Option[String] in HistorizationService #2203

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import com.normation.inventory.domain.NodeId
import com.normation.rudder.db.DB

/**
* At each deployment, we compare the content of the groups/PI/CR in the ldap with the content
* At each deployment, we compare the content of the groups/directives/rules in the ldap with the content
* in the database
* If there is a change (serial updated, name changed, size of group modification, etc)
* we close the previous entry, and add a new one
Expand Down Expand Up @@ -106,6 +106,12 @@ class HistorizationServiceImpl(
}
}

// Compare and Option[String] with a String, to check if they are equals
// returns true if entry is Some(value), or if entry is none and value is empty
private[this] def compareOptionString(entry: Option[String], value:String): Boolean = {
entry.getOrElse("") == value
}

override def updateNodes(allNodeInfo: Set[NodeInfo]) : Box[Unit] = {

val nodeInfos = allNodeInfo.filterNot(_.isPolicyServer).toSeq
Expand All @@ -117,7 +123,7 @@ class HistorizationServiceImpl(
// detect changes
val changed = nodeInfos.filter(x => registered.get(x.id.value) match {
case None => true
case Some(entry) => (entry.nodeName != x.hostname || entry.nodeDescription != x.description )
case Some(entry) => entry.nodeName != x.hostname || !compareOptionString(entry.nodeDescription, x.description)
})

// a node closable is a node that is current in the database, but don't exist in the
Expand All @@ -143,7 +149,7 @@ class HistorizationServiceImpl(
case None => true
case Some((entry, nodes)) =>
(entry.groupName != x.nodeGroup.name ||
entry.groupDescription != x.nodeGroup.description ||
!compareOptionString(entry.groupDescription, x.nodeGroup.description) ||
nodes.map(x => NodeId(x.nodes)).toSet != x.nodeGroup.serverList ||
DB.Historize.fromSQLtoDynamic(entry.groupStatus) != Some(x.nodeGroup.isDynamic))
}).toSeq.map( _.nodeGroup )
Expand Down Expand Up @@ -178,11 +184,11 @@ class HistorizationServiceImpl(
case None => true
case Some(entry) => (
entry.directiveName != directive.name
|| entry.directiveDescription != directive.shortDescription
|| !compareOptionString(entry.directiveDescription, directive.shortDescription)
|| entry.priority != directive.priority
|| entry.techniqueHumanName != technique.name
|| entry.techniqueName != fullActiveTechnique.techniqueName.value
|| entry.techniqueDescription != technique.description
|| !compareOptionString(entry.techniqueDescription, technique.description)
|| entry.techniqueVersion != directive.techniqueVersion.toString
)
}
Expand Down