|
9 | 9 | import json |
10 | 10 | import mock |
11 | 11 | import requests |
| 12 | +import unittest |
12 | 13 |
|
13 | 14 | from django.contrib.auth.models import User |
14 | 15 | from django.test import TransactionTestCase |
@@ -539,3 +540,29 @@ def test_run_command_good(self): |
539 | 540 | build.sha = 'somereallylongsha' |
540 | 541 | rc, output = c.run('echo hi') |
541 | 542 | 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