๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ”ฅ ํ”„๋กœ์ ํŠธ/๋ผ๊พธ๋ผ๊พธ4

[์„ค๊ณ„] Image ์ „์†ก๊ณผ ๋ฐ์ดํ„ฐ ์ „์†ก API ๋ถ„๋ฆฌ ํ˜„์žฌ ์ƒํ™ฉ ๋ณธ ํ”„๋กœ์ ํŠธ๋Š” ๋ฐ์ดํ„ฐ JSON๊ณผ ์ด๋ฏธ์ง€(form-data)๋ฅผ ํ•˜๋‚˜์˜ API๋ฅผ ํ†ตํ•ด ์ „์†กํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ œ์  ๋ณดํ†ต ์ด๋ฏธ์ง€์™€ JSON๋ฐ์ดํ„ฐ๋ฅผ ํ•จ๊ป˜ ๋ณด๋‚ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. API๋ฅผ ์ „์†กํ•  ๋•Œ๋Š” ๋ณดํ†ต content/type์„ application/json์œผ๋กœ ์ „์†กํ•˜๋Š”๋ฐ ์ด๊ฒƒ์€ multipart/formdata ๋ฐฉ์‹์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• ์ด์— ๋”ฐ๋ผ, ๋ฐฉ๋ฒ•์€ 2๊ฐ€์ง€ ์ธ๋ฐ ๋ถ„๋ฆฌํ•ด์„œ ์š”์ฒญํ•˜๊ธฐ ์„œ๋ฒ„๋Š” ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•˜๊ณ , ์ €์žฅ๋œ ์ด๋ฏธ์ง€์˜ id(๋˜๋Š” ํŒŒ์ผ๋ช…)๋ฅผ ํด๋ผ์ด์–ธํŠธ์— ์ „์†กํ•ฉ๋‹ˆ๋‹ค. ํด๋ผ์ด์–ธํŠธ๋Š” ์ด๋ฏธ์ง€์˜ id์™€ ์ „์†กํ•  ๋ฐ์ดํ„ฐ๋ฅผ application/json์œผ๋กœ ์ „์†กํ•ฉ๋‹ˆ๋‹ค. base64 ์ธ์ฝ”๋”ฉ ์ด๋ฏธ์ง€๋ฅผ base64๋กœ ์ธ์ฝ”๋”ฉํ•ด์„œ application/json์œผ๋กœ ์ „์†กํ•  ๋ฐ์ดํ„ฐ์™€ base64๋กœ ์ธ์ฝ”๋”ฉ๋œ ์ด๋ฏธ์ง€๋ฅผ ํ•จ๊ป˜.. 2023. 8. 13.
[์˜ค๋ฅ˜] multipart์—์„œ PUT์ด ๋จนํžˆ์ง€ ์•Š๋Š” ์˜ค๋ฅ˜ ๋ฌธ์ œ ์ƒํ™ฉ PUT ๋ฐฉ์‹์œผ๋กœ multipart๋ฅผ ๋ณด๋ƒˆ๋Š”๋ฐ, ๊ธฐ๋Šฅ ์ž์ฒด๋Š” ์ž˜ ๋Œ์•„๊ฐ”์œผ๋‚˜ ํ…Œ์ŠคํŠธํ•  ๋•Œ ์ž๊พธ ์˜ค๋ฅ˜๊ฐ€ ์ƒ๊น€ ๋ฐœ์ƒ ์›์ธ ๊ธฐ๋ณธ์ ์œผ๋กœ multipart ์š”์ฒญ์€ GET/POST๋งŒ ์ง€์›ํ•œ๋‹ค ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• POST๋กœ ์ˆ˜์ •ํ•˜์˜€๋”๋‹ˆ ๋Œ์•„๊ฐ”๋‹ค! ๋ฆฌํŒฉํ† ๋ง ์• ์ดˆ์— API ์„ค๊ณ„ ์›์น™์—๋„ ์กฐ๊ธˆ ์–ด๊ธ‹๋‚œ ๊ฒƒ ๊ฐ™์•„์„œ ๊ฒธ์‚ฌ๊ฒธ์‚ฌ ์ˆ˜์ •ํ–ˆ๋‹ค PUT์€ ํŠน์ • ๋ฆฌ์†Œ์Šค๋ฅผ ๊ฐฑ์‹ ํ•˜๋Š” ์—ญํ• ์„ ํ•˜๋Š”๋ฐ multipart๋กœ ๋ณด๋‚ด๋ฉด ํ•œ๋ฒˆ์— ์—ฌ๋Ÿฌ ๋ฆฌ์†Œ์Šค๋ฅผ ์ฒ˜๋ฆฌํ•˜๋ฏ€๋กœ ์ด๋ฏธ์ง€ ๊ฐ™์€ ๊ฒฝ์šฐ๋ฅผ PUT์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋ ค๋ฉด ์ด๋ฏธ์ง€๋“ฑ์— ๋Œ€ํ•œ ๋ฆฌ์†Œ์Šค URI์— ๋ณ„๋„์˜ PUT ์š”์ฒญ์„ ๋ณด๋‚ด์„œ ๊ฐฑ์‹ ํ•˜๊ณ  ์ผ๋ฐ˜์ ์ธ ํผ์€ ๋”ฐ๋กœ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•œ๋‹ค. ๋ผ๊พธ๋ผ๊พธ profileUpdate์—์„œ ํ•œ URI๋กœ PUT์„ ๋ณด๋‚ด์„œ ์—ฌ๋Ÿฌ ๋ฆฌ์†Œ์Šค(ํšŒ์› ์ •๋ณด + ์ด๋ฏธ์ง€)๋ฅผ ํ•œ๊บผ๋ฒˆ์— ์ฒ˜๋ฆฌํ•˜๋ ค๊ณ  ํ–ˆ์œผ๋ฏ€๋กœ PUT์ด ์ ํ•ฉ์น˜ .. 2023. 8. 13.
[์ถ”์ธก] ๊ธฐ์กด Spring Security๋ฅผ ์ ์šฉํ•œ ์ƒํ™ฉ์—์„œ OAuth2 ์ ์šฉ์ด ์•ˆ ๋จนํ˜”๋˜ ์ด์œ  ์ถ”์ธก ๋ฌธ์ œ ์ƒํ™ฉ ์ž์ฒด ํšŒ์›๊ฐ€์ž…์—์„œ jwt refresh & access token์„ ์ง์ ‘ ๋งŒ๋“ค์–ด์„œ ์ ์šฉํ•œ ์ƒํ™ฉ ์ด ์ƒํ™ฉ์—์„œ oAuth2 ์ ์šฉ ์‹œ๋„ํ•˜์˜€์œผ๋‚˜ ์‹คํŒจ ์˜ˆ์ƒ ์†Œ๋งˆ ๋ฉ˜ํ† ๋‹˜๊ป˜์„œ ์•Œ๋ ค์ฃผ์‹  ๊ฑด๋ฐ ์šฐ๋ฆฌ ํ”„๋กœ์ ํŠธ๋ž‘ ๋น„์Šทํ•œ ์ƒํ™ฉ์ธ ๊ฒƒ ๊ฐ™์•„ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค ์ •์„์ ์ธ ๋ฐฉ๋ฒ•) jwk/jws๋Š” jwt์™€ ํ•จ๊ป˜ ์”€ ํ† ํฐ ํƒˆ์ทจํ•˜๋ฉด ๋งˆ์Œ๋Œ€๋กœ ์“ธ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— signature ๋„ฃ์–ด์„œ ์•”ํ˜ธํ™” ํ›„ ๋น„๋Œ€์นญ์œผ๋กœ ๊ฒ€์ฆํ•จ (์ง„์งœ ์„œ๋ฒ„์—์„œ ๋ณด๋‚ธ ๊ฒƒ์ธ์ง€ ํ™•์ธ) ์†Œ์…œ๋กœ๊ทธ์ธ์ด๋ž‘ ๊ฐ™์ด ์“ธ ๋•Œ์˜ ๋ฌธ์ œ์  ์ผ๋ฐ˜ ๋กœ๊ทธ์ธ ์‹œ spring์—์„œ ์“ฐ๋Š” token์ด๋ž‘ ์†Œ์…œ ๋กœ๊ทธ์ธ ์‹œ ๋‚˜์˜ค๋Š” token์ด ๋ถ„๋ฆฌ๋˜์–ด ์žˆ์Œ ๊ทธ๋Ÿฌ๋‚˜ spring ์ž์ฒด์—์„œ ์ด 2๊ฐœ๋ฅผ ํ•˜๋‚˜์˜ token์œผ๋กœ ํ•ฉ์ณ์„œ clientํ•œํ…Œ ๋ณด๋‚ด์คŒ(๋‘˜์ด ์„œ๋กœ ๋‹ค๋ฅธ ์œ ์ €๋กœ ์žกํžˆ๋Š” ๊ฒƒ์„ ๋ง‰๊ธฐ ์œ„ํ•จ) ⇒ โœจ๊ทผ๋ฐ ๋‚ด.. 2023. 8. 13.
[์˜ค๋ฅ˜] WebMvcTest์—์„œ body๊ฐ’์ด empty์ธ ๊ฒฝ์šฐ ๋ฌธ์ œ ์ƒํ™ฉ ProfileUpdateController์—์„œ status๋Š” ํ™•์ธ๋˜๋Š”๋ฐ body์—์„œ ์ž๊พธ null๊ฐ’์ด ๋ฐœ์ƒํ•˜๋Š” ์˜ค๋ฅ˜ ๋ฐœ์ƒ String์„ ๋ฐ˜ํ™˜๊ฐ’์œผ๋กœ ํ•˜๋ฉด ์ž˜ ๋˜๋Š”๋ฐ dto์˜ body์—์„œ๋งŒ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฒจ์„œ ๊ฐ™์ด ์—ฌ๋Ÿฌ๋ชจ๋กœ ๊ณ ๋ฏผํ–ˆ๋‹ค. Multipart๋ฅผ ์ธ์ž๋กœ ๋ฐ›๋Š” ๊ฒƒ์ด๋ผ multipart์˜ ๋ฌธ์ œ์ธ ์ค„ ์•Œ์•˜์œผ๋‚˜.... ๋ฐœ์ƒ ์›์ธ ProfileUpdateController๋กœ ์ „๋‹ฌ๋œ JSON์ด ๋งŒ๋“ค์–ด๋‚ธ Response ๊ฐ์ฒด๊ฐ€ ์šฐ๋ฆฌ๊ฐ€ ์˜ˆ์ƒํ•œ ๊ฒƒ๊ณผ ๋‹ค๋ฅธ ๊ฐ์ฒด๋ผ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ์˜€๋‹ค (Multipart๋ž‘ 1๋„ ์ƒ๊ด€์—†์—ˆ๋‹ค^^) https://velog.io/@devmizz/Spring-WebMvcTest%EC%97%90%EC%84%9C-Response-Body%EA%B0%80-Empty%EC%9D%BC-%EB%95%8C 2023. 8. 13.