Skip to content
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

Fixes exit context when request is blocked in springwebmvc adaptor #1353

Merged
merged 6 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
}
return true;
} catch (BlockException e) {
handleBlockException(request, response, e);
try {
handleBlockException(request, response, e);
} finally {
ContextUtil.exit();
}
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,21 @@ public void testOriginParser() throws Exception {
final String headerName = "S-User";
configureRulesFor(springMvcPathVariableUrl, 0, limitOrigin);

// This will be passed since the caller is different: userB
this.mvc.perform(get("/foo/1").accept(MediaType.TEXT_PLAIN).header(headerName, "userB"))
.andExpect(status().isOk())
.andExpect(content().string("foo 1"));

// This will be blocked and reponse json.
// This will be blocked since the caller is same: userA
this.mvc.perform(
get("/foo/2").accept(MediaType.APPLICATION_JSON).header(headerName, limitOrigin))
.andExpect(status().isOk())
.andExpect(content().json(ResultWrapper.blocked().toJsonString()));

// This will be passed since the caller is different: ""
this.mvc.perform(get("/foo/3").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(ResultWrapper.blocked().toJsonString()));
.andExpect(content().string("foo 3"));

FlowRuleManager.loadRules(null);
}
Expand Down Expand Up @@ -115,7 +118,7 @@ public void testRuntimeException() throws Exception {
assertEquals(i + 1, cn.passQps(), 0.01);
}

// This will be blocked and reponse json.
// This will be blocked and response json.
this.mvc.perform(get(url))
.andExpect(status().isOk())
.andExpect(content().string(ResultWrapper.blocked().toJsonString()));
Expand Down