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
61f612f5
Commit
61f612f5
authored
Aug 07, 2019
by
Robert Czechowski
Browse files
Fix error handling in save task
parent
f1d0ae52
Pipeline
#199
failed with stage
in 9 minutes and 26 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/functions.rs
View file @
61f612f5
...
...
@@ -379,7 +379,7 @@ pub fn save_submission<T: MedalConnection>(conn: &T, task_id: i32, session_token
.ok_or
(
MedalError
::
AccessDenied
)
?
;
// TODO SessionTimeout
if
session
.csrf_token
!=
csrf_token
{
return
Err
(
MedalError
::
Csrf
Error
);
return
Err
(
MedalError
::
Csrf
CheckFailed
);
}
let
submission
=
Submission
{
id
:
None
,
...
...
src/main.rs
View file @
61f612f5
...
...
@@ -602,7 +602,7 @@ mod tests {
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
();
let
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
();
...
...
@@ -610,6 +610,13 @@ mod tests {
let
content
=
resp
.text
()
.unwrap
();
assert_eq!
(
content
,
"{}"
);
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
params
=
[(
"data"
,
"SomeData"
),(
"grade"
,
"2"
),(
"csrf_token"
,
csrf
)];
let
mut
resp
=
client
.post
(
"http://localhost:8085/save/1"
)
.form
(
&
params
)
.send
()
.unwrap
();
...
...
@@ -623,6 +630,13 @@ mod tests {
let
content
=
resp
.text
()
.unwrap
();
assert_eq!
(
content
,
"SomeData"
);
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>"
));
})
}
}
src/webfw_iron.rs
View file @
61f612f5
...
...
@@ -202,7 +202,7 @@ impl<'c, 'a, 'b> From<AugMedalError<'c, 'a, 'b>> for IronError {
}
functions
::
MedalError
::
AccessDenied
=>
{
IronError
{
error
:
Box
::
new
(
SessionError
{
message
:
"Access denied"
.to_string
()
}),
response
:
Response
::
with
(
status
::
Forbidden
)
}
response
:
Response
::
with
(
status
::
Unauthorized
)
}
}
functions
::
MedalError
::
CsrfCheckFailed
=>
{
IronError
{
error
:
Box
::
new
(
SessionError
{
message
:
"CSRF Error"
.to_string
()
}),
...
...
@@ -214,11 +214,11 @@ impl<'c, 'a, 'b> From<AugMedalError<'c, 'a, 'b>> for IronError {
}
functions
::
MedalError
::
DatabaseError
=>
{
IronError
{
error
:
Box
::
new
(
SessionError
{
message
:
"Database Error"
.to_string
()
}),
response
:
Response
::
with
(
status
::
Forbidden
)
}
response
:
Response
::
with
(
status
::
InternalServerError
)
}
}
functions
::
MedalError
::
PasswordHashingError
=>
{
IronError
{
error
:
Box
::
new
(
SessionError
{
message
:
"Error hashing the passwords"
.to_string
()
}),
response
:
Response
::
with
(
status
::
Forbidden
)
}
response
:
Response
::
with
(
status
::
InternalServerError
)
}
}
functions
::
MedalError
::
UnmatchedPasswords
=>
{
IronError
{
error
:
Box
::
new
(
SessionError
{
message
:
...
...
@@ -482,12 +482,9 @@ fn submission_post<C>(req: &mut Request) -> IronResult<Response>
*/
let
result
=
with_conn!
[
functions
::
save_submission
,
C
,
req
,
task_id
,
&
session_token
,
&
csrf_token
,
data
,
grade
,
subtask
];
with_conn!
[
functions
::
save_submission
,
C
,
req
,
task_id
,
&
session_token
,
&
csrf_token
,
data
,
grade
,
subtask
]
.aug
(
req
)
?
;
match
result
{
Ok
(
_
)
=>
Ok
(
Response
::
with
((
status
::
Ok
,
mime!
(
Application
/
Json
),
format!
(
"{{}}"
)))),
Err
(
_
)
=>
Ok
(
Response
::
with
((
status
::
BadRequest
,
mime!
(
Application
/
Json
),
format!
(
"{{}}"
)))),
}
Ok
(
Response
::
with
((
status
::
Ok
,
mime!
(
Application
/
Json
),
result
)))
}
fn
task
<
C
>
(
req
:
&
mut
Request
)
->
IronResult
<
Response
>
...
...
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