Created
August 6, 2014 03:47
-
-
Save ledlogic/b152370b95e971b3992f to your computer and use it in GitHub Desktop.
Test case example attempting to catch a dropped f5 connection via a Spock functional test.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.***.catalog.url | |
import org.apache.http.client.HttpClient; | |
import static groovyx.net.http.ContentType.* | |
import static groovyx.net.http.Method.* | |
import groovyx.net.http.* | |
import org.apache.http.Header | |
import org.apache.http.HttpResponse; | |
import org.apache.http.client.HttpClient | |
import org.apache.http.client.params.ClientPNames; | |
import org.apache.http.impl.client.DefaultHttpClient | |
import org.apache.http.message.BasicHeader | |
import org.apache.http.protocol.BasicHttpContext | |
import org.apache.http.protocol.HttpContext | |
import spock.lang.* | |
import com.***.common.test.FunctionalTestConstants | |
import com.***.common.test.HttpContextUtil | |
// 1st: attempt overall timeout | |
//@Timeout(value=5) | |
class StackOverflowSpec extends Specification { | |
@Shared | |
static HTTPBuilder http | |
@Shared | |
def util = HttpContextUtil | |
def setupSpec() { | |
http = new HTTPBuilder(FunctionalTestConstants.PROVIDED_SERVER_ROOT) | |
} | |
// 2nd: attempt method timeout | |
//@Timeout(value=5) | |
def "Burp command injection"() { | |
HttpContext localContext = new BasicHttpContext(); | |
HttpClient httpClient = new DefaultHttpClient(); | |
Header header = new BasicHeader('Cookie', 'badcookie=ping%20-n%2020%20127.0.0.1||x;'); | |
Header[] headers = [ header ]; | |
def fromUrl = '[url1]' | |
def targetUrl = '[url1]' | |
HttpResponse response | |
when: | |
// 3rd: attempt waitfor timeout | |
//waitFor({ | |
response = util.routeUrlViaClientWithHeadersHttpResponse(localContext, httpClient, headers, fromUrl, targetUrl) | |
//}) | |
then: | |
Header[] responseHeaders = response.getAllHeaders() | |
for (Header responseHeader: responseHeaders) { | |
System.out.println("responseHeader[" + responseHeader + "]") | |
} | |
} | |
def waitFor(Closure condition) { | |
waitFor(null, condition) | |
} | |
def waitFor(Double timeoutSecs, Closure condition) { | |
waitFor(timeoutSecs, null, condition) | |
} | |
def waitFor(Double timeoutSecs, Double intervalSecs, Closure condition) { | |
timeoutSecs = timeoutSecs ?: 5 | |
intervalSecs = intervalSecs ?: 0.5 | |
def loops = Math.ceil(timeoutSecs / intervalSecs) | |
def pass = condition() | |
def i = 0 | |
while (pass == false && i++ < loops) { | |
Thread.sleep((intervalSecs * 1000) as long) | |
pass = condition() | |
} | |
if (i >= loops) { | |
throw new AssertionError("condition did not pass in $timeoutSecs seconds") | |
} | |
true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment