summaryrefslogtreecommitdiffstats
path: root/application/tests/test_api_v1.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-02-08 01:34:01 +0100
committerFlorian Pritz <bluewind@xinu.at>2015-02-08 01:34:01 +0100
commitc302c5cc0143d96391aa544c15e4e0b64cba1182 (patch)
tree2020f0fac5869baae9200b1b36919b3ad4acb59b /application/tests/test_api_v1.php
parent56879097fd4246c78175867086af6d0c24a4ae89 (diff)
Add more tests
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/tests/test_api_v1.php')
-rw-r--r--application/tests/test_api_v1.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/application/tests/test_api_v1.php b/application/tests/test_api_v1.php
index 18f2a37f6..faf0d9af7 100644
--- a/application/tests/test_api_v1.php
+++ b/application/tests/test_api_v1.php
@@ -84,6 +84,26 @@ class test_api_v1 extends Test {
}
}
+ public function test_callEndpointsWithoutEnoughPermissions()
+ {
+ $apikey = $this->createUserAndApikey();
+ $endpoints = array(
+ "user/apikeys",
+ "user/create_apikey",
+ );
+ foreach ($endpoints as $endpoint) {
+ $ret = $this->CallEndpoint("POST", $endpoint, array(
+ "apikey" => $apikey,
+ ));
+ $this->expectError("call $endpoint without enough permissions", $ret);
+ $this->t->is_deeply(array(
+ 'status' => "error",
+ 'error_id' => "api/insufficient-permissions",
+ 'message' => "Access denied: Access level too low",
+ ), $ret, "expected error");
+ }
+ }
+
public function test_create_apikey_createNewKey()
{
$this->createUser(1);
@@ -98,6 +118,22 @@ class test_api_v1 extends Test {
$this->t->isnt($ret["data"]["new_key"], "", "apikey not empty");
}
+ public function test_apikeys_getApikey()
+ {
+ $userid = $this->createUser(2);
+ $apikey = $this->createApikey($userid);
+ $ret = $this->CallEndpoint("POST", "user/apikeys", array(
+ "username" => "testuser-api_v1-2",
+ "password" => "testpass2",
+ ));
+ $this->expectSuccess("get apikeys", $ret);
+
+ $this->t->is($ret["data"][0]["key"], $apikey, "expected key 1");
+ $this->t->is($ret["data"][0]["access_level"], "apikey", "expected key 1 acces_level");
+ $this->t->is($ret["data"][0]["comment"], "", "expected key 1 comment");
+ $this->t->ok(is_int($ret["data"][0]["created"]) , "expected key 1 creation time is int");
+ }
+
public function test_history_empty()
{
$apikey = $this->createUserAndApikey();