diff --git a/src/test/scala/code/api/oauthTest.scala b/src/test/scala/code/api/oauthTest.scala index 3787979ac..45c625559 100644 --- a/src/test/scala/code/api/oauthTest.scala +++ b/src/test/scala/code/api/oauthTest.scala @@ -6,6 +6,7 @@ import oauth._ import OAuth._ import net.liftweb.util.Helpers._ import net.liftweb.http.S +import net.liftweb.common.Box import code.api.test.{ServerSetup, APIResponse} import code.model.dataAccess.OBPUser import code.model.{Consumer => OBPConsumer, Token => OBPToken} @@ -66,15 +67,45 @@ class OAuthTest extends ServerSetup{ Token(token, secret) } + case class Browser() extends HtmlUnit{ + implicit val driver = webDriver + def getVerifier(loginPage: String, userName: String, password: String) : Box[String] = { + tryo{ + go.to(loginPage) + textField("username").value = userName + val pwField = NameQuery("password").webElement + pwField.clear() + pwField.sendKeys(password) + click on XPathQuery("""//input[@type='submit']""") + val newURL = currentUrl + val verifier = + if(newURL.contains("verifier")) + { + //we got redirected + val params = newURL.split("&") + params(1).split("=")(0) + } + else{ + //the verifier is in the page + XPathQuery("""//div[@id='verifier']""").element.text + } + close() + quit() + verifier + } + } + } + /************************ the tags ************************/ object RequestToken extends Tag("requestToken") - object Validator extends Tag("validator") + object Verifier extends Tag("verifier") + object Oauth extends Tag("oauth") /************************ the tests ************************/ feature("request token"){ - scenario("we get a request token", RequestToken) { + scenario("we get a request token", RequestToken, Oauth) { Given("The application is registered and does not have a callback URL") When("the request is sent") val reply = getRequestToken(consumer, OAuth.oob) @@ -83,7 +114,7 @@ class OAuthTest extends ServerSetup{ And("we can extract the token") val requestToken = extractToken(reply.body) } - scenario("we get a request token with a callback URL", RequestToken) { + scenario("we get a request token with a callback URL", RequestToken, Oauth) { Given("The application is registered and have a callback URL") When("the request is sent") val reply = getRequestToken(consumer, "localhost:8080/app") @@ -92,14 +123,14 @@ class OAuthTest extends ServerSetup{ And("we can extract the token") val requestToken = extractToken(reply.body) } - scenario("we don't get a request token since the application is not registered", RequestToken) { + scenario("we don't get a request token since the application is not registered", RequestToken, Oauth) { Given("The application not registered") When("the request is sent") val reply = getRequestToken(notRegisteredConsumer, OAuth.oob) Then("we should get a 401 created code") reply.code should equal (401) } - scenario("we don't get a request token since the application is not registered even with a callback URL", RequestToken) { + scenario("we don't get a request token since the application is not registered even with a callback URL", RequestToken, Oauth) { Given("The application not registered") When("the request is sent") val reply = getRequestToken(notRegisteredConsumer, "localhost:8080/app") @@ -107,50 +138,46 @@ class OAuthTest extends ServerSetup{ reply.code should equal (401) } } - feature("validator"){ - scenario("user login and get redirected to the application back", Validator){ + feature("Verifier"){ + scenario("user login and get redirected to the application back", Verifier, Oauth){ Given("we will use a valid request token") val reply = getRequestToken(consumer, "http://localhost:8000") val requestToken = extractToken(reply.body) val loginPage = (oauthRequest / "authorize" <