Skip to content

Commit

Permalink
Simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Feb 20, 2018
1 parent fa97a1f commit 05b5649
Showing 1 changed file with 34 additions and 50 deletions.
84 changes: 34 additions & 50 deletions batch_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,47 +75,45 @@ func TestBatch(t *testing.T) {
}

var virtBatchTest = `function batchTest (request, session, config) {
// Set up a response object
var response = {
Body: "",
Headers: {
"content-type": "application/json"
},
Code: 202
}
// Batch request
var batch = {
"requests": [
// Set up a response object
var response = {
Body: "",
Headers: {
"content-type": "application/json"
},
Code: 202
}
// Batch request
var batch = {
"requests": [
{
"method": "GET",
"headers": {},
"body": "",
"body": "",
"relative_url": "{upstream_URL}"
},
{
"method": "GET",
"headers": {},
"body": "",
"body": "",
"relative_url": "{upstream_URL}"
}
],
"suppress_parallel_execution": false
}
var newBody = TykBatchRequest(JSON.stringify(batch))
"suppress_parallel_execution": false
}
var newBody = TykBatchRequest(JSON.stringify(batch))
var asJS = JSON.parse(newBody)
for (var i in asJS) {
if (asJS[i].code == 0){
response.Code = 404
}
}
return TykJsResponse(response, session.meta_data)
response.Code = 500
}
}
return TykJsResponse(response, session.meta_data)
}`

func TestSSLBatch(t *testing.T) {

func TestVirtualEndpointBatch(t *testing.T) {
_, _, combinedClientPEM, clientCert := genCertificate(&x509.Certificate{})
clientCert.Leaf, _ = x509.ParseCertificate(clientCert.Certificate[0])

Expand All @@ -134,23 +132,15 @@ func TestSSLBatch(t *testing.T) {
upstream.StartTLS()
defer upstream.Close()

_, _, combinedPEM, _ := genServerCertificate()
serverCertID, _ := CertificateManager.Add(combinedPEM, "")
defer CertificateManager.Delete(serverCertID)

clientCertID, _ := CertificateManager.Add(combinedClientPEM, "")
defer CertificateManager.Delete(clientCertID)

virtBatchTest = strings.Replace(virtBatchTest, "{upstream_URL}", upstream.URL, 2)
defer upstream.Close()
log.Debug(upstream.URL)

upstreamHost := strings.TrimPrefix(upstream.URL, "https://")

config.Global.Security.Certificates.Upstream = map[string]string{upstreamHost: clientCertID}
config.Global.HttpServerOptions.UseSSL = true
config.Global.HttpServerOptions.SSLCertificates = []string{serverCertID}
config.Global.ProxySSLInsecureSkipVerify = true

defer resetTestConfig()

ts := newTykTestServer()
Expand All @@ -165,30 +155,24 @@ func TestSSLBatch(t *testing.T) {
Path: "/virt",
Method: "GET",
}
v := spec.VersionData.Versions["v1"]
v.UseExtendedPaths = true
v.ExtendedPaths = apidef.ExtendedPathsSet{
Virtual: []apidef.VirtualMeta{virtualMeta},
}
spec.VersionData.Versions["v1"] = v
updateAPIVersion(spec, "v1", func(v *apidef.VersionInfo) {
v.UseExtendedPaths = true
v.ExtendedPaths = apidef.ExtendedPathsSet{
Virtual: []apidef.VirtualMeta{virtualMeta},
}
})
})
client := &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
}}}

t.Run("Skip verification", func(t *testing.T) {
ts.Run(t, test.TestCase{
Path: "/virt", Code: 202, Client: client,
})
config.Global.ProxySSLInsecureSkipVerify = true

ts.Run(t, test.TestCase{Path: "/virt", Code: 202})
})

t.Run("Verification required", func(t *testing.T) {

config.Global.ProxySSLInsecureSkipVerify = false

ts.Run(t, test.TestCase{
Path: "/virt", Code: 404, Client: client,
})
ts.Run(t, test.TestCase{Path: "/virt", Code: 500})
})

}

0 comments on commit 05b5649

Please sign in to comment.