org.springframework.mock.web.MockHttpServletRequest.addHeader()

Here are the examples of the java api org.springframework.mock.web.MockHttpServletRequest.addHeader() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

294 Examples 7

19 Source : TestJsonAccessLayout.java
with Apache License 2.0
from kdgregory

// ----------------------------------------------------------------------------
// Support code
// ----------------------------------------------------------------------------
private void constructMocks(final String requestUri, final String queryString, final String responseContent, String... headers) throws Exception {
    final byte[] responseBytes = responseContent.getBytes(StandardCharsets.UTF_8);
    request = new MockHttpServletRequest(EXPECTED_REQUEST_METHOD, requestUri);
    response = new MockHttpServletResponse();
    // the mock request doesn't parse the query string, so we'll do it
    if (!StringUtil.isBlank(queryString)) {
        request.setQueryString(queryString);
        for (String param : queryString.split("&")) {
            String[] paramKV = param.split("=");
            request.addParameter(paramKV[0], paramKV[1]);
        }
    }
    // same headers for both request and response; this is just a test
    for (String header : headers) {
        String[] headerKV = header.split("=");
        request.addHeader(headerKV[0], headerKV[1]);
        response.setHeader(headerKV[0], headerKV[1]);
    }
    serverAdapter = new ServerAdapter() {

        @Override
        public long getRequestTimestamp() {
            return System.currentTimeMillis() - EXPECTED_ELAPSED_TIME;
        }

        @Override
        public long getContentLength() {
            return responseBytes.length;
        }

        @Override
        public int getStatusCode() {
            return EXPECTED_STATUS_CODE;
        }

        @Override
        public Map<String, String> buildResponseHeaderMap() {
            Map<String, String> result = new HashMap<String, String>();
            for (String key : response.getHeaderNames()) {
                // doesn't properly handle multiple headers, but we don't use them here
                result.put(key, response.getHeader(key));
            }
            return result;
        }
    };
}

19 Source : AwsCognitoIdTokenProcessorTest.java
with MIT License
from IxorTalk

@Test(expected = BadJOSEException.clreplaced)
public void whenSignedJWTWithoutMatchingKeyInAuthorizationHeaderProvidedParseExceptionOccurs() throws Exception {
    request.addHeader("Authorization", newJwtToken(UNKNOWN_KID, "role1").serialize());
    replacedertThat(awsCognitoIdTokenProcessor.getAuthentication(request)).isNull();
}

19 Source : WebDAVMethodTest.java
with GNU Lesser General Public License v3.0
from Alfresco

private void replacedertStatusCode(int expectedStatusCode, String userAgent) {
    // Fresh objects needed for each status code test.
    createRequestObjects();
    req.addHeader("User-Agent", userAgent);
    method.setDetails(req, resp, davHelper, null);
    int statusCode = method.getStatusForAccessDeniedException();
    replacedertEquals("Incorrect status code for user-agent string \"" + userAgent + "\"", expectedStatusCode, statusCode);
}

19 Source : TppRedirectUriBodyValidatorImplTest.java
with Apache License 2.0
from adorsys

@Test
void validate_RedirectApproach_success() {
    when(aspspProfileServiceWrapper.getScaRedirectFlow()).thenReturn(ScaRedirectFlow.REDIRECT);
    when(scaApproachResolver.resolveScaApproach()).thenReturn(ScaApproach.REDIRECT);
    request.addHeader(TPP_REDIRECT_URI, "some.url");
    tppRedirectUriBodyValidator.validate(request, messageError);
    verify(scaApproachResolver, times(1)).resolveScaApproach();
    replacedertTrue(messageError.getTppMessages().isEmpty());
}

19 Source : RequestResponseLogMessageTest.java
with Apache License 2.0
from adorsys

@Test
void withRequestHeaders_shouldAddRequestHeaders() {
    // Given
    String firstHeaderName = "Header 1";
    String firstHeaderValue = "Header 1 value";
    String secondHeaderName = "Header 2";
    String secondHeaderValue = "Header 2 value";
    request.addHeader(firstHeaderName, firstHeaderValue);
    request.addHeader(secondHeaderName, secondHeaderValue);
    String expectedMessage = String.format(REQUEST_HEADERS_MESSAGE_FORMAT, firstHeaderName, firstHeaderValue, secondHeaderName, secondHeaderValue);
    // When
    RequestResponseLogMessage logMessage = RequestResponseLogMessage.builder(request, response).withRequestHeaders().build();
    // Then
    replacedertEquals(expectedMessage, logMessage.getMessage());
}

18 Source : UploadDeferLengthValidatorTest.java
with MIT License
from tomdesair

@Test(expected = InvalidUploadLengthException.clreplaced)
public void validateUploadLengthNotNumeric() throws Exception {
    servletRequest.addHeader(HttpHeader.UPLOAD_LENGTH, "TEST");
    // When we validate the request
    validator.validate(HttpMethod.POST, servletRequest, null, null);
// Expect an InvalidUploadLengthException
}

18 Source : UploadDeferLengthValidatorTest.java
with MIT License
from tomdesair

@Test(expected = InvalidUploadLengthException.clreplaced)
public void validateUploadDeferLengthNot1() throws Exception {
    servletRequest.addHeader(HttpHeader.UPLOAD_DEFER_LENGTH, 2);
    // When we validate the request
    validator.validate(HttpMethod.POST, servletRequest, null, null);
// Expect an InvalidUploadLengthException
}

18 Source : ContentTypeValidatorTest.java
with MIT License
from tomdesair

@Test(expected = InvalidContentTypeException.clreplaced)
public void validateInvalidHeader() throws Exception {
    servletRequest.addHeader(HttpHeader.CONTENT_TYPE, "application/octet-stream");
    validator.validate(HttpMethod.PATCH, servletRequest, null, null);
// Expect a InvalidContentTypeException exception
}

18 Source : ContentTypeValidatorTest.java
with MIT License
from tomdesair

@Test
public void validateValid() throws Exception {
    servletRequest.addHeader(HttpHeader.CONTENT_TYPE, ContentTypeValidator.APPLICATION_OFFSET_OCTET_STREAM);
    try {
        validator.validate(HttpMethod.PATCH, servletRequest, null, null);
    } catch (Exception ex) {
        fail();
    }
// No exception is thrown
}

18 Source : PartialUploadsExistValidatorTest.java
with MIT License
from tomdesair

@Test(expected = InvalidPartialUploadIdException.clreplaced)
public void testInvalidNoUploads1() throws Exception {
    servletRequest.addHeader(HttpHeader.UPLOAD_CONCAT, "final;   ");
    // When we validate the request
    validator.validate(HttpMethod.POST, servletRequest, uploadStorageService, null);
// No Exception is thrown
}

18 Source : PartialUploadsExistValidatorTest.java
with MIT License
from tomdesair

@Test(expected = InvalidPartialUploadIdException.clreplaced)
public void testInvalidNoUploads2() throws Exception {
    servletRequest.addHeader(HttpHeader.UPLOAD_CONCAT, "final;");
    // When we validate the request
    validator.validate(HttpMethod.POST, servletRequest, uploadStorageService, null);
// No Exception is thrown
}

18 Source : TokenBrokerResolverTest.java
with Apache License 2.0
from SAP

@Test
public void iasTokenResolutionTest() {
    request.addHeader("Authorization", "bearer " + IAS_TOKEN);
    String token = tokenBroker.resolve(request);
    replacedertThat(token).isEqualTo(XSUAA_TOKEN);
}

18 Source : TokenBrokerResolverTest.java
with Apache License 2.0
from SAP

@Test
public void xsuaaTokenResolutionTest() {
    request.addHeader("Authorization", "bearer " + XSUAA_TOKEN);
    String token = tokenBroker.resolve(request);
    replacedertThat(token).isEqualTo(XSUAA_TOKEN);
}

18 Source : IasXsuaaExchangeBrokerTest.java
with Apache License 2.0
from SAP

@Test(expected = InvalidBearerTokenException.clreplaced)
public void invalidAuthorizationHeader2Test() {
    request.addHeader("Auth", "bearer " + IAS_TOKEN);
    cut.resolve(request);
}

18 Source : IasXsuaaExchangeBrokerTest.java
with Apache License 2.0
from SAP

@Test
public void iasTokenResolutionTest() {
    request.addHeader("Authorization", "bearer " + IAS_TOKEN);
    String token = cut.resolve(request);
    replacedertThat(token).isEqualTo(XSUAA_TOKEN);
}

18 Source : IasXsuaaExchangeBrokerTest.java
with Apache License 2.0
from SAP

@Test
public void xsuaaTokenResolutionTest() {
    request.addHeader("Authorization", "bearer " + XSUAA_TOKEN);
    String token = cut.resolve(request);
    replacedertThat(token).isEqualTo(XSUAA_TOKEN);
}

18 Source : IasXsuaaExchangeBrokerTest.java
with Apache License 2.0
from SAP

@Test(expected = InvalidBearerTokenException.clreplaced)
public void invalidAuthorizationHeaderTest() {
    request.addHeader("Authorization", IAS_TOKEN);
    cut.resolve(request);
}

18 Source : BasicCredentialExtractorTest.java
with Apache License 2.0
from SAP

@Test
public void testCombinedCredentials() {
    request.addHeader("Authorization", "Bearer " + XSUAA_TOKEN);
    TokenBrokerResolver extractor = new TokenBrokerResolver(getXsuaaServiceConfiguration(), tokenCache, oAuth2TokenService, authenticationMethods(AuthenticationMethod.OAUTH2, AuthenticationMethod.BASIC));
    String token = extractor.resolve(request);
    replacedertThat(token).isEqualTo(XSUAA_TOKEN);
}

18 Source : BasicCredentialExtractorTest.java
with Apache License 2.0
from SAP

@Test
public void testBasicCredentialsMulreplacedenancy() {
    TokenBrokerResolver extractor = new TokenBrokerResolver(getXsuaaServiceConfiguration(), tokenCache, oAuth2TokenService, authenticationConfiguration);
    request.addHeader("X-Idenreplacedy-Zone-Subdomain", "other");
    request.addHeader("Authorization", "basic " + Base64.getEncoder().encodeToString("myuser:mypreplaced".getBytes()));
    String token = extractor.resolve(request);
    replacedertThat(token).isEqualTo("other_token_pwd");
}

18 Source : BasicCredentialExtractorTest.java
with Apache License 2.0
from SAP

@Test
public void testCombinedCredentials_shouldTakeBasicAsFallback() {
    request.addHeader("Authorization", "basic " + Base64.getEncoder().encodeToString("myuser:mypreplaced".getBytes()));
    TokenBrokerResolver extractor = new TokenBrokerResolver(getXsuaaServiceConfiguration(), tokenCache, oAuth2TokenService, authenticationMethods(AuthenticationMethod.BASIC, AuthenticationMethod.OAUTH2));
    String token = extractor.resolve(request);
    replacedertThat(token).isEqualTo("token_pwd");
}

18 Source : BasicCredentialExtractorTest.java
with Apache License 2.0
from SAP

@Test
public void testOAuth2Credentials() {
    TokenBrokerResolver extractor = new TokenBrokerResolver(getXsuaaServiceConfiguration(), tokenCache, oAuth2TokenService, authenticationMethods(AuthenticationMethod.OAUTH2));
    request.addHeader("Authorization", "Bearer " + XSUAA_TOKEN);
    String token = extractor.resolve(request);
    replacedertThat(token).isEqualTo(XSUAA_TOKEN);
}

18 Source : BasicCredentialExtractorTest.java
with Apache License 2.0
from SAP

@Test
public void testMultipleAuthorizationHeaders_useSecondMethod() {
    TokenBrokerResolver extractor = new TokenBrokerResolver(getXsuaaServiceConfiguration(), tokenCache, oAuth2TokenService, new DefaultAuthenticationInformationExtractor(AuthenticationMethod.OAUTH2, AuthenticationMethod.CLIENT_CREDENTIALS));
    request.addHeader("Authorization", "basic " + Base64.getEncoder().encodeToString("client1234:secret1234".getBytes()));
    String token = extractor.resolve(request);
    replacedertThat(token).isEqualTo("token_cc");
}

18 Source : BasicCredentialExtractorTest.java
with Apache License 2.0
from SAP

@Test(expected = IllegalArgumentException.clreplaced)
public void testInvalidCombinedCredentials() {
    AuthenticationInformationExtractor invalidCombination = new DefaultAuthenticationInformationExtractor() {

        @Override
        public List<AuthenticationMethod> getAuthenticationMethods(HttpServletRequest request) {
            return Arrays.asList(AuthenticationMethod.BASIC, AuthenticationMethod.CLIENT_CREDENTIALS);
        }
    };
    request.addHeader("Authorization", "Bearer " + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c");
    TokenBrokerResolver credentialExtractor = new TokenBrokerResolver(getXsuaaServiceConfiguration(), tokenCache, oAuth2TokenService, invalidCombination);
    credentialExtractor.resolve(request);
}

18 Source : BasicCredentialExtractorTest.java
with Apache License 2.0
from SAP

@Test
public void testMultipleBasicAuthorizationHeaders_useSecond() {
    TokenBrokerResolver extractor = new TokenBrokerResolver(getXsuaaServiceConfiguration(), tokenCache, oAuth2TokenService, authenticationConfiguration);
    request.addHeader("Authorization", "basic " + Base64.getEncoder().encodeToString("myuser".getBytes()));
    request.addHeader("Authorization", "basic " + Base64.getEncoder().encodeToString("myuser:mypreplaced".getBytes()));
    request.addHeader("X-Idenreplacedy-Zone-Subdomain", "other");
    String token = extractor.resolve(request);
    replacedertThat(token).isEqualTo("other_token_pwd");
}

18 Source : BasicCredentialExtractorTest.java
with Apache License 2.0
from SAP

@Test
public void testMultipleAuthorizationHeaders_useMatchOfFirstMethod() {
    TokenBrokerResolver extractor = new TokenBrokerResolver(getXsuaaServiceConfiguration(), tokenCache, oAuth2TokenService, authenticationConfiguration);
    request.addHeader("Authorization", "basic " + Base64.getEncoder().encodeToString("myuser:mypreplaced".getBytes()));
    request.addHeader("Authorization", "bearer " + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHRfYXR0ciI6eyJlbmhhbmNlciI6IlhTVUFBIn19._cocFCqqATDXx6eBUoF22W9F8VwUVYY59XdLGdEDFso");
    String token = extractor.resolve(request);
    replacedertThat(token).isEqualTo("token_pwd");
    // Change order of configured methods
    extractor.setAuthenticationConfig(new DefaultAuthenticationInformationExtractor(AuthenticationMethod.OAUTH2, AuthenticationMethod.BASIC));
    token = extractor.resolve(request);
    replacedertThat(token).startsWith("eyJhbGciOiJIUzI1N");
}

18 Source : BasicCredentialExtractorTest.java
with Apache License 2.0
from SAP

@Test
public void testBasicCredentialsNoMulreplacedenancy() {
    TokenBrokerResolver extractor = new TokenBrokerResolver(getXsuaaServiceConfiguration(), tokenCache, oAuth2TokenService, authenticationConfiguration);
    request.addHeader("Authorization", "basic " + Base64.getEncoder().encodeToString("myuser:mypreplaced".getBytes()));
    String token = extractor.resolve(request);
    replacedertThat(token).isEqualTo("token_pwd");
}

18 Source : TestJsonAccessLayout.java
with Apache License 2.0
from kdgregory

@Test
public void testForwardedFor() throws Exception {
    JsonAccessLayout layout = new JsonAccessLayout();
    constructMocks("/example", "", "success!");
    request.addHeader("X-Forwarded-For", "10.64.1.2");
    applyLayoutAndParse(layout);
    Domreplacederts.replacedertEquals("forwardedFor", "10.64.1.2", dom, "/data/forwardedFor");
}

18 Source : TestJsonAccessLayout.java
with Apache License 2.0
from kdgregory

@Test
public void testEnableHostnames() throws Exception {
    JsonAccessLayout layout = new JsonAccessLayout();
    layout.setEnableHostname(true);
    layout.setEnableRemoteHost(true);
    layout.setEnableServer(true);
    constructMocks("/example", "name=value", "success!");
    request.addHeader("Host", "www.example.com");
    applyLayoutAndParse(layout);
    // hostname comes from local management beans, we'll just verify that it exists
    String hostname = new XPathWrapper("/data/hostname").evaluatereplacedtring(dom);
    replacedertFalse("hostname present and non-blank", StringUtil.isBlank(hostname));
    // the rest of these come from the request
    Domreplacederts.replacedertEquals("remote IP", "127.0.0.1", dom, "/data/remoteIP");
    Domreplacederts.replacedertEquals("remote hostname", "localhost", dom, "/data/remoteHost");
    Domreplacederts.replacedertEquals("destination hostname", "www.example.com", dom, "/data/server");
}

18 Source : AwsCognitoIdTokenProcessorTest.java
with MIT License
from IxorTalk

@Test
public void whenSignedJWTWithMatchingKeyInAuthorizationHeaderProvidedAuthenticationIsReturned() throws Exception {
    request.addHeader("Authorization", newJwtToken(KNOWN_KID, "role1").serialize());
    Authentication authentication = awsCognitoIdTokenProcessor.getAuthentication(request);
    replacedertThat(authentication.isAuthenticated()).isTrue();
}

18 Source : AwsCognitoIdTokenProcessorTest.java
with MIT License
from IxorTalk

@Test(expected = ParseException.clreplaced)
public void whenAuthorizationHeaderWithInvalidJWTValueProvidedParseExceptionOccurs() throws Exception {
    request.addHeader("Authorization", "Invalid JWT");
    awsCognitoIdTokenProcessor.getAuthentication(request);
}

18 Source : AwsCognitoIdTokenProcessorTest.java
with MIT License
from IxorTalk

@Test(expected = ParseException.clreplaced)
public void whenUnsignedAuthorizationHeaderProvidedParseExceptionOccurs() throws Exception {
    request.addHeader("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTMzNywidXNlcm5hbWUiOiJqb2huLmRvZSJ9");
    replacedertThat(awsCognitoIdTokenProcessor.getAuthentication(request)).isNull();
}

18 Source : AwsCognitoIdTokenProcessorTest.java
with MIT License
from IxorTalk

@Test(expected = BadJWTException.clreplaced)
public void whenExpiredJWTWithMatchingKeyInAuthorizationHeaderProvidedAuthenticationIsReturned() throws Exception {
    request.addHeader("Authorization", newJwtToken(KNOWN_KID, "expired").serialize());
    awsCognitoIdTokenProcessor.getAuthentication(request);
}

18 Source : AwsCognitoIdTokenProcessorTest.java
with MIT License
from IxorTalk

@Test(expected = ParseException.clreplaced)
public void whenAuthorizationHeaderWithEmptyJWTValueProvidedParseExceptionOccurs() throws Exception {
    request.addHeader("Authorization", "");
    awsCognitoIdTokenProcessor.getAuthentication(request);
}

18 Source : CsrfTokenServiceTest.java
with MIT License
from InnovateUKGitHub

private HttpServletRequest mockRequestWithHeaderValue(final String value) {
    final MockHttpServletRequest request = mockRequest();
    request.addHeader("X-CSRF-TOKEN", value);
    return request;
}

18 Source : CommonServiceTest.java
with GNU Affero General Public License v3.0
from consiglionazionaledellericerche

public void saveApplication(String callId, String applicationId, String userName, String preplacedword) throws LoginException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader(CMISService.AUTHENTICATION_HEADER, cmisAuthenticatorFactory.getTicket(userName, preplacedword));
    Response response = manageApplication.loadApplication(request, callId, applicationId, userName, false);
    replacedertEquals(ApplicationService.StatoDomanda.INIZIALE.getValue(), getValueFromResponse(response, JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value()));
    MultivaluedMap<String, String> formParams = createFormParams(response);
    formParams.addAll("aspect", cmisService.createAdminSession().getObject(callId).<List<String>>getPropertyValue(JCONONPropertyIds.CALL_ELENCO_ASPECTS.value()));
    response = manageApplication.saveApplication(request, formParams);
    replacedertEquals(ApplicationService.StatoDomanda.PROVVISORIA.getValue(), getValueFromResponse(response, JCONONPropertyIds.APPLICATION_STATO_DOMANDA.value()));
}

18 Source : CommonServiceTest.java
with GNU Affero General Public License v3.0
from consiglionazionaledellericerche

public Response removeApplication(String applicationId, String userName, String preplacedword) throws LoginException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader(CMISService.AUTHENTICATION_HEADER, cmisAuthenticatorFactory.getTicket(userName, preplacedword));
    return manageApplication.deleteApplication(request, applicationId);
}

18 Source : CommonServiceTest.java
with GNU Affero General Public License v3.0
from consiglionazionaledellericerche

public void confirmUser(String userName, String pin) throws LoginException, URISyntaxException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader(CMISService.AUTHENTICATION_HEADER, cmisAuthenticatorFactory.getTicket(adminUserName, adminPreplacedword));
    Response response = securityRest.confirmAccount(request, userName, pin, "it");
    replacedertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
}

18 Source : CommonServiceTest.java
with GNU Affero General Public License v3.0
from consiglionazionaledellericerche

public CMISUser createUser(String preplacedword) throws LoginException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader(CMISService.AUTHENTICATION_HEADER, cmisAuthenticatorFactory.getTicket(adminUserName, adminPreplacedword));
    MultivaluedMap<String, String> formParams = new MultivaluedHashMap<String, String>();
    formParams.add("firstName", "Mario");
    formParams.add("lastName", "Rossi");
    formParams.add("email", "[email protected]");
    formParams.add("preplacedword", preplacedword);
    formParams.add("confirmPreplacedword", preplacedword);
    formParams.add("straniero", "false");
    formParams.add("codicefiscale", "RSSMRA80A01H501U");
    Response response = securityRest.doCreateUser(request, formParams, "it");
    replacedertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    return getValueFromResponse(response, "user");
}

18 Source : CommonServiceTest.java
with GNU Affero General Public License v3.0
from consiglionazionaledellericerche

public Response deleteCall(String callId) throws LoginException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader(CMISService.AUTHENTICATION_HEADER, cmisAuthenticatorFactory.getTicket(adminUserName, adminPreplacedword));
    return manageCall.deleteCall(request, callId, null);
}

18 Source : CorsHandlerTest.java
with Apache License 2.0
from cloudendpoints

private static void initializeValidRequest(MockHttpServletRequest request) {
    request.addHeader("Access-Control-Request-Method", VALID_METHOD);
    request.addHeader("Access-Control-Request-Headers", TEST_HEADER);
    request.addHeader("Origin", ORIGIN);
}

18 Source : EndpointsPeerAuthenticatorTest.java
with Apache License 2.0
from cloudendpoints

@Test
public void testAuthenticate_appEngineRunTimeUnmatchedXAppengineHeader() {
    System.setProperty(EnvUtil.ENV_APPENGINE_RUNTIME, "Production");
    request.addHeader(EndpointsPeerAuthenticator.APPENGINE_PEER, "invalid");
    replacedertFalse(authenticator.authenticate(request));
}

18 Source : TppRedirectUriBodyValidatorImplTest.java
with Apache License 2.0
from adorsys

@Test
void validate_RedirectApproachAndRedirectPreferredHeaderTrue_TppRedirectUriIsBlank_error() {
    when(aspspProfileServiceWrapper.getScaRedirectFlow()).thenReturn(ScaRedirectFlow.REDIRECT);
    when(scaApproachResolver.resolveScaApproach()).thenReturn(ScaApproach.REDIRECT);
    request.addHeader(TPP_REDIRECT_URI, "");
    tppRedirectUriBodyValidator.validate(request, messageError);
    verify(scaApproachResolver, times(1)).resolveScaApproach();
    replacedertFalse(messageError.getTppMessages().isEmpty());
    replacedertEquals(MessageCategory.ERROR, messageError.getTppMessage().getCategory());
    replacedertEquals(MessageErrorCode.FORMAT_ERROR_BLANK_HEADER, messageError.getTppMessage().getMessageErrorCode());
}

17 Source : AuthorizationExtractorTest.java
with MIT License
from woowacourse-teams

@DisplayName("요청의 헤더에서 토큰을 추출한다.")
@Test
void extractTest() {
    request.addHeader("Authorization", TOKEN_TYPE + TOKEN);
    replacedertThat(authorizationExtractor.extract(request)).isEqualTo(TOKEN);
}

17 Source : AuthorizationExtractorTest.java
with MIT License
from woowacourse-teams

@DisplayName("올바르지 않은 토큰인 경우 예외를 반환한다.")
@ParameterizedTest
@ValueSource(strings = { "", "Barer abc", "Digest ABC" })
void invalidTokenExtractTest(String expectedToken) {
    request.addHeader("Authorization", expectedToken);
    replacedertThatThrownBy(() -> authorizationExtractor.extract(request)).isInstanceOf(TokenInvalidException.clreplaced).hasMessage("유효하지 않은 토큰입니다.");
}

17 Source : UploadInfoTest.java
with MIT License
from tomdesair

@Test
public void testGetCreatorIpAddressesWithXForwardedFor() throws Exception {
    MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    servletRequest.setRemoteAddr("10.11.12.13");
    servletRequest.addHeader(HttpHeader.X_FORWARDED_FOR, "24.23.22.21, 192.168.1.1");
    UploadInfo info = new UploadInfo(servletRequest);
    replacedertThat(info.getCreatorIpAddresses(), is("24.23.22.21, 192.168.1.1, 10.11.12.13"));
}

17 Source : UploadLengthValidatorTest.java
with MIT License
from tomdesair

@Test(expected = MaxUploadLengthExceededException.clreplaced)
public void validateAboveMaxUploadLength() throws Exception {
    when(uploadStorageService.getMaxUploadSize()).thenReturn(200L);
    servletRequest.addHeader(HttpHeader.UPLOAD_LENGTH, 300L);
    validator.validate(HttpMethod.POST, servletRequest, uploadStorageService, null);
// Expect a MaxUploadLengthExceededException
}

17 Source : UploadDeferLengthValidatorTest.java
with MIT License
from tomdesair

@Test
public void validateUploadDeferLength1Present() throws Exception {
    servletRequest.addHeader(HttpHeader.UPLOAD_DEFER_LENGTH, 1);
    // When we validate the request
    try {
        validator.validate(HttpMethod.POST, servletRequest, null, null);
    } catch (Exception ex) {
        fail();
    }
// No Exception is thrown
}

17 Source : UploadDeferLengthValidatorTest.java
with MIT License
from tomdesair

@Test(expected = InvalidUploadLengthException.clreplaced)
public void validateUploadLengthAndUploadDeferLength1Present() throws Exception {
    servletRequest.addHeader(HttpHeader.UPLOAD_DEFER_LENGTH, 1);
    servletRequest.addHeader(HttpHeader.UPLOAD_LENGTH, 300L);
    // When we validate the request
    validator.validate(HttpMethod.POST, servletRequest, null, null);
// Expect an InvalidUploadLengthException
}

17 Source : UploadDeferLengthValidatorTest.java
with MIT License
from tomdesair

@Test
public void validateUploadLengthPresent() throws Exception {
    servletRequest.addHeader(HttpHeader.UPLOAD_LENGTH, 300L);
    // When we validate the request
    try {
        validator.validate(HttpMethod.POST, servletRequest, null, null);
    } catch (Exception ex) {
        fail();
    }
// No Exception is thrown
}

17 Source : UploadDeferLengthValidatorTest.java
with MIT License
from tomdesair

@Test
public void validateUploadLengthNotPresentOnFinal() throws Exception {
    // servletRequest.addHeader(HttpHeader.UPLOAD_LENGTH, 300L);
    servletRequest.addHeader(HttpHeader.UPLOAD_CONCAT, "final;1234 5678");
    // When we validate the request
    try {
        validator.validate(HttpMethod.POST, servletRequest, null, null);
    } catch (Exception ex) {
        fail();
    }
// No Exception is thrown
}

See More Examples