Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 在'中传递不记名令牌;网络测试&x27;没有VisualStudio?_Visual Studio_Visual Studio 2015_Fiddler_Azure Application Insights - Fatal编程技术网

Visual studio 在'中传递不记名令牌;网络测试&x27;没有VisualStudio?

Visual studio 在'中传递不记名令牌;网络测试&x27;没有VisualStudio?,visual-studio,visual-studio-2015,fiddler,azure-application-insights,Visual Studio,Visual Studio 2015,Fiddler,Azure Application Insights,我想在Azure的Application Insights可用性功能中导入“.webtest”。我没有Visual Studio的测试版,但建议使用Fiddler作为创建web测试的另一个选项 我需要在REST API上执行2个请求: 从connect/token端点请求承载令牌 在头中使用承载令牌(从上述请求中检索)执行GET atapi/resources 这是典型的客户端凭证OAuth 2流 我似乎想不出怎么用Fiddler来做这件事。基本上,我需要从请求1的响应体中提取一个值,并将其用作

我想在Azure的Application Insights可用性功能中导入“.webtest”。我没有Visual Studio的测试版,但建议使用Fiddler作为创建web测试的另一个选项

我需要在REST API上执行2个请求:

  • connect/token
    端点请求承载令牌
  • 在头中使用承载令牌(从上述请求中检索)执行GET at
    api/resources
  • 这是典型的客户端凭证OAuth 2流

    我似乎想不出怎么用Fiddler来做这件事。基本上,我需要从请求1的响应体中提取一个值,并将其用作请求2中的头值

    这是web测试在不传递令牌的情况下的外观:

    <?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>
    

    假设这是下面的示例,您可以使用正则表达式提取来获取它

    {“令牌类型”:“承载”、“作用域”:“用户模拟”、“到期日”:“3600…”“访问令牌”:“{{令牌}”,…}

    <?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>
    
    
    
    如果您需要通过发布JSON登录到,请向致意:

    {
      user: 'youruser', 
      password: 'yourpassword'
    }
    
    first base64对json进行编码:

    > echo "{user: 'youruser', password: 'yourpassword'}" | base64
    e3VzZXI6ICd5b3VydXNlcicsIHBhc3N3b3JkOiAneW91cnBhc3N3b3JkJ30K
    
    然后在StringHttpBody标记中传递此base64值

    <?xml version="1.0" encoding="utf-8"?>
    <WebTest Name="login-healthcheck" Id="e91b6e1d-3fa0-475f-a18b-b694b463589c" Owner="" Priority="0" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="" ResultsLocale="">
      <Items>
        <Request Method="POST" Guid="ef9d1d00-5663-476a-a3cb-ccf49c4d2229" Version="1.1" Url="https://yourapp.com/auth/login" ThinkTime="8" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
          <Headers>
            <Header Name="Content-Type" Value="application/json" />
          </Headers>
          <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>
          <StringHttpBody ContentType="application/json" InsertByteOrderMark="False">e3VzZXI6ICd5b3VydXNlcicsIHBhc3N3b3JkOiAneW91cnBhc3N3b3JkJ30K</StringHttpBody>
        </Request>
        <Request Method="GET" Guid="d566422f-af74-47bf-90aa-0c66db6ef567" Version="1.1" Url="https://yourapp.com/api/v1/healthcheck" ThinkTime="0" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False">
          <Headers>
            <Header Name="Authorization" Value="Bearer {{token}}" />
          </Headers>
        </Request>
      </Items>
    </WebTest>
    
    
    
    很好。有没有办法在没有VS测试版本的情况下编写这样的测试?从我所看到的,Fiddler除了录制和回放请求之外,做不了更多的事情。