@@ -0,0 +1,3022 @@
+/*%0A * Copyright 2015 Shredder121.%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 */%0Apackage com.github.shredder121.gh_event_api.handler;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.springframework.boot.test.*;%0Aimport org.springframework.context.annotation.Bean;%0Aimport org.springframework.http.*;%0Aimport org.springframework.test.annotation.DirtiesContext;%0Aimport org.springframework.test.context.junit4.SpringJUnit4ClassRunner;%0A%0Aimport com.github.shredder121.gh_event_api.GHEventApiServer;%0Aimport com.github.shredder121.gh_event_api.handler.create.CreateHandler;%0A%0A@RunWith(SpringJUnit4ClassRunner.class)%0A@WebIntegrationTest(%7B%22secret=secret%22, %22spring.main.show-banner=false%22%7D)%0A@SpringApplicationConfiguration(classes = %7BHmacBehaviorTest.class, GHEventApiServer.class%7D)%0A@DirtiesContext%0Apublic class HmacBehaviorTest %7B%0A%0A    private final TestRestTemplate restTemplate = new TestRestTemplate();%0A%0A    @Test%0A    public void testHmacIncorrect() %7B%0A        HttpHeaders headers = new HttpHeaders();%0A        headers.add(%22X-GitHub-Event%22, %22create%22);%0A        headers.add(%22X-Hub-Signature%22, %22bogus%22);%0A        headers.setContentType(MediaType.APPLICATION_JSON);%0A        ResponseEntity%3C?%3E response = restTemplate.postForEntity(%22http://127.0.0.1:8080%22, new HttpEntity%3C%3E(%22%7B%7D%22, headers), null);%0A        assertEquals(%22Known party, but Hmac incorrect%22, HttpStatus.FORBIDDEN, response.getStatusCode());%0A    %7D%0A%0A    @Test%0A    public void testHmacMissing() %7B%0A        HttpHeaders headers = new HttpHeaders();%0A        headers.add(%22X-GitHub-Event%22, %22create%22);%0A        headers.setContentType(MediaType.APPLICATION_JSON);%0A        ResponseEntity%3C?%3E response = restTemplate.postForEntity(%22http://127.0.0.1:8080%22, new HttpEntity%3C%3E(%22%7B%7D%22, headers), null);%0A        assertEquals(%22Unknown party, return 404%22, HttpStatus.NOT_FOUND, response.getStatusCode());%0A    %7D%0A%0A    @Test%0A    public void testHmacOkay() %7B%0A        HttpHeaders headers = new HttpHeaders();%0A        headers.add(%22X-GitHub-Event%22, %22create%22);%0A        headers.add(%22X-Hub-Signature%22, %22sha1=5d61605c3feea9799210ddcb71307d4ba264225f%22);%0A        headers.setContentType(MediaType.APPLICATION_JSON);%0A        ResponseEntity%3C?%3E response = restTemplate.postForEntity(%22http://127.0.0.1:8080%22, new HttpEntity%3C%3E(%22%7B%7D%22, headers), null);%0A        assertEquals(%22Hmac fine, return 200%22, HttpStatus.OK, response.getStatusCode());%0A    %7D%0A%0A    @Bean%0A    public CreateHandler handlerBean() %7B%0A        return payload -%3E %7B%0A        %7D;%0A    %7D%0A%7D%0A

Add HmacBehaviorTest which verifies returned status codes