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