Repository navigation
COG-1153: AppointmentResource.confirm → POST (server + AdminPortal caller) #336
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
Open
patrickbradley-cog
wants to merge
1
commit into
master
Choose a base branch
from
devin/cog-1153-w1-appointmentresourceconfirm-post-server-angular-caller
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
52 changes: 52 additions & 0 deletions
52
UserFront/src/test/java/com/userFront/resource/AppointmentResourceTest.java
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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.userFront.resource; | ||
|
|
||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.Mockito; | ||
| import org.mockito.runners.MockitoJUnitRunner; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
| import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
|
|
||
| import com.userFront.service.AppointmentService; | ||
|
|
||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class AppointmentResourceTest { | ||
|
|
||
| @Mock | ||
| private AppointmentService appointmentService; | ||
|
|
||
| @InjectMocks | ||
| private AppointmentResource appointmentResource; | ||
|
|
||
| private MockMvc mockMvc; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| mockMvc = MockMvcBuilders.standaloneSetup(appointmentResource).build(); | ||
| } | ||
|
|
||
| @Test | ||
| public void confirmAcceptsPost() throws Exception { | ||
| mockMvc.perform(post("/api/appointment/42/confirm")) | ||
| .andExpect(status().isOk()); | ||
|
|
||
| verify(appointmentService).confirmAppointment(42L); | ||
| } | ||
|
|
||
| @Test | ||
| public void confirmRejectsGet() throws Exception { | ||
| mockMvc.perform(get("/api/appointment/42/confirm")) | ||
| .andExpect(status().isMethodNotAllowed()); | ||
|
|
||
| verify(appointmentService, never()).confirmAppointment(Mockito.anyLong()); | ||
| } | ||
| } |
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.
🟡 CSRF cookie blocks appointment confirmation
When an
XSRF-TOKENcookie exists,confirmAppointmenttriggers a preflight that rejects itsX-XSRF-TOKENheader. RequestFilter omits that header from its preflight response, so the appointment remains unconfirmed.Learn more
The admin portal calls the backend across ports, so the browser applies CORS. Without the cookie, the confirmation POST has no custom header. With the cookie,
confirmAppointmentaddsX-XSRF-TOKEN, forcing an OPTIONS preflight. RequestFilter answers OPTIONS but omits that header fromAccess-Control-Allow-Headers. The browser blocks the POST before the controller can confirm the appointment. This applies whenever the portal can read anXSRF-TOKENcookie, including after a CSRF cookie is introduced.Example: With
document.cookiecontainingXSRF-TOKEN=abc, clicking Confirm causes an OPTIONS request asking permission forx-xsrf-token. The filter excludes it, so the browser never sends the POST and the appointment stays unconfirmed.Recommended fix: Add
x-xsrf-tokento the OPTIONSAccess-Control-Allow-Headerslist inRequestFilterwhen sending the header, and cover the cookie-present cross-origin flow in a browser-level test.Was this helpful? React with 👍 or 👎 to provide feedback.
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.
This is correct, but it can't happen on
mastertoday. CSRF is disabled (SecurityConfig:.csrf().disable()), so nothing ever sets anXSRF-TOKENcookie. That means the header is never added, and the confirm POST is still a simple CORS request with no preflight. The ticket requires the header now so it's ready when CSRF is turned on.I'm keeping the fix out of this PR on purpose.
RequestFilterbelongs to COG-1165 (W2), which replaces it with a declarativeCorsConfigurationSource. W2 is also when CSRF (and so the cookie) gets turned on, soX-XSRF-TOKENneeds to be in that config's allowed headers. The W1 tickets are meant to be file-disjoint, so I'm leavingRequestFilteralone here and flagging this to the coordinator for COG-1165.