TedeeWebhookAuthenticationInterceptor.java

1
package org.sanmibuh.tedee.lock.infrastructure.primary;
2
3
import static java.nio.charset.StandardCharsets.UTF_8;
4
import static org.sanmibuh.tedee.lock.infrastructure.TedeeInfrastructureConfiguration.CALLBACK_SECRET_HEADER;
5
6
import jakarta.servlet.http.HttpServletRequest;
7
import jakarta.servlet.http.HttpServletResponse;
8
import java.security.MessageDigest;
9
import lombok.RequiredArgsConstructor;
10
import org.jspecify.annotations.Nullable;
11
import org.sanmibuh.tedee.lock.infrastructure.TedeeProperties;
12
import org.springframework.http.HttpStatus;
13
import org.springframework.stereotype.Component;
14
import org.springframework.web.servlet.HandlerInterceptor;
15
16
@Component
17
@RequiredArgsConstructor
18
final class TedeeWebhookAuthenticationInterceptor implements HandlerInterceptor {
19
20
  private final TedeeProperties tedeeProperties;
21
22
  @Override
23
  public boolean preHandle(
24
      final HttpServletRequest request, final HttpServletResponse response, final Object handler) {
25 1 1. preHandle : negated conditional → KILLED
    if (isCallbackSecretValid(request.getHeader(CALLBACK_SECRET_HEADER))) {
26 1 1. preHandle : replaced boolean return with false for org/sanmibuh/tedee/lock/infrastructure/primary/TedeeWebhookAuthenticationInterceptor::preHandle → KILLED
      return true;
27
    }
28 1 1. preHandle : removed call to jakarta/servlet/http/HttpServletResponse::setStatus → KILLED
    response.setStatus(HttpStatus.UNAUTHORIZED.value());
29 1 1. preHandle : replaced boolean return with true for org/sanmibuh/tedee/lock/infrastructure/primary/TedeeWebhookAuthenticationInterceptor::preHandle → KILLED
    return false;
30
  }
31
32
  private boolean isCallbackSecretValid(final @Nullable String callbackSecret) {
33 2 1. isCallbackSecretValid : negated conditional → KILLED
2. isCallbackSecretValid : replaced boolean return with true for org/sanmibuh/tedee/lock/infrastructure/primary/TedeeWebhookAuthenticationInterceptor::isCallbackSecretValid → KILLED
    return callbackSecret != null
34 1 1. isCallbackSecretValid : negated conditional → KILLED
        && MessageDigest.isEqual(
35
            tedeeProperties.callbackSecret().getBytes(UTF_8), callbackSecret.getBytes(UTF_8));
36
  }
37
}

Mutations

25

1.1
Location : preHandle
Killed by : org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest]/[method:should_rejectEventWithoutDispatching_whenCallbackSecretIsIncorrect()]
negated conditional → KILLED

26

1.1
Location : preHandle
Killed by : org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest]/[method:should_dispatchReportLockStatusCommand_whenLockStatusChanged()]
replaced boolean return with false for org/sanmibuh/tedee/lock/infrastructure/primary/TedeeWebhookAuthenticationInterceptor::preHandle → KILLED

28

1.1
Location : preHandle
Killed by : org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest]/[method:should_rejectEventWithoutDispatching_whenCallbackSecretIsIncorrect()]
removed call to jakarta/servlet/http/HttpServletResponse::setStatus → KILLED

29

1.1
Location : preHandle
Killed by : org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest]/[method:should_rejectEventWithoutDispatching_whenCallbackSecretIsIncorrect()]
replaced boolean return with true for org/sanmibuh/tedee/lock/infrastructure/primary/TedeeWebhookAuthenticationInterceptor::preHandle → KILLED

33

1.1
Location : isCallbackSecretValid
Killed by : org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest]/[method:should_rejectEventWithoutDispatching_whenCallbackSecretIsMissingAndBodyIsMalformed()]
negated conditional → KILLED

2.2
Location : isCallbackSecretValid
Killed by : org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest]/[method:should_rejectEventWithoutDispatching_whenCallbackSecretIsIncorrect()]
replaced boolean return with true for org/sanmibuh/tedee/lock/infrastructure/primary/TedeeWebhookAuthenticationInterceptor::isCallbackSecretValid → KILLED

34

1.1
Location : isCallbackSecretValid
Killed by : org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.primary.TedeeEventControllerTest]/[method:should_rejectEventWithoutDispatching_whenCallbackSecretIsIncorrect()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support