-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersonalDataCheckServiceTest.java
More file actions
189 lines (141 loc) · 6.07 KB
/
Copy pathPersonalDataCheckServiceTest.java
File metadata and controls
189 lines (141 loc) · 6.07 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
package org.eclipse.foodity.elasticsearch.service;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
class PersonalDataCheckServiceTest {
private final PersonalDataCheckService service = new PersonalDataCheckService();
@Test
void shouldNotFlagCoordinateTupleAsPhoneNumber() {
String content = "6.0366893 -4.9784965 54.0 3.0";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagUuidLikeNumericFragmentAsPhoneNumber() {
String content = "17024320-1817-4a6e-89f3-e3203273be1f";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagDateTimeFragmentAsPhoneNumber() {
String content = "16/06/2021 16:53";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagBarcodeLikeNumericIdentifierAsPhoneNumber() {
String content = "0000000000017";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagSlashSeparatedNumericIdentifierAsPhoneNumber() {
String content = "000/000/000/0017";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagSlashPathNumericIdentifierAsPhoneNumber() {
String content = "000/000/000/5";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagSlashTailNumericIdentifierAsPhoneNumber() {
String content = "0000000015707/8";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagDecimalNumericValueAsPhoneNumber() {
String content = "13.6857142857143";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagLeadingZerosIdentifierAsPhoneNumber() {
String content = "0000000005";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldFlagRealPhoneNumber() {
String content = "contact: +33 6 12 34 56 78";
assertThrows(PersonalDataException.class, () -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagLocalPhoneNumberWithoutCountryPrefix() {
String content = "0612345678";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagSlashSeparatedLocalPhoneWithoutCountryPrefix() {
String content = "06/12/34/56/78";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldFlagEuropeanInternationalPhoneNumber() {
String content = "0044 20 7946 0958";
assertThrows(PersonalDataException.class, () -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagNonEuropeanInternationalPhoneNumber() {
String content = "+1 202 555 0123";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldFlagRealEmailAddress() {
String content = "mail=test.user@foodity.org";
assertThrows(PersonalDataException.class, () -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldFlagPhoneOnSecondLineOfMultiLineInput() {
String content = "harmless header line\ncontact: +33 6 12 34 56 78";
assertThrows(PersonalDataException.class, () -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagInternationalNumberBelowMinimumLength() {
String content = "+1 234 5678";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagInvalidCountryCodeNumber() {
String content = "+99 12 34 56 78";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldNotFlagVoipNumber() {
String content = "+33 7 00 11 22 33";
assertDoesNotThrow(() -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldFlagTenDigitEuropeanNumber() {
String content = "+32 2 555 12 34";
assertThrows(PersonalDataException.class, () -> service
.validateHardPersonalDataOnly(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))));
}
@Test
void shouldRaiseWarningOnPrivacyKeyword() {
String content = "numero de telephone du contact";
assertThrows(PersonalDataWarningConfirmationRequiredException.class, () -> service
.validateForUpload(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), false));
}
@Test
void shouldProceedWhenKeywordWarningsConfirmed() {
String content = "adresse du fournisseur";
assertDoesNotThrow(() -> service
.validateForUpload(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), true));
}
}