-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathFileControllerTest.php
More file actions
157 lines (138 loc) · 4.73 KB
/
FileControllerTest.php
File metadata and controls
157 lines (138 loc) · 4.73 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Tests\Api\Controller;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Tests\Api\ApiTestCase;
/**
* @internal
* @group DB
*/
final class FileControllerTest extends ApiTestCase {
/**
* @runInSeparateProcess
*/
public function testValidateUsignUuidWithInvalidData():void {
$this->getMockAppConfig();
$this->request
->withPath('/api/v1/file/validate/uuid/invalid')
->assertResponseCode(404);
$response = $this->assertRequest();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertCount(1, $body['ocs']['data']['errors']);
$this->assertArrayHasKey(0, $body['ocs']['data']['errors']);
$this->assertEquals('Invalid data to validate file', $body['ocs']['data']['errors'][0]['message']);
}
/**
* @runInSeparateProcess
*/
public function testValidateUsignFileIdWithInvalidData():void {
$this->request
->withPath('/api/v1/file/validate/file_id/171')
->assertResponseCode(404);
$response = $this->assertRequest();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertCount(1, $body['ocs']['data']['errors']);
$this->assertArrayHasKey(0, $body['ocs']['data']['errors']);
$this->assertEquals('Invalid data to validate file', $body['ocs']['data']['errors'][0]['message']);
}
/**
* @runInSeparateProcess
*/
public function testValidateWithSuccessUsingUnloggedUser():void {
$user = $this->createAccount('username', 'password');
$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
'identify' => [
'email' => 'person@test.coop',
],
],
],
'userManager' => $user,
]);
$this->request
->withPath('/api/v1/file/validate/uuid/' . $file->getUuid());
$response = $this->assertRequest();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertFalse($body['ocs']['data']['signers'][0]['me'], "It's me");
$this->assertFalse($body['ocs']['data']['settings']['canRequestSign'], 'Can permission to request sign');
$this->assertFalse($body['ocs']['data']['settings']['canSign'], 'Can permission to sign');
}
/**
* @runInSeparateProcess
*/
public function testValidateWithSuccessUsingSigner():void {
$user = $this->createAccount('username', 'password');
$user->setEMailAddress('person@test.coop');
$appConfig = $this->getMockAppConfig();
$appConfig->setValueArray(Application::APP_ID, 'identify_methods', [
[
'name' => 'email',
'enabled' => 1,
],
]);
$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
'identify' => [
'email' => 'person@test.coop',
],
],
],
'userManager' => $user,
]);
$this->request
->withRequestHeader([
'Authorization' => 'Basic ' . base64_encode('username:password')
])
->withPath('/api/v1/file/validate/uuid/' . $file->getUuid());
$response = $this->assertRequest();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertTrue($body['ocs']['data']['signers'][0]['me'], "It's me");
$this->assertFalse($body['ocs']['data']['settings']['canRequestSign'], 'Can permission to request sign');
$this->assertTrue($body['ocs']['data']['settings']['canSign'], 'Can permission to sign');
}
/**
* @runInSeparateProcess
*/
public function testControllerListWithEmptyData():void {
$this->createAccount('username', 'password');
$this->request
->withRequestHeader([
'Authorization' => 'Basic ' . base64_encode('username:password')
])
->withPath('/api/v1/file/list');
$response = $this->assertRequest();
$body = json_decode($response->getBody()->getContents(), true);
$this->assertCount(0, $body['ocs']['data']['data']);
}
/**
* @runInSeparateProcess
*/
public function testSendNewFile():void {
$this->createAccount('allowrequestsign', 'password');
$this->getMockAppConfig()->setValueArray(Application::APP_ID, 'groups_request_sign', ['admin','testGroup']);
$this->request
->withRequestHeader([
'Authorization' => 'Basic ' . base64_encode('allowrequestsign:password'),
'Content-Type' => 'application/json',
])
->withPath('/api/v1/file')
->withMethod('POST')
->withRequestBody([
'name' => 'test',
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
]);
$this->assertRequest();
}
}