0

WCAT を使用して、ASP.NET MVC アプリケーションに対して負荷テストを実行しています。このアプリは偽造防止トークンのセキュリティ検証を使用しているため、偽造防止 Cookie 値を取得するたびに有効なトークンを挿入するために、WCAT スクリプト値で postdata 値を動的に生成できるかどうか疑問に思っています。

何か案は?前もって感謝します。

4

1 に答える 1

1

私はそれができると確信していますが、有効な偽造防止トークンを生成する WCAT トランザクションをスクリプト化する方法を知りません。

代わりに、ValidateAntiForgeryTokenAttribute() をすべての POST アクションに適用する条件付きフィルターを実装しました。条件付きフィルターを配置したら、AppSettings 値を追加して、属性をオン/オフにすることができます。つまり、負荷テストを行っているときはオフにします。

条件付きフィルターの実装方法については、こちらをご覧ください。

私のプロジェクトでは、次のように Global.asax.cs Application_Start() で条件付きフィルターを有効または無効にします。

bool useAntiForgeryToken = string.Compare(ConfigurationManager.AppSettings["useAntiForgeryToken"], "true", StringComparison.InvariantCultureIgnoreCase) == 0;
if (useAntiForgeryToken) {

    // Ensure that all POST actions are automatically decorated with the ValidateAntiForgeryTokenAttribute.
    IEnumerable<Func<ControllerContext, ActionDescriptor, object>> conditions =
        new Func<ControllerContext, ActionDescriptor, object>[] {
        (controllerContext, actionDescriptor) =>
            string.Equals(controllerContext.HttpContext.Request.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase ) ? new ValidateAntiForgeryTokenAttribute() : null
    };

    // Create the conditional filter using the condition we defined
    var provider = new ConditionalFilterProvider(conditions);

    // And add the conditional filter
    FilterProviders.Providers.Add(provider);
}

そして、web.config に次のような AppSetting があります。

<appSettings>
    <add key="useAntiForgeryToken" value="true">
</appSettings>

注: 偽造防止トークンを無効にするだけでなく、次のように web.config で requestValidation モードを 2.0 に設定する必要があります (参照)。

<httpRuntime requestValidationMode="2.0">

これらの準備が整ったら、WCAT スクリプトを再度実行すると、正常に動作するはずです。

于 2013-11-28T02:10:13.163 に答える