Merge pull request #367 from MasseGuillaume/sbt-6362

Fix sbt/sbt#6362
This commit is contained in:
eugene yokota 2021-03-07 00:29:34 -05:00 committed by GitHub
commit 0028ecf058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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()
}
}