Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
CTF
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grzegorz
CTF
Commits
5d812cb4
Commit
5d812cb4
authored
Mar 24, 2016
by
adam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic endpoint testing
parent
f11fca4f
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
91 additions
and
15 deletions
+91
-15
main.py
tests/main.py
+22
-14
auth_api.json
tests/scenarios/auth_api.json
+10
-0
login_page_up.json
tests/scenarios/login_page_up.json
+1
-1
solutions_completed.json
tests/scenarios/solutions_completed.json
+11
-0
solutions_completed_my.json
tests/scenarios/solutions_completed_my.json
+11
-0
submit_flag.json
tests/scenarios/submit_flag.json
+11
-0
tasks_endpoint.json
tests/scenarios/tasks_endpoint.json
+7
-0
teams_endpoint.json
tests/scenarios/teams_endpoint.json
+7
-0
who_am_i_endpoint.json
tests/scenarios/who_am_i_endpoint.json
+11
-0
No files found.
tests/main.py
View file @
5d812cb4
...
@@ -2,7 +2,7 @@ import requests
...
@@ -2,7 +2,7 @@ import requests
import
json
import
json
import
os
import
os
SCENARIOS_PATH
=
"
./
scenarios/"
;
SCENARIOS_PATH
=
"scenarios/"
;
class
Test
:
class
Test
:
...
@@ -14,7 +14,7 @@ class Test:
...
@@ -14,7 +14,7 @@ class Test:
if
scenario
.
get
(
"method"
)
==
"GET"
:
if
scenario
.
get
(
"method"
)
==
"GET"
:
self
.
send_get_request
(
scenario
)
self
.
send_get_request
(
scenario
)
elif
scenario
.
get
(
"method"
)
==
"POST"
:
elif
scenario
.
get
(
"method"
)
==
"POST"
:
self
.
send_post_request
self
.
send_post_request
(
scenario
)
else
:
else
:
print
"Skipping "
,
scenario
[
"name"
],
" please specify request method."
print
"Skipping "
,
scenario
[
"name"
],
" please specify request method."
...
@@ -37,12 +37,16 @@ class Test:
...
@@ -37,12 +37,16 @@ class Test:
return
return
if
res
.
status_code
==
200
:
if
res
.
status_code
==
200
:
if
scenario
.
get
(
"expected_output"
):
if
scenario
.
get
(
"expected_output"
)
!=
None
:
if
scenario
.
get
(
"expected_output"
)
==
res
.
json
():
if
scenario
.
get
(
"expected_output"
)
==
res
.
json
():
print
"Test {0} OK!"
.
format
(
scenario
[
"name"
])
print
"Test {0} OK!"
.
format
(
scenario
[
"name"
])
return
else
:
print
"Test {0}, expected {1} but got {2}!"
.
format
(
scenario
[
"name"
],
print
"Test {0}, expected {1} but got {2}!"
.
format
(
scenario
[
"name"
],
scenario
[
"expected_output"
],
res
.
json
())
scenario
[
"expected_output"
],
res
.
json
())
else
:
print
"Test {0} OK!"
.
format
(
scenario
[
"name"
])
else
:
print
"Test {0} failed!"
.
format
(
scenario
[
"name"
])
def
send_post_request
(
self
,
scenario
):
def
send_post_request
(
self
,
scenario
):
if
scenario
.
get
(
"user"
):
if
scenario
.
get
(
"user"
):
...
@@ -50,19 +54,23 @@ class Test:
...
@@ -50,19 +54,23 @@ class Test:
else
:
else
:
auth
=
None
auth
=
None
res
=
requests
.
p
ath
(
scenario
[
"url"
],
auth
=
auth
,
data
=
scenario
.
get
(
"payload"
))
res
=
requests
.
p
ost
(
scenario
[
"url"
],
auth
=
auth
,
data
=
scenario
.
get
(
"payload"
))
if
res
.
status_code
==
200
:
if
res
.
status_code
==
200
:
if
scenario
.
get
(
"expected_output"
):
if
scenario
.
get
(
"expected_output"
)
!=
None
:
if
scenario
.
get
(
"expected_output"
)
==
res
.
json
():
if
scenario
.
get
(
"expected_output"
)
==
res
.
json
():
print
"Test {0} OK!"
.
format
(
scenario
[
"name"
])
print
"Test {0} OK!"
.
format
(
scenario
[
"name"
])
return
else
:
print
"Test {0}, expected {1} but got {2}!"
.
format
(
scenario
[
"name"
],
print
"Test {0}, expected {1} but got {2}!"
.
format
(
scenario
[
"name"
],
scenario
[
"expected_output"
],
res
.
json
())
scenario
[
"expected_output"
],
res
.
json
())
print
"Test {0} failed!"
.
format
(
scenario
[
"name"
])
else
:
print
"Test {0} OK!"
.
format
(
scenario
[
"name"
])
else
:
print
"Test {0} failed!"
.
format
(
scenario
[
"name"
])
test
=
Test
(
)
file_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
SCENARIOS_PATH
)
test
.
load_test_scenarios
(
SCENARIOS_PATH
)
test
=
Test
()
test
.
load_test_scenarios
(
file_path
)
test
.
run
()
test
.
run
()
tests/scenarios/auth_api.json
0 → 100644
View file @
5d812cb4
{
"name"
:
"'Auth api' is up"
,
"description"
:
"This scenario checks if auth api is up and working"
,
"url"
:
"http://localhost:8080/api/v1/auth"
,
"method"
:
"GET"
,
"user"
:
{
"login"
:
"rosiu1"
,
"password"
:
"rosiu321"
}
}
tests/scenarios/login_page_up.json
View file @
5d812cb4
{
{
"name"
:
"
Login_page_
up"
,
"name"
:
"
'Login' page is
up"
,
"description"
:
"Checks if login page is up"
,
"description"
:
"Checks if login page is up"
,
"method"
:
"GET"
,
"method"
:
"GET"
,
"url"
:
"http://localhost:8080/"
"url"
:
"http://localhost:8080/"
...
...
tests/scenarios/solutions_completed.json
0 → 100644
View file @
5d812cb4
{
"name"
:
"'Solutions completed' page is up"
,
"description"
:
"Checks if solutions completed returns empty list"
,
"method"
:
"GET"
,
"url"
:
"http://localhost:8080/api/v1/solutions/completed"
,
"expected_output"
:
[],
"user"
:
{
"login"
:
"rosiu1"
,
"password"
:
"rosiu321"
}
}
tests/scenarios/solutions_completed_my.json
0 → 100644
View file @
5d812cb4
{
"name"
:
"'My solutions' page is up"
,
"description"
:
"Checks if my solutions retuns empty object"
,
"method"
:
"GET"
,
"url"
:
"http://localhost:8080/api/v1/solutions/my"
,
"user"
:
{
"login"
:
"rosiu1"
,
"password"
:
"rosiu321"
}
}
tests/scenarios/submit_flag.json
0 → 100644
View file @
5d812cb4
{
"name"
:
"'Submit flag'"
,
"description"
:
"Submits flag, if test wil be ran 2 times without pruging database it will fail (one flag cannot be submited more that once)"
,
"url"
:
"http://localhost:8080/api/v1/solutions/1/"
,
"method"
:
"POST"
,
"user"
:
{
"login"
:
"rosiu1"
,
"password"
:
"rosiu321"
},
"payload"
:
"459fffa9c2211f96df77c7d8ff72f2b7"
}
tests/scenarios/tasks_endpoint.json
0 → 100644
View file @
5d812cb4
{
"name"
:
"'Tasks' api page is up"
,
"description"
:
"This scenario checks if tasks endpoint is up and working."
,
"url"
:
"http://localhost:8080/api/v1/tasks"
,
"method"
:
"GET"
,
"expected_output"
:
[{
"name"
:
"Szyfro1"
,
"level"
:
1
},{
"name"
:
"Szyfro2"
,
"level"
:
2
},{
"name"
:
"SQL Injection"
,
"level"
:
3
},{
"name"
:
"Inna dziura"
,
"level"
:
4
}]
}
tests/scenarios/teams_endpoint.json
0 → 100644
View file @
5d812cb4
{
"name"
:
"'Teams' page is up"
,
"description"
:
"This is scenario checks if teams resources have been correctly populated."
,
"url"
:
"http://localhost:8080/api/v1/teams"
,
"method"
:
"GET"
,
"expected_output"
:
[{
"name"
:
"misiaczki"
,
"description"
:
"misiaczki opis"
,
"members"
:[{
"name"
:
"gpietrus1"
,
"password"
:
"41b450e73c974fca46911eba84e114f2"
,
"email"
:
"gpietrusza@gmail.com"
,
"admin"
:
false
},{
"name"
:
"mehow1"
,
"password"
:
"c4d24515428cb3ad50e7840be8718f23"
,
"email"
:
"mehow@gmail.com"
,
"admin"
:
false
},{
"name"
:
"rosiu1"
,
"password"
:
"188ed9df2dac8e10f5c5fd2e02383765"
,
"email"
:
"rosiu@gmail.com"
,
"admin"
:
false
},{
"name"
:
"anteq1"
,
"password"
:
"1a7fcdd5a9fd433523268883cfded9d0"
,
"email"
:
"antonigrzanka@gmail.com"
,
"admin"
:
false
}]},{
"name"
:
"prosiaczki"
,
"description"
:
"prosiaczki opis"
,
"members"
:[{
"name"
:
"gpietrus2"
,
"password"
:
"41b450e73c974fca46911eba84e114f2"
,
"email"
:
"gpietrusza@gmail.com"
,
"admin"
:
false
},{
"name"
:
"mehow2"
,
"password"
:
"c4d24515428cb3ad50e7840be8718f23"
,
"email"
:
"mehow@gmail.com"
,
"admin"
:
false
},{
"name"
:
"rosiu2"
,
"password"
:
"188ed9df2dac8e10f5c5fd2e02383765"
,
"email"
:
"rosiu@gmail.com"
,
"admin"
:
false
},{
"name"
:
"anteq2"
,
"password"
:
"1a7fcdd5a9fd433523268883cfded9d0"
,
"email"
:
"antonigrzanka@gmail.com"
,
"admin"
:
false
}]},{
"name"
:
"dupeczki"
,
"description"
:
"dupeczki opis"
,
"members"
:[{
"name"
:
"gpietrus3"
,
"password"
:
"41b450e73c974fca46911eba84e114f2"
,
"email"
:
"gpietrusza@gmail.com"
,
"admin"
:
false
},{
"name"
:
"mehow3"
,
"password"
:
"c4d24515428cb3ad50e7840be8718f23"
,
"email"
:
"mehow@gmail.com"
,
"admin"
:
false
},{
"name"
:
"rosiu3"
,
"password"
:
"188ed9df2dac8e10f5c5fd2e02383765"
,
"email"
:
"rosiu@gmail.com"
,
"admin"
:
false
},{
"name"
:
"anteq3"
,
"password"
:
"1a7fcdd5a9fd433523268883cfded9d0"
,
"email"
:
"antonigrzanka@gmail.com"
,
"admin"
:
false
}]}]
}
tests/scenarios/who_am_i_endpoint.json
0 → 100644
View file @
5d812cb4
{
"name"
:
"'Who am I' is up"
,
"description"
:
"This is scenario checks if who_am_i endpoint is up and working"
,
"url"
:
"http://localhost:8080/api/v1/whoami"
,
"method"
:
"GET"
,
"user"
:
{
"login"
:
"rosiu1"
,
"password"
:
"rosiu321"
},
"expected_output"
:
{
"userName"
:
"rosiu1"
,
"teamName"
:
"misiaczki"
}
}
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