Skip to content
Closed
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
1 change: 1 addition & 0 deletions back/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {

// Redis
implementation("org.springframework.boot:spring-boot-starter-data-redis")
implementation ("org.springframework.session:spring-session-data-redis")

// Session
implementation("org.springframework.session:spring-session-data-redis")
Expand Down
6 changes: 6 additions & 0 deletions back/src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
spring:
session:
store-type: redis
data:
redis:
host: localhost
port: 6379
datasource:
url: jdbc:h2:mem:db_test;MODE=PostgreSQL;
username: sa
Expand Down
8 changes: 4 additions & 4 deletions back/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
spring:
application:
name: back
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
- org.springframework.boot.autoconfigure.session.SessionAutoConfiguration
#autoconfigure:
# exclude:
# - org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
# - org.springframework.boot.autoconfigure.session.SessionAutoConfiguration
config:
import: optional:file:.env[.properties]
flyway:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
Expand Down Expand Up @@ -122,8 +121,9 @@ void t3() throws Exception {
.andExpect(jsonPath("$.email").value(email))
.andReturn();

MockHttpSession session = (MockHttpSession) result.getRequest().getSession(false);
assertThat(session).isNotNull();
var jsessionid = result.getResponse().getCookie("JSESSIONID");
assertThat(jsessionid).isNotNull();
assertThat(jsessionid.getValue()).isNotBlank();
}

@Test
Expand All @@ -144,14 +144,11 @@ void t4() throws Exception {
@Test
@DisplayName("성공 - 게스트 로그인")
void t5() throws Exception {
MvcResult result = mvc.perform(post(BASE + "/guest").with(csrf()))
mvc.perform(post(BASE + "/guest").with(csrf()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.email").exists())
.andExpect(jsonPath("$.role").value("GUEST"))
.andReturn();

MockHttpSession session = (MockHttpSession) result.getRequest().getSession(false);
assertThat(session).isNotNull();
.andExpect(cookie().exists("JSESSIONID"));
}

@Test
Expand All @@ -178,10 +175,11 @@ void t7() throws Exception {
.andExpect(status().isOk())
.andReturn();

MockHttpSession session = (MockHttpSession) loginRes.getRequest().getSession(false);
var jsessionid = loginRes.getResponse().getCookie("JSESSIONID");
assertThat(jsessionid).isNotNull();

mvc.perform(get(BASE + "/me")
.session(session))
.cookie(jsessionid))
.andExpect(status().isOk())
.andExpect(jsonPath("$.email").value(email));
}
Expand All @@ -200,12 +198,12 @@ void t8() throws Exception {
.andExpect(status().isOk())
.andReturn();

MockHttpSession session = (MockHttpSession) loginRes.getRequest().getSession(false);
assertThat(session).isNotNull();
var jsessionid = loginRes.getResponse().getCookie("JSESSIONID");
assertThat(jsessionid).isNotNull();

mvc.perform(post(BASE + "/logout")
.with(csrf())
.session(session))
.cookie(jsessionid))
.andExpect(status().isOk());
}
}
Loading