使用CSV Feeder的加特林登录场景

问题描述 投票:0回答:1

我必须用Gatling / Scala编写一些测试。在我的具体情况下,我必须使用用户名和密码登录到网站(此外,还有密钥库安全性)。有一个包含很多用户/密码行的CSV文件,我的目标是使用该CSV文件中的每个用户/密码登录。

问题是我不知道该怎么做。我只用一个用户就可以使用用户名/密码和密钥斗篷的安全令牌登录。到目前为止还可以,但是还不够。这是我到目前为止所做的。

头等舱:

class LasttestBestand extends Simulation {

  val context = Context.ladeContext("de", "integ")
  val userCredentials = TestdatenImport.ladeTestDaten("de")

  val httpProtocol = http
    .baseUrl(s"${context.protocol}://${context.host}")
    .inferHtmlResources(
      BlackList(""".*\.css""", """.*\.js""", """.*\.ico""", """.*\.woff"""),
      WhiteList()
    )
    .acceptHeader("application/json, text/plain, */*")
    .acceptEncodingHeader("gzip, deflate")
    .acceptLanguageHeader("de,en-US;q=0.7,en;q=0.3")
    .disableFollowRedirect
    .userAgentHeader(
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:63.0) Gecko/20100101 Firefox/63.0"
    )

  val scn = scenario("Lasttest Bestand")
    .feed(userCredentials.csvFeeder)
    .exec(Login.holeAccessToken("${Benutzername}", "${Passwort}", context))
    .exec(Suche.ladeKundensucheResourcen(context))

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

供稿器类别:

class TestdatenImport(val csvFeeder: BatchableFeederBuilder[String]) {}

object TestdatenImport {

  def ladeTestDaten(land: String) = {
    val csvFeeder = csv(s"data/eca-bb3-${land}-testdaten.csv").circular

    new TestdatenImport(
      csvFeeder
    )
  }
}

登录:

object Login {
  def holeAccessToken(
      benutzer: String,
      passwort: String,
      context: Context
  ): ChainBuilder = {
    val keycloakUri = s"${context.protocol}://${context.keycloakHost}"
    val redirectUri =
      s"${context.protocol}%3A%2F%2F${context.host}%2Fapp%2F%3Fredirect_fragment%3D%252Fsuche"

    exec(
      http("Login Page")
        .get(
          s"$keycloakUri/auth/realms/${context.realm}/protocol/openid-connect/auth"
        )
        .queryParam("client_id", "bestand-js")
        .queryParam("redirect_uri", redirectUri)
        .queryParam("state", UUID.randomUUID().toString())
        .queryParam("nonce", UUID.randomUUID().toString())
        .queryParam("response_mode", "fragment")
        .queryParam("response_type", "code")
        .queryParam("scope", "openid")
        .header(
          "Accept",
          "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
        )
        .header("Upgrade-Insecure-Requests", "1")
        .check(status.is(200))
        .check(
          css("#kc-form-login")
            .ofType[Node]
            .transform(variable => {
              variable.getAttribute("action")
            })
            .saveAs("loginUrl")
        )
    ).exec(
        http("Login")
          .post("${loginUrl}")
          .formParam("username", benutzer)
          .formParam("password", passwort)
          .header(
            "Accept",
            "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
          )
          .header("Upgrade-Insecure-Requests", "1")
          .check(status.is(302))
          .check(
            header("Location")
              .transform(url => {
                url.substring(url.indexOf("code=") + 5, url.length())
              })
              .saveAs("code")
          )
          .check(header("Location").saveAs("nextPage"))
      )
      .exec(
        http("Fetch Token")
          .post(
            s"$keycloakUri/auth/realms/${context.realm}/protocol/openid-connect/token"
          )
          .header("Accept", "*/*")
          .header("Origin", s"${context.protocol}://${context.host}")
          .formParam("code", "${code}")
          .formParam("grant_type", "authorization_code")
          .formParam("client_id", "bestand-js")
          .formParam("redirect_uri", redirectUri)
          .check(status.is(200))
          .check(
            jsonPath("$..access_token")
              .saveAs("accessToken")
          )
      )
  }
}

您可以看到我向方案添加了一个供稿器,但是我不知道如何在CSV文件中存在用户/密码行的次数“重复”登录。我该怎么办?

scala security gatling
1个回答
0
投票

注入与您在CSV文件中的条目一样多的用户,例如:

scn.inject(
  rampUsers(numberOfEntries) during(10 minutes)
)
© www.soinside.com 2019 - 2024. All rights reserved.