WireMock.Net is a flexible library for stubbing and mocking web HTTP responses using requests matching criteria.
mobile app <=> backend
to mobile app <=> wiremock server
- but Im wondering if thats possible without changing the code of the app. I know that's possible with changing the codebase, from targeting my BE endpoints to target localhost (for iOS), but I'm wondering if thats doable somehow without changing the targeted endpoint in the codebase (for example with some proxy + wiremock settings). Unfortunately it's not possible to change the codebase, so I need to take it more like a blackbox. Any help? :) (also worth noting I'm running on a iOS simulator)
8/20/2020 1:37:54 AM [Info] : WireMock.Net server listening at http://localhost:8700
$ echo "$(curl -H 'Accept:*/*' http://localhost:8700)"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to localhost port 8700: Connection refused
WireMockServer.Start
. When we run tests in CI then we want to use docker container with WireMock and connect to it from the test code and from the tested application. Besides that difference, we would like to have a consistent API to define mocking rules. However, it doesn't seem to be possible right now because WireMock client uses different models to define mappings (MappingModel
) and the MappingConverter
which could convert IMapping
to MappingModel
has internal
modifier. Is it possible to expose the method which could perform that conversion? Or am I doing something wrong and there's an option to define Mappings once and use it with WireMockServer and with standalone (docker) app?
WireMockServerSettings settings = null;
settings = new WireMockServerSettings
{
Urls = new[] { appSettings["url"] },
StartAdminInterface = true,
AllowPartialMapping =true,
Logger = new WireMockConsoleLogger(),
ProxyAndRecordSettings = new ProxyAndRecordSettings
{
Url = appSettings["proxyUrl"],
}
};
var wiremockServer = StandAloneApp.Start(settings);
wiremockServer
.Given(
Request.Create().WithPath("/Accounts/api/securityhelper/getauthtoken")
.UsingGet()
.WithCookie("paycorAuth", new RegexMatcher(".*"))
)
//.AtPriority(100)
.RespondWith(
Response.Create()
.WithProxy(appSettings["proxyUrl"])
.WithBody("12345")
);
wiremockServer.SaveStaticMappings();
Console.WriteLine("Press any key to stop the server");
Console.ReadKey();
}
}
@genesispvtltd I did already comment on your issue (WireMock-Net/WireMock.Net#580) and I'll copy-paste the info also here as a reference:
Short answer: WireMock.Net does not yet support a "Smart Proxy" functionality as you describe.
Long answer: This can probably be implemented as defined here:
Scenario 1
In case the real endpoint is up (we need to determine the criteria for up, like != 200 OK), proxy the request + response to the real endpoint.
Scenario 2
In case the real endpoint is down, try to find a configured mapping:
If the mapping is found, return that mapping.
If the mapping is not found, just return default 404 'mapping not found'.
@StefH need some information regarding NTLM authentication some of our endpoints are using NTLM authentication so i need to use proxying there so the code looks like below Cookie AuthCookie = null;
try
{
var authRequest = WebRequest.Create("https://localhost:7777/Accounts/Auth") as HttpWebRequest;
authRequest.CookieContainer = new CookieContainer();
authRequest.AllowAutoRedirect = false;
authRequest.ContentType = "application/x-www-form-urlencoded";
authRequest.KeepAlive = true;
CredentialCache userCredentials = new CredentialCache();
userCredentials.Add(
new Uri("https://live.com/"),
"NTLM",
new NetworkCredential("username", "Password", ""));
authRequest.Credentials = userCredentials;
using (var authResponse = authRequest.GetResponse() as HttpWebResponse)
{
AuthCookie = authResponse.Cookies["payment"];
}
}
catch (Exception ex)
{
}
And I have created a stub as well wireMockServer
.Given(
Request.Create().WithPath("/Accounts/Auth")
.UsingGet()
)
.RespondWith(
Response.Create()
.WithProxy(proxyUrl)
);
But when I proxy I am getting the underlying connection is closed message any example how I can use NTLM authentication I would appreciate thanks
Hello!
I try to install the WireMock.Net NuGet package (https://www.nuget.org/packages/WireMock.Net/) with the command line: "Install-Package WireMock.Net"
After a while, the command line tells me: "Install-Package: Unable to find dependent package(s) (Handlebars.Net)"? Handlebars.Net is a dependency of WireMock, however, I thought, NuGet resolves the dependencies automatically.