mercedes-benz / sechub

SecHub provides a central API to test software with different security tools.
https://mercedes-benz.github.io/sechub/
MIT License
259 stars 61 forks source link

Fileupload size exceed shall return NOT_ACCEPTABLE #160

Closed de-jcup closed 4 years ago

de-jcup commented 4 years ago

We must change the behaviour of file upload size exceed. It shall return a NOT_ACCEPTABLE and not an internal server error.

Also at the moment we have very often following flaky test:

com.daimler.sechub.integrationtest.scenario2.FileUploadSizeScenario2IntTest.when_file_exceeds_5MB_a_server_error_is_thrown

Here we expect an HttpServerErrorException but some times we got a SocketException (see following example stacktrace ) what is really disturbing because we often got broken builds where everything is okay.

We have following possibilities

java.lang.AssertionError: 
Expected: an instance of org.springframework.web.client.HttpServerErrorException
     but: <org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://localhost:8243/api/project/scenario2_project1/job/04666978-a301-4fd6-b680-112acbd91804/sourcecode": Connection reset; nested exception is java.net.SocketException: Connection reset> is a org.springframework.web.client.ResourceAccessException
Stacktrace was: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://localhost:8243/api/project/scenario2_project1/job/04666978-a301-4fd6-b680-112acbd91804/sourcecode": Connection reset; nested exception is java.net.SocketException: Connection reset
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:751)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:677)
    at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:452)
    at com.daimler.sechub.integrationtest.internal.TestRestHelper.upload(TestRestHelper.java:202)
    at com.daimler.sechub.integrationtest.api.AsUser.upload(AsUser.java:59)
    at com.daimler.sechub.integrationtest.scenario2.FileUploadSizeScenario2IntTest.handleBigUpload(FileUploadSizeScenario2IntTest.java:93)
    at com.daimler.sechub.integrationtest.scenario2.FileUploadSizeScenario2IntTest.when_file_exceeds_5MB_a_server_error_is_thrown(FileUploadSizeScenario2IntTest.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
    at com.daimler.sechub.integrationtest.api.IntegrationTestSetup$IntegrationTestStatement.evaluate(IntegrationTestSetup.java:159)
    at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
    at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:115)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
    at sun.security.ssl.OutputRecord.writeBuffer(OutputRecord.java:431)
    at sun.security.ssl.OutputRecord.write(OutputRecord.java:417)
    at sun.security.ssl.SSLSocketImpl.writeRecordInternal(SSLSocketImpl.java:879)
    at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:850)
    at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
    at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:124)
    at org.apache.http.impl.io.SessionOutputBufferImpl.write(SessionOutputBufferImpl.java:160)
    at org.apache.http.impl.io.ContentLengthOutputStream.write(ContentLengthOutputStream.java:113)
    at org.apache.http.entity.ByteArrayEntity.writeTo(ByteArrayEntity.java:112)
    at org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(DefaultBHttpClientConnection.java:156)
    at org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(CPoolProxy.java:152)
    at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:238)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
    at org.springframework.http.client.BufferingClientHttpRequestWrapper.executeInternal(BufferingClientHttpRequestWrapper.java:63)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:109)
    at com.daimler.sechub.integrationtest.internal.TestSecHubRestAPIClientHttpRequestInterceptor.intercept(TestSecHubRestAPIClientHttpRequestInterceptor.java:52)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:93)
    at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:77)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:742)
    ... 20 more
de-jcup commented 4 years ago

Sometimes we got HTTP server errors and sometimes they are Socketconnection errors.

The problem is about the embedded tomcat which does (sometimes) swallow up to big parts - and missing spring boot configuration ala server.tomcat.*.maxSwallowSize

So we got a flaky test.

see