Commit b7d2b4f7 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Test for contest participation requirement

parent c39b2380
Pipeline #939 passed with stage
in 7 minutes and 8 seconds
......@@ -291,7 +291,7 @@ mod tests {
let mut contest = Contest::new("directory".to_string(),
"public.yaml".to_string(),
"RenamedContestName".to_string(),
1,
1, // Time: 1 Minute
true,
None,
None,
......@@ -308,7 +308,7 @@ mod tests {
let mut contest = Contest::new("directory".to_string(),
"public.yaml".to_string(),
"PublicContestName".to_string(),
1,
1, // Time: 1 Minute
true,
None,
None,
......@@ -331,7 +331,7 @@ mod tests {
let mut contest = Contest::new("directory".to_string(),
"private.yaml".to_string(),
"PrivateContestName".to_string(),
1,
1, // Time: 1 Minute
false,
None,
None,
......@@ -381,6 +381,29 @@ mod tests {
contest.taskgroups.push(taskgroup);
contest.save(&conn);
// ID: 4
let mut contest = Contest::new("directory".to_string(),
"publicround2.yaml".to_string(),
"PublicContestRoundTwoName".to_string(),
1, // Time: 1 Minute
true,
None,
None,
None,
None,
None,
None,
Some("public.yaml".to_string()),
None,
None);
let mut taskgroup = Taskgroup::new("TaskgroupName".to_string(), None);
let task = Task::new("taskdir1".to_string(), 3); // ID: 7
taskgroup.tasks.push(task);
let task = Task::new("taskdir2".to_string(), 4); // ID: 8
taskgroup.tasks.push(task);
contest.taskgroups.push(taskgroup);
contest.save(&conn);
let mut config = config::read_config_from_file(Path::new("thisfileshoudnotexist"));
config.port = Some(port);
config.cookie_signing_secret = Some("testtesttesttesttesttesttesttest".to_string());
......@@ -635,7 +658,7 @@ mod tests {
let content = resp.text().unwrap();
assert!(content.contains("PublicContestName"));
assert!(content.contains("InfiniteContestName"));
//assert!(content.contains("PrivateContestName"));
assert!(!content.contains("PrivateContestName"));
assert!(!content.contains("WrongContestName"));
assert!(!content.contains("RenamedContestName"));
assert!(content.contains("<a href=\"/contest/1\">PublicContestName</a>"));
......@@ -1093,4 +1116,66 @@ mod tests {
assert_eq!(resp.status(), StatusCode::FOUND);
})
}
#[test]
fn check_contest_requirement() {
start_server_and_fn(8092, |conn| {
addsimpleuser(conn, "testusr".to_string(), "testpw".to_string(), false, false);
}, || {
let client = reqwest::Client::builder().cookie_store(true)
.redirect(reqwest::RedirectPolicy::none())
.build()
.unwrap();
let resp = login(8092, &client, "testusr", "testpw");
assert_eq!(resp.status(), StatusCode::FOUND);
// Check contest can not be started
let mut resp = client.get("http://localhost:8092/contest/4").send().unwrap();
assert_eq!(resp.status(), StatusCode::OK);
let content = resp.text().unwrap();
assert!(!content.contains("csrf_token"));
assert!(!content.contains("<a href=\"/task/7\">☆☆☆</a></li>"));
assert!(!content.contains("<a href=\"/task/8\">☆☆☆☆</a></li>"));
// Start other contest
let mut resp = client.get("http://localhost:8092/contest/1").send().unwrap();
assert_eq!(resp.status(), StatusCode::OK);
let content = resp.text().unwrap();
let pos = content.find("type=\"hidden\" name=\"csrf_token\" value=\"").expect("CSRF-Token not found");
let csrf = &content[pos + 39..pos + 49];
let params = [("csrf_token", csrf)];
let resp = client.post("http://localhost:8092/contest/1").form(&params).send().unwrap();
assert_eq!(resp.status(), StatusCode::FOUND);
let mut resp = client.get("http://localhost:8092/contest/1").send().unwrap();
assert_eq!(resp.status(), StatusCode::OK);
let content = resp.text().unwrap();
assert!(content.contains("<a href=\"/task/1\">☆☆☆</a></li>"));
assert!(content.contains("<a href=\"/task/2\">☆☆☆☆</a></li>"));
// Check contest can be started now
let mut resp = client.get("http://localhost:8092/contest/4").send().unwrap();
assert_eq!(resp.status(), StatusCode::OK);
let content = resp.text().unwrap();
let pos = content.find("type=\"hidden\" name=\"csrf_token\" value=\"").expect("CSRF-Token not found");
let csrf = &content[pos + 39..pos + 49];
let params = [("csrf_token", csrf)];
let resp = client.post("http://localhost:8092/contest/4").form(&params).send().unwrap();
assert_eq!(resp.status(), StatusCode::FOUND);
let mut resp = client.get("http://localhost:8092/contest/4").send().unwrap();
assert_eq!(resp.status(), StatusCode::OK);
let content = resp.text().unwrap();
assert!(content.contains("<a href=\"/task/7\">☆☆☆</a></li>"));
assert!(content.contains("<a href=\"/task/8\">☆☆☆☆</a></li>"));
})
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment