mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 15:27:01 +00:00
test/Use the local_identity_provider props explicitly
This commit is contained in:
parent
901c75e38d
commit
7ace7c5b92
@ -10,7 +10,7 @@ object Constant extends MdcLoggable {
|
||||
logger.info("Instantiating Constants")
|
||||
|
||||
final val HostName = APIUtil.getPropsValue("hostname").openOrThrowException(ErrorMessages.HostnameNotSpecified)
|
||||
final val LocalIdentityProvider = APIUtil.getPropsValue("local_identity_provider", HostName)
|
||||
def localIdentityProvider = APIUtil.getPropsValue("local_identity_provider", HostName)
|
||||
|
||||
// This is the part before the version. Do not change this default!
|
||||
final val ApiPathZero = APIUtil.getPropsValue("apiPathZero", ApiStandards.obp.toString)
|
||||
|
||||
@ -745,7 +745,7 @@ import net.liftweb.util.Helpers._
|
||||
def getResourceUserId(username: String, password: String): Box[Long] = {
|
||||
findUserByUsernameLocally(username) match {
|
||||
// We have a user from the local provider.
|
||||
case Full(user) if (user.getProvider() == Constant.LocalIdentityProvider) =>
|
||||
case Full(user) if (user.getProvider() == Constant.localIdentityProvider) =>
|
||||
if (
|
||||
user.validated_? &&
|
||||
// User is NOT locked AND the password is good
|
||||
@ -779,7 +779,7 @@ import net.liftweb.util.Helpers._
|
||||
Empty
|
||||
}
|
||||
// We have a user from an external provider.
|
||||
case Full(user) if (user.getProvider() != Constant.LocalIdentityProvider) =>
|
||||
case Full(user) if (user.getProvider() != Constant.localIdentityProvider) =>
|
||||
APIUtil.getPropsAsBoolValue("connector.user.authentication", false) match {
|
||||
case true if !LoginAttempt.userIsLocked(username) =>
|
||||
val userId =
|
||||
|
||||
@ -106,7 +106,7 @@ class UserInvitation extends MdcLoggable {
|
||||
else {
|
||||
// Resource User table
|
||||
createResourceUser(
|
||||
provider = Constant.LocalIdentityProvider, // TODO Make provider an enum
|
||||
provider = Constant.localIdentityProvider, // TODO Make provider an enum
|
||||
providerId = Some(usernameVar.is),
|
||||
name = Some(usernameVar.is),
|
||||
email = Some(email),
|
||||
|
||||
@ -197,7 +197,7 @@ class DirectLoginTest extends ServerSetup with BeforeAndAfter {
|
||||
assertResponse(response, ErrorMessages.InvalidConsumerKey)
|
||||
}
|
||||
|
||||
scenario("Missing DirecLogin header") {
|
||||
scenario("Missing DirectLogin header") {
|
||||
|
||||
//setupUserAndConsumer
|
||||
|
||||
@ -338,6 +338,61 @@ class DirectLoginTest extends ServerSetup with BeforeAndAfter {
|
||||
val currentUserOldStyle = responseCurrentUserOldStyle.body.extract[UserJsonV300]
|
||||
currentUserOldStyle.username shouldBe USERNAME
|
||||
|
||||
currentUserNewStyle.username shouldBe currentUserOldStyle.username
|
||||
}
|
||||
|
||||
scenario("Login with correct everything and use props local_identity_provider_url", ApiEndpoint1, ApiEndpoint2) {
|
||||
|
||||
setPropsValues("local_identity_provider"-> Constant.HostName)
|
||||
|
||||
Given("the app we are testing is registered and active")
|
||||
Then("We should be able to find it")
|
||||
//assert(registeredApplication(KEY) == true)
|
||||
|
||||
When("the header and credentials are good")
|
||||
val request = directLoginRequest
|
||||
val response = makePostRequestAdditionalHeader(request, "", validHeaders)
|
||||
var token = "INVALID"
|
||||
Then("We should get a 201 - OK and a token")
|
||||
response.code should equal(201)
|
||||
response.body match {
|
||||
case JObject(List(JField(name, JString(value)))) =>
|
||||
name should equal("token")
|
||||
value.length should be > 0
|
||||
token = value
|
||||
case _ => fail("Expected a token")
|
||||
}
|
||||
|
||||
// TODO Check that we are logged in. TODO Add an endpoint like /me that returns the currently logged in user.
|
||||
When("when we use the token it should work")
|
||||
val headerWithToken = ("Authorization", "DirectLogin token=%s".format(token))
|
||||
val validHeadersWithToken = List(accessControlOriginHeader, headerWithToken)
|
||||
val request2 = baseRequest / "obp" / "v2.0.0" / "my" / "accounts"
|
||||
val response2 = makeGetRequest(request2, validHeadersWithToken)
|
||||
|
||||
Then("We should get a 200 - OK and an empty list of accounts")
|
||||
response2.code should equal(200)
|
||||
response2.body match {
|
||||
case JArray(List()) =>
|
||||
case _ => fail("Expected empty list of accounts")
|
||||
}
|
||||
|
||||
When("when we use the token to get current user and it should work - New Style")
|
||||
val requestCurrentUserNewStyle = baseRequest / "obp" / "v3.0.0" / "users" / "current"
|
||||
val responseCurrentUserNewStyle = makeGetRequest(requestCurrentUserNewStyle, validHeadersWithToken)
|
||||
And("We should get a 200")
|
||||
responseCurrentUserNewStyle.code should equal(200)
|
||||
val currentUserNewStyle = responseCurrentUserNewStyle.body.extract[UserJsonV300]
|
||||
currentUserNewStyle.username shouldBe USERNAME
|
||||
|
||||
When("when we use the token to get current user and it should work - Old Style")
|
||||
val requestCurrentUserOldStyle = baseRequest / "obp" / "v2.0.0" / "users" / "current"
|
||||
val responseCurrentUserOldStyle = makeGetRequest(requestCurrentUserOldStyle, validHeadersWithToken)
|
||||
And("We should get a 200")
|
||||
responseCurrentUserOldStyle.code should equal(200)
|
||||
val currentUserOldStyle = responseCurrentUserOldStyle.body.extract[UserJsonV300]
|
||||
currentUserOldStyle.username shouldBe USERNAME
|
||||
|
||||
currentUserNewStyle.username shouldBe currentUserOldStyle.username
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user