Skip to content
Permalink
Browse files

Some code style fixes

Reenabling push of test coverage to codacy
  • Loading branch information...
atooni committed Jun 5, 2019
1 parent 2e44436 commit 9ff485b6647ac95283f050389ce03ae86b10764b
@@ -101,7 +101,7 @@ jobs:
- bash $TRAVIS_BUILD_DIR/scripts/dropbox_uploader.sh list
#- bash $TRAVIS_BUILD_DIR/scripts/build-akka.sh
script:
- sbt clean update publishLocal publishM2 unidoc cleanCoverage
- sbt clean update publishLocal publishM2 unidoc cleanCoverage codacyCoverage
after_failure:
- bash $TRAVIS_BUILD_DIR/scripts/upload-results.sh
after_success:
@@ -10,7 +10,7 @@ import blended.updater.config._
import blended.updater.config.json.PrickleProtocol._
import org.scalatest.{FreeSpec, Matchers}

import scala.collection.{immutable, immutable => sci}
import scala.collection.{immutable => sci}
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.util.Try
@@ -37,7 +37,9 @@ class CollectorServiceSpec

"should GET /container return container infos" in {
Get("/container") ~> infoRoute ~> check {
responseAs[Seq[RemoteContainerState]] should be(Seq(RemoteContainerState(ContainerInfo("uuid", Map("foo" -> "bar"), List(), List(), 1L, List()), List())))
responseAs[Seq[RemoteContainerState]] should be(Seq(
RemoteContainerState(ContainerInfo("uuid", Map("foo" -> "bar"), List(), List(), 1L, List()), List())
))
}
getCurrentStateLatch.isOpen should be(true)
}
@@ -82,18 +84,18 @@ class CollectorServiceSpec

// that we want to use
val service = new CollectorService with DummyBlendedSecurityDirectives with PrickleSupport {
override def getOverlayConfigs() : immutable.Seq[OverlayConfig] = List(OverlayConfig("o1", "1", List(), Map()))
override def getOverlayConfigs() : sci.Seq[OverlayConfig] = List(OverlayConfig("o1", "1", List(), Map()))

// unused
override def processContainerInfo(info : ContainerInfo) : ContainerRegistryResponseOK = ???

override def getCurrentState() : immutable.Seq[RemoteContainerState] = ???
override def getCurrentState() : sci.Seq[RemoteContainerState] = ???

override def registerRuntimeConfig(rc : RuntimeConfig) : Unit = ???

override def registerOverlayConfig(oc : OverlayConfig) : Unit = ???

override def getRuntimeConfigs() : immutable.Seq[RuntimeConfig] = ???
override def getRuntimeConfigs() : sci.Seq[RuntimeConfig] = ???

override def addUpdateAction(containerId : String, updateAction : UpdateAction) : Unit = ???

@@ -13,7 +13,6 @@ import javax.security.auth.login.LoginException

import scala.collection.JavaConverters._
import scala.collection.mutable
import scala.util.Try

class LDAPLoginModule extends AbstractLoginModule {

@@ -30,7 +29,7 @@ class LDAPLoginModule extends AbstractLoginModule {
}

// obtain the initial LDAP Context
private[this] lazy val dirContext : Try[DirContext] = Try {
private[this] lazy val dirContext : DirContext = {

try {
val env : mutable.Map[String, String] = mutable.Map(
@@ -39,8 +38,8 @@ class LDAPLoginModule extends AbstractLoginModule {
Context.SECURITY_AUTHENTICATION -> "simple"
)

env ++= ldapCfg.systemUser.map(u => (Context.SECURITY_PRINCIPAL -> u))
env ++= ldapCfg.systemPassword.map(u => (Context.SECURITY_CREDENTIALS -> u))
env ++= ldapCfg.systemUser.map(u => Context.SECURITY_PRINCIPAL -> u)
env ++= ldapCfg.systemPassword.map(u => Context.SECURITY_CREDENTIALS -> u)

new InitialDirContext(new util.Hashtable[String, Object](env.asJava))
} catch {
@@ -56,7 +55,7 @@ class LDAPLoginModule extends AbstractLoginModule {
// First of all we will obtain the directory context

try {
dirContext.get
dirContext
} catch {
case t : Throwable =>
log.error(t)(t.getMessage())
@@ -69,9 +68,9 @@ class LDAPLoginModule extends AbstractLoginModule {
true
}

override protected def postCommit() : Unit = dirContext.get.close()
override protected def postAbort() : Unit = dirContext.get.close()
override protected def postLogout() : Unit = dirContext.get.close()
override protected def postCommit() : Unit = dirContext.close()
override protected def postAbort() : Unit = dirContext.close()
override protected def postLogout() : Unit = dirContext.close()

@throws[LoginException]
private[this] def validateUser() : String = {
@@ -85,21 +84,23 @@ class LDAPLoginModule extends AbstractLoginModule {
val userSearchFormat = new MessageFormat(ldapCfg.userSearch)
val filter = userSearchFormat.format(Array(doRFC2254Encoding(user)))

val r = dirContext.get.search(ldapCfg.userBase, filter, constraint)
val r = dirContext.search(ldapCfg.userBase, filter, constraint)

LdapSearchResult(r).result match {
case Nil => throw new LoginException(s"User [$user] not found in LDAP.")
case head :: tail =>
if (tail.length > 0) {
if (tail.nonEmpty) {
log.warn(s"Search for user [$user] returned [${1 + tail.length}] records, using first record only.")
}

val name = head.getNameInNamespace()

dirContext.get.addToEnvironment(Context.SECURITY_PRINCIPAL, name)
dirContext.get.addToEnvironment(Context.SECURITY_CREDENTIALS, pwd)
dirContext.addToEnvironment(Context.SECURITY_PRINCIPAL, name)
dirContext.addToEnvironment(Context.SECURITY_CREDENTIALS, pwd)

dirContext.get.getAttributes("", null)
// scalastyle:off null
dirContext.getAttributes("", null)
// scalastyle:on null
log.info(s"User [$user] authenticated with LDAP name [$name]")
name
}
@@ -109,12 +110,12 @@ class LDAPLoginModule extends AbstractLoginModule {
throw new LoginException(t.getMessage())
} finally {
ldapCfg.systemUser match {
case None => dirContext.get.removeFromEnvironment(Context.SECURITY_PRINCIPAL)
case Some(u) => dirContext.get.addToEnvironment(Context.SECURITY_PRINCIPAL, u)
case None => dirContext.removeFromEnvironment(Context.SECURITY_PRINCIPAL)
case Some(u) => dirContext.addToEnvironment(Context.SECURITY_PRINCIPAL, u)
}
ldapCfg.systemPassword match {
case None => dirContext.get.removeFromEnvironment(Context.SECURITY_CREDENTIALS)
case Some(p) => dirContext.get.addToEnvironment(Context.SECURITY_CREDENTIALS, p)
case None => dirContext.removeFromEnvironment(Context.SECURITY_CREDENTIALS)
case Some(p) => dirContext.addToEnvironment(Context.SECURITY_CREDENTIALS, p)
}
}
}
@@ -127,13 +128,14 @@ class LDAPLoginModule extends AbstractLoginModule {
val groupSearchFormat = new MessageFormat(ldapCfg.groupSearch)
val filter = groupSearchFormat.format(Array(doRFC2254Encoding(member)))

val r = dirContext.get.search(ldapCfg.groupBase, filter, constraint)
val r = dirContext.search(ldapCfg.groupBase, filter, constraint)

LdapSearchResult(r).result.map { sr =>
sr.getAttributes().get(ldapCfg.groupAttribute).get().toString()
}
}

// scalastyle:off cyclomatic.complexity
// convenience method to encode a filter string
private[this] def doRFC2254Encoding(inputString : String) : String = inputString match {
case s if s.isEmpty() => ""
@@ -144,5 +146,5 @@ class LDAPLoginModule extends AbstractLoginModule {
case s if s.startsWith("\0") => "\\00" + doRFC2254Encoding(s.substring(1))
case s => s.substring(0, 1) + doRFC2254Encoding(s.substring(1))
}

// scalastyle:on cyclomatic.complexity
}

0 comments on commit 9ff485b

Please sign in to comment.
You can’t perform that action at this time.