Skip to content

Commit

Permalink
Merge pull request #208 from dispatch/0.14/realm-with-scheme
Browse files Browse the repository at this point in the history
[0.14] Allow to set scheme in as keyword
  • Loading branch information
farmdawgnation authored Nov 18, 2018
2 parents 0243e8b + ba00ab7 commit e871029
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/requests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ trait ParamVerbs extends RequestVerbs {
}

trait AuthVerbs extends RequestVerbs {
def as(user: String, password: String): Req =
this.as(new Realm.Builder(user, password).build())
def as(user: String, password: String, scheme: AuthScheme): Req =
this.as(new Realm.Builder(user, password).setScheme(scheme).build())

/** Basic auth, use with care. */
def as_!(user: String, password: String): Req =
Expand Down
18 changes: 18 additions & 0 deletions core/src/test/scala/basic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package dispatch.spec

import java.nio.charset.Charset

import org.asynchttpclient.Realm
import org.asynchttpclient.Realm.AuthScheme
import org.scalacheck._
import org.scalacheck.Prop._

object BasicSpecification
extends Properties("Basic")
Expand Down Expand Up @@ -165,4 +168,19 @@ with DispatchCleanup {
req.toRequest.getUrl ?= "http://127.0.0.1:%d/?%s".format(server.port, expectedParams.mkString("&"))
}
}

property("Building a Realm without a scheme should throw NPE") = {
forAll(Gen.zip(Gen.alphaStr, Gen.alphaStr)) { case (user, password) =>
throws(classOf[NullPointerException])(new Realm.Builder(user, password).build())
}
}

property("Build a Realm using as") = {
forAll(Gen.zip(Gen.alphaStr, Gen.alphaStr, Gen.oneOf(AuthScheme.values()))) { case (user, password, scheme) =>
val realm = localhost.as(user, password, scheme).toRequest.getRealm
realm.getScheme ?= scheme
realm.getPrincipal ?= user
realm.getPassword ?= password
}
}
}

0 comments on commit e871029

Please sign in to comment.