blob: 205076c56d8fecccc837ee6b9d45f41648df33b3 [file] [log] [blame]
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +05301# 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 Koderer78e5a8b2015-08-03 15:04:53 +020017from tempest.api.compute.keypairs import base
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080018from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080019from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050020from tempest.lib import exceptions as lib_exc
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053021
22
Marc Koderer78e5a8b2015-08-03 15:04:53 +020023class KeyPairsNegativeTestJSON(base.BaseKeypairTest):
Jordan Pittier3b46d272017-04-12 16:17:28 +020024 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080025 @decorators.idempotent_id('29cca892-46ae-4d48-bc32-8fe7e731eb81')
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053026 def test_keypair_create_with_invalid_pub_key(self):
27 # Keypair should not be created with a non RSA public key
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053028 pub_key = "ssh-rsa JUNK nova@ubuntu"
Masayuki Igawa4b29e472015-02-16 10:41:54 +090029 self.assertRaises(lib_exc.BadRequest,
zhufl5bcd7ee2017-01-13 17:47:14 +080030 self.create_keypair, pub_key=pub_key)
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053031
Jordan Pittier3b46d272017-04-12 16:17:28 +020032 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080033 @decorators.idempotent_id('7cc32e47-4c42-489d-9623-c5e2cb5a2fa5')
nayna-patel179077c2014-01-15 12:27:16 +000034 def test_keypair_delete_nonexistent_key(self):
35 # Non-existent key deletion should throw a proper error
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000036 k_name = data_utils.rand_name("keypair-non-existent")
Masayuki Igawabfa07602015-01-20 18:47:17 +090037 self.assertRaises(lib_exc.NotFound, self.client.delete_keypair,
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053038 k_name)
39
Jordan Pittier3b46d272017-04-12 16:17:28 +020040 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080041 @decorators.idempotent_id('dade320e-69ca-42a9-ba4a-345300f127e0')
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053042 def test_create_keypair_with_empty_public_key(self):
43 # Keypair should not be created with an empty public key
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053044 pub_key = ' '
zhufl5bcd7ee2017-01-13 17:47:14 +080045 self.assertRaises(lib_exc.BadRequest, self.create_keypair,
46 pub_key=pub_key)
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053047
Jordan Pittier3b46d272017-04-12 16:17:28 +020048 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080049 @decorators.idempotent_id('fc100c19-2926-4b9c-8fdc-d0589ee2f9ff')
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053050 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 S6a5dfb22013-11-28 14:31:40 +053052 pub_key = 'ssh-rsa ' + 'A' * 2048 + ' openstack@ubuntu'
zhufl5bcd7ee2017-01-13 17:47:14 +080053 self.assertRaises(lib_exc.BadRequest, self.create_keypair,
54 pub_key=pub_key)
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053055
Jordan Pittier3b46d272017-04-12 16:17:28 +020056 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080057 @decorators.idempotent_id('0359a7f1-f002-4682-8073-0c91e4011b7c')
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053058 def test_create_keypair_with_duplicate_name(self):
59 # Keypairs with duplicate names should not be created
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000060 k_name = data_utils.rand_name('keypair')
Ken'ichi Ohmichie364bce2015-07-17 10:27:59 +000061 self.client.create_keypair(name=k_name)
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053062 # Now try the same keyname to create another key
zhufl5bcd7ee2017-01-13 17:47:14 +080063 self.assertRaises(lib_exc.Conflict, self.create_keypair,
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053064 k_name)
David Kranz173f0e02015-02-06 13:47:57 -050065 self.client.delete_keypair(k_name)
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053066
Jordan Pittier3b46d272017-04-12 16:17:28 +020067 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080068 @decorators.idempotent_id('1398abe1-4a84-45fb-9294-89f514daff00')
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053069 def test_create_keypair_with_empty_name_string(self):
70 # Keypairs with name being an empty string should not be created
zhufl5bcd7ee2017-01-13 17:47:14 +080071 self.assertRaises(lib_exc.BadRequest, self.create_keypair,
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053072 '')
73
Jordan Pittier3b46d272017-04-12 16:17:28 +020074 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080075 @decorators.idempotent_id('3faa916f-779f-4103-aca7-dc3538eee1b7')
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053076 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')
zhufl5bcd7ee2017-01-13 17:47:14 +080079 self.assertRaises(lib_exc.BadRequest, self.create_keypair,
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053080 k_name)
81
Jordan Pittier3b46d272017-04-12 16:17:28 +020082 @decorators.attr(type=['negative'])
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080083 @decorators.idempotent_id('45fbe5e0-acb5-49aa-837a-ff8d0719db91')
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053084 def test_create_keypair_invalid_name(self):
85 # Keypairs with name being an invalid name should not be created
86 k_name = 'key_/.\@:'
zhufl5bcd7ee2017-01-13 17:47:14 +080087 self.assertRaises(lib_exc.BadRequest, self.create_keypair,
Hoisaleshwara Madan V S6a5dfb22013-11-28 14:31:40 +053088 k_name)