在加特林使用OAuth1

时间:2018-07-09 17:02:37

标签: scala oauth load-testing gatling

我正在尝试在具有OAuth1身份验证的Rest API上测试运行负载测试,事实证明这非常具有挑战性。 目前,我有这个httprequestbuilder基于其他我正在寻找答案的东西,但它仍返回401

 import client.test.util.{OAuthToken, OAuthUserAssistant}
    import io.gatling.http.request.builder.HttpRequestBuilder
    import org.asynchttpclient.oauth.{ConsumerKey, OAuthSignatureCalculator, RequestToken}

    object OAuth1Assistant {    
      private val consumerKey: ConsumerKey = new ConsumerKey(consumer, consumerSecret)



    private val oauthToken: OAuthToken = OAuthUserAssistant.builder()
            .withAuthority(canonicalDomain)
            .withConsumerKey(consumer)
.withConsumerSecret(consumersecret)
                .withUsername(username)
                .withPassword(password)
                .build
                .getToken

          println(oauthToken)
        println(consumerKey)
          private val getRequestToken: RequestToken = new RequestToken(oauthToken.getToken, oauthToken.getTokenSecret)

          /**
            * Wrapper that enhances an HttpRequestBuilder with OAuth
            *
            * @param httpRequestBuilder requestBuilder to add oauth to
            */
          implicit class OAuthWrapper(httpRequestBuilder: HttpRequestBuilder) {

            /**
              * Attaches an OAuthSignatureCalculator to the HttpRequestBuilder in context
              *
              * @return
              */
            def withOAuth: HttpRequestBuilder = {
              httpRequestBuilder.signatureCalculator(new OAuthSignatureCalculator(consumerKey, getRequestToken))
            }
            println(httpRequestBuilder.signatureCalculator(new OAuthSignatureCalculator(consumerKey, getRequestToken)))
          }

        }

我通过查看此图片和其他人的类似内容来创建此图片 https://github.com/gatling/gatling/blob/master/src/sphinx/http/http_request.rst

.signWithOAuth1(consumerKey: Expression[String],
                clientSharedSecret: Expression[String],
                token: Expression[String],
                tokenSecret: Expression[String])

感谢您的帮助

0 个答案:

没有答案