@@ -0,0 +1,3421 @@
+package com.quizdeck.filters;%0A%0Aimport com.quizdeck.QuizDeckApplication;%0Aimport com.quizdeck.services.AuthenticationService;%0Aimport io.jsonwebtoken.Claims;%0Aimport io.jsonwebtoken.Jwts;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.boot.test.SpringApplicationConfiguration;%0Aimport org.springframework.http.HttpHeaders;%0Aimport org.springframework.http.HttpStatus;%0Aimport org.springframework.mock.web.MockFilterChain;%0Aimport org.springframework.mock.web.MockFilterConfig;%0Aimport org.springframework.mock.web.MockHttpServletRequest;%0Aimport org.springframework.mock.web.MockHttpServletResponse;%0Aimport org.springframework.test.context.junit4.SpringJUnit4ClassRunner;%0A%0Aimport javax.annotation.Resource;%0Aimport javax.servlet.ServletException;%0Aimport java.io.IOException;%0A%0Aimport static org.hamcrest.core.Is.is;%0Aimport static org.hamcrest.core.IsEqual.equalTo;%0Aimport static org.junit.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertThat;%0A%0A/**%0A * Created by Brandon on 2/13/2016.%0A */%0A@RunWith(SpringJUnit4ClassRunner.class)%0A@SpringApplicationConfiguration(classes = QuizDeckApplication.class)%0Apublic class AuthenticationFilterTest %7B%0A    @Resource(name = %22secretKey%22)%0A    private String secretKey;%0A    @Autowired%0A    private AuthenticationService authService;%0A%0A    private AuthenticationFilter filter;%0A    private MockHttpServletRequest request;%0A    private MockHttpServletResponse response;%0A    private MockFilterChain chain;%0A%0A    @Before%0A    public void setup() %7B%0A        this.filter = new AuthenticationFilter(this.secretKey);%0A        this.filter.init(new MockFilterConfig());%0A%0A        this.request = new MockHttpServletRequest();%0A        this.response = new MockHttpServletResponse();%0A        this.chain = new MockFilterChain();%0A    %7D%0A%0A    @After%0A    public void teardown() %7B%0A        this.filter.destroy();%0A    %7D%0A%0A    @Test%0A    public void addsClaims() throws IOException, ServletException %7B%0A        String token = authService.buildToken(%22testUser%22, %22User%22);%0A%0A        request.setServletPath(%22/rest/secure/getClaims/%22);%0A        request.addHeader(HttpHeaders.AUTHORIZATION, %22Bearer %22 + token);%0A%0A        filter.doFilter(request, response, chain);%0A%0A        assertNotNull(request.getAttribute(AuthenticationFilter.CLAIMS_ATTRIBUTE));%0A    %7D%0A%0A    @Test%0A    public void errorsWithBadHeader() throws IOException, ServletException %7B%0A        request.setServletPath(%22/rest/secure/getClaims/%22);%0A        request.addHeader(HttpHeaders.AUTHORIZATION, %22NotBearer%22);%0A%0A        filter.doFilter(request, response, chain);%0A%0A        assertThat(response.getStatus(), is(equalTo(HttpStatus.UNAUTHORIZED.value())));%0A    %7D%0A%0A    @Test%0A    public void errorsWithMalformedHeader() throws IOException, ServletException %7B%0A        request.setServletPath(%22/rest/secure/getClaims/%22);%0A        request.addHeader(HttpHeaders.AUTHORIZATION, %22Bearer abc.abc.abc%22);%0A%0A        filter.doFilter(request, response, chain);%0A%0A        assertThat(response.getStatus(), is(equalTo(HttpStatus.UNAUTHORIZED.value())));%0A    %7D%0A%0A    @Test%0A    public void errorsWithNoHeader() throws IOException, ServletException %7B%0A        request.setServletPath(%22/rest/secure/getClaims/%22);%0A%0A        filter.doFilter(request, response, chain);%0A%0A        assertThat(response.getStatus(), is(equalTo(HttpStatus.UNAUTHORIZED.value())));%0A    %7D%0A%7D%0A

Add Auth Filter test