@@ -0,0 +1,2842 @@
+/*%0A * Copyright 2016-2017 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage de.vorb.platon.web.api.common;%0A%0Aimport de.vorb.platon.security.SignatureComponents;%0Aimport de.vorb.platon.security.SignatureTokenValidator;%0Aimport de.vorb.platon.web.api.errors.RequestException;%0A%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.InjectMocks;%0Aimport org.mockito.Mock;%0Aimport org.mockito.runners.MockitoJUnitRunner;%0Aimport org.springframework.http.HttpStatus;%0A%0Aimport java.time.Instant;%0A%0Aimport static java.time.temporal.ChronoUnit.DAYS;%0Aimport static org.assertj.core.api.Assertions.assertThatCode;%0Aimport static org.assertj.core.api.Assertions.assertThatExceptionOfType;%0Aimport static org.mockito.Matchers.eq;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class RequestValidatorTest %7B%0A%0A    @InjectMocks%0A    private RequestValidator requestValidator;%0A%0A    @Mock%0A    private SignatureTokenValidator signatureTokenValidator;%0A%0A    @Test%0A    public void doesNotThrowIfRequestWasValid() throws Exception %7B%0A%0A        final String identifier = %22/api/comments/1234%22;%0A        final Instant expirationTime = Instant.now().plus(1, DAYS);%0A        final SignatureComponents signatureComponents = SignatureComponents.of(identifier, expirationTime, new byte%5B1%5D);%0A%0A        when(signatureTokenValidator.isSignatureValid(eq(signatureComponents))).thenReturn(true);%0A%0A        assertThatCode(() -%3E requestValidator.verifyValidRequest(signatureComponents.toString(), identifier))%0A                .doesNotThrowAnyException();%0A%0A        verify(signatureTokenValidator).isSignatureValid(eq(signatureComponents));%0A    %7D%0A%0A    @Test%0A    public void throwsBadRequestIfRequestWasInvalid() throws Exception %7B%0A%0A        assertThatExceptionOfType(RequestException.class)%0A                .isThrownBy(() -%3E requestValidator.verifyValidRequest(%22invalid signature%22, %22/api/comments/1234%22))%0A                .matches(requestException -%3E requestException.getHttpStatus() == HttpStatus.BAD_REQUEST)%0A                .withMessageContaining(%22signature%22)%0A                .withMessageContaining(%22invalid%22)%0A                .withMessageContaining(%22expired%22)%0A                .withCauseExactlyInstanceOf(IllegalArgumentException.class);%0A%0A    %7D%0A%0A%7D%0A

Test RequestValidator