Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2012 OpenStack Foundation |
| 4 | # Copyright 2013 IBM Corp |
| 5 | # All Rights Reserved. |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | # not use this file except in compliance with the License. You may obtain |
| 9 | # a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 16 | # License for the specific language governing permissions and limitations |
| 17 | # under the License. |
| 18 | |
| 19 | from tempest.api.compute import base |
| 20 | from tempest.common.utils import data_utils |
| 21 | from tempest import exceptions |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 22 | from tempest import test |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 23 | |
| 24 | |
| 25 | class KeyPairsNegativeTestJSON(base.BaseV2ComputeTest): |
| 26 | _interface = 'json' |
| 27 | |
| 28 | @classmethod |
| 29 | def setUpClass(cls): |
| 30 | super(KeyPairsNegativeTestJSON, cls).setUpClass() |
| 31 | cls.client = cls.keypairs_client |
| 32 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 33 | def _create_keypair(self, keypair_name, pub_key=None): |
| 34 | self.client.create_keypair(keypair_name, pub_key) |
| 35 | self.addCleanup(self.client.delete_keypair, keypair_name) |
| 36 | |
| 37 | @test.attr(type=['negative', 'gate']) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 38 | def test_keypair_create_with_invalid_pub_key(self): |
| 39 | # Keypair should not be created with a non RSA public key |
| 40 | k_name = data_utils.rand_name('keypair-') |
| 41 | pub_key = "ssh-rsa JUNK nova@ubuntu" |
| 42 | self.assertRaises(exceptions.BadRequest, |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 43 | self._create_keypair, k_name, pub_key) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 44 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 45 | @test.attr(type=['negative', 'gate']) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 46 | def test_keypair_delete_nonexistant_key(self): |
| 47 | # Non-existant key deletion should throw a proper error |
| 48 | k_name = data_utils.rand_name("keypair-non-existant-") |
| 49 | self.assertRaises(exceptions.NotFound, self.client.delete_keypair, |
| 50 | k_name) |
| 51 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 52 | @test.attr(type=['negative', 'gate']) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 53 | def test_create_keypair_with_empty_public_key(self): |
| 54 | # Keypair should not be created with an empty public key |
| 55 | k_name = data_utils.rand_name("keypair-") |
| 56 | pub_key = ' ' |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 57 | self.assertRaises(exceptions.BadRequest, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 58 | k_name, pub_key) |
| 59 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 60 | @test.attr(type=['negative', 'gate']) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 61 | def test_create_keypair_when_public_key_bits_exceeds_maximum(self): |
| 62 | # Keypair should not be created when public key bits are too long |
| 63 | k_name = data_utils.rand_name("keypair-") |
| 64 | pub_key = 'ssh-rsa ' + 'A' * 2048 + ' openstack@ubuntu' |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 65 | self.assertRaises(exceptions.BadRequest, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 66 | k_name, pub_key) |
| 67 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 68 | @test.attr(type=['negative', 'gate']) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 69 | def test_create_keypair_with_duplicate_name(self): |
| 70 | # Keypairs with duplicate names should not be created |
| 71 | k_name = data_utils.rand_name('keypair-') |
| 72 | resp, _ = self.client.create_keypair(k_name) |
| 73 | self.assertEqual(200, resp.status) |
| 74 | # Now try the same keyname to create another key |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 75 | self.assertRaises(exceptions.Conflict, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 76 | k_name) |
| 77 | resp, _ = self.client.delete_keypair(k_name) |
| 78 | self.assertEqual(202, resp.status) |
| 79 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 80 | @test.attr(type=['negative', 'gate']) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 81 | def test_create_keypair_with_empty_name_string(self): |
| 82 | # Keypairs with name being an empty string should not be created |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 83 | self.assertRaises(exceptions.BadRequest, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 84 | '') |
| 85 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 86 | @test.attr(type=['negative', 'gate']) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 87 | def test_create_keypair_with_long_keynames(self): |
| 88 | # Keypairs with name longer than 255 chars should not be created |
| 89 | k_name = 'keypair-'.ljust(260, '0') |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 90 | self.assertRaises(exceptions.BadRequest, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 91 | k_name) |
| 92 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 93 | @test.attr(type=['negative', 'gate']) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 94 | def test_create_keypair_invalid_name(self): |
| 95 | # Keypairs with name being an invalid name should not be created |
| 96 | k_name = 'key_/.\@:' |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 97 | self.assertRaises(exceptions.BadRequest, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 98 | k_name) |
| 99 | |
| 100 | |
| 101 | class KeyPairsNegativeTestXML(KeyPairsNegativeTestJSON): |
| 102 | _interface = 'xml' |