SSO login using scala script

994 views Asked by At

I have recorded a scala script using gatling, where it records "opentoken" as well in scala file. This scala file works fine incase of one user where as if increase no of user it does not records, because of SSo token, so Is there any way by which we can generate sso-token for scala file for login.
So how can generate opentoke dynamically for below scala file?

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class RecLoginLogoutP extends Simulation {

    val httpProtocol = http
        .baseURL("https://mywebsite.com")
        .inferHtmlResources(BlackList(""".*\.css.*|.*\.js.*|.*\.png.*|.*\.gif.*|.*\.jpeg.*|.*\.ico.*"""), WhiteList())
        .acceptHeader("""text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8""")
        .acceptEncodingHeader("""gzip, deflate""")
        .acceptLanguageHeader("""en-US,en;q=0.5""")
        .connection("""keep-alive""")
        .contentTypeHeader("""application/ocsp-request""")
        .userAgentHeader("""Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0""")



    val uri1 = """http://somewebsite.com/gsalphasha2g2"""
    val uri2 = """https://mywebsite.com:443"""
    val uri3 = """sso-mywebsite.com"""
    val uri4 = """www.mywebsite.com"""
    val uri5 = """cloudsso-test.mywebsite.com"""

    val scn = scenario("RecLoginLogoutP")
        .exec(http("request_0")
            .get("""/"""))
        .pause(1)
        .exec(http("request_1")
            .post(uri1 + """""")
            .body(RawFileBody("RecLoginLogoutP_request_0001.txt"))
            .resources(http("request_2")
            .post(uri1 + """""")
            .body(RawFileBody("RecLoginLogoutP_request_0002.txt"))))
        .pause(1)
        .exec(http("request_3")
            .get("""/sp/startSSO.ping?PartnerIdpId=cloudsso-test.mywebsite.com&TargetResource=https://mywebsite.com/"""))
        .pause(24)
        .exec(http("request_4")
            .post("https://" + uri3 + """:443/autho/login/loginaction.html""")
            .formParam("""userid""", """userName""")
            .formParam("""password""", """password""")
            .formParam("""target""", """""")
            .formParam("""smauthreason""", """""")
            .formParam("""smquerydata""", """""")
            .formParam("""smagentname""", """""")
            .formParam("""postpreservationdata""", """""")
            .formParam("""SMENC""", """""")
            .formParam("""SMLOCALE""", """"""))
        .pause(2)
        .exec(http("request_5")
            .get("https://" + uri5 + """:443/idp/Y61KXp/SSOServer.ping""")
            .resources(http("request_6")
            .post(uri2 + """/""")
            **.formParam("""opentoken""", """YKHHMSLKKSJHHFHFHFH-9fdfdjkhhjkfkdshfjdshjnythkkdjfdfdfdfdffdfdfd**""")))**
        .pause(105)
        // logout
        .exec(http("request_7")
            .get("""/c/portal/logout""")
            .resources(http("request_8")
            .get(uri2 + """/sp/startSSO.ping?PartnerIdpId=cloudsso-test.mywebsite.com&TargetResource=https://mywebsite.com/""")))
        .pause(12)
        .exec(http("request_9")
            .get("https://" + uri4 + """:443/autho/sclnup.html"""))

    setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
1

There are 1 answers

0
levo4ka On

I not sure, if a understand you problem correct, but for do login for couple of user you should add your token into correlation parameter in script, because it cannot be the same for different user.

P.S. In my usage of Gatling I do not use opentoken in login at all. But as I know, you can get this token from response of previous request -> save it into correlation name -> use it like parameters.