Sundar
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:Julian Michelmann
05/19/2023, 2:53 PM...
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:553)
at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:344)
at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
... 23 more
Caused by: java.lang.IllegalStateException: Wait strategy failed. Container exited with code 1
at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:523)
... 25 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for URL to be accessible (<http://localhost:49189/__admin/mappings> should return HTTP [200])
at org.testcontainers.containers.wait.strategy.HttpWaitStrategy.waitUntilReady(HttpWaitStrategy.java:320)
at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:964)
at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:490)
... 25 more
...
It seems that the container is failing. The container logs look like this:
Exception in thread "main" java.lang.ClassNotFoundException: com.ninecookies.wiremock.extensions.JsonBodyTransformer
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader$3.apply(ExtensionLoader.java:71)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader$3.apply(ExtensionLoader.java:67)
at wiremock.com.google.common.collect.Iterators$6.transform(Iterators.java:829)
at wiremock.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:52)
at wiremock.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:52)
at wiremock.com.google.common.collect.Maps.uniqueIndex(Maps.java:1391)
at wiremock.com.google.common.collect.Maps.uniqueIndex(Maps.java:1353)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader.asMap(ExtensionLoader.java:40)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader.loadExtension(ExtensionLoader.java:32)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader.load(ExtensionLoader.java:36)
at com.github.tomakehurst.wiremock.standalone.CommandLineOptions.buildExtensions(CommandLineOptions.java:378)
at com.github.tomakehurst.wiremock.standalone.CommandLineOptions.<init>(CommandLineOptions.java:369)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:49)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:133)
Maybe Iām doing something wrong? To be honest, Iām not sure how this is working and what is expectedā¦Tanumoy Mitra
05/25/2023, 4:29 PMOleg Nenashev
05/27/2023, 9:40 AMKaustav Surai
06/10/2023, 9:39 AM