-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from pngmbh/upstream-image-access-check
check image access on `deis pull`
- Loading branch information
Showing
12 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
@requests_mock.Mocker(real_http=True, adapter=adapter) | ||
@mock.patch('api.models.release.publish_release', lambda *args: None) | ||
@mock.patch('api.models.release.docker_get_port', mock_port) | ||
@mock.patch('api.models.release.docker_check_access', lambda *args: None) | ||
class BuildTest(DeisTransactionTestCase): | ||
|
||
"""Tests build notification from build system""" | ||
|
@@ -591,6 +592,44 @@ def test_build_image_in_registry_with_auth(self, mock_requests): | |
response = self.client.post(url, body) | ||
self.assertEqual(response.status_code, 201, response.data) | ||
|
||
def test_build_image_no_registry_password(self, mock_requests): | ||
"""build with image from private registry, but no password given""" | ||
app_id = self.create_app() | ||
|
||
# post an image as a build | ||
with mock.patch('api.models.release.docker_check_access') as mock_check_access: | ||
mock_check_access.side_effect = Exception('no no no') # let the image access fail | ||
url = "/v2/apps/{app_id}/builds".format(**locals()) | ||
image = 'autotest/example' | ||
response = self.client.post(url, {'image': image}) | ||
self.assertEqual(response.status_code, 400, response.data) | ||
|
||
def test_build_image_wrong_registry_password(self, mock_requests): | ||
"""build with image from private registry, but wrong password given""" | ||
app_id = self.create_app() | ||
|
||
# post an image as a build using registry hostname | ||
url = "/v2/apps/{app_id}/builds".format(**locals()) | ||
image = 'autotest/example' | ||
response = self.client.post(url, {'image': image}) | ||
self.assertEqual(response.status_code, 201, response.data) | ||
|
||
# add the required PORT information | ||
url = '/v2/apps/{app_id}/config'.format(**locals()) | ||
body = {'values': json.dumps({'PORT': '80'})} | ||
response = self.client.post(url, body) | ||
self.assertEqual(response.status_code, 201, response.data) | ||
|
||
# set some registry information | ||
with mock.patch('api.models.release.docker_check_access') as mock_check_access: | ||
mock_check_access.side_effect = Exception('no no no') # let the image access fail | ||
url = '/v2/apps/{app_id}/config'.format(**locals()) | ||
body = {'registry': json.dumps({'username': 'bob', 'password': 'zoomzoom'})} | ||
response = self.client.post(url, body) | ||
self.assertEqual(response.status_code, 400, response.data) | ||
mock_check_access.assert_called_with( | ||
image, {'username': 'bob', 'password': 'zoomzoom', 'email': '[email protected]'}) | ||
|
||
def test_build_image_in_registry_with_auth_no_port(self, mock_requests): | ||
"""add authentication to the build but with no PORT config""" | ||
app_id = self.create_app() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import json | ||
import requests_mock | ||
from unittest import mock | ||
|
||
from django.core.cache import cache | ||
from django.contrib.auth.models import User | ||
|
@@ -136,7 +137,11 @@ def test_registry_deploy(self, mock_requests): | |
self.assertEqual(response.data['registry']['password'], 's3cur3pw1') | ||
|
||
# post a new build | ||
url = "/v2/apps/{app_id}/builds".format(**locals()) | ||
body = {'image': 'autotest/example'} | ||
response = self.client.post(url, body) | ||
self.assertEqual(response.status_code, 201, response.data) | ||
with mock.patch('api.models.release.docker_check_access') as mock_check_access: | ||
url = "/v2/apps/{app_id}/builds".format(**locals()) | ||
body = {'image': 'autotest/example'} | ||
response = self.client.post(url, body) | ||
self.assertEqual(response.status_code, 201, response.data) | ||
mock_check_access.assert_called_with( | ||
'autotest/example', | ||
{'password': 's3cur3pw1', 'username': 'bob', 'email': '[email protected]'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .dockerclient import publish_release, get_port, RegistryException # noqa | ||
from .dockerclient import publish_release, get_port, check_access, RegistryException # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters