Skip to content

Commit

Permalink
fix: conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
eunbii0213 committed Sep 12, 2023
1 parent e1cd075 commit 0aa0036
Showing 1 changed file with 1 addition and 212 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package nextstep.org.apache.coyote.http11;

import nextstep.jwp.model.User;
import support.StubSocket;
import org.apache.coyote.http11.Http11Processor;
import org.apache.coyote.http11.cookie.HttpCookie;
import org.apache.coyote.http11.cookie.SessionManager;
import org.junit.jupiter.api.Test;
import support.StubSocket;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -34,214 +31,6 @@ void index() throws IOException {
"",
new String(Files.readAllBytes(new File(resource.getFile()).toPath())));

assertThat(socket.output()).contains(expected);
}

@Test
void index_css() {
// given
final String request = String.join("\r\n", "GET /css/styles.css HTTP/1.1 ",
"Host: localhost:8080 ",
"Accept: text/css,*/*;q=0.1 ",
"Connection: keep-alive ",
"",
"");
final var socket = new StubSocket(request);
final var processor = new Http11Processor(socket);

// when
processor.process(socket);

// then
var expected = String.join("\r\n",
"HTTP/1.1 200 OK ",
"Content-Type: text/css;charset=utf-8 ");

assertThat(socket.output()).contains(expected);
}

@Test
void index_js() {
// given
final String request = String.join("\r\n", "GET scripts.js HTTP/1.1 ",
"Host: localhost:8080 ",
"Accept: text/css,*/*;q=0.1 ",
"Connection: keep-alive ",
"",
"");
final var socket = new StubSocket(request);
final var processor = new Http11Processor(socket);

// when
processor.process(socket);

// then
var expected = String.join("\r\n",
"HTTP/1.1 200 OK ",
"Content-Type: Application/javascript;charset=utf-8 ");

assertThat(socket.output()).contains(expected);
}

@Test
void login_success_redirect_index() throws IOException {
// given
final String request = String.join("\r\n", "GET /login?account=gugu&password=password HTTP/1.1\r\nHost: localhost:8080\r\n\r\n");

final var socket = new StubSocket(request);
final var processor = new Http11Processor(socket);
final URL resource = getClass().getClassLoader().getResource("static/index.html");

// when
processor.process(socket);

// then
var expected = String.join("\r\n",
"HTTP/1.1 200 OK ",
"Content-Type: text/html;charset=utf-8 ",
"Content-Length: 5564 ",
"",
new String(Files.readAllBytes(new File(resource.getFile()).toPath())));

assertThat(socket.output()).isEqualTo(expected);
}

@Test
void login_failed_redirect_401() throws IOException {
// given
final String request = String.join("\r\n", "GET /login?account=judy&password=j HTTP/1.1\r\nHost: localhost:8080\r\n\r\n");

final var socket = new StubSocket(request);
final var processor = new Http11Processor(socket);
final URL resource = getClass().getClassLoader().getResource("static/401.html");

// when
processor.process(socket);

// then
var expected = String.join("\r\n",
"HTTP/1.1 401 Unauthorized ",
"Content-Type: text/html;charset=utf-8 ",
"Content-Length: 2426 ",
"",
new String(Files.readAllBytes(new File(resource.getFile()).toPath())));

assertThat(socket.output()).isEqualTo(expected);
}

@Test
void register_redirect_index() throws IOException {
// given
final var socket = new StubSocket("GET /register HTTP/1.1\r\nHost: localhost:8080\r\n\r\n");
final var processor = new Http11Processor(socket);
final URL resource = getClass().getClassLoader().getResource("static/register.html");

// when
processor.process(socket);

// then
var expected = String.join("\r\n",
"HTTP/1.1 200 OK ",
"Content-Type: text/html;charset=utf-8 ",
"Content-Length: 4319 ",
"",
new String(Files.readAllBytes(new File(resource.getFile()).toPath())));

assertThat(socket.output()).contains(expected);
}

@Test
void login_not_saved_jsession() throws IOException {
// given
final String request = String.join("\r\n", "GET /login HTTP/1.1 ",
"Host: localhost:8080 ",
"Connection: keep-alive ",
"Cookie: JSESSIONID=74262fcd-872c-4bcb-ace8-4bb003882817",
"Content-Type: application/x-www-form-urlencoded ",
"Accept: */* ",
"",
"");

final var socket = new StubSocket(request);
final var processor = new Http11Processor(socket);
final URL resource = getClass().getClassLoader().getResource("static/login.html");

// when
processor.process(socket);

// then
var expected = String.join("\r\n",
"HTTP/1.1 200 OK ",
"Content-Type: text/html;charset=utf-8 ",
"Content-Length: 3796 ",
"",
new String(Files.readAllBytes(new File(resource.getFile()).toPath())));

assertThat(socket.output()).isEqualTo(expected);
}

@Test
void login_saved_jsession_redirect_index() throws IOException {
// given
final User judy = new User("judy", "judy", "[email protected]");
final HttpCookie httpCookie = new HttpCookie();
httpCookie.changeJSessionId("74262fcd-872c-4bcb-ace8-4bb003882818");
SessionManager.add(judy, httpCookie);

final String request = String.join("\r\n", "GET /login HTTP/1.1 ",
"Host: localhost:8080 ",
"Connection: keep-alive ",
"Cookie: JSESSIONID=74262fcd-872c-4bcb-ace8-4bb003882818",
"Content-Type: application/x-www-form-urlencoded ",
"Accept: */* ",
"",
"");

final var socket = new StubSocket(request);
final var processor = new Http11Processor(socket);
final URL resource = getClass().getClassLoader().getResource("static/index.html");

// when
processor.process(socket);

// then
var expected = String.join("\r\n",
"HTTP/1.1 200 OK ",
"Content-Type: text/html;charset=utf-8 ",
"Content-Length: 5564 ",
"",
new String(Files.readAllBytes(new File(resource.getFile()).toPath())));

assertThat(socket.output()).isEqualTo(expected);
}

@Test
void register_post() throws IOException {
// given
final String request = String.join("\r\n", "POST /register HTTP/1.1 ",
"Host: localhost:8080 ",
"Connection: keep-alive ",
"Content-Length: 80 ",
"Content-Type: application/x-www-form-urlencoded ",
"Accept: */* ",
"",
"account=gugu&password=password&email=hkkang%40woowahan.com ");

final var socket = new StubSocket(request);
final var processor = new Http11Processor(socket);
final URL resource = getClass().getClassLoader().getResource("static/index.html");

// when
processor.process(socket);

// then
var expected = String.join("\r\n",
"HTTP/1.1 200 OK ",
"Content-Type: text/html;charset=utf-8 ",
"Content-Length: 5564 ",
"",
new String(Files.readAllBytes(new File(resource.getFile()).toPath())));

assertThat(socket.output()).contains(expected);
}
}

0 comments on commit 0aa0036

Please sign in to comment.