-
-
Notifications
You must be signed in to change notification settings - Fork 209
Settings
The interface WireMockServerSettings.cs defines the configuration from the WireMock.Net server.
The port to listen on.
Use SSL.
Defines to if the admin interface should be started.
Defines if the static mappings should be read at startup.
Watch the static mapping files + folder for changes when running.
Allow the usage of CSharpCodeMatcher, default is not allowed because it can be dangerous to execute all C# code.
By default, the .NETStandard version from WireMock.Net can use the default .NET self-signed development certificate. See HTTPS-SSL for more info.
However, it's also possible to use your own certificate, which can use defined in the Certificate Store or in a .pfx
file.
To configure this you need to define the correct values for the CertificateSettings
. See example below:
var server = WireMockServer.Start(new WireMockServerSettings
{
Urls = new[] { "https://localhost:8443" },
CertificateSettings = new WireMockCertificateSettings
{
X509StoreName = "My",
X509StoreLocation = "CurrentUser",
X509StoreThumbprintOrSubjectName = "FE16586076A8B3F3E2F1466803A6C4C7CA35455B" // This can be a Thumbprint, SubjectName or null
// X509CertificateFilePath = "example.pfx",
// X509CertificatePassword = "wiremock"
}
});
Where
-
X509StoreName
= The Certificate StoreName. One of: AddressBook, AuthRoot, CertificateAuthority, My, Root, TrustedPeople, TrustedPublisher. -
X509StoreLocation
= The Certificate StoreLocation. Can be CurrentUser or LocalMachine. -
X509StoreThumbprintOrSubjectName
= This can be the Certifcate Thumbprint, Certifcate SubjectName or null. If it's null, the first match on the hostname Certicate is used. -
X509CertificateFilePath
= The full path to the X509Certificate2.pfx
file -
X509CertificatePassword
= The password for the X509Certificate2.pfx
file
Note that:
- X509StoreName and X509StoreLocation should be defined
- OR
- X509CertificateFilePath and X509CertificatePassword should be defined
📝 See also these links on how to generate a EC or RSA
- https://www.scottbrady91.com/openssl/creating-elliptical-curve-keys-using-openssl
- https://www.scottbrady91.com/openssl/creating-rsa-keys-using-openssl
- https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.Console.NET6.WithCertificate
You can enable ProxyAndRecord functionality by defining the ProxyAndRecordSettings and by specifying an Url. See code example below.
var server = WireMockServer.Start(new FluentMockServerSettings
{
Urls = new[] { "http://localhost:9095/" },
StartAdminInterface = true,
ProxyAndRecordSettings = new ProxyAndRecordSettings
{
Url = "http://www.bbc.com",
SaveMapping = true,
SaveMappingToFile = true,
BlackListedHeaders = new [] { "dnt", "Content-Length" },
BlackListedCookies = new [] { "c1", "c2" },
SaveMappingForStatusCodePattern = "2xx",
AllowAutoRedirect = true,
WebProxySettings = new WebProxySettings
{
UserName = "test",
Password = "pwd",
Address = "http://company.proxy"
},
UseDefinedRequestMatchers = false,
AppendGuidToSavedMappingFile = true,
ReplaceSettings = new ProxyUrlReplaceSettings
{
"OldValue" = "old",
"NewValue" = "new"
}
}
});
Where
-
Url
= The url to proxy to -
SaveMapping
= Save the mapping for each request/response to the internal Mappings -
SaveMappingToFile
= Save the mapping for each request/response to also file. -
SaveMappingForStatusCodePattern
= Only save request/response to the internal Mappings if the status code is included in this pattern. (Note that SaveMapping must also be set to true.) The pattern can contain a single value like "200", but also ranges like "2xx", "100,300,600" or "100-299,6xx" are supported. -
BlackListedHeaders
= Defines a list from headers which will excluded from the saved mappings. -
ClientX509Certificate2ThumbprintOrSubjectName
= The clientCertificate thumbprint or subject name fragment to use. -
WebProxySettings
= Defines the WebProxySettings. -
AllowAutoRedirect
= Proxy requests should follow redirection (30x). Default null / false. -
UseDefinedRequestMatchers
= When SaveMapping is set to true, this setting can be used to control the behavior of the generated request matchers for the new mapping. -
AppendGuidToSavedMappingFile
= Append an unique GUID to the filename from the saved mapping file. -
ReplaceSettings
= Defines the ProxyUrlReplaceSettings.
-
Address
= Contains the address of the proxy server. -
UserName
= The user name associated with the credentials. -
Password
= The password for the user name associated with the credentials.
This setting defines an old path param and a new path param to be replaced in the Url when proxying.
-
OldValue
= The old path value to be replaced. -
NewValue
= The new path value to use. -
IgnoreCase
= Defines if the case should be ignore when replacing.
When you a request like localhost:9095/earth/story/20170510-terrifying-20m-tall-rogue-waves-are-actually-real
, this request is proxied to the bbc.com
and the mapping definition is saved to __admin\mappings\ab38efae-4e4d-4f20-8afe-635533ec2535.json
.
The URLs to listen on, if this is defined the port setting is not used.
The StartTimeout from WireMock.Net, default 10 seconds.
Defines if the matching should be done with exact matching or partial matching. Partial matching means that the best matching mapping is used for a input request. In case this setting is set to null or false, only Exact matching is done. This means that only when an exact 100% match is found for an input request, the response is handled. Else you get a error (404). This setting is default set to false.
Allow the usage of CSharpCodeMatcher (default is not allowed).
Allow a Body for all HTTP Methods. (default set to false).
Allow any HttpStatusCode in the response. Also null, 0, empty or invalid. (default set to false). Note : this will not work when hosting a Docker container in Azure
The username needed for __admin access.
The password needed for __admin access.
The AzureAD Tenant needed for __admin access.
The AzureAD Audience / Resource for __admin access.
The RequestLog expiration in hours (optional).
The MaxRequestLog count (optional).
Set to true to disable Json deserialization when processing requests. (default set to false).
Disable support for GZip and Deflate request body decompression. (default set to false).
Handle all requests synchronously. This could solve some issues when running multiple unit tests using 1 WireMock.Net instance. (default set to false).
Throw an exception when a Matcher fails because of invalid input. (default set to false).
Action which is called (with the IAppBuilder or IApplicationBuilder) before the internal WireMockMiddleware is initialized. [Optional]
Action which is called (with the IAppBuilder or IApplicationBuilder) after the internal WireMockMiddleware is initialized. [Optional]
Action which is called with IServiceCollection when ASP.NET Core DI is being configured. [Optional]
Use the RegexExtended instead of the default Regex.
The IWireMockLogger interface which logs Debug, Info, Warning or Error.
By default this is implemented by a default console logger WireMockConsoleLogger.cs.
But also a Null logger is available WireMockNullLogger.cs.
And you can implement your own logger, like WireMockLog4NetLogger.cs.
Handler to interact with the file system to read and write static mapping files.
By default this is implemented by the LocalFileSystemHandler.cs, however you can implement your own version as defined here as an example CustomFileSystemFileHandler.cs.
Implementing your own version from this FileSystemHandler can be useful when running in Azure or Docker Containers.
Policies to use when using CORS. By default CORS is disabled. [Optional] This is a Enum Flag with these values:
- None
- AllowAnyHeader
- AllowAnyMethod
- AllowAnyOrigin
- AllowAll
- Home
- What is WireMock.Net
- WireMock.Org
- References
- Settings
- Admin REST API
- Proxying
- Stubbing
- Webhook
- Request Matching
- Response Templating
- Unit Testing
- Using WireMock
- Advanced
- Errors