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
c4d4a730
Commit
c4d4a730
authored
Apr 01, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev/tests' into single_flag
parents
9c8f4d3f
5d812cb4
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
162 additions
and
0 deletions
+162
-0
example_scenario.json
tests/example_scenario.json
+12
-0
main.py
tests/main.py
+76
-0
auth_api.json
tests/scenarios/auth_api.json
+10
-0
login_page_up.json
tests/scenarios/login_page_up.json
+6
-0
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/example_scenario.json
0 → 100644
View file @
c4d4a730
{
"name"
:
"Example scenario"
,
"description"
:
"This is an example scenario."
,
"url"
:
"http://google.com/"
,
"method"
:
"GET"
,
"user"
:
{
"login"
:,
"password"
:,
},
"payload"
:
{},
"expected_output"
:
{}
}
tests/main.py
0 → 100644
View file @
c4d4a730
import
requests
import
json
import
os
SCENARIOS_PATH
=
"scenarios/"
;
class
Test
:
def
__init__
(
self
):
self
.
scenarios
=
[]
def
run
(
self
):
for
scenario
in
self
.
scenarios
:
if
scenario
.
get
(
"method"
)
==
"GET"
:
self
.
send_get_request
(
scenario
)
elif
scenario
.
get
(
"method"
)
==
"POST"
:
self
.
send_post_request
(
scenario
)
else
:
print
"Skipping "
,
scenario
[
"name"
],
" please specify request method."
def
load_test_scenarios
(
self
,
scenarios_path
):
scenario_names
=
[
scenario_file
for
scenario_file
in
os
.
listdir
(
scenarios_path
)
if
scenario_file
.
endswith
(
'.json'
)]
for
scenario_name
in
scenario_names
:
with
open
(
os
.
path
.
join
(
scenarios_path
,
scenario_name
))
as
scenario_file
:
self
.
scenarios
.
append
(
json
.
load
(
scenario_file
))
def
send_get_request
(
self
,
scenario
):
if
scenario
.
get
(
"user"
):
auth
=
(
scenario
[
"user"
][
"login"
],
scenario
[
"user"
][
"password"
])
else
:
auth
=
None
try
:
res
=
requests
.
get
(
scenario
[
"url"
],
auth
=
auth
)
except
Exception
:
print
"Test {0} failed!"
.
format
(
scenario
[
"name"
])
return
if
res
.
status_code
==
200
:
if
scenario
.
get
(
"expected_output"
)
!=
None
:
if
scenario
.
get
(
"expected_output"
)
==
res
.
json
():
print
"Test {0} OK!"
.
format
(
scenario
[
"name"
])
else
:
print
"Test {0}, expected {1} but got {2}!"
.
format
(
scenario
[
"name"
],
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
):
if
scenario
.
get
(
"user"
):
auth
=
(
scenario
[
"user"
][
"login"
],
scenario
[
"user"
][
"password"
])
else
:
auth
=
None
res
=
requests
.
post
(
scenario
[
"url"
],
auth
=
auth
,
data
=
scenario
.
get
(
"payload"
))
if
res
.
status_code
==
200
:
if
scenario
.
get
(
"expected_output"
)
!=
None
:
if
scenario
.
get
(
"expected_output"
)
==
res
.
json
():
print
"Test {0} OK!"
.
format
(
scenario
[
"name"
])
else
:
print
"Test {0}, expected {1} but got {2}!"
.
format
(
scenario
[
"name"
],
scenario
[
"expected_output"
],
res
.
json
())
else
:
print
"Test {0} OK!"
.
format
(
scenario
[
"name"
])
else
:
print
"Test {0} failed!"
.
format
(
scenario
[
"name"
])
file_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
SCENARIOS_PATH
)
test
=
Test
()
test
.
load_test_scenarios
(
file_path
)
test
.
run
()
tests/scenarios/auth_api.json
0 → 100644
View file @
c4d4a730
{
"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
0 → 100644
View file @
c4d4a730
{
"name"
:
"'Login' page is up"
,
"description"
:
"Checks if login page is up"
,
"method"
:
"GET"
,
"url"
:
"http://localhost:8080/"
}
tests/scenarios/solutions_completed.json
0 → 100644
View file @
c4d4a730
{
"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 @
c4d4a730
{
"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 @
c4d4a730
{
"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 @
c4d4a730
{
"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 @
c4d4a730
{
"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 @
c4d4a730
{
"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