-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathEncryptedDataTest.php
More file actions
189 lines (152 loc) · 5.82 KB
/
Copy pathEncryptedDataTest.php
File metadata and controls
189 lines (152 loc) · 5.82 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
namespace Tests\Feature\Api;
use Faker\Factory as Faker;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use ProcessMaker\Cache\Screens\ScreenCacheFactory;
use ProcessMaker\Models\Screen;
use ProcessMaker\Models\User;
use Tests\Feature\Shared\RequestHelper;
use Tests\TestCase;
class EncryptedDataTest extends TestCase
{
use RequestHelper;
public function setUpClearCache()
{
$screenCache = ScreenCacheFactory::getScreenCache();
$screenCache->clearCompiledAssets();
}
public function test_encrypt_text_ok()
{
// Initialize Faker
$faker = Faker::create();
// Prepare screen config
$content = file_get_contents(__DIR__ . '/screens/test_encrypted_field.json');
$content = str_replace('"9999999999"', $this->user->id, $content);
$content = str_replace('"8888888888"', '', $content);
$config = json_decode($content, true);
// Create required dummy objects
$screen = Screen::factory()->create(['config' => $config]);
// Build data to send
$data = [
'field_name' => 'form_input_1',
'plain_text' => $faker->sentence(),
'screen_id' => $screen->id,
];
// Call endpoint
$response = $this->apiCall('POST', route('api.encrypted_data.encrypt_text'), $data);
// Asserts
$response->assertStatus(200);
$this->assertTrue(Str::isUuid($response->content()));
}
public function test_encrypt_text_uuid()
{
// Initialize Faker
$faker = Faker::create();
// Prepare screen config
$content = file_get_contents(__DIR__ . '/screens/test_encrypted_field.json');
$content = str_replace('"9999999999"', $this->user->id, $content);
$content = str_replace('"8888888888"', '', $content);
$config = json_decode($content, true);
// Create required dummy objects
$screen = Screen::factory()->create(['config' => $config]);
// Build data to send
$data = [
'field_name' => 'form_input_1',
'plain_text' => $faker->sentence(),
'screen_id' => $screen->id,
];
// Call endpoint
$response = $this->apiCall('POST', route('api.encrypted_data.encrypt_text'), $data);
// Asserts
$response->assertStatus(200);
$uuid1 = $response->content();
// The first time the record should be created
$this->assertTrue(Str::isUuid($uuid1));
// Build data to send
$data = [
'uuid' => $uuid1,
'field_name' => 'form_input_1',
'plain_text' => $faker->sentence(),
'screen_id' => $screen->id,
];
// Call endpoint
$response = $this->apiCall('POST', route('api.encrypted_data.encrypt_text'), $data);
// Asserts, the returned uuid should be the same that the previous beacuse only the data is updated
$response->assertStatus(200);
$uuid2 = $response->content();
$this->assertEquals($uuid1, $uuid2);
// Build data to send
$data = [
'uuid' => 'invalid_uuid',
'field_name' => 'form_input_1',
'plain_text' => $faker->sentence(),
'screen_id' => $screen->id,
];
// Call endpoint
$response = $this->apiCall('POST', route('api.encrypted_data.encrypt_text'), $data);
// Asserts, the returned status code should be 422 because is an invalid uuid
$response->assertStatus(422);
}
public function test_encrypt_text_field_name_empty()
{
// Initialize Faker
$faker = Faker::create();
// Create required dummy objects
$screen = Screen::factory()->create();
// Build data to send
$data = [
'field_name' => '', // Empty
'plain_text' => $faker->sentence(),
'screen_id' => $screen->id,
];
// Call endpoint
$response = $this->apiCall('POST', route('api.encrypted_data.encrypt_text'), $data);
// Asserts
$response->assertStatus(422);
$responseData = $response->json();
$this->assertIsArray($responseData);
$this->assertEquals($responseData['message'], 'The Field name field is required.');
$this->assertIsArray($responseData['errors']);
}
public function test_encrypt_text_text_plain_empty()
{
// Initialize Faker
$faker = Faker::create();
// Create required dummy objects
$screen = Screen::factory()->create();
// Build data to send
$data = [
'field_name' => $faker->word(),
'plain_text' => '', // Empty
'screen_id' => $screen->id,
];
// Call endpoint
$response = $this->apiCall('POST', route('api.encrypted_data.encrypt_text'), $data);
// Asserts
$response->assertStatus(422);
$responseData = $response->json();
$this->assertIsArray($responseData);
$this->assertEquals($responseData['message'], 'The Plain text field is required.');
$this->assertIsArray($responseData['errors']);
}
public function test_encrypt_text_screen_id_not_found()
{
// Initialize Faker
$faker = Faker::create();
// Build data to send
$data = [
'field_name' => $faker->word(),
'plain_text' => $faker->sentence(),
'screen_id' => 9999999,
];
// Call endpoint
$response = $this->apiCall('POST', route('api.encrypted_data.encrypt_text'), $data);
// Asserts
$response->assertStatus(422);
$responseData = $response->json();
$this->assertIsArray($responseData);
$this->assertEquals($responseData['message'], 'The selected Screen id is invalid.');
$this->assertIsArray($responseData['errors']);
}
}