"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "keystone/tests/unit/test_contrib_ec2_core.py" between
keystone-15.0.0.tar.gz and keystone-15.0.1.tar.gz

About: OpenStack Keystone (Core Service: Identity) provides an authentication and authorization service for other OpenStack services. Provides a catalog of endpoints for all OpenStack services.
The "Stein" series (maintained release).

test_contrib_ec2_core.py  (keystone-15.0.0):test_contrib_ec2_core.py  (keystone-15.0.1)
skipping to change at line 15 skipping to change at line 15
# a copy of the License at # a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import datetime
import hashlib
from keystoneclient.contrib.ec2 import utils as ec2_utils from keystoneclient.contrib.ec2 import utils as ec2_utils
from oslo_utils import timeutils
from six.moves import http_client from six.moves import http_client
from keystone.common import provider_api from keystone.common import provider_api
from keystone.common import utils
from keystone.tests import unit from keystone.tests import unit
from keystone.tests.unit import test_v3 from keystone.tests.unit import test_v3
PROVIDERS = provider_api.ProviderAPIs PROVIDERS = provider_api.ProviderAPIs
class EC2ContribCoreV3(test_v3.RestfulTestCase): class EC2ContribCoreV3(test_v3.RestfulTestCase):
def setUp(self): def setUp(self):
super(EC2ContribCoreV3, self).setUp() super(EC2ContribCoreV3, self).setUp()
self.cred_blob, self.credential = unit.new_ec2_credential( self.cred_blob, self.credential = unit.new_ec2_credential(
self.user['id'], self.project_id) self.user['id'], self.project_id)
PROVIDERS.credential_api.create_credential( PROVIDERS.credential_api.create_credential(
self.credential['id'], self.credential) self.credential['id'], self.credential)
def test_valid_authentication_response_with_proper_secret(self): def test_valid_authentication_response_with_proper_secret(self):
signer = ec2_utils.Ec2Signer(self.cred_blob['secret']) signer = ec2_utils.Ec2Signer(self.cred_blob['secret'])
timestamp = utils.isotime(timeutils.utcnow())
credentials = { credentials = {
'access': self.cred_blob['access'], 'access': self.cred_blob['access'],
'secret': self.cred_blob['secret'], 'secret': self.cred_blob['secret'],
'host': 'localhost', 'host': 'localhost',
'verb': 'GET', 'verb': 'GET',
'path': '/', 'path': '/',
'params': { 'params': {
'SignatureVersion': '2', 'SignatureVersion': '2',
'Action': 'Test', 'Action': 'Test',
'Timestamp': '2007-01-31T23:59:59Z' 'Timestamp': timestamp
}, },
} }
credentials['signature'] = signer.generate(credentials) credentials['signature'] = signer.generate(credentials)
resp = self.post( resp = self.post(
'/ec2tokens', '/ec2tokens',
body={'credentials': credentials}, body={'credentials': credentials},
expected_status=http_client.OK) expected_status=http_client.OK)
self.assertValidProjectScopedTokenResponse(resp, self.user) self.assertValidProjectScopedTokenResponse(resp, self.user)
def test_valid_authentication_response_with_signature_v4(self):
signer = ec2_utils.Ec2Signer(self.cred_blob['secret'])
timestamp = utils.isotime(timeutils.utcnow())
hashed_payload = (
'GET\n'
'/\n'
'Action=Test\n'
'host:localhost\n'
'x-amz-date:' + timestamp + '\n'
'\n'
'host;x-amz-date\n'
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
)
body_hash = hashlib.sha256(hashed_payload.encode()).hexdigest()
amz_credential = (
'AKIAIOSFODNN7EXAMPLE/%s/us-east-1/iam/aws4_request,' %
timestamp[:8])
credentials = {
'access': self.cred_blob['access'],
'secret': self.cred_blob['secret'],
'host': 'localhost',
'verb': 'GET',
'path': '/',
'params': {
'Action': 'Test',
'X-Amz-Algorithm': 'AWS4-HMAC-SHA256',
'X-Amz-SignedHeaders': 'host,x-amz-date,',
'X-Amz-Credential': amz_credential
},
'headers': {
'X-Amz-Date': timestamp
},
'body_hash': body_hash
}
credentials['signature'] = signer.generate(credentials)
resp = self.post(
'/ec2tokens',
body={'credentials': credentials},
expected_status=http_client.OK)
self.assertValidProjectScopedTokenResponse(resp, self.user)
def test_authenticate_with_empty_body_returns_bad_request(self): def test_authenticate_with_empty_body_returns_bad_request(self):
self.post( self.post(
'/ec2tokens', '/ec2tokens',
body={}, body={},
expected_status=http_client.BAD_REQUEST) expected_status=http_client.BAD_REQUEST)
def test_authenticate_without_json_request_returns_bad_request(self): def test_authenticate_without_json_request_returns_bad_request(self):
self.post( self.post(
'/ec2tokens', '/ec2tokens',
body='not json', body='not json',
expected_status=http_client.BAD_REQUEST) expected_status=http_client.BAD_REQUEST)
def test_authenticate_without_request_body_returns_bad_request(self): def test_authenticate_without_request_body_returns_bad_request(self):
self.post( self.post(
'/ec2tokens', '/ec2tokens',
expected_status=http_client.BAD_REQUEST) expected_status=http_client.BAD_REQUEST)
def test_authenticate_without_proper_secret_returns_unauthorized(self): def test_authenticate_without_proper_secret_returns_unauthorized(self):
signer = ec2_utils.Ec2Signer('totally not the secret') signer = ec2_utils.Ec2Signer('totally not the secret')
timestamp = utils.isotime(timeutils.utcnow())
credentials = { credentials = {
'access': self.cred_blob['access'], 'access': self.cred_blob['access'],
'secret': 'totally not the secret', 'secret': 'totally not the secret',
'host': 'localhost', 'host': 'localhost',
'verb': 'GET', 'verb': 'GET',
'path': '/', 'path': '/',
'params': { 'params': {
'SignatureVersion': '2', 'SignatureVersion': '2',
'Action': 'Test', 'Action': 'Test',
'Timestamp': '2007-01-31T23:59:59Z' 'Timestamp': timestamp
},
}
credentials['signature'] = signer.generate(credentials)
self.post(
'/ec2tokens',
body={'credentials': credentials},
expected_status=http_client.UNAUTHORIZED)
def test_authenticate_expired_request(self):
self.config_fixture.config(
group='credential',
auth_ttl=5
)
signer = ec2_utils.Ec2Signer(self.cred_blob['secret'])
past = timeutils.utcnow() - datetime.timedelta(minutes=10)
timestamp = utils.isotime(past)
credentials = {
'access': self.cred_blob['access'],
'secret': self.cred_blob['secret'],
'host': 'localhost',
'verb': 'GET',
'path': '/',
'params': {
'SignatureVersion': '2',
'Action': 'Test',
'Timestamp': timestamp
},
}
credentials['signature'] = signer.generate(credentials)
self.post(
'/ec2tokens',
body={'credentials': credentials},
expected_status=http_client.UNAUTHORIZED)
def test_authenticate_expired_request_v4(self):
self.config_fixture.config(
group='credential',
auth_ttl=5
)
signer = ec2_utils.Ec2Signer(self.cred_blob['secret'])
past = timeutils.utcnow() - datetime.timedelta(minutes=10)
timestamp = utils.isotime(past)
hashed_payload = (
'GET\n'
'/\n'
'Action=Test\n'
'host:localhost\n'
'x-amz-date:' + timestamp + '\n'
'\n'
'host;x-amz-date\n'
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
)
body_hash = hashlib.sha256(hashed_payload.encode()).hexdigest()
amz_credential = (
'AKIAIOSFODNN7EXAMPLE/%s/us-east-1/iam/aws4_request,' %
timestamp[:8])
credentials = {
'access': self.cred_blob['access'],
'secret': self.cred_blob['secret'],
'host': 'localhost',
'verb': 'GET',
'path': '/',
'params': {
'Action': 'Test',
'X-Amz-Algorithm': 'AWS4-HMAC-SHA256',
'X-Amz-SignedHeaders': 'host,x-amz-date,',
'X-Amz-Credential': amz_credential
},
'headers': {
'X-Amz-Date': timestamp
}, },
'body_hash': body_hash
} }
credentials['signature'] = signer.generate(credentials) credentials['signature'] = signer.generate(credentials)
self.post( self.post(
'/ec2tokens', '/ec2tokens',
body={'credentials': credentials}, body={'credentials': credentials},
expected_status=http_client.UNAUTHORIZED) expected_status=http_client.UNAUTHORIZED)
 End of changes. 9 change blocks. 
2 lines changed or deleted 123 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)