Skip to content

Commit d9dcb28

Browse files
author
Niedzielski Marcin
committed
POM-436 - Recaptcha in DTO object
1 parent 9b4cf62 commit d9dcb28

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

src/main/java/pl/gov/coi/pomocua/ads/messages/MessageResource.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ public class MessageResource {
3636
private final CaptchaValidator captchaValidator;
3737

3838
@PostMapping
39-
public ResponseEntity<Void> sendMessage(@Valid @RequestBody SendMessageDTO messageDefinition,
40-
@RequestParam(value = "recaptcha-response", required = false) final String recaptchaResponse) {
39+
public ResponseEntity<Void> sendMessage(@Valid @RequestBody SendMessageDTO messageDefinition) {
4140

42-
if (!captchaValidator.validate(recaptchaResponse)) {
41+
if (!captchaValidator.validate(messageDefinition.recaptchaResponse)) {
4342
throw new CaptchaException();
4443
}
4544

src/main/java/pl/gov/coi/pomocua/ads/messages/SendMessageDTO.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,26 @@ public final class SendMessageDTO {
1111

1212
@NotNull
1313
public final Long offerId;
14+
1415
public final String text;
16+
1517
@NotEmpty
1618
@Email(regexp = EMAIL_REGEX)
1719
public final String replyEmail;
20+
1821
@NotNull
1922
@AssertTrue(message = "{terms-and-conditions.validation}")
2023
public final boolean tosApproved;
2124

25+
public final String recaptchaResponse;
26+
2227
public SendMessageDTO(Long offerId, String text, String replyEmail,
23-
boolean tosApproved) {
28+
boolean tosApproved, String recaptchaResponse) {
2429
this.offerId = offerId;
2530
this.text = text;
2631
this.replyEmail = replyEmail;
2732
this.tosApproved = tosApproved;
33+
this.recaptchaResponse = recaptchaResponse;
2834
}
2935

3036

src/test/java/pl/gov/coi/pomocua/ads/messages/MessageResourceTest.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ void shouldSendEmailToOfferCreator() throws Exception {
8787
offer.id,
8888
"message body",
8989
"reply@email.invalid",
90-
true
90+
true,
91+
""
9192
), Void.class);
9293

9394
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
@@ -136,7 +137,8 @@ void shouldFailWhenEmailPrefixIsIncorrect() {
136137
offer.id,
137138
"message body",
138139
".email@message@text.test",
139-
true
140+
true,
141+
""
140142
), Void.class);
141143

142144
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
@@ -152,7 +154,8 @@ void shouldFailWhenEmailPrefixIsIncorrect_andWhenHeaderLanguageIsPL_expectPolish
152154
offer.id,
153155
"message body",
154156
".email@message@text.test",
155-
true
157+
true,
158+
""
156159
), headers);
157160

158161
ResponseEntity<ErrorResponse> response = restTemplate.postForEntity("/api/message", entity, ErrorResponse.class);
@@ -175,7 +178,8 @@ void shouldFailWhenEmailPrefixIsIncorrect_andWhenHeaderLanguageIsEn_expectEnglis
175178
offer.id,
176179
"message body",
177180
".email@message@text.test",
178-
true
181+
true,
182+
""
179183
), headers);
180184

181185
ResponseEntity<ErrorResponse> response = restTemplate.postForEntity("/api/message", entity, ErrorResponse.class);
@@ -196,7 +200,8 @@ void shouldFailWhenEmailSuffixIsIncorrect() {
196200
offer.id,
197201
"message body",
198202
"email@invalid",
199-
true
203+
true,
204+
""
200205
), Void.class);
201206

202207
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
@@ -210,7 +215,8 @@ void shouldFailWithoutAcceptingToS() {
210215
offer.id,
211216
"abc",
212217
"reply@email.invalid",
213-
false
218+
false,
219+
""
214220
), Void.class);
215221

216222
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
@@ -221,7 +227,8 @@ void shouldFailWithoutOfferId() {
221227
null,
222228
"abc",
223229
"reply@email.invalid",
224-
true
230+
true,
231+
""
225232
), Void.class);
226233

227234
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
@@ -235,7 +242,8 @@ void shouldFailWithoutEmail() {
235242
offer.id,
236243
"text",
237244
"",
238-
true
245+
true,
246+
""
239247
), Void.class);
240248

241249
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
@@ -248,7 +256,8 @@ void shouldFailWhenOfferAuthorDoesNotExist() {
248256
offer.id,
249257
"text",
250258
"reply@email.invalid",
251-
true
259+
true,
260+
""
252261
), Void.class);
253262

254263
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
@@ -261,7 +270,8 @@ void shouldFailForNotExistingOffer() {
261270
1L,
262271
"text",
263272
"reply@email.invalid",
264-
true
273+
true,
274+
""
265275
), Void.class);
266276

267277
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);

0 commit comments

Comments
 (0)