首页 > 解决方案 > QAF:运行带有 NTLM 请求的脚本时出现“401 未经授权:访问被拒绝”

问题描述

我已经实现了 NTLMAuthClient 类

rest.client.impl=com.qmetry.qaf.automation.ws.client.NTLMAuthClient

进入项目属性,但仍然出现上述错误。

这是我正在使用的 JSON 请求模板,我不确定该结构是否是导致错误的原因:

{
    "headers":
    {
        "Authorization":
        [
            {
                "username": "${ntlm.user}",
                "password": "${ntlm.password}"
            },
            {
                "domain": "${ntlm.domain}"
            }
        ],
        "Content-Type":"application/json"
    },
    
    "endPoint": "",
    "baseUrl": "${base_url}/api/data/v4/contacts(integrationkey='${clientNumber}')",
    "method": "PATCH",
    
    "body":
    {
        "userid": ""
    }
}

以下是 QMetry 报告的回复:

要求

客户端出站请求 PATCH https://xxxx.com/CRMDEV2/api/data/v4/contacts(integrationkey='xxxx') 授权:[{username=xxxx, password=xxxx}, {domain=xxxx}] 内容-类型:应用程序/json {"userid":""}

回应

客户端入站响应 401 REQ_ID:3d391170-40d7-4ea6-80ca-2531a7fe73ff 服务器:WWW-Authenticate:NTLM WWW-Authenticate:Negotiate Set-Cookie:ReqClientId=21490c2c-bdfe-4c00-9330-401ca0bb5811;到期=格林威治标准时间 2071 年 10 月 22 日星期四 11:59:11;路径=/; 安全的; HttpOnly 内容长度:49 日期:2021 年 10 月 22 日星期五 11:59:11 GMT 内容类型:文本/纯 HTTP 错误 401 - 未经授权:访问被拒绝

感谢帮助。

我正在使用的 QAF 和 Selenium 版本:

QAF 版本:2.1.14

硒:3.141.59

标签: javajsonapintlmqaf

解决方案


请参阅NTLMAuthClient java-doc。而不是请求调用标头中的授权,您应该尝试提供由NTLMAuthClient.

NTLMAuthClient类使用以下属性:

ntlm.user - The user name. This should not include the domain to authenticate with. For example: "user" is correct whereas "DOMAIN\\user" is not.
ntlm.password - The password
ntlm.workstation - workstation (default is blank) The workstation the authentication request is originating from. Essentially, the computer name for this machine.
ntlm.domain- domain The domain to authenticate within (default is blank). 
#register NTLMAuthClient
rest.client.impl=com.qmetry.qaf.automation.ws.client.NTLMAuthClient

在您的属性文件中设置上述属性,然后在请求调用标头中尝试未经授权。


推荐阅读