Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
67da8467
Commit
67da8467
authored
1 year ago
by
ml bonhomme
Committed by
Erwan Rouchet
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add Ponos task authentication to CreateTask API endpoint
parent
bf875555
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2039
Add Ponos task authentication to CreateTask API endpoint
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/ponos/api.py
+3
-0
3 additions, 0 deletions
arkindex/ponos/api.py
arkindex/ponos/tests/test_api.py
+36
-4
36 additions, 4 deletions
arkindex/ponos/tests/test_api.py
with
39 additions
and
4 deletions
arkindex/ponos/api.py
+
3
−
0
View file @
67da8467
...
...
@@ -29,6 +29,7 @@ from arkindex.ponos.permissions import (
IsAgentOrTaskAdmin
,
IsAgentOrTaskAdminOrReadOnly
,
IsAssignedAgentOrReadOnly
,
IsTask
,
)
from
arkindex.ponos.renderers
import
PublicKeyPEMRenderer
from
arkindex.ponos.serializers
import
(
...
...
@@ -311,6 +312,8 @@ class TaskCreate(CreateAPIView):
Create a task with a parent
"""
authentication_classes
=
(
TaskAuthentication
,
)
permission_classes
=
(
IsTask
,
)
serializer_class
=
NewTaskSerializer
...
...
This diff is collapsed.
Click to expand it.
arkindex/ponos/tests/test_api.py
+
36
−
4
View file @
67da8467
...
...
@@ -1467,8 +1467,34 @@ class TestAPI(FixtureAPITestCase):
)
)
def
test_task_create_
empty_body
(
self
):
def
test_task_create_
requires_task_auth
(
self
):
response
=
self
.
client
.
post
(
reverse
(
"
api:task-create
"
))
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_401_UNAUTHORIZED
)
self
.
assertDictEqual
(
response
.
json
(),
{
'
detail
'
:
'
Authentication credentials were not provided.
'
}
)
def
test_task_create_user_forbidden
(
self
):
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
post
(
reverse
(
"
api:task-create
"
))
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_401_UNAUTHORIZED
)
self
.
assertDictEqual
(
response
.
json
(),
{
'
detail
'
:
'
Authentication credentials were not provided.
'
}
)
def
test_task_create_agent_forbidden
(
self
):
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
post
(
reverse
(
"
api:task-create
"
),
HTTP_AUTHORIZATION
=
f
'
Bearer
{
self
.
agent
.
token
}
'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_401_UNAUTHORIZED
)
self
.
assertDictEqual
(
response
.
json
(),
{
'
detail
'
:
'
Authentication credentials were not provided.
'
}
)
def
test_task_create_empty_body
(
self
):
response
=
self
.
client
.
post
(
reverse
(
"
api:task-create
"
),
HTTP_AUTHORIZATION
=
f
'
Ponos
{
self
.
task1
.
token
}
'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertDictEqual
(
response
.
json
(),
...
...
@@ -1489,6 +1515,7 @@ class TestAPI(FixtureAPITestCase):
"
image
"
:
"
registry.gitlab.com/test
"
,
"
parents
"
:
[],
},
HTTP_AUTHORIZATION
=
f
'
Ponos
{
self
.
task1
.
token
}
'
,
format
=
"
json
"
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
...
...
@@ -1517,6 +1544,7 @@ class TestAPI(FixtureAPITestCase):
"
image
"
:
"
registry.gitlab.com/test
"
,
"
parents
"
:
[
str
(
self
.
task1
.
id
),
str
(
self
.
task2
.
id
),
str
(
task3
.
id
)],
},
HTTP_AUTHORIZATION
=
f
'
Ponos
{
task3
.
token
}
'
,
format
=
"
json
"
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
...
...
@@ -1545,6 +1573,7 @@ class TestAPI(FixtureAPITestCase):
"
image
"
:
"
registry.gitlab.com/test
"
,
"
parents
"
:
[
str
(
self
.
task1
.
id
),
str
(
self
.
task2
.
id
),
str
(
task3
.
id
)],
},
HTTP_AUTHORIZATION
=
f
'
Ponos
{
task3
.
token
}
'
,
format
=
"
json
"
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
...
...
@@ -1558,7 +1587,7 @@ class TestAPI(FixtureAPITestCase):
)
def
test_task_create_duplicate
(
self
):
self
.
process
.
tasks
.
create
(
task
=
self
.
process
.
tasks
.
create
(
run
=
0
,
depth
=
3
,
slug
=
"
sibling
"
,
...
...
@@ -1573,6 +1602,7 @@ class TestAPI(FixtureAPITestCase):
"
image
"
:
"
registry.gitlab.com/test
"
,
"
parents
"
:
[
str
(
self
.
task1
.
id
),
str
(
self
.
task2
.
id
)],
},
HTTP_AUTHORIZATION
=
f
'
Ponos
{
task
.
token
}
'
,
format
=
"
json
"
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
...
...
@@ -1593,7 +1623,7 @@ class TestAPI(FixtureAPITestCase):
image
=
"
registry.gitlab.com/test
"
,
)
with
self
.
assertNumQueries
(
8
):
with
self
.
assertNumQueries
(
9
):
response
=
self
.
client
.
post
(
reverse
(
"
api:task-create
"
),
data
=
{
...
...
@@ -1604,6 +1634,7 @@ class TestAPI(FixtureAPITestCase):
"
command
"
:
"
echo Test
"
,
"
env
"
:
{
"
test
"
:
"
test
"
,
"
test2
"
:
"
test2
"
},
},
HTTP_AUTHORIZATION
=
f
'
Ponos
{
task3
.
token
}
'
,
format
=
"
json
"
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
...
...
@@ -1643,7 +1674,7 @@ class TestAPI(FixtureAPITestCase):
image
=
"
registry.gitlab.com/test
"
,
)
with
self
.
assertNumQueries
(
8
):
with
self
.
assertNumQueries
(
9
):
response
=
self
.
client
.
post
(
reverse
(
"
api:task-create
"
),
data
=
{
...
...
@@ -1655,6 +1686,7 @@ class TestAPI(FixtureAPITestCase):
"
env
"
:
{
"
test
"
:
"
test
"
,
"
test2
"
:
"
test2
"
},
"
has_docker_socket
"
:
True
,
},
HTTP_AUTHORIZATION
=
f
'
Ponos
{
task3
.
token
}
'
,
format
=
"
json
"
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment