Skip to content

Commit

Permalink
Merge pull request #207 from dispatch/1.0/realm-with-scheme
Browse files Browse the repository at this point in the history
[1.0] Allow to set scheme in as keyword
  • Loading branch information
farmdawgnation authored Nov 4, 2018
2 parents f575941 + 016ddea commit 6687f2a
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 @@ -166,4 +169,19 @@ with DispatchCleanup {
req.toRequest.getUrl ?= "http://127.0.0.1:%d/?%s".format(port, expectedParams.mkString("&"))
}
}

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

property("Build a Realm using as") = {
forAll(Gen.zip(Gen.alphaNumStr, Gen.alphaNumStr, 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 6687f2a

Please sign in to comment.