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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
<?php
use PHPUnit\Framework\TestCase;
final class LoginTest extends ApiTestCase
{
// ── Successful login ──────────────────────────────────────────────────────
public function test_perform_login_success(): void
{
[$status, $body] = $this->post($this->apiUrl, [
'op' => 'perform-login',
'user' => 'test',
'password' => 'test',
]);
$this->assertEquals(200, $status);
$this->assertEquals('ok', $body['result'] ?? null);
$this->assertEquals('test', $body['user'] ?? null);
}
// ── Missing parameters ────────────────────────────────────────────────────
public function test_perform_login_missing_password(): void
{
[$status, $body] = $this->post($this->apiUrl, [
'op' => 'perform-login',
'user' => 'test',
]);
$this->assertEquals(400, $status);
$this->assertArrayHasKey('error', $body);
}
public function test_perform_login_missing_username(): void
{
[$status, $body] = $this->post($this->apiUrl, [
'op' => 'perform-login',
'password' => 'test',
]);
$this->assertEquals(400, $status);
$this->assertArrayHasKey('error', $body);
}
public function test_perform_login_no_params(): void
{
[$status, $body] = $this->post($this->apiUrl, [
'op' => 'perform-login',
]);
$this->assertEquals(400, $status);
$this->assertArrayHasKey('error', $body);
}
// ── Invalid credentials ───────────────────────────────────────────────────
public function test_perform_login_wrong_password(): void
{
[$status, $body] = $this->post($this->apiUrl, [
'op' => 'perform-login',
'user' => 'test',
'password' => 'wrongpassword',
]);
$this->assertEquals(401, $status);
$this->assertArrayHasKey('error', $body);
}
public function test_perform_login_nonexistent_user(): void
{
[$status, $body] = $this->post($this->apiUrl, [
'op' => 'perform-login',
'user' => 'nonexistent',
'password' => 'test',
]);
$this->assertEquals(401, $status);
$this->assertArrayHasKey('error', $body);
}
// ── Username case-insensitivity ───────────────────────────────────────────
public function test_perform_login_uppercase_username(): void
{
[$status, $body] = $this->post($this->apiUrl, [
'op' => 'perform-login',
'user' => 'TEST',
'password' => 'test',
]);
$this->assertEquals(200, $status);
$this->assertEquals('ok', $body['result'] ?? null);
// username is normalised to lowercase
$this->assertEquals('test', $body['user'] ?? null);
}
}
|