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 | |
Marc Koderer | 78e5a8b | 2015-08-03 15:04:53 +0200 | [diff] [blame] | 17 | from tempest.api.compute.keypairs import base |
Ken'ichi Ohmichi | 757833a | 2017-03-10 10:30:30 -0800 | [diff] [blame] | 18 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 19 | from tempest.lib import decorators |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 20 | from tempest.lib import exceptions as lib_exc |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 21 | |
| 22 | |
Marc Koderer | 78e5a8b | 2015-08-03 15:04:53 +0200 | [diff] [blame] | 23 | class KeyPairsNegativeTestJSON(base.BaseKeypairTest): |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 24 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 25 | @decorators.idempotent_id('29cca892-46ae-4d48-bc32-8fe7e731eb81') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 26 | def test_keypair_create_with_invalid_pub_key(self): |
| 27 | # Keypair should not be created with a non RSA public key |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 28 | pub_key = "ssh-rsa JUNK nova@ubuntu" |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 29 | self.assertRaises(lib_exc.BadRequest, |
zhufl | 5bcd7ee | 2017-01-13 17:47:14 +0800 | [diff] [blame] | 30 | self.create_keypair, pub_key=pub_key) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 31 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 32 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 33 | @decorators.idempotent_id('7cc32e47-4c42-489d-9623-c5e2cb5a2fa5') |
nayna-patel | 179077c | 2014-01-15 12:27:16 +0000 | [diff] [blame] | 34 | def test_keypair_delete_nonexistent_key(self): |
| 35 | # Non-existent key deletion should throw a proper error |
Ken'ichi Ohmichi | 4937f56 | 2015-03-23 00:15:01 +0000 | [diff] [blame] | 36 | k_name = data_utils.rand_name("keypair-non-existent") |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 37 | self.assertRaises(lib_exc.NotFound, self.client.delete_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 38 | k_name) |
| 39 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 40 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 41 | @decorators.idempotent_id('dade320e-69ca-42a9-ba4a-345300f127e0') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 42 | def test_create_keypair_with_empty_public_key(self): |
| 43 | # Keypair should not be created with an empty public key |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 44 | pub_key = ' ' |
zhufl | 5bcd7ee | 2017-01-13 17:47:14 +0800 | [diff] [blame] | 45 | self.assertRaises(lib_exc.BadRequest, self.create_keypair, |
| 46 | pub_key=pub_key) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 47 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 48 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 49 | @decorators.idempotent_id('fc100c19-2926-4b9c-8fdc-d0589ee2f9ff') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 50 | def test_create_keypair_when_public_key_bits_exceeds_maximum(self): |
| 51 | # Keypair should not be created when public key bits are too long |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 52 | pub_key = 'ssh-rsa ' + 'A' * 2048 + ' openstack@ubuntu' |
zhufl | 5bcd7ee | 2017-01-13 17:47:14 +0800 | [diff] [blame] | 53 | self.assertRaises(lib_exc.BadRequest, self.create_keypair, |
| 54 | pub_key=pub_key) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 55 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 56 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 57 | @decorators.idempotent_id('0359a7f1-f002-4682-8073-0c91e4011b7c') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 58 | def test_create_keypair_with_duplicate_name(self): |
| 59 | # Keypairs with duplicate names should not be created |
Ken'ichi Ohmichi | 4937f56 | 2015-03-23 00:15:01 +0000 | [diff] [blame] | 60 | k_name = data_utils.rand_name('keypair') |
Ken'ichi Ohmichi | e364bce | 2015-07-17 10:27:59 +0000 | [diff] [blame] | 61 | self.client.create_keypair(name=k_name) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 62 | # Now try the same keyname to create another key |
zhufl | 5bcd7ee | 2017-01-13 17:47:14 +0800 | [diff] [blame] | 63 | self.assertRaises(lib_exc.Conflict, self.create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 64 | k_name) |
David Kranz | 173f0e0 | 2015-02-06 13:47:57 -0500 | [diff] [blame] | 65 | self.client.delete_keypair(k_name) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 66 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 67 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 68 | @decorators.idempotent_id('1398abe1-4a84-45fb-9294-89f514daff00') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 69 | def test_create_keypair_with_empty_name_string(self): |
| 70 | # Keypairs with name being an empty string should not be created |
zhufl | 5bcd7ee | 2017-01-13 17:47:14 +0800 | [diff] [blame] | 71 | self.assertRaises(lib_exc.BadRequest, self.create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 72 | '') |
| 73 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 74 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 75 | @decorators.idempotent_id('3faa916f-779f-4103-aca7-dc3538eee1b7') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 76 | def test_create_keypair_with_long_keynames(self): |
| 77 | # Keypairs with name longer than 255 chars should not be created |
| 78 | k_name = 'keypair-'.ljust(260, '0') |
zhufl | 5bcd7ee | 2017-01-13 17:47:14 +0800 | [diff] [blame] | 79 | self.assertRaises(lib_exc.BadRequest, self.create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 80 | k_name) |
| 81 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 82 | @decorators.attr(type=['negative']) |
Ken'ichi Ohmichi | 6c92edf | 2017-01-27 17:32:10 -0800 | [diff] [blame] | 83 | @decorators.idempotent_id('45fbe5e0-acb5-49aa-837a-ff8d0719db91') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 84 | def test_create_keypair_invalid_name(self): |
| 85 | # Keypairs with name being an invalid name should not be created |
| 86 | k_name = 'key_/.\@:' |
zhufl | 5bcd7ee | 2017-01-13 17:47:14 +0800 | [diff] [blame] | 87 | self.assertRaises(lib_exc.BadRequest, self.create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 88 | k_name) |