import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import io.gatling.http.request.builder.HttpRequestBuilder
import io.gatling.http.util.HttpHelper
import com.ning.http.client._
import com.ning.http.client.Realm.AuthScheme
import com.ning.http.client.Response
import java.util.Random
import java.util.HashMap
class IwaKerberosSimulation extends Simulation {
//Since we are replaying same saml request, change the replay window configuration parameter in IWA.config on IIS machine to a value of number of seconds in a day
val saml_request = “PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c2FtbDJwOkF1dGhuUmVxdWVzdCB4bWxuczpzYW1sMnA9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDpwcm90b2NvbCIgQXNzZXJ0aW9uQ29uc3VtZXJTZXJ2aWNlVVJMPSJodHRwczovL3RydW5rLnN5bWFudGVjLmNvbS9zc2ctc2FtbC9zYW1sL3VzZXJEYXRhP2lkPTQ4NmY4ZTAyLTJjYzgtNGQ1ZC1iYmE3LWRjZTUzNjUxZjE2MCIgRGVzdGluYXRpb249Imh0dHBzOi8vZ2toYWRrZS1paXM2LmluZm9zZWMuc2FtaXdhdGVzdC5zeW1jbGFiLm5ldCIgSUQ9Il82ZGI5ZTQwMzI2MzI0N2M0YmQ5ZTllMTAzMmE1ZGY1OCIgSXNzdWVJbnN0YW50PSIyMDE1LTAzLTIzVDA1OjI3OjU3Ljg0N1oiIFZlcnNpb249IjIuMCI+PHNhbWwyOklzc3VlciB4bWxuczpzYW1sMj0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOmFzc2VydGlvbiIgRm9ybWF0PSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6bmFtZWlkLWZvcm1hdDplbnRpdHkiPnNhbS1zcDwvc2FtbDI6SXNzdWVyPjxkczpTaWduYXR1cmUgeG1sbnM6ZHM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvMDkveG1sZHNpZyMiPjxkczpTaWduZW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NtS3RBMHR3QXFuU2c1cGVXeUxsQkl3Zm1WZVh0NnpYRkdnSWVlR09nN1dDcWxkbExiWEQ1Vm5FWFJnc0dsQ3Y4cGpmbis2STlWYUw5eWZPaVo4Ym43OTkvSjYrK3RIR3MwbVlBc09taXpoNTVtQzljUDJsNUliUT09PC9kczpTaWduYXR1cmVWYWx1ZT48L2RzOlNpZ25hdHVyZT48L3NhbWwycDpBdXRoblJlcXVlc3Q+”
//This is IWA Server URL or Load balancer URL
val iwaURL = “https://gkhadke-iis6.infosec.samiwatest.symclab.net”
val samURL = “https://trunk.symantec.com” //This is the SAM URL or IP address based on how you have setup SAM Gateway. If hostname is being used, it should be resolvable on performance test client using /etc/hosts file.
val connector_id = “486f8e02-2cc8-4d5d-bba7-dce53651f160” //This is the identity service connector uuid in SAM for IWA-IdP
val samlResponseRegex = regex("""<input type=“hidden” name=“SAMLResponse” id=“SAMLResponse” value="([^"])" />""").saveAs(“SAMLResponse”)
val viewStateRegex = regex("""<input type=“hidden” name="__VIEWSTATE" id="__VIEWSTATE" value="([^"])" />""").saveAs("__VIEWSTATE")
val viewStateGeneratorRegex = regex("""<input type=“hidden” name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="([^"])" />""").saveAs("__VIEWSTATEGENERATOR")
val eventValidationRegex = regex("""<input type=“hidden” name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="([^"])" />""").saveAs("__EVENTVALIDATION")
val nameIdRegex = regex("""<input type=“hidden” name=“nameId” value="([^"])"/>""").saveAs(“nameId”)
val mailRegex = regex("""<input type=“hidden” name=“mail” value="([^"])"/>""").saveAs(“mail”)
val samaccountnameRegex = regex("""<input type=“hidden” name=“samaccountname” value="([^"])"/>""").saveAs(“samaccountname”)
val relayStateURLRegex = regex("""<input type=“hidden” name=“relayStateURL” value="([^"])"/>""").saveAs(“relayStateURL”)
val signedKeyRegex = regex("""<input type=“hidden” name=“signedkey” value="([^"])"/>""").saveAs(“signedKey”)
val ssgTrustKeyRegex = regex("""<input type=“hidden” name=“ssg_trust_key” value="([^"])"/>""").saveAs(“ssgTrustKey”)
val ssgIdpIdRegex = regex("""<input type=“hidden” name=“ssg_idp_id” value="([^"])"/>""").saveAs(“ssgIdpId”)
val transactionIDRegex = regex("""<input type=“hidden” name=“transactionID” value="([^"])"/>""").saveAs(“transactionID”)
val formPostURLRegex = regex("""<form name=“acsForm” action="([^"]*)" method=“post” target="_blank">""").saveAs(“formPostURL”)
val fedIDRegex = regex("""([^"]*)""").saveAs(“federatedId”)
val scn = scenario(“IWA Kerberos Simulation”)
.during(100 seconds) {
exec(
http(“Kerberos Test”)
.post(iwaURL)
.formParam(“SAMLRequest”, saml_request)
.check(status.is(200))
.check(samlResponseRegex)
.check(viewStateRegex)
.check(viewStateGeneratorRegex)
.check(eventValidationRegex)
)
.pause(3)
.exec(
http(“POST UserData to SAML Service on SAM”)
.post(samURL + “/ssg-saml/saml/userData?id=” + connector_id)
.formParam(“SAMLResponse”, “”"${SAMLResponse}""")
.formParam("__VIEWSTATE", “”"${__VIEWSTATE}""")
.formParam("__VIEWSTATEGENERATOR", “”"${__VIEWSTATEGENERATOR}""")
.formParam("__EVENTVALIDATION", “”"${__EVENTVALIDATION}""")
.check(status.is(200))
.check(formPostURLRegex)
.check(relayStateURLRegex)
.check(signedKeyRegex)
.check(ssgTrustKeyRegex)
.check(ssgIdpIdRegex)
.check(transactionIDRegex)
.check(nameIdRegex)
.check(mailRegex)
.check(samaccountnameRegex)
.check(nameIdRegex)
)
.pause(3)
.exec(
http(“POST SAML Response to SAM”)
.post("""${formPostURL}""")
.formParam(“relayStateURL”, “”"${relayStateURL}""")
.formParam(“signedkey”, “”"${signedKey}""")
.formParam(“ssg_trust_key”, “”"${ssgTrustKey}""")
.formParam(“ssg_idp_id”, “”"${ssgIdpId}""")
.formParam(“transactionID”, “”"${transactionID}""")
.formParam(“samaccountname”, “”"${samaccountname}""")
.formParam(“mail”, “”"${mail}""")
.formParam(“nameId”, “”"${nameId}""")
.check(status.is(200))
)
.pause(1)
.exec(
http(“GET on SAM SSO Portal URL”)
.get(samURL)
.check(status.is(200))
.check(fedIDRegex)
)
.exec(
session => {
println("====Federated Id for logged in user ====> " + session(“federatedId”).as[String])
session
})
}
val httpConf = http
.baseURL(iwaURL)
.authRealm(HttpHelper.buildRealm(getRandomUser(), “password@2”, AuthScheme.KERBEROS, false, None, None))
.acceptHeader(“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”)
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.5”)
.connectionHeader(“keep-alive”)
.contentTypeHeader(“application/x-www-form-urlencoded”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0”)
setUp(scn.inject(atOnceUsers(1)).protocols(httpConf))
def getRandomUser(): String = {
val myHashMap = new HashMapInteger, String
myHashMap.put(0, “girish_khadke”)
myHashMap.put(1, “prasad_bokare”)
myHashMap.put(2, “gary_krall”)
val generator = new Random()
val values = myHashMap.values.toArray()
val randomValue = values(generator.nextInt(values.length)).asInstanceOf[String]
randomValue
}
}
This is my gatling simulation script.
I am trying to run the scenario for ~24 hours using random usernames.
Problem here is the protocolConfiguration DSL element can not use CSV feeder and it also can not take a list of httpConfigurations with same URL but different realm (using a new username) needs to be build everytime for each request.
Any idea on how this can be done?