1

AzureのApplication Insights Availability機能で「.webtest」をインポートしたいとします。私はVisual Studioのテスト版を持っていませんが、this MSDN articleは、Webテストを作成する別のオプションとしてFiddlerを使用するよう提案しています。 connect/tokenエンドポイントからのベアラトークンVisual Studioを使用せずに「Webテスト」でベアラトークンを渡す?

  1. 要求:

    私はREST APIの2つの要求を実行する必要があります。

  2. ヘッダー内のベアラトークン(上記の要求から取得)を使用してapi/resourcesでGETを実行します。

これは一般的なクライアントの認証情報OAuth 2の流れです。

私はフィドラーでこれを行う方法を理解できないようです。

<?xml version="1.0" encoding="utf-8"?> 
<TestCase Name="FiddlerGeneratedWebTest" Id="" Owner="" Description="" Priority="0" Enabled="True" CssProjectStructure="" CssIteration="" DeploymentItemsEditable="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="" RequestCallbackClass="" TestCaseCallbackClass=""> 
    <Items> 
    <Request Method="POST" Version="1.1" Url="https://example.com/connect/token" ThinkTime="8" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8"> 
     <Headers> 
     <Header Name="Content-Type" Value="application/x-www-form-urlencoded" /> 
     </Headers> 
     <FormPostHttpBody ContentType="application/x-www-form-urlencoded"> 
     <FormPostParameter Name="client_id" Value="myclientid" UrlEncode="True" /> 
     <FormPostParameter Name="client_secret" Value="password123" UrlEncode="True" /> 
     <FormPostParameter Name="grant_type" Value="client_credentials" UrlEncode="True" /> 
     <FormPostParameter Name="scope" Value="myscopes" UrlEncode="True" /> 
     </FormPostHttpBody> 
    </Request> 
    <Request Method="GET" Version="1.1" Url="https://example.com/api/resources" ThinkTime="0" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8"> 
     <Headers> 
     <Header Name="Authorization" Value="Bearer {{token}}" /> 
     </Headers> 
    </Request> 
    </Items> 
</TestCase> 

答えて

1

と仮定:基本的に私は、これは、Webテストはトークンを通過せずに次のようになります。2.

要求で要求1のレスポンスボディから値を抽出し、ヘッダ値としてそれを使用する必要がありますこれは、次の例のように正規表現の抽出を使用して取得することができます。

{"token_type":"Bearer","scope":"user_impersonation","expires_in":"3600 ... "access_token":"{{TOKEN}}", ...}

<?xml version="1.0" encoding="utf-8"?> 
<TestCase Name="FiddlerGeneratedWebTest" Id="" Owner="" Description="" Priority="0" Enabled="True" CssProjectStructure="" CssIteration="" DeploymentItemsEditable="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="" RequestCallbackClass="" TestCaseCallbackClass=""> 
    <Items> 
    <Request Method="POST" Version="1.1" Url="https://example.com/connect/token" ThinkTime="8" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8"> 
     <ExtractionRules> 
      <ExtractionRule Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ExtractRegularExpression, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" VariableName="token" DisplayName="Extract Regular Expression" Description="Extract text from the response matching a regular expression and place it into the test context."> 
       <RuleParameters> 
       <RuleParameter Name="RegularExpression" Value=".*&quot;access_token&quot;:&quot;([^&quot;]*)&quot;.*" /> 
       <RuleParameter Name="IgnoreCase" Value="True" /> 
       <RuleParameter Name="Required" Value="True" /> 
       <RuleParameter Name="Index" Value="0" /> 
       <RuleParameter Name="HtmlDecode" Value="True" /> 
       <RuleParameter Name="UseGroups" Value="True" /> 
       </RuleParameters> 
      </ExtractionRule> 
     </ExtractionRules> 
     <Headers> 
     <Header Name="Content-Type" Value="application/x-www-form-urlencoded" /> 
     </Headers> 
     <FormPostHttpBody ContentType="application/x-www-form-urlencoded"> 
     <FormPostParameter Name="client_id" Value="myclientid" UrlEncode="True" /> 
     <FormPostParameter Name="client_secret" Value="password123" UrlEncode="True" /> 
     <FormPostParameter Name="grant_type" Value="client_credentials" UrlEncode="True" /> 
     <FormPostParameter Name="scope" Value="myscopes" UrlEncode="True" /> 
     </FormPostHttpBody> 
    </Request> 
    <Request Method="GET" Version="1.1" Url="https://example.com/api/resources" ThinkTime="0" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8"> 
     <Headers> 
     <Header Name="Authorization" Value="Bearer {{token}}" /> 
     </Headers> 
    </Request> 
    </Items> 
</TestCase> 
+0

は素晴らしい作品。このようなテストをVSテスト版なしで作成する方法はありますか?私が見ることのできるところから、Fiddlerは記録や再生要求以上のことはできません。 – davenewza

関連する問題