|
23 | 23 | @requests_mock.Mocker(real_http=True, adapter=adapter) |
24 | 24 | @mock.patch('api.models.release.publish_release', lambda *args: None) |
25 | 25 | @mock.patch('api.models.release.docker_get_port', mock_port) |
| 26 | +@mock.patch('api.models.release.docker_check_access', lambda *args: None) |
26 | 27 | class BuildTest(DeisTransactionTestCase): |
27 | 28 |
|
28 | 29 | """Tests build notification from build system""" |
@@ -591,6 +592,44 @@ def test_build_image_in_registry_with_auth(self, mock_requests): |
591 | 592 | response = self.client.post(url, body) |
592 | 593 | self.assertEqual(response.status_code, 201, response.data) |
593 | 594 |
|
| 595 | + def test_build_image_no_registry_password(self, mock_requests): |
| 596 | + """build with image from private registry, but no password given""" |
| 597 | + app_id = self.create_app() |
| 598 | + |
| 599 | + # post an image as a build |
| 600 | + with mock.patch('api.models.release.docker_check_access') as mock_check_access: |
| 601 | + mock_check_access.side_effect = Exception('no no no') # let the image access fail |
| 602 | + url = "/v2/apps/{app_id}/builds".format(**locals()) |
| 603 | + image = 'autotest/example' |
| 604 | + response = self.client.post(url, {'image': image}) |
| 605 | + self.assertEqual(response.status_code, 400, response.data) |
| 606 | + |
| 607 | + def test_build_image_wrong_registry_password(self, mock_requests): |
| 608 | + """build with image from private registry, but wrong password given""" |
| 609 | + app_id = self.create_app() |
| 610 | + |
| 611 | + # post an image as a build using registry hostname |
| 612 | + url = "/v2/apps/{app_id}/builds".format(**locals()) |
| 613 | + image = 'autotest/example' |
| 614 | + response = self.client.post(url, {'image': image}) |
| 615 | + self.assertEqual(response.status_code, 201, response.data) |
| 616 | + |
| 617 | + # add the required PORT information |
| 618 | + url = '/v2/apps/{app_id}/config'.format(**locals()) |
| 619 | + body = {'values': json.dumps({'PORT': '80'})} |
| 620 | + response = self.client.post(url, body) |
| 621 | + self.assertEqual(response.status_code, 201, response.data) |
| 622 | + |
| 623 | + # set some registry information |
| 624 | + with mock.patch('api.models.release.docker_check_access') as mock_check_access: |
| 625 | + mock_check_access.side_effect = Exception('no no no') # let the image access fail |
| 626 | + url = '/v2/apps/{app_id}/config'.format(**locals()) |
| 627 | + body = {'registry': json.dumps({'username': 'bob', 'password': 'zoomzoom'})} |
| 628 | + response = self.client.post(url, body) |
| 629 | + self.assertEqual(response.status_code, 400, response.data) |
| 630 | + mock_check_access.assert_called_with( |
| 631 | + image, {'username': 'bob', 'password': 'zoomzoom', 'email': 'autotest@deis.io'}) |
| 632 | + |
594 | 633 | def test_build_image_in_registry_with_auth_no_port(self, mock_requests): |
595 | 634 | """add authentication to the build but with no PORT config""" |
596 | 635 | app_id = self.create_app() |
|
0 commit comments