NTLM authentication for REST api in Karate framework - karate

Have anyone tried NTLM authentication implemented in Karate framework which i could refer? I get 401 authorization issue while I try building a test and pass header argument.
#BeforeClass
public static void before() {
System.setProperty("http.auth.ntlm.domain", "***");
System.setProperty("jcifs.smb.client.domain", "***");
System.setProperty("jcifs.smb.client.username", "***");
System.setProperty("jcifs.smb.client.password", "***");
System.setProperty("java.protocol.handler.pkgs", "jcifs");
}

Unfortunately NTLM support is not yet implemented in Karate. There is an open feature request: https://github.com/intuit/karate/issues/372 We'll need you or someone to contribute this from the open-source community.
Meanwhile you should be able to work-around this by using a Java library or custom Java code that does the necessary authentication. Refer to the Java inter-op section of the Karate documentation: https://github.com/intuit/karate#calling-java
EDIT: also see https://stackoverflow.com/a/51150286/143475
EDIT - you can use curl ! https://stackoverflow.com/a/64352676/143475

Related

SPNEGO authentication with Selenium Web Driver

I have SPNEGO authentication for my applications and am doing automated testing using selenium HtmlUnitDriver.
I have tried running the browser automation code inside login context of SPNEGO authentication, but it seems like it is not working,
The body of the lambda is in authentication context already. And SPNEGO is working for REST calls, but not for HtmlUnitDriver.
myACtion -> {
WebDriver driver = new HtmlUnitDriver();
driver.navigate().to(url);
}
Subject.doAs(loginContext.getSubject(), myAction);
If someone can tell me how to use SPNEGO keytab authentication with HtmlUnitDriver in selenium, I would really appreciate.
There is no support so far.
If you like to see this supported i can offer this:
implement a complete working minimal sample using only org.apache.httpcomponents 4.5.10 (maybe this might help https://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html)
open a HtmlUnit issue on github and provide your sample code
i will add the required support to HtmlUnit

Tests in the repo - virtserver

I am exploring the xero java sdk on the github. I am examining the tests in the com.veersoft.api.client. Many tests have the following
new ApiClient("https://virtserver.swaggerhub.com/Xero/accounting/2.0.0",null,null,null);
What is that 'virtserver' url in the above api?
The virtserver is a virtual server on swaggerhub where we have our OpenAPI spec documents. We've mocked up API responses for endpoints and call those to test the models in the Java SDK.
https://app.swaggerhub.com/apis/Xero/accounting/2.0.0

Versioning with WebAPI .Net Core does not work as expected

I am trying to introduce URL versioning into my .Net Core WebAPI application. I am also using Swagger web tools for ease of use for users.
Now, while trying to introduce versioning into my application, I referenced the docs here: https://github.com/Microsoft/aspnet-api-versioning/wiki/New-Services-Quick-Start#aspnet-core
Now, I made following code changes into my code:
Startup.cs/ConfigureServices I added code below:
services.AddApiVersioning(options => {
options.AssumeDefaultVersionWhenUnspecified = true;
});
Now, my controller annotations before any kind of versioning was added, looked like below:
[Produces("application/json")]
[Route("api/controllerName")]
and produces a URL which looks like something below:
http://localhost:12003/swagger/#!/Workspace/GetAll
Now, I added annotations below to enable api versioning:
. [ApiVersion("1.0")]
[Produces("application/json")]
[Route("api/v{version:apiVersion}/workspace")]
and now when I click on the same method listed in my swagger UI
the url looks like below:
http://localhost:12003/swagger/#!/controllername/ApiV_versionGetAll
While what I was expecting was something like:
http://localhost:12003/swagger/#!/controllername/V1.0/GetAll
Also on my swagger it is now asking me explicitly about entering version number. So I think my question boils down to two major points:
How I can I fix my URL? and what am I doing wrong?
Why is swagger now asking me to enter version number in API UI when I have explicitly stated that the version is going to be 1.0 in the annotation of the controller?
What you are missing is the complementary package for API versioning that supports an API version-aware API Explorer:
https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer
Install-Package Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer
The API Explorer is how Swagger generators like Swashbuckle do all their work. The source and links are also available in the API versioning repo.
To achieve the result you want, you need to configure API version substitution in the URL:
services.AddMvcCore().AddVersionedApiExplorer( options => options.SubstituteApiVersionInUrl = true );
Note: that the call the AddMvcCore() is no longer required in API Versioning 3.0+
Documentation and samples are available in the official API versioning repo. I recommend reviewing the API Documentation wiki topic:
https://github.com/Microsoft/aspnet-api-versioning/wiki/API-Documentation
The accepted answer extends this package, which is fine as long as it stay up-to-date with the flavor of API versioning you are using. API Versioning always ships compatible API Explorer extensions on every release.
Setting up api versioning with swagger is indeed a tricky thing as it is lot's of pieces that need to be setup correctly.
Luckily for us, there's a great nuget packages called SwashbuckleAspNetVersioningShim which solves this in an excellent way.
Add it
Install-Package SwashbuckleAspNetVersioningShim -Version 2.2.1
Then follow the readme here

Dynamically controlled swagger / openapi mock server for testing purposes

I'm looking for a project/tool that is able to get swagger / openapi specifications file as a parameter and generate a mock server that can be controlled programmatically via a REST API interface.
For example - if my API contains the following endpoint: "POST /v1/create"
and I have a swagger specs that describe that API, I would like my mock server to be executed in a way similar to:
mock-server -f swagger.yaml -p 8080
While the server runs, It will be possible to interact with it's own REST API (on some control interface via a different port) and change the behavior of the running swagger mock server - i.e: change response code, set response content etc'
I would like to use such mock-server as part of my system-tests suite to better verify my service behavior when interacting with other services - without the need to run those 'real' services.
I'm looking for something similar in spirit to Shopyify's ToxiProxy (https://github.com/Shopify/toxiproxy) but with the above capabilities.
Thanks!
Eldad
I know I'm a bit late to the party on this one, but for future searchers, MockLab now supports auto-generation of mock APIs from an imported Swagger definition and Swaggerhub webhooks.
More details here:
https://www.mocklab.io/blog/mocklab-now-supports-swagger-and-swaggerhub/
I believe Specmatic should help you with this.
mock-server -f swagger.yaml -p 8080
Specmatic works exactly this way. To start a mock server with an OpenAPI specification file we can run below command.
specmatic stub service.yaml --port 8080
Here is the documentation.
While the server runs, It will be possible to interact with it's own REST API (on some control interface via a different port) and change the behaviour of the running swagger mock server - i.e: change response code, set response content etc'
This is also supported. Specmatic has a http interface to which you can post the request and response mappings / expectations. We call this dynamic mocks. Here is the documentation.
Here is a video on this.
Disclosure: I am lead dev and CTO at Specmatic

How to invoke MobileFirst adapters with curl and SOAP?

Good day,
We have the requirement to call a MobileFirst Adapter via curl and SOAP, ommiting authentication.
An example how to do it with curl and application/x-www-form-urlencoded looks like this, but we also require to invoke the adapter using SOAP.
curl -XPOST -d 'adapter=PushAdapter&procedure=sendNotifications&parameters=["[\"UserA\",\"UserB\"]", "Pushed.you"]' http://localhost:10080/application/invoke
The reason is, we want to trigger sending PushNotifications through a network zone that only allows SOAP.
We are open to different suggestions, like implementing a new JavaAdapter (not JS), implementing an extra WebService, or anything that pops up which could fulfil the requirement in an acceptable way.
I hope someone can come up with an idea how to call Adapters via SOAP, ommiting authentication.
Thank you,
gizmore
---- Edit ---
I added a new Java Adapter, like the video from Hasan suggests.
Thank you very much for that hint :)
There i added a WebService like this:
#WebService
#Path("/soap")
#OAuthSecurity(enabled=false) // Disable the imfAuthentication :)
public class ExternalPushService {
#POST
#Path("/push")
#WebMethod(action="push")
public String push(#WebParam(name="name") String name) {
return name + "ABC";
}
}
I can now do HTTP POST Requests to the http://localhost:10080/app/adapters/PushBridge/soap/push Endpoint, but the SOAP is not parsed.
Instead i get the complete Envelope in the "name" parameter.
If i do a SOAP call to PushBridge/soap, i get 405 Method not allowed.
Does someone have an idea, how i can get SOAP working out of the box there?
Answer is: NO
when you adding #WebService in your java adapter this the warring facing:
Problem description:This annotation requires a web service project. Convert the Java project to a web project targeting the specified runtime environment
SOAP base service are based on the JAX-WS specification.
but
Java adapters are based on the JAX-RS specification.
https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-0/server-side-development/java-adapter/