Skip to content

Commit e187dc5

Browse files
committed
Use server-managed restart script
Remove deployment-time script upload and run the existing restart script on the server instead.
1 parent 7603813 commit e187dc5

6 files changed

Lines changed: 141 additions & 185 deletions

File tree

.github/workflows/ec2-deploy.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ jobs:
7373
REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
7474
SPRING_BOOT_IMAGE="ghcr.io/${REPO_LOWER}:${{ github.sha }}"
7575
ENV_B64=$(printf '%s' "${{ secrets.ENV_FILE }}" | base64 -w 0)
76-
SCRIPT_B64=$(base64 -w 0 deploy/restart_if_infra_down.sh)
7776
COMMAND_ID=$(aws ssm send-command \
7877
--instance-ids "${{ secrets.SSM_INSTANCE_ID }}" \
7978
--document-name "AWS-RunShellScript" \
80-
--parameters "{\"commands\":[\"cd /apps/senifit && echo ${ENV_B64} | base64 -d > /apps/senifit/.env && echo ${SCRIPT_B64} | base64 -d > /apps/senifit/restart_if_infra_down.sh && chmod +x /apps/senifit/restart_if_infra_down.sh && export SPRING_BOOT_IMAGE=${SPRING_BOOT_IMAGE} && sudo /apps/senifit/restart_if_infra_down.sh\"]}" \
79+
--parameters "{\"commands\":[\"cd /apps/senifit && echo ${ENV_B64} | base64 -d > /apps/senifit/.env && export SPRING_BOOT_IMAGE=${SPRING_BOOT_IMAGE} && sudo /apps/senifit/restart_if_infra_down.sh\"]}" \
8180
--comment "Deploy was image ${SPRING_BOOT_IMAGE}" \
8281
--output text \
8382
--query "Command.CommandId")

deploy/README.md

Lines changed: 0 additions & 57 deletions
This file was deleted.

deploy/docker-compose.yml

Lines changed: 0 additions & 89 deletions
This file was deleted.

deploy/restart_if_infra_down.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# 로컬 Docker 개발 환경 설정
2+
# 사용법: ./gradlew bootRun --args='--spring.profiles.active=dev-local'
3+
# 사전 조건: cd src/dev && docker compose up -d
4+
5+
server:
6+
port: 8443
7+
ssl:
8+
enabled: true
9+
key-store: classpath:cert/localhost.p12
10+
key-store-type: PKCS12
11+
key-store-password: '!senifit0527@'
12+
key-alias: localhost
13+
14+
spring:
15+
datasource:
16+
url: jdbc:mysql://localhost:3306/dev?rewriteBatchedStatements=true
17+
driver-class-name: com.mysql.cj.jdbc.Driver
18+
username: senifit
19+
password: '!senifiT2025'
20+
pbkdf2_pepper: 8ZvnK2f7CYVU/UEXT55uE1VeVdbzqGm7okaUwmOZaUIc6Sb/Cv310TI3GFRz+CqB7GbgCzM/EPskIqoP+OwK7A==
21+
22+
jpa:
23+
database: mysql
24+
hibernate:
25+
ddl-auto: none
26+
show-sql: true
27+
properties:
28+
hibernate:
29+
format_sql: true
30+
dialect: org.hibernate.dialect.MySQL8Dialect
31+
jdbc:
32+
batch_size: 20
33+
order_inserts: true
34+
order_updates: true
35+
36+
data:
37+
redis:
38+
host: localhost
39+
port: 6379
40+
password: '!senifiT2025'
41+
42+
session:
43+
store-type: redis
44+
timeout: 5400s
45+
46+
app:
47+
s3:
48+
region: ap-northeast-2
49+
bucket: senifit-program-bk
50+
video-prefix: video/
51+
thumb-prefix: thumb/
52+
presign:
53+
expiry-seconds: 7200
54+
content-disposition: inline
55+
force-content-type: false
56+
57+
logging:
58+
level:
59+
root: info
60+
com.senifit: debug
61+
org.hibernate.SQL: debug
62+
org.hibernate.type.descriptor.sql.BasicBinder: trace
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.senifit.was.security;
2+
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
7+
import org.springframework.boot.test.context.SpringBootTest;
8+
import org.springframework.mock.web.MockHttpSession;
9+
import org.springframework.test.web.servlet.MockMvc;
10+
import org.springframework.test.web.servlet.MvcResult;
11+
12+
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin;
13+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
14+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
15+
16+
/**
17+
* 세션 기반 인증 테스트
18+
*
19+
* 이 테스트는 백엔드의 세션 관리가 정상 동작하는지 검증합니다.
20+
* - 로그인 후 세션 쿠키가 유지되는지
21+
* - 세션을 통한 인증된 요청이 정상 처리되는지
22+
* - 세션 없이 요청하면 401/403이 반환되는지
23+
*/
24+
@SpringBootTest
25+
@AutoConfigureMockMvc
26+
class SessionAuthenticationTest {
27+
28+
@Autowired
29+
private MockMvc mockMvc;
30+
31+
@Test
32+
@DisplayName("인증 없이 보호된 API 호출 시 403 반환")
33+
void unauthenticatedRequest_shouldReturn403() throws Exception {
34+
mockMvc.perform(get("/center"))
35+
.andExpect(status().isForbidden());
36+
}
37+
38+
@Test
39+
@DisplayName("로그인 후 세션으로 인증된 API 호출 성공")
40+
void authenticatedRequest_withSession_shouldSucceed() throws Exception {
41+
// 1. 로그인 수행 (테스트용 계정 필요)
42+
// 실제 테스트 시에는 테스트용 계정 정보로 변경 필요
43+
MvcResult loginResult = mockMvc.perform(
44+
formLogin("/auth/signin")
45+
.user("id", "test_account") // 실제 테스트 계정으로 변경
46+
.password("password", "test_password") // 실제 비밀번호로 변경
47+
).andReturn();
48+
49+
// 2. 로그인 응답에서 세션 추출
50+
MockHttpSession session = (MockHttpSession) loginResult.getRequest().getSession();
51+
52+
// 3. 세션을 포함하여 보호된 API 호출
53+
if (loginResult.getResponse().getStatus() == 200) {
54+
mockMvc.perform(get("/center").session(session))
55+
.andExpect(status().isOk());
56+
}
57+
}
58+
59+
@Test
60+
@DisplayName("세션 없이 요청 → 새 세션으로 요청: 403 반환")
61+
void requestWithoutSessionCookie_shouldReturn403() throws Exception {
62+
// 첫 번째 요청 (세션 없음)
63+
MvcResult result1 = mockMvc.perform(get("/center"))
64+
.andExpect(status().isForbidden())
65+
.andReturn();
66+
67+
// 두 번째 요청 (다른 세션)
68+
mockMvc.perform(get("/center"))
69+
.andExpect(status().isForbidden());
70+
}
71+
72+
@Test
73+
@DisplayName("로그인 엔드포인트는 인증 없이 접근 가능")
74+
void loginEndpoint_shouldBeAccessible() throws Exception {
75+
mockMvc.perform(get("/health"))
76+
.andExpect(status().isOk());
77+
}
78+
}

0 commit comments

Comments
 (0)