summaryrefslogtreecommitdiffstats
path: root/application/test/tests/api_v2/test_create_apikey.php
blob: 203eb55311db59d3984e2848702901bd8dac79ff (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?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_create_apikey extends common {

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

	public function test_create_apikey_createNewKey()
	{
		$this->createUser(1);
		$ret = $this->CallEndpoint("POST", "user/create_apikey", array(
			"username" => "apiv2testuser1",
			"password" => "testpass1",
			"access_level" => "apikey",
			"comment" => "main api key",
		));
		$this->expectSuccess("create-apikey", $ret);

		$this->t->isnt($ret["data"]["new_key"], "", "apikey not empty");
	}

	public function test_authentication_invalidPassword()
	{
		$userid = $this->createUser(3);
		$ret = $this->CallEndpoint("POST", "user/create_apikey", array(
			"username" => "apiv2testuser3",
			"password" => "wrongpass",
		));
		$this->expectError("invalid password", $ret);

		$this->t->is_deeply(array (
			'status' => 'error',
			'error_id' => 'user/login-failed',
			'message' => 'Login failed',
		), $ret, "expected error");
	}

	public function test_authentication_invalidUser()
	{
		$userid = $this->createUser(4);
		$ret = $this->CallEndpoint("POST", "user/create_apikey", array(
			"username" => "apiv2testuserinvalid",
			"password" => "testpass4",
		));
		$this->expectError("invalid username", $ret);

		$this->t->is_deeply(array (
			'status' => 'error',
			'error_id' => 'user/login-failed',
			'message' => 'Login failed',
		), $ret, "expected error");
	}
}