Skip to content

Commit f7a3e02

Browse files
authored
ref(hooks): remove push hook model as the builder stopped using it (#985)
ref deis/builder#407
1 parent 4af252d commit f7a3e02

7 files changed

Lines changed: 30 additions & 119 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.8 on 2016-08-16 21:22
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('api', '0012_auto_20160816_1934'),
12+
]
13+
14+
operations = [
15+
migrations.AlterUniqueTogether(
16+
name='push',
17+
unique_together=set([]),
18+
),
19+
migrations.RemoveField(
20+
model_name='push',
21+
name='app',
22+
),
23+
migrations.RemoveField(
24+
model_name='push',
25+
name='owner',
26+
),
27+
migrations.DeleteModel(
28+
name='Push',
29+
),
30+
]

rootfs/api/models/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ class Meta:
114114

115115

116116
from .app import App, validate_id_is_docker_compatible, validate_reserved_names, validate_app_structure # noqa
117-
from .push import Push # noqa
118117
from .key import Key, validate_base64 # noqa
119118
from .certificate import Certificate, validate_certificate # noqa
120119
from .domain import Domain # noqa

rootfs/api/models/push.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

rootfs/api/serializers.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -457,19 +457,6 @@ class Meta:
457457
read_only_fields = ['common_name', 'fingerprint', 'san', 'domains', 'subject', 'issuer']
458458

459459

460-
class PushSerializer(serializers.ModelSerializer):
461-
"""Serialize a :class:`~api.models.Push` model."""
462-
463-
app = serializers.SlugRelatedField(slug_field='id', queryset=models.App.objects.all())
464-
owner = serializers.ReadOnlyField(source='owner.username')
465-
466-
class Meta:
467-
"""Metadata options for a :class:`PushSerializer`."""
468-
model = models.Push
469-
fields = ['owner', 'app', 'sha', 'fingerprint', 'receive_user', 'receive_repo',
470-
'ssh_connection', 'ssh_original_command', 'created', 'updated']
471-
472-
473460
class PodSerializer(serializers.BaseSerializer):
474461
name = serializers.CharField()
475462
state = serializers.CharField()

rootfs/api/tests/test_hooks.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -122,65 +122,6 @@ def test_key_hook(self, mock_requests):
122122
response = self.client.get(url, HTTP_X_DEIS_BUILDER_AUTH=settings.BUILDER_KEY)
123123
self.assertEqual(response.status_code, 404)
124124

125-
def test_push_hook(self, mock_requests):
126-
"""Test creating a Push via the API"""
127-
app_id = self.create_app()
128-
129-
# prepare a push body
130-
body = {
131-
'sha': 'df1e628f2244b73f9cdf944f880a2b3470a122f4',
132-
'fingerprint': '88:25:ed:67:56:91:3d:c6:1b:7f:42:c6:9b:41:24:80',
133-
'receive_user': 'autotest',
134-
'receive_repo': '{app_id}'.format(**locals()),
135-
'ssh_connection': '10.0.1.10 50337 172.17.0.143 22',
136-
'ssh_original_command': "git-receive-pack '{app_id}.git'".format(**locals()),
137-
}
138-
# post a request without the auth header
139-
url = "/v2/hooks/push".format(**locals())
140-
response = self.client.post(url, body)
141-
self.assertEqual(response.status_code, 403)
142-
# now try with the builder key in the special auth header
143-
response = self.client.post(url, body,
144-
HTTP_X_DEIS_BUILDER_AUTH=settings.BUILDER_KEY)
145-
self.assertEqual(response.status_code, 201, response.data)
146-
for k in ('owner', 'app', 'sha', 'fingerprint', 'receive_repo', 'receive_user',
147-
'ssh_connection', 'ssh_original_command'):
148-
self.assertIn(k, response.data)
149-
150-
def test_push_abuse(self, mock_requests):
151-
"""Test a user pushing to an unauthorized application"""
152-
# create a legit app as "autotest"
153-
app_id = self.create_app()
154-
155-
# register an evil user
156-
username, password = 'eviluser', 'password'
157-
first_name, last_name = 'Evil', 'User'
158-
email = 'evil@deis.io'
159-
submit = {
160-
'username': username,
161-
'password': password,
162-
'first_name': first_name,
163-
'last_name': last_name,
164-
'email': email,
165-
}
166-
url = '/v2/auth/register'
167-
response = self.client.post(url, submit)
168-
self.assertEqual(response.status_code, 201, response.data)
169-
# prepare a push body that simulates a git push
170-
body = {
171-
'sha': 'df1e628f2244b73f9cdf944f880a2b3470a122f4',
172-
'fingerprint': '88:25:ed:67:56:91:3d:c6:1b:7f:42:c6:9b:41:24:99',
173-
'receive_user': 'eviluser',
174-
'receive_repo': '{app_id}'.format(**locals()),
175-
'ssh_connection': '10.0.1.10 50337 172.17.0.143 22',
176-
'ssh_original_command': "git-receive-pack '{app_id}.git'".format(**locals()),
177-
}
178-
# try to push as "eviluser"
179-
url = "/v2/hooks/push".format(**locals())
180-
response = self.client.post(url, body,
181-
HTTP_X_DEIS_BUILDER_AUTH=settings.BUILDER_KEY)
182-
self.assertEqual(response.status_code, 403)
183-
184125
def test_build_hook(self, mock_requests):
185126
"""Test creating a Build via an API Hook"""
186127
app_id = self.create_app()

rootfs/api/urls.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@
8282
views.KeyHookViewSet.as_view({'get': 'app'})),
8383
url(r'^hooks/key/(?P<fingerprint>.+)/?',
8484
views.KeyHookViewSet.as_view({'get': 'public_key'})),
85-
url(r'^hooks/push/?',
86-
views.PushHookViewSet.as_view({'post': 'create'})),
8785
url(r'^hooks/build/?',
8886
views.BuildHookViewSet.as_view({'post': 'create'})),
8987
url(r'^hooks/config/?',

rootfs/api/views.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -454,22 +454,6 @@ def users(self, request, *args, **kwargs):
454454
return Response(data, status=status.HTTP_200_OK)
455455

456456

457-
class PushHookViewSet(BaseHookViewSet):
458-
"""API hook to create new :class:`~api.models.Push`"""
459-
model = models.Push
460-
serializer_class = serializers.PushSerializer
461-
462-
def create(self, request, *args, **kwargs):
463-
app = get_object_or_404(models.App, id=request.data['receive_repo'])
464-
request.user = get_object_or_404(User, username=request.data['receive_user'])
465-
# check the user is authorized for this app
466-
if not permissions.is_app_user(request, app):
467-
raise PermissionDenied()
468-
request.data['app'] = app
469-
request.data['owner'] = request.user
470-
return super(PushHookViewSet, self).create(request, *args, **kwargs)
471-
472-
473457
class BuildHookViewSet(BaseHookViewSet):
474458
"""API hook to create new :class:`~api.models.Build`"""
475459
model = models.Build

0 commit comments

Comments
 (0)