-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,353 additions
and
724 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
FROM centos:6 | ||
FROM centos:7 | ||
|
||
MAINTAINER APEL Administrator <[email protected]> | ||
|
||
# Add EPEL repo so we can get pip | ||
RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm | ||
RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm | ||
|
||
# Add IGTF trust repo, so it can be installed | ||
RUN touch /etc/yum.repos.d/EGI-trustanchors.repo | ||
|
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 |
---|---|---|
|
@@ -15,4 +15,4 @@ | |
@author Greg Corbett | ||
""" | ||
__version__ = '1, 4, 0' | ||
__version__ = '1, 5, 0' |
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 |
---|---|---|
|
@@ -15,4 +15,4 @@ | |
@author Greg Corbett | ||
""" | ||
__version__ = '1, 4, 0' | ||
__version__ = '1, 5, 0' |
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,92 @@ | ||
"""This file allows test to be imported as a python package.""" | ||
""" | ||
Copyright (C) 2016 STFC. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
@author Greg Corbett | ||
""" | ||
__version__ = '1, 4, 0' | ||
|
||
# Example output from the provider list on the CMDB | ||
PROVIDERS = {'total_rows': 735, | ||
'offset': 695, | ||
'rows': [ | ||
{'id': '1', | ||
'key': ['service'], | ||
'value':{ | ||
'sitename': 'TEST2', | ||
'provider_id': 'TEST2', | ||
'type': 'cloud'}}, | ||
{'id': '2', | ||
'key': ['service'], | ||
'value':{ | ||
'sitename': 'TEST', | ||
'provider_id': 'TEST', | ||
'hostname': 'allowed_host.test', | ||
'type': 'cloud'}}, | ||
{'id': '3', | ||
'key': ['service'], | ||
'value':{ | ||
'sitename': 'TEST', | ||
'provider_id': 'TEST', | ||
'hostname': 'allowed_host2.test', | ||
'type': 'cloud'}}]} | ||
|
||
# An example APEL Cloud Message V0.2 | ||
MESSAGE = """APEL-cloud-message: v0.2 | ||
VMUUID: TestVM1 2013-02-25 17:37:27+00:00 | ||
SiteName: CESGA | ||
MachineName: one-2421 | ||
LocalUserId: 19 | ||
LocalGroupId: 101 | ||
GlobalUserName: NULL | ||
FQAN: NULL | ||
Status: completed | ||
StartTime: 1361813847 | ||
EndTime: 1361813870 | ||
SuspendDuration: NULL | ||
WallDuration: NULL | ||
CpuDuration: NULL | ||
CpuCount: 1 | ||
NetworkType: NULL | ||
NetworkInbound: 0 | ||
NetworkOutbound: 0 | ||
Memory: 1000 | ||
Disk: NULL | ||
StorageRecordId: NULL | ||
ImageId: NULL | ||
CloudType: OpenNebula | ||
%% | ||
VMUUID: TestVM1 2015-06-25 17:37:27+00:00 | ||
SiteName: CESGA | ||
MachineName: one-2422 | ||
LocalUserId: 13 | ||
LocalGroupId: 131 | ||
GlobalUserName: NULL | ||
FQAN: NULL | ||
Status: completed | ||
StartTime: 1361413847 | ||
EndTime: 1361811870 | ||
SuspendDuration: NULL | ||
WallDuration: NULL | ||
CpuDuration: NULL | ||
CpuCount: 1 | ||
NetworkType: NULL | ||
NetworkInbound: 0 | ||
NetworkOutbound: 0 | ||
Memory: 1000 | ||
Disk: NULL | ||
StorageRecordId: NULL | ||
ImageId: NULL | ||
CloudType: OpenNebula | ||
%%""" |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""This module tests the helper methods of the CloudRecordView class.""" | ||
|
||
import logging | ||
|
||
from django.test import TestCase | ||
from mock import Mock | ||
|
||
from api.tests import PROVIDERS | ||
from api.views.CloudRecordView import CloudRecordView | ||
|
||
|
||
class CloudRecordHelperTest(TestCase): | ||
"""Tests the helper methods of the CloudRecordView class.""" | ||
|
||
def setUp(self): | ||
"""Prevent logging from appearing in test output.""" | ||
logging.disable(logging.CRITICAL) | ||
|
||
def test_signer_is_valid(self): | ||
""" | ||
Test the CloudRecordView._signer_is_valid method. | ||
That method determines wether a POST request should be allowed or not. | ||
""" | ||
# mock the external call to the CMDB to retrieve the providers | ||
# used in the _signer_is_valid method we are testing | ||
CloudRecordView._get_provider_list = Mock(return_value=PROVIDERS) | ||
test_cloud_view = CloudRecordView() | ||
|
||
# The DN corresponds to a host listed as a provider | ||
allowed_dn = "/C=XX/O=XX/OU=XX/L=XX/CN=allowed_host.test" | ||
|
||
# The Host this DN corresponds to will | ||
# be explicitly granted POST rights | ||
extra_dn = "/C=XX/O=XX/OU=XX/L=XX/CN=special_host.test" | ||
|
||
# The Host this DN corresponds to will | ||
# have its POST rights explicitly revoked | ||
banned_dn = "/C=XX/O=XX/OU=XX/L=XX/CN=allowed_host2.test" | ||
|
||
# The Host this DN corresponds is unknown to the system, | ||
# it should not be granted POST rights | ||
unknown_dn = "/C=XX/O=XX/OU=XX/L=XX/CN=mystery_host.test" | ||
|
||
# Grant/Revoke POST fights | ||
with self.settings(ALLOWED_TO_POST=[extra_dn], | ||
BANNED_FROM_POST=[banned_dn]): | ||
|
||
# DNs corresponding to hosts listed as a provider should be valid | ||
# i.e have POST rights | ||
self.assertTrue(test_cloud_view._signer_is_valid(allowed_dn)) | ||
|
||
# DNs corresponding to hosts with explicit access should be valid | ||
# i.e have POST rights | ||
self.assertTrue(test_cloud_view._signer_is_valid(extra_dn)) | ||
|
||
# DNs corresponding to banned hosts should be invalid | ||
# i.e not have POST rights | ||
self.assertFalse(test_cloud_view._signer_is_valid(banned_dn)) | ||
|
||
# DNs corresponding to unknonw hosts should be invalid | ||
# i.e not have POST rights | ||
self.assertFalse(test_cloud_view._signer_is_valid(unknown_dn)) | ||
|
||
# mock the external call to the CMDB to retrieve the providers | ||
# used in the _signer_is_valid method we are testing | ||
# now we are mocking a failure of the CMDB to respond as expected | ||
CloudRecordView._get_provider_list = Mock(return_value={}) | ||
# in which case we should reject all POST requests | ||
self.assertFalse(test_cloud_view._signer_is_valid(allowed_dn)) |
Oops, something went wrong.