-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate Accept and Content-Type header for compatible API #54103
Changes from all commits
a4f80ca
c99b818
c9c0e55
258542e
548fbd9
0dbea8a
4cf6bc1
3ac22b1
38721fe
f2db19f
b83b4ce
cf1d340
5c4a02d
0ef7e18
835ce56
f440231
84f1dde
d106d1b
cf61bbd
f00f438
ae1799f
a0fce89
7e55744
00fe62d
a6f0b9a
4eff534
2d4161c
6830f97
587f84d
7b092f5
ef25920
1c2fece
2374c20
eeae41f
e7d9b29
268bc1c
15f4be5
017c804
3d975f3
09ef281
bf09243
30f1c40
a013a03
6c28434
37d6426
1d57fe7
0662ef3
86f8bc0
b292080
a4f472d
bb827bc
e9a4fbd
f876d46
47fd5cb
bcb11fd
225a00b
ebaa7c9
c96bd86
10e8d1b
3181daf
9bd396a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
import java.util.stream.StreamSupport; | ||
|
||
/** | ||
|
@@ -43,7 +44,6 @@ protected AbstractCompatRestTest(@Name("yaml") ClientYamlTestCandidate testCandi | |
super(testCandidate); | ||
} | ||
|
||
|
||
private static final Logger staticLogger = LogManager.getLogger(AbstractCompatRestTest.class); | ||
|
||
public static final String COMPAT_TESTS_PATH = "/rest-api-spec/test-compat"; | ||
|
@@ -66,38 +66,48 @@ public static Iterable<Object[]> createParameters() throws Exception { | |
}); | ||
finalTestCandidates.add(testCandidates.toArray()); | ||
} | ||
localCandidates.keySet().forEach(lc -> finalTestCandidates.add(new Object[]{lc})); | ||
localCandidates.keySet().forEach(lc -> finalTestCandidates.add(new Object[] { lc })); | ||
return finalTestCandidates; | ||
} | ||
|
||
|
||
private static void mutateTestCandidate(ClientYamlTestCandidate testCandidate) { | ||
testCandidate.getTestSection().getExecutableSections().stream().filter(s -> s instanceof DoSection).forEach(ds -> { | ||
testCandidate.getSetupSection().getExecutableSections().stream().filter(s -> s instanceof DoSection).forEach(updateDoSection()); | ||
testCandidate.getTestSection().getExecutableSections().stream().filter(s -> s instanceof DoSection).forEach(updateDoSection()); | ||
} | ||
|
||
private static Consumer<? super ExecutableSection> updateDoSection() { | ||
return ds -> { | ||
DoSection doSection = (DoSection) ds; | ||
//TODO: be more selective here | ||
// TODO: be more selective here | ||
doSection.setIgnoreWarnings(true); | ||
|
||
String compatibleHeader = createCompatibleHeader(); | ||
//TODO decide which one to use - Accept or Content-Type | ||
doSection.getApiCallSection() | ||
.addHeaders(Map.of( | ||
CompatibleConstants.COMPATIBLE_HEADER, compatibleHeader, | ||
"Content-Type", compatibleHeader | ||
)); | ||
}); | ||
// for cat apis accept headers would break tests which expect txt response | ||
if (doSection.getApiCallSection().getApi().startsWith("cat") == false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have tests that need Accept header to be empty - expecting text response There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can punt on the cat api's for now, and this is sufficient for now. this code is temporary and i can address this later. |
||
doSection.getApiCallSection() | ||
.addHeaders( | ||
Map.of( | ||
CompatibleConstants.COMPATIBLE_ACCEPT_HEADER, | ||
compatibleHeader, | ||
CompatibleConstants.COMPATIBLE_CONTENT_TYPE_HEADER, | ||
compatibleHeader | ||
) | ||
); | ||
} | ||
|
||
}; | ||
} | ||
|
||
private static String createCompatibleHeader() { | ||
return "application/vnd.elasticsearch+json;compatible-with=" + CompatibleConstants.COMPATIBLE_VERSION; | ||
} | ||
|
||
|
||
private static Map<ClientYamlTestCandidate, ClientYamlTestCandidate> getLocalCompatibilityTests() throws Exception { | ||
Iterable<Object[]> candidates = | ||
ESClientYamlSuiteTestCase.createParameters(ExecutableSection.XCONTENT_REGISTRY, COMPAT_TESTS_PATH); | ||
Iterable<Object[]> candidates = ESClientYamlSuiteTestCase.createParameters(ExecutableSection.XCONTENT_REGISTRY, COMPAT_TESTS_PATH); | ||
Map<ClientYamlTestCandidate, ClientYamlTestCandidate> localCompatibilityTests = new HashMap<>(); | ||
StreamSupport.stream(candidates.spliterator(), false) | ||
.flatMap(Arrays::stream).forEach(o -> localCompatibilityTests.put((ClientYamlTestCandidate) o, (ClientYamlTestCandidate) o)); | ||
.flatMap(Arrays::stream) | ||
.forEach(o -> localCompatibilityTests.put((ClientYamlTestCandidate) o, (ClientYamlTestCandidate) o)); | ||
return localCompatibilityTests; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how much details do we want on this exception?
at the moment it helped debugging tests when seeing which failed validation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good level of detail.