2013-09-02 2 views
0

WCAT를 사용하여 ASP.NET MVC 어플리케이션에 대한로드 테스트를 수행하고 있습니다. 이 응용 프로그램은 위조 토큰 보안 유효성 검사를 사용하기 때문에 위조 방지 쿠키 값을 얻을 때마다 유효한 토큰을 주입하기 위해 WCAT 스크립트 값에 동적으로 postdata 값을 생성 할 수 있는지 궁금합니다.WCAT로드 테스트와 함께 ValidateAntiForgeryTokenAttribute() 작업

아이디어가 있으십니까? 미리 감사드립니다.

답변

1

확신 할 수 있지만 유효한 위조 토큰을 생성하는 WCAT 트랜잭션을 스크립팅하는 방법을 알지 못합니다.

대신에, 내가 한 것은 모든 POST 작업에 ValidateAntiForgeryTokenAttribute()를 적용하는 조건부 필터를 구현하는 것입니다. 일단 조건부 필터가 있으면 속성을 설정/해제 할 수있는 AppSettings 값을 추가 할 수 있습니다. 즉,로드 테스트를 수행하는 경우로드 테스트를 종료합니다.

조건부 필터 here을 구현하는 방법을 배울 수 있습니다. 내 프로젝트에서

, 나는 활성화하고이 같은 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에서 2.0으로 requestValidation 모드를 설정 (reference)가 필요합니다 :

<httpRuntime requestValidationMode="2.0"> 

이러한 작업이 완료되면 WCAT 스크립트를 다시 실행하여 황금색이어야합니다.

관련 문제