Commit 9e378175 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Test group creation (group code login test part still missing)

parent 98583c60
......@@ -128,7 +128,9 @@ impl MedalConnection for Connection {
street = $7,
zip = $8,
city = $9,
grade = $10 WHERE id = $11",
grade = $10,
is_teacher = $11
WHERE id = $12",
&[&session.username,
&session.password,
&session.salt,
......@@ -139,6 +141,7 @@ impl MedalConnection for Connection {
&session.zip,
&session.city,
&session.grade,
&session.is_teacher,
&session.id])
.unwrap();
}
......
......@@ -128,7 +128,9 @@ impl MedalConnection for Connection {
street = ?7,
zip = ?8,
city = ?9,
grade = ?10 WHERE id = ?",
grade = ?10,
is_teacher = ?11
WHERE id = ?12",
&[&session.username,
&session.password,
&session.salt,
......@@ -139,6 +141,7 @@ impl MedalConnection for Connection {
&session.zip,
&session.city,
&session.grade,
&session.is_teacher,
&session.id])
.unwrap();
}
......
......@@ -393,6 +393,36 @@ mod tests {
let resp = login_for_tests(8084, &client, "testusr", "testpw");
assert_eq!(resp.status(), &StatusCode::Found);
let header = resp.headers();
let set_cookie = header.get::<reqwest::header::SetCookie>().expect("No coockies transmitted");
assert_eq!(set_cookie.len(), 1);
let cookie = reqwest::header::Cookie(set_cookie.to_vec());
let mut resp = client.get("http://localhost:8084").header(cookie.clone()).send().unwrap();
assert_eq!(resp.status(), &StatusCode::Ok);
let mut content = String::new();
resp.read_to_string(&mut content).unwrap();
assert!(content.contains("[Lehrer]"));
assert!(content.contains("Gruppenverwaltung"));
let mut resp = client.get("http://localhost:8084/group/").header(cookie.clone()).send().unwrap();
assert_eq!(resp.status(), &StatusCode::Ok);
let mut content = String::new();
resp.read_to_string(&mut content).unwrap();
assert!(content.contains("Gruppe anlegen"));
let params = [("name", "groupname"), ("tag", "marker"), ("csrf", "76CfTPJaoz")];
let resp = client.post("http://localhost:8084/group/").form(&params).header(cookie.clone()).send().unwrap();
assert_eq!(resp.status(), &StatusCode::Forbidden);
let pos = content.find("type=\"hidden\" name=\"csrf\" value=\"").expect("CSRF-Token not found");
let csrf = &content[pos+33..pos+43];
let params = [("name", "groupname"), ("tag", "marker"), ("csrf", csrf)];
let resp = client.post("http://localhost:8084/group/").form(&params).header(cookie).send().unwrap();
assert_eq!(resp.status(), &StatusCode::Found);
})
}
......
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