Anitt Rajendran
02/27/2023, 9:41 PMAlessandro Bramati
03/02/2023, 9:52 AMwireMockConfiguration = options()
.disableRequestJournal()
.usingFilesUnderDirectory(rootFolder)
.port(Integer.parseInt(getProperty("port")))
.adminAuthenticator(getAdminAuthenticator())
.jettyAcceptors(Integer.parseInt(getPropertyOrDefault("acceptor.threads", DEFAULT_ACCEPTOR_THREADS)))
.keystorePath(getProperty("keystore.path"))
.keystorePassword(getProperty("keystore.password"))
.trustStorePath(getProperty("truststore.path"))
.trustStorePassword(getProperty("truststore.password"))
.extensions(
new AdminRequestLoggingFilter(),
new ServiceRequestLoggingFilter(),
new ServiceResponseLoggingFilter(),
new ResponseTemplateTransformer(true));
Here the error:
SL failure trying to make a proxied request from WireMock to ...
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
My keystore contains my private cert and the truststore contains the server certificate (everything ok with curl).
Is there something missing?
Thanks
AlessandroAaron
03/02/2023, 4:23 PMbasicAuth
keys support regex matching? https://stackoverflow.com/questions/75614289/wiremock-json-template-basicauth-and-doesnotmatch-not-working
I ran this locally and was getting the same error, even with switching to basicAuthCredentials
.Mukesh Bijalwan
03/03/2023, 1:09 PMSundar
03/08/2023, 12:10 PMYash Agarwal
03/14/2023, 9:56 AM"org.springframework.cloud:spring-cloud-starter-contract-stub-runner"
But I am getting the following error and not sure why. Any help ?
Request was not matched
=======================
-----------------------------------------------------------------------------------------------------------------------
| Closest stub | Request |
-----------------------------------------------------------------------------------------------------------------------
|
GET | GET
/ldap_directory_items/v2/group_members?key=key&name=APP-O | /ldap_directory_items/v2/group_members?key=key&name=APP-O
AUTH2-ABCD&size=100000 | AUTH2-ABCD&size=100000
|
|
-----------------------------------------------------------------------------------------------------------------------
Alex P
03/20/2023, 7:43 PMflag1[enabled]=true&transfer[destination]=target_account&metadata[userId]=1-2-3-4&metadata[sessionId]=a-b-c
I am having a hard time to use the values in the response. I am parsing the form via
{{formData request.body 'params' urlDecode=true}}
and I can see the values fine when doing
{{#each params}}
{{@index}} - {{@key}} - {{this}}
{{/each}}
But I cannot access the individual fields, no matter what I try, e.g.,
{{"metadata[userId]"}}
{{metadata\[userId\]}}
{{metadata.userId}}
My Google-fu also failed me 😕Alex P
03/21/2023, 8:39 AMassign
and a formData
expressions at the top of my response (referenced via bodyFileName
) and it seems that they get replaced by an empty line, i.e., I have a few empty lines before my JSON response body starts.
For now I just cram everything in one line and start the JSON object there, too, but it is really unreadable 😕
{{#assign 'a'}}...{{/assign}}{{#assign 'b'}}...{{/assign}}{{formData ...}}{
"id": ...
...
}
Is there a better way to suppress the empty lines in this case?Alex P
03/23/2023, 2:17 PM"request": {
"method": "POST",
"urlPattern": "/store|/v2/store",
"queryParameters": {
"client": {
"matches": "STORE-ABC-.+"
},
...
}
}
and the second looks like this
"request": {
"method": "POST",
"urlPattern": "/store|/v2/store",
"queryParameters": {
"client": {
"matches": "STORE-123-.+"
},
...
}
},
Both have additional but the same query parameters to match. Both also have different body patterns to match.
When I send this request (from WireMock's log)
POST /v2/store?client=STORE-123-12345&user=userId&realm=realm&key=sessionId
I see that WireMock only tries the other request (STORE-ABC) but fails because it cannot match some parts of the body patterns of STORE-ABC, even though STORE-123 would match.
So I wonder if WireMock even tries the STORE-123 mock because I cannot see it in the log.
More curiosly, at the very end I get a "closest stub" that is a completely different stub where of course neither URL nor body match; how come it shows this, and not for example the stubs it tried?Alex P
03/23/2023, 2:19 PMmappings
folder, e.g., by adding a disabled: true
field or so? 🤔Alex P
03/23/2023, 3:41 PMDELETE
endpoint, and I have a response bodyFileName
that has something like
{
"message": "Deleted {{arguments.count}} items"
}
And then I would have a stub like this
{
"request": ...,
"response": {
"bodyFileName": ...,
"arguments": {
"count": 1
}
...
}
Or can I use the metadata
for that? 🤔Alex P
03/23/2023, 4:34 PMAlex P
03/23/2023, 5:11 PMid
or name
in the response of __admin/requests/find
🤔
(Sorry for the bombardement of questions 😄 )Devaraj Rathinasamy
03/24/2023, 9:36 PMAlex Dunga
03/28/2023, 11:34 AMJakub S
03/31/2023, 1:36 PMOleg Nenashev
04/10/2023, 8:14 PMOleg Nenashev
04/30/2023, 10:03 AMOleg Nenashev
04/30/2023, 10:05 AMEjiroghene Ineneji
05/02/2023, 6:00 PMEjiroghene Ineneji
05/02/2023, 6:00 PMEjiroghene Ineneji
05/02/2023, 6:01 PMShruti Mishra
05/03/2023, 11:49 AMShruti Mishra
05/08/2023, 10:06 AMShruti Mishra
05/08/2023, 10:06 AMEjiroghene Ineneji
05/08/2023, 12:39 PMEjiroghene Ineneji
05/08/2023, 12:39 PMEjiroghene Ineneji
05/09/2023, 12:29 PMNikita Karpuk
05/09/2023, 6:00 PMwiremock-testcontainers-java
and would like to validate it with you
Current API
private final Map<String, Extension> extensions = new HashMap<>();
WireMockContainer withExtension(String id, Collection<String> classNames, Collection<File> jars)
WireMockContainer withExtension(String id, Collection<String> classNames, File jarDirectory)
WireMockContainer withExtension(String id, String className)
example of usage
.withExtension("Webhook",
Collections.singleton("org.wiremock.webhooks.Webhooks"),
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-webhooks-extension-2.35.0.jar").toFile()))
.withExtension("JSON Body Transformer",
Collections.singleton("com.ninecookies.wiremock.extensions.JsonBodyTransformer"),
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-extensions-0.4.1-jar-with-dependencies.jar").toFile()));
Problem:
• Field id
brings confusion, it forces developers to create random string literal for each method invocation, since this id
has no influence on behavior - values will be very random (absence of control / validation)
• We store extention details className
and jar
as a value in HashMap<ID, Extention>
, so we are not able to utilize Collections benefits like check for uniqueness (HashSet)
• Even if developer mixed classNames with wrong jars
withExtnetion("ExtA", "JarB").withExtention("ExtB", "JarA")
it will work
Improvement Options:
Option 1
private final Set<String> extensionClassNames = new LinkedHashSet<>();
private final Set<File> extensionJars = new LinkedHashSet<>();
WireMockContainer withExtension(Collection<String> classNames, File jar)
WireMockContainer withExtension(Collection<String> classNames, Collection<File> jars);
WireMockContainer withExtension(Collection<String> classNames, Path jarDirectory)
Benefits:
• Store all extensionJars in a LinkedHashSet to preserve an order and keep only unique values
• Store all extensionClassNames in a LinkedHashSet to preserve an order and keep only unique value
• all params for --extention
will be stored in one collection extensionClassNames
- easy to build cli command for docker
• all params for /var/wiremock/extentions
will be stored in one collection extensionJars
- easy to build cli command for docker
• Allow developer to organize and keep related Jars and classNames in one method
Problem:
• Even if developer mixed classNames with wrong jars
withExtnetion("ExtA", "JarB").withExtention("ExtB", "JarA")
it will work
Option 2
private final Set<String> extensionClassNames = new LinkedHashSet<>();
private final Set<File> extensionJars = new LinkedHashSet<>();
WireMockContainer withExtensionFile(Collection<String> classNames)
WireMockContainer withExtensionClass(Collection<File> jars);
Benefits:
• Store all extensionJars in a LinkedHashSet to preserve an order and keep only unique values
• Store all extensionClassNames in a LinkedHashSet to preserve an order and keep only unique value
• all params for --extention
will be stored in one collection extensionClassNames
- easy to build cli command for docker
• all params for /var/wiremock/extentions
will be stored in one collection extensionJars
- easy to build cli command for docker
• Very straignt forward apiShruti Mishra
05/14/2023, 10:14 AMpackage com.example.wiremock.stub;
import java.io.UnsupportedEncodingException;
import org.apache.commons.codec.binary.Base64;
import org.springframework.stereotype.Component;
import com.example.wiremock.errorhandler.BadRequestError;
import com.example.wiremock.errorhandler.MockError;
import com.example.wiremock.errorhandler.MockErrorResponse;
import com.example.wiremock.luukuresponse.LuukkuBasicInfoResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.common.Errors;
import com.github.tomakehurst.wiremock.common.Errors.Error;
import com.github.tomakehurst.wiremock.common.Errors.Error.Source;
import com.github.tomakehurst.wiremock.common.Json;
import com.github.tomakehurst.wiremock.extension.requestfilter.RequestFilterAction;
import com.github.tomakehurst.wiremock.extension.requestfilter.StubRequestFilter;
import com.github.tomakehurst.wiremock.http.HttpHeader;
import com.github.tomakehurst.wiremock.http.Request;
import com.github.tomakehurst.wiremock.http.ResponseDefinition;
import java.util.ArrayList;
import java.util.List;
@Component
public class BasicAuthRequestFilter extends StubRequestFilter {
public String decodeJwt(String token) throws UnsupportedEncodingException {
String payload = token.split("\\.")[1];
return new String(Base64.decodeBase64(payload), "UTF-8");
}
@Override
public RequestFilterAction filter(Request request){
if (request.header("Authorization").firstValue().matches("Bearer [a-zA-Z0-9&._-]{1,}")) {
String authtoken = request.header("Authorization").firstValue();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
Errors errors;
String str;
try {
String pattern = "^\\S{4}75-\\S{4}$";
str = decodeJwt(authtoken);
Token token = objectMapper.readValue(str, Token.class);
String test = token.getRepresentation().getId();
if(test.matches(pattern)) {
Error error = new Error(400, null, "response", null);
List<Error> listOfErros = new ArrayList<>();
listOfErros.add(error);
Errors errorList = new Errors(listOfErros);
return RequestFilterAction.stopWith(ResponseDefinition.badRequest(errorList));
}
} catch (UnsupportedEncodingException | JsonProcessingException e) {
e.printStackTrace();
}
return RequestFilterAction.continueWith(request);
}
return null;
}
@Override
public String getName() {
return "Authorization";
}
Below is the error snapshot: