Compare commits

..

No commits in common. "14e37b9e387205aace7a1999637aef9efc8d7692" and "7dee5b60f9a2a923101e08a96cbd18dde25861bf" have entirely different histories.

6 changed files with 8 additions and 71 deletions

View file

@ -3,6 +3,8 @@ package be.jeffcheasey88.peeratcode.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.SortedSet;
import java.util.TreeSet;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;

View file

@ -493,8 +493,8 @@ public class DatabaseRepository {
ensureConnection(); ensureConnection();
PreparedStatement statement = DatabaseQuery.INSERT_GROUP.prepare(this.con); PreparedStatement statement = DatabaseQuery.INSERT_GROUP.prepare(this.con);
statement.setString(1, group.getName()); statement.setString(1, group.getName());
statement.setObject(2, group.getLinkToChapter()); statement.setInt(2, group.getLinkToChapter());
statement.setObject(3, group.getLinkToPuzzle()); statement.setInt(3, group.getLinkToPuzzle());
if(statement.executeUpdate() >= 0) return insertUserInGroup(group, creator); if(statement.executeUpdate() >= 0) return insertUserInGroup(group, creator);
} catch (Exception e){} } catch (Exception e){}
return false; return false;

View file

@ -25,7 +25,8 @@ public class GroupJoin implements Response{
@Route(path = "^\\/groupJoin$", type = POST, needLogin = true) @Route(path = "^\\/groupJoin$", type = POST, needLogin = true)
public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception { public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception {
HttpUtil.skipHeaders(reader); HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
if (this.repo.insertUserInGroup(new Group((JSONObject) HttpUtil.readJson(reader)), user)) { if (this.repo.insertUserInGroup(new Group((JSONObject) HttpUtil.readJson(reader)), user)) {
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *"); HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
} else { } else {

View file

@ -25,7 +25,7 @@ public class GroupQuit implements Response{
@Route(path = "^\\/groupQuit$", type = POST, needLogin = true) @Route(path = "^\\/groupQuit$", type = POST, needLogin = true)
public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception { public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception {
HttpUtil.skipHeaders(reader); HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
if (this.repo.leaveGroup(new Group((JSONObject) HttpUtil.readJson(reader)), user)) { if (this.repo.leaveGroup(new Group((JSONObject) HttpUtil.readJson(reader)), user)) {
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *"); HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");

View file

@ -1,64 +0,0 @@
package be.jeffcheasey88.peeratcode.routes;
import static org.junit.jupiter.api.Assertions.fail;
import org.json.simple.JSONObject;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import be.jeffcheasey88.peeratcode.Main;
import be.jeffcheasey88.peeratcode.webclient.WebClient;
@TestInstance(Lifecycle.PER_CLASS)
public class TmpRoutesTests {
private Thread server;
private WebClient client;
@BeforeAll
void init(){
server = new Thread(new Runnable(){
@Override
public void run(){
try {
Main.main(null);
} catch (Exception e) {
e.printStackTrace();
};
}
});
server.start();
client = new WebClient("localhost", 80);
}
@AfterAll
void close(){
server.interrupt();
}
@Test
void testOnDeployed(){
try {
JSONObject content = new JSONObject();
content.put("name", "testTeam1");
content.put("chapter", 2);
client.auth("JeffCheasey88", "TheoPueDesPieds");
client.route("/groupCreate", "POST", content.toJSONString());
client.assertResponseCode(200);
client.route("/groupJoin","POST",content.toJSONString());
client.assertResponseCode(200);
client.route("/groupQuit", "POST", content.toJSONString());
client.assertResponseCode(200);
}catch(Exception e){
fail(e);
}
}
}

View file

@ -50,16 +50,14 @@ public class WebClient {
login.put("pseudo", user); login.put("pseudo", user);
login.put("passwd", password); login.put("passwd", password);
route("/login", "POST", login.toJSONString()); route("/login", "POST", login.toJSONString());
System.out.println("["+host+"] /login "+login);
for(String line : this.headers){ for(String line : this.headers){
Matcher matcher = AUTORIZATION.matcher(line); Matcher matcher = AUTORIZATION.matcher(line);
if(matcher.matches()){ if(matcher.matches()){
this.token = matcher.group(1); this.token = matcher.group(1);
System.out.println(host+": "+token); System.out.println(token);
break; break;
} }
System.out.println("["+host+"] "+line);
} }
} }