Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
30b13029
Commit
30b13029
authored
Feb 14, 2019
by
Robert Czechowski
Browse files
Tests: Add test to check login with wrong credentials
parent
2a0d8652
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main.rs
View file @
30b13029
...
...
@@ -221,7 +221,7 @@ mod tests {
use
super
::
*
;
use
std
::
io
::
Read
;
fn
start_server_and_fn
<
F
>
(
f
:
F
)
where
F
:
FnOnce
()
{
fn
start_server_and_fn
<
F
>
(
port
:
u16
,
f
:
F
)
where
F
:
FnOnce
()
{
use
std
::{
thread
,
time
};
use
std
::
sync
::
mpsc
::
channel
;
let
(
start_tx
,
start_rx
)
=
channel
();
...
...
@@ -231,6 +231,7 @@ mod tests {
let
mut
conn
=
Connection
::
open_in_memory
()
.unwrap
();
db_apply_migrations
::
test
(
&
mut
conn
);
let
mut
config
=
read_config_from_file
(
Path
::
new
(
"thisfileshoudnotexist"
));
config
.port
=
Some
(
port
);
let
srvr
=
start_server
(
conn
,
config
);
start_tx
.send
(())
.unwrap
();
...
...
@@ -249,13 +250,35 @@ mod tests {
#[test]
fn
start_server_and_check_request
()
{
start_server_and_fn
(||{
start_server_and_fn
(
8080
,
||{
let
mut
resp
=
reqwest
::
get
(
"http://localhost:8080"
)
.unwrap
();
assert!
(
resp
.status
()
.is_success
());
let
mut
content
=
String
::
new
();
resp
.read_to_string
(
&
mut
content
);
assert!
(
content
.contains
(
"<h1>Jugendwettbewerb Informatik</h1>"
));
assert!
(
!
content
.contains
(
"Error"
));
let
mut
resp
=
reqwest
::
get
(
"http://localhost:8080/contest"
)
.unwrap
();
assert!
(
resp
.status
()
.is_success
());
let
mut
content
=
String
::
new
();
resp
.read_to_string
(
&
mut
content
);
assert!
(
content
.contains
(
"<h1>Wettbewerbe</h1>"
));
assert!
(
!
content
.contains
(
"Error"
));
})
}
#[test]
fn
check_login_wrong_credentials
()
{
start_server_and_fn
(
8081
,
||{
let
params
=
[(
"username"
,
"nonexistingusername"
),
(
"password"
,
"wrongpassword"
)];
let
client
=
reqwest
::
Client
::
new
()
.unwrap
();
let
mut
resp
=
client
.post
(
"http://localhost:8081/login"
)
.form
(
&
params
)
.send
()
.unwrap
();
let
mut
content
=
String
::
new
();
resp
.read_to_string
(
&
mut
content
);
assert!
(
content
.contains
(
"<h1>Jugendwettbewerb Informatik</h1>"
));
assert!
(
content
.contains
(
"<h1>Login</h1>"
));
assert!
(
content
.contains
(
"Login fehlgeschlagen."
));
assert!
(
!
content
.contains
(
"Error"
));
})
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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