mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 17:37:00 +00:00
Merge branch 'develop' of github.com:OpenBankProject/OBP-API into develop
This commit is contained in:
commit
7e1f01b8f5
@ -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" <<? List(("oauth_token", requestToken.value))).to_uri.toString
|
||||
object browser extends HtmlUnit{
|
||||
implicit val driver = webDriver
|
||||
def getVerifier(loginPage: String, userName: String, password: String) : String = {
|
||||
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 params = newURL.split("&")
|
||||
val verifier = params(1).split("=")(0)
|
||||
close()
|
||||
quit()
|
||||
verifier
|
||||
}
|
||||
}
|
||||
browser.getVerifier(loginPage, user1.email.get, user1Password).nonEmpty should equal (true)
|
||||
val browser = new Browser()
|
||||
When("the browser is launched to login")
|
||||
val verifier = browser.getVerifier(loginPage, user1.email.get, user1Password)
|
||||
Then("we should get a verifier")
|
||||
verifier.get.nonEmpty should equal (true)
|
||||
}
|
||||
scenario("user login and is asked to enter the verifier", Validator){
|
||||
scenario("user login and is asked to enter the verifier manually", Verifier, Oauth){
|
||||
Given("we will use a valid request token")
|
||||
val reply = getRequestToken(consumer, OAuth.oob)
|
||||
val requestToken = extractToken(reply.body)
|
||||
val loginPage = (oauthRequest / "authorize" <<? List(("oauth_token", requestToken.value))).to_uri.toString
|
||||
object browser extends HtmlUnit{
|
||||
implicit val driver = webDriver
|
||||
def getVerifier(loginPage: String, userName: String, password: String) : String = {
|
||||
go.to(loginPage)
|
||||
textField("username").value = userName
|
||||
val pwField = NameQuery("password").webElement
|
||||
pwField.clear()
|
||||
pwField.sendKeys(password)
|
||||
click on XPathQuery("""//input[@type='submit']""")
|
||||
val x = XPathQuery("""//div[@id='verifier']""").element
|
||||
x.text
|
||||
}
|
||||
}
|
||||
browser.getVerifier(loginPage, user1.email.get, user1Password).nonEmpty should equal (true)
|
||||
val browser = new Browser()
|
||||
When("the browser is launched to login")
|
||||
val verifier = browser.getVerifier(loginPage, user1.email.get, user1Password)
|
||||
Then("we should get a verifier")
|
||||
verifier.get.nonEmpty should equal (true)
|
||||
}
|
||||
scenario("user cannot login because there is no token", Verifier, Oauth){
|
||||
Given("we will use a valid request token")
|
||||
val loginPage = (oauthRequest / "authorize").to_uri.toString
|
||||
val browser = new Browser()
|
||||
When("the browser is launched to login")
|
||||
val verifier = browser.getVerifier(loginPage, user1.email.get, user1Password)
|
||||
Then("we should get a verifier")
|
||||
verifier.isEmpty should equal (true)
|
||||
}
|
||||
scenario("user cannot login because then token does not exist", Verifier, Oauth){
|
||||
Given("we will use a valid request token")
|
||||
val loginPage = (oauthRequest / "authorize" <<? List(("oauth_token", randomString(4)))).to_uri.toString
|
||||
val browser = new Browser()
|
||||
When("the browser is launched to login")
|
||||
val verifier = browser.getVerifier(loginPage, user1.email.get, user1Password)
|
||||
Then("we should get a verifier")
|
||||
verifier.isEmpty should equal (true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user