From 8219cd386540f29a7707ef09bbdbcb9120639d95 Mon Sep 17 00:00:00 2001 From: Everett Sochowski Date: Tue, 11 Feb 2014 12:24:48 +0100 Subject: [PATCH 1/3] Add test that demonstrates permissions bug where get permissions json is missing values --- src/test/scala/code/api/API121Test.scala | 35 ++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/test/scala/code/api/API121Test.scala b/src/test/scala/code/api/API121Test.scala index db5eeef48..94fc7b0e1 100644 --- a/src/test/scala/code/api/API121Test.scala +++ b/src/test/scala/code/api/API121Test.scala @@ -56,6 +56,8 @@ import code.api.test.{ServerSetup, APIResponse} import code.util.APIUtil.OAuth._ import code.model.ViewCreationJSON +import scala.reflect.runtime.universe._ + class API1_2_1Test extends ServerSetup{ @@ -174,6 +176,13 @@ class API1_2_1Test extends ServerSetup{ val user3 = Some((consumer, token3)) /************************* test tags ************************/ + + /** + * Example: To run tests with tag "getPermissions": + * mvn test -D tagsToInclude + * + * This is made possible by the scalatest maven plugin + */ object CurrentTest extends Tag("currentScenario") object API1_2 extends Tag("api1.2.1") @@ -1018,9 +1027,31 @@ class API1_2_1Test extends ServerSetup{ val reply = getAccountPermissions(bankId, bankAccount.id, user1) Then("we should get a 200 ok code") reply.code should equal (200) - reply.body.extract[PermissionsJSON] - } + val permissions = reply.body.extract[PermissionsJSON] + + def stringNotEmpty(s : String) { + s should not equal null + s should not equal "" + } + + for { + permission <- permissions.permissions + } { + val user = permission.user + //TODO: Need to come up with a better way to check that information is not missing + // idea: reflection on all the json case classes, marking "required" information with annotations + stringNotEmpty(user.id) + stringNotEmpty(user.provider) + + for { + view <- permission.views + } { + stringNotEmpty(view.id) + } + } + } + scenario("we will not get one bank account permissions", API1_2, GetPermissions) { Given("We will not use an access token") val bankId = randomBank From a854705ef282fa3a5706fe368d83912fd716acaf Mon Sep 17 00:00:00 2001 From: Everett Sochowski Date: Tue, 11 Feb 2014 12:33:46 +0100 Subject: [PATCH 2/3] Fix bug where incomplete data on views were being returned for permissions --- src/main/scala/code/model/dataAccess/Connectors.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/code/model/dataAccess/Connectors.scala b/src/main/scala/code/model/dataAccess/Connectors.scala index 6898921e9..07b41e01d 100644 --- a/src/main/scala/code/model/dataAccess/Connectors.scala +++ b/src/main/scala/code/model/dataAccess/Connectors.scala @@ -487,7 +487,7 @@ class MongoDBLocalStorage extends LocalStorage { acc <- HostedAccount.find(By(HostedAccount.accountID,account.id)) } yield { - val views: List[ViewImpl] = ViewImpl.findAllFields(Seq[SelectableField](ViewImpl.id_), By(ViewImpl.account, acc), By(ViewImpl.isPublic_, false)) + val views: List[ViewImpl] = ViewImpl.findAll(By(ViewImpl.account, acc), By(ViewImpl.isPublic_, false)) //all the user that have access to at least to a view val users = views.map(_.users.toList).flatten.distinct val usersPerView = views.map(v =>(v, v.users.toList)) From 40b2563271ff5b89ff04f0c7cfe66a1992dde629 Mon Sep 17 00:00:00 2001 From: Everett Sochowski Date: Tue, 11 Feb 2014 12:51:00 +0100 Subject: [PATCH 3/3] Add tests for permissions bug that were previously added in v1.2.1 tests to the v1.2 test suite too --- src/test/scala/code/api/API12Test.scala | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/test/scala/code/api/API12Test.scala b/src/test/scala/code/api/API12Test.scala index d80da5fbd..4843bf5f2 100644 --- a/src/test/scala/code/api/API12Test.scala +++ b/src/test/scala/code/api/API12Test.scala @@ -175,6 +175,13 @@ class API1_2Test extends ServerSetup{ val user3 = Some((consumer, token3)) /************************* test tags ************************/ + + /** + * Example: To run tests with tag "getPermissions": + * mvn test -D tagsToInclude + * + * This is made possible by the scalatest maven plugin + */ object CurrentTest extends Tag("currentScenario") object API1_2 extends Tag("api1.2") @@ -1020,6 +1027,30 @@ class API1_2Test extends ServerSetup{ Then("we should get a 200 ok code") reply.code should equal (200) reply.body.extract[PermissionsJSON] + + val permissions = reply.body.extract[PermissionsJSON] + + def stringNotEmpty(s : String) { + s should not equal null + s should not equal "" + } + + for { + permission <- permissions.permissions + } { + val user = permission.user + + //TODO: Need to come up with a better way to check that information is not missing + // idea: reflection on all the json case classes, marking "required" information with annotations + stringNotEmpty(user.id) + stringNotEmpty(user.provider) + + for { + view <- permission.views + } { + stringNotEmpty(view.id) + } + } } scenario("we will not get one bank account permissions", API1_2, GetPermissions) {