Skip to content

Commit aa9bb8f

Browse files
author
Matthew Fisher
committed
test(controller): add expected unit test failures for response codes
When testing the security holes found recently, we found a few response codes that were not what was to be expected. Adding test coverage around this such that we can address these tests in future refactors.
1 parent 18cf1a9 commit aa9bb8f

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

controller/api/tests/test_app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ def test_unauthorized_user_cannot_see_app(self):
277277
url = '{}/{}/logs'.format(base_url, app_id)
278278
response = self.client.get(url, HTTP_AUTHORIZATION='token {}'.format(unauthorized_token))
279279
self.assertEqual(response.status_code, 403)
280+
url = '{}/{}'.format(base_url, app_id)
281+
response = self.client.get(url, HTTP_AUTHORIZATION='token {}'.format(unauthorized_token))
282+
self.assertEqual(response.status_code, 403)
283+
response = self.client.delete(url,
284+
HTTP_AUTHORIZATION='token {}'.format(unauthorized_token))
285+
self.assertEqual(response.status_code, 403)
280286

281287
def test_app_info_not_showing_wrong_app(self):
282288
app_id = 'autotest'

controller/api/tests/test_container.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import json
1010
import mock
1111
import requests
12+
import unittest
1213

1314
from django.contrib.auth.models import User
1415
from django.test import TransactionTestCase
@@ -539,3 +540,29 @@ def test_run_command_good(self):
539540
build.sha = 'somereallylongsha'
540541
rc, output = c.run('echo hi')
541542
self.assertEqual(json.loads(output)['entrypoint'], '/runner/init')
543+
544+
@unittest.expectedFailure
545+
def test_scale_with_unauthorized_user_returns_403(self):
546+
"""An unauthorized user should not be able to access an app's resources.
547+
548+
If an unauthorized user is trying to scale an app he or she does not have access to, it
549+
should return a 403. Currently, it returns a 404. FIXME!
550+
"""
551+
url = '/v1/apps'
552+
response = self.client.post(url, HTTP_AUTHORIZATION='token {}'.format(self.token))
553+
self.assertEqual(response.status_code, 201)
554+
app_id = response.data['id']
555+
# post a new build
556+
url = "/v1/apps/{app_id}/builds".format(**locals())
557+
body = {'image': 'autotest/example', 'sha': 'a'*40,
558+
'procfile': json.dumps({'web': 'node server.js', 'worker': 'node worker.js'})}
559+
response = self.client.post(url, json.dumps(body), content_type='application/json',
560+
HTTP_AUTHORIZATION='token {}'.format(self.token))
561+
unauthorized_user = User.objects.get(username='autotest2')
562+
unauthorized_token = Token.objects.get(user=unauthorized_user).key
563+
# scale up with unauthorized user
564+
url = "/v1/apps/{app_id}/scale".format(**locals())
565+
body = {'web': 4}
566+
response = self.client.post(url, json.dumps(body), content_type='application/json',
567+
HTTP_AUTHORIZATION='token {}'.format(unauthorized_token))
568+
self.assertEqual(response.status_code, 403)

0 commit comments

Comments
 (0)