我们正试图测试使用Windows身份验证的api。我正在使用休息保证软件包来测试api的。任何建议如何将Windows用户登录到API请求标头?在io.restassured api测试中使用Windows身份验证
回答
已经解决了我的问题 因此,目前很难做到这一点,因为您需要为REST Assured配置HTTPClient,但它仅支持已弃用的AbstractHttpClient
。这是我的实现。但我没有能力测试它...
import io.restassured.RestAssured;
import org.apache.http.annotation.Contract;
import org.apache.http.annotation.ThreadingBehavior;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthSchemeFactory;
import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.auth.AuthSchemeRegistry;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.AuthSchemes;
import org.apache.http.impl.auth.BasicSchemeFactory;
import org.apache.http.impl.auth.DigestSchemeFactory;
import org.apache.http.impl.auth.win.WindowsCredentialsProvider;
import org.apache.http.impl.auth.win.WindowsNegotiateScheme;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.impl.client.SystemDefaultCredentialsProvider;
import org.apache.http.impl.client.SystemDefaultHttpClient;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import static io.restassured.config.HttpClientConfig.httpClientConfig;
import static java.net.HttpURLConnection.HTTP_OK;
public class WinHttpClientTest {
@Test
public void test() {
@Contract(threading = ThreadingBehavior.IMMUTABLE)
class WindowsNTLMSchemeFactory implements AuthSchemeProvider, AuthSchemeFactory {
private final String servicePrincipalName;
public WindowsNTLMSchemeFactory(final String servicePrincipalName) {
super();
this.servicePrincipalName = servicePrincipalName;
}
@Override
public AuthScheme create(final HttpContext context) {
return new WindowsNegotiateScheme(AuthSchemes.NTLM, servicePrincipalName);
}
@Override
public AuthScheme newInstance(HttpParams params) {
return new WindowsNegotiateScheme(AuthSchemes.NTLM, null) ;
}
}
@Contract(threading = ThreadingBehavior.IMMUTABLE)
class WindowsNegotiateSchemeFactory implements AuthSchemeProvider, AuthSchemeFactory {
private final String servicePrincipalName;
public WindowsNegotiateSchemeFactory(final String servicePrincipalName) {
super();
this.servicePrincipalName = servicePrincipalName;
}
@Override
public AuthScheme create(final HttpContext context) {
return new WindowsNegotiateScheme(AuthSchemes.SPNEGO, servicePrincipalName);
}
@Override
public AuthScheme newInstance(HttpParams params) {
return new WindowsNegotiateScheme(AuthSchemes.SPNEGO, null);
}
}
AuthSchemeRegistry authSceme = new AuthSchemeRegistry();
authSceme.register(AuthSchemes.BASIC, new BasicSchemeFactory());
authSceme.register(AuthSchemes.DIGEST, new DigestSchemeFactory());
authSceme.register(AuthSchemes.NTLM, new WindowsNTLMSchemeFactory(null));
authSceme.register(AuthSchemes.SPNEGO, new WindowsNegotiateSchemeFactory(null));
final CredentialsProvider credsProvider = new WindowsCredentialsProvider(new SystemDefaultCredentialsProvider());
AbstractHttpClient httpClient = new SystemDefaultHttpClient();
httpClient.setAuthSchemes(authSceme);
httpClient.setCredentialsProvider(credsProvider);
RestAssured.config = RestAssured.config().httpClient(httpClientConfig().httpClientFactory(() -> httpClient));
given()
.log().all()
.when()
.get("http://httpbin.org/get")
.then()
.log().all()
.statusCode(HTTP_OK);
}
}
这与认证无关。答案只会在标题中设置信息。 – Piazzolla
@Piazzolla的问题是:如何将Windows用户登录到API请求头?你想要什么? – RocketRaccoon
是的,这是问题的最后一部分,但至少标题和问题包括“Windows身份验证”以及有关哪个用户的信息不是仅用于身份验证的信息。我可以看到,我的答案可能会有点困难。 – Piazzolla
- 1. 测试HTTPS身份验证
- 2. 在IIS中使用Windows身份验证
- 3. 在Windows身份验证中使用SimpleMembershiProvider
- 4. 使用Perforce API测试用户身份验证?
- 5. web api中的Windows身份验证2
- 6. 如何使用Windows身份验证加载测试网页
- 7. 测试使用Windows身份验证的Intranet站点
- 8. 使用Windows身份验证的简单身份验证代理
- 9. 使用SoapUI和Windows身份验证测试Web服务
- 10. Sitecore的身份验证使用API身份验证/登录
- 11. 测试与Jasmine使用会话身份验证的AJAX API?
- 12. 使用Laravel5身份验证的Codeception功能API测试
- 13. 在ASP .NET Web Api中打开身份验证身份验证
- 14. 在Web API中使用Windows身份验证的自定义RoleProvider
- 15. 如何在API控制器中测试身份验证
- 16. Windows身份验证和Asp.Net Web API
- 17. Windows Azure表REST Api身份验证
- 18. 在IIS中启用Windows身份验证
- 19. Windows API清除身份验证令牌
- 20. 在Django Rest Framework中使用身份验证测试POST
- 21. 在Symfony2中使用WebTestCase测试oAuth/Facebook身份验证
- 22. 在REST WCF Web API中使用Windows身份验证对用户进行身份验证
- 23. Outlook REST API:尝试使用AZURE AD身份验证调用API
- 24. Windows身份验证 - 针对不同用户进行测试
- 25. Rails Api身份验证与用户身份验证
- 26. 使用的MVC API使用Windows身份验证从VBA
- 27. 使用窗体身份验证cookie中缓存角色 - (Windows身份验证)
- 28. 在Windows上使用OpenSSL通过身份验证访问REST API
- 29. 从使用Windows身份验证
- 30. 使用asp.net进行Windows身份验证
我也想找到这个。运气好的话? – Piazzolla