This commit is contained in:
Guillaume Massé 2021-03-06 22:42:32 -05:00
parent ea20a1d0f4
commit 3132647ac1
2 changed files with 35 additions and 3 deletions

View File

@ -47,9 +47,13 @@ object Credentials {
.headOption
.toRight(keys.head + " not specified in credentials file: " + path)
IvyUtil.separate(List(RealmKeys, HostKeys, UserKeys, PasswordKeys).map(get)) match {
case (Nil, List(realm, host, user, pass)) =>
Right(new DirectCredentials(realm, host, user, pass))
IvyUtil.separate(List(HostKeys, UserKeys, PasswordKeys).map(get)) match {
case (Nil, List(host, user, pass)) =>
IvyUtil.separate(List(RealmKeys).map(get)) match {
case (_, List(realm)) => Right(new DirectCredentials(realm, host, user, pass))
case _ => Right(new DirectCredentials(null, host, user, pass))
}
case (errors, _) => Left(errors.mkString("\n"))
}
} else

View File

@ -0,0 +1,28 @@
package sbt.internal.librarymanagement
import sbt.librarymanagement.ivy.Credentials
import java.io.File
import java.nio.file.Files
import org.scalatest.funsuite.AnyFunSuite
class CredentialsSpec extends AnyFunSuite {
test("load credential file without authentication") {
val credentialsFile = File.createTempFile("credentials", "tmp")
val content =
"""|host=example.org
|user=username
|password=password""".stripMargin
Files.write(credentialsFile.toPath(), content.getBytes())
val Right(credentials) = Credentials.loadCredentials(credentialsFile)
assert(credentials.realm == null)
credentialsFile.delete()
}
}