-
Notifications
You must be signed in to change notification settings - Fork 15.2k
KAFKA-3578: Allow cross origin HTTP requests on all HTTP methods #1288
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,18 +31,19 @@ | |
| import org.powermock.api.easymock.annotation.MockStrict; | ||
| import org.powermock.modules.junit4.PowerMockRunner; | ||
|
|
||
| import javax.ws.rs.client.Client; | ||
| import javax.ws.rs.client.ClientBuilder; | ||
| import javax.ws.rs.client.Invocation; | ||
| import javax.ws.rs.client.WebTarget; | ||
| import javax.ws.rs.core.Response; | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import javax.ws.rs.client.Client; | ||
| import javax.ws.rs.client.ClientBuilder; | ||
| import javax.ws.rs.client.Invocation; | ||
| import javax.ws.rs.client.WebTarget; | ||
| import javax.ws.rs.core.Response; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| @RunWith(PowerMockRunner.class) | ||
|
|
@@ -71,15 +72,15 @@ private Map<String, String> baseWorkerProps() { | |
|
|
||
| @Test | ||
| public void testCORSEnabled() { | ||
| checkCORSRequest("*", "http://bar.com", "http://bar.com"); | ||
| checkCORSRequest("*", "http://bar.com", "http://bar.com", "PUT"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCORSDisabled() { | ||
| checkCORSRequest("", "http://bar.com", null); | ||
| checkCORSRequest("", "http://bar.com", null, null); | ||
| } | ||
|
|
||
| public void checkCORSRequest(String corsDomain, String origin, String expectedHeader) { | ||
| public void checkCORSRequest(String corsDomain, String origin, String expectedHeader, String method) { | ||
| // To be able to set the Origin, we need to toggle this flag | ||
| System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); | ||
|
|
||
|
|
@@ -92,10 +93,12 @@ public Object answer() throws Throwable { | |
| return null; | ||
| } | ||
| }); | ||
|
|
||
| PowerMock.replayAll(); | ||
|
|
||
| Map<String, String> workerProps = baseWorkerProps(); | ||
| workerProps.put(WorkerConfig.ACCESS_CONTROL_ALLOW_ORIGIN_CONFIG, corsDomain); | ||
| workerProps.put(WorkerConfig.ACCESS_CONTROL_ALLOW_METHODS_CONFIG, method); | ||
| WorkerConfig workerConfig = new StandaloneConfig(workerProps); | ||
| server = new RestServer(workerConfig); | ||
| server.start(herder); | ||
|
|
@@ -107,6 +110,15 @@ public Object answer() throws Throwable { | |
| assertEquals(200, response.getStatus()); | ||
|
|
||
| assertEquals(expectedHeader, response.getHeaderString("Access-Control-Allow-Origin")); | ||
|
|
||
| response = request("/connector-plugins/FileStreamSource/validate") | ||
| .header("Referer", origin + "/page") | ||
| .header("Origin", origin) | ||
| .header("Access-Control-Request-Method", method) | ||
| .options(); | ||
| assertEquals(404, response.getStatus()); | ||
| assertEquals(expectedHeader, response.getHeaderString("Access-Control-Allow-Origin")); | ||
| assertEquals(method, response.getHeaderString("Access-Control-Allow-Methods")); | ||
|
Contributor
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. Should we be checking the
Contributor
Author
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. Ack |
||
| PowerMock.verifyAll(); | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The 404 seemed odd to me, so I want to make sure I understand why we're seeing it (since I would normally interpret that as an error). It seems that CORS doesn't require that you return a particular HTTP status code, so for the preflighted request it's actually ok if we return any code here. In the case of Jetty, it looks like the
CrossOriginFilter'schainPreflightoption defaults to true such that theOPTIONSrequest continues on for normal handling. Since we don't implementOPTIONSfor any of our endpoints (and the one under test, specifically), we end up with a 404. Is that correct?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.
That's correct. This is purely for testing purpose and making sure the
Access-Control-Allow-Methodsheader is properly set.