Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
c55c519c
Commit
c55c519c
authored
Aug 07, 2019
by
Robert Czechowski
Browse files
Test task loading / saving
parent
fd85d088
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main.rs
View file @
c55c519c
...
...
@@ -580,6 +580,49 @@ mod tests {
let
params
=
[(
"csrf_token"
,
csrf
)];
let
resp
=
client
.post
(
"http://localhost:8085/contest/1"
)
.form
(
&
params
)
.send
()
.unwrap
();
assert_eq!
(
resp
.status
(),
StatusCode
::
FOUND
);
let
mut
resp
=
client
.get
(
"http://localhost:8085/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>"
));
let
mut
resp
=
client
.get
(
"http://localhost:8085/task/1"
)
.send
()
.unwrap
();
assert_eq!
(
resp
.status
(),
StatusCode
::
OK
);
let
content
=
resp
.text
()
.unwrap
();
let
pos
=
content
.find
(
"#taskid=1&csrftoken="
)
.expect
(
"CSRF-Token not found"
);
let
csrf
=
&
content
[
pos
+
20
..
pos
+
30
];
let
mut
resp
=
client
.get
(
"http://localhost:8085/load/1"
)
.send
()
.unwrap
();
assert_eq!
(
resp
.status
(),
StatusCode
::
OK
);
let
content
=
resp
.text
()
.unwrap
();
assert_eq!
(
content
,
"{}"
);
let
params
=
[(
"data"
,
"WrongData"
),(
"grade"
,
"1"
),(
"csrf_token"
,
"FNQU4QsEMY"
)];
let
mut
resp
=
client
.post
(
"http://localhost:8085/save/1"
)
.form
(
&
params
)
.send
()
.unwrap
();
assert_eq!
(
resp
.status
(),
StatusCode
::
FORBIDDEN
);
let
mut
resp
=
client
.get
(
"http://localhost:8085/load/1"
)
.send
()
.unwrap
();
assert_eq!
(
resp
.status
(),
StatusCode
::
OK
);
let
content
=
resp
.text
()
.unwrap
();
assert_eq!
(
content
,
"{}"
);
let
params
=
[(
"data"
,
"SomeData"
),(
"grade"
,
"2"
),(
"csrf_token"
,
csrf
)];
let
mut
resp
=
client
.post
(
"http://localhost:8085/save/1"
)
.form
(
&
params
)
.send
()
.unwrap
();
assert_eq!
(
resp
.status
(),
StatusCode
::
OK
);
let
content
=
resp
.text
()
.unwrap
();
assert_eq!
(
content
,
"{}"
);
let
mut
resp
=
client
.get
(
"http://localhost:8085/load/1"
)
.send
()
.unwrap
();
assert_eq!
(
resp
.status
(),
StatusCode
::
OK
);
let
content
=
resp
.text
()
.unwrap
();
assert_eq!
(
content
,
"SomeData"
);
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment