summaryrefslogtreecommitdiffstats
path: root/application/test/tests/api_v2/test_user_delete_apikey.php
blob: 062b0d6c1d47b810b5aba01d6cb4518ca989ade9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/*
 * Copyright 2016 Florian "Bluewind" Pritz <bluewind@server-speed.net>
 *
 * Licensed under AGPLv3
 * (see COPYING for full license text)
 *
 */

namespace test\tests\api_v2;

class test_user_delete_apikey extends common {

	public function __construct()
	{
		parent::__construct();
		$this->startServer(23206);
		$this->userCounter = 6100;
	}

	public function test_delete_apikey_deleteOwnKey()
	{
		$apikey = $this->createUserAndApikey("full");
		$ret = $this->CallEndpoint("POST", "user/delete_apikey", array(
			"apikey" => $apikey,
			"delete_key" => $apikey,
		));
		$this->expectSuccess("delete apikey", $ret);

		$this->t->is($ret["data"]["deleted_keys"][$apikey]["key"], $apikey, "expected key");
	}

	public function test_delete_apikey_errorDeleteOtherUserKey()
	{
		$apikey = $this->createUserAndApikey("full");
		$apikey2 = $this->createUserAndApikey("full");
		$ret = $this->CallEndpoint("POST", "user/delete_apikey", array(
			"apikey" => $apikey,
			"delete_key" => $apikey2,
		));
		$this->expectError("delete apikey of other user", $ret);
		$this->t->is_deeply(array(
			'status' => 'error',
			'error_id' => 'user/delete_apikey/failed',
			'message' => 'Apikey deletion failed. Possibly wrong owner.',
		), $ret, "expected error");
	}

}