我正在验证OTP服务的提供者协议,它具有基本Auth用户名和密码,并且请求中的标头为“ Authorization”:“ abc”

问题描述 投票:0回答:1

代码:

@TestTarget
    public final Target target = new HttpTarget("https", "digital-dev.mashreq.com/api/otp-service/api/v1/otp", 8080, "/generate");
    private static ConfigurableWebApplicationContext application;


    @TargetRequestFilter
    public void exampleRequestFilter (HttpRequest request) throws UnsupportedEncodingException {
        // Authorization header Base64 encoded...
        request.addHeader("Authorization", "Basic " + base64StringOf("OtpUser", "otp@123"));
        request.addHeader("Content-Type", "application/json");
        request.addHeader("Authorization", "Basic T3RwVXNlcjpvdHBAMTIz");

    }

    private String base64StringOf(String username, String password) {
        return Base64.getEncoder().encodeToString((username + ":" + password).getBytes());
    }

控制台:

java.lang.AssertionError: 
0 - Expected a header 'Authorization' but was missing
1 - assert expectedStatus == actualStatus
           |              |  |
           200            |  404
                          false

我认为我做错了,但仍然找不到解决方法。

java pact
1个回答
0
投票

有两个问题:

  1. 您的提供者没有返回带有键Authorization的标头
  2. 提供者以404响应

对于(1),您是否希望OTP在授权标头中返回,或者这是一个错误? OTP是作为正文项还是标题返回的? (返回另一个Authorization标头IMO似乎很奇怪。)>

对于(2),这可能是由于提供者的设置不正确。也许

您还发布了两个Authorization标头-这似乎很奇怪。

FWIW我现在可以立即访问此API,但是它失败,并显示404,表明未找到消息:

{"timestamp":"2020-02-09T11:28:39.411+0000","status":404,"error":"Not Found","message":"No message available","path":"/api/v1/otp:8080"}%                                                                                                                                                                                   
  1. 仅是为了确保您不打算在此网站上发布有效的凭证
  • 也许需要设置提供商状态才能使OTP正常工作?
  • © www.soinside.com 2019 - 2024. All rights reserved.