Skip to content

Commit 264a604

Browse files
author
Jon Wayne Parrott
committed
Adding test for customer-supplied disk encryption key. Fixes #281
Change-Id: I4380eabd4602cc06cd6946ac0ca20d1d543c3935
1 parent 2a813b9 commit 264a604

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

compute/encryption/generate_wrapped_rsa_key_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,40 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
import os
15+
1416
import generate_wrapped_rsa_key
17+
from googleapiclient import discovery
18+
from oauth2client.client import GoogleCredentials
1519

1620

1721
def test_main():
1822
generate_wrapped_rsa_key.main(None)
23+
24+
25+
def test_create_disk(cloud_config):
26+
credentials = GoogleCredentials.get_application_default()
27+
compute = discovery.build('compute', 'beta', credentials=credentials)
28+
29+
# Generate the key.
30+
key_bytes = os.urandom(32)
31+
google_public_key = generate_wrapped_rsa_key.get_google_public_cert_key()
32+
wrapped_rsa_key = generate_wrapped_rsa_key.wrap_rsa_key(
33+
google_public_key, key_bytes)
34+
35+
# Create the disk, if the encryption key is invalid, this will raise.
36+
compute.disks().insert(
37+
project=cloud_config.project,
38+
zone='us-central1-f',
39+
body={
40+
'name': 'new-encrypted-disk',
41+
'diskEncryptionKey': {
42+
'rsaEncryptedKey': wrapped_rsa_key.decode('utf-8')
43+
}
44+
}).execute()
45+
46+
# Delete the disk.
47+
compute.disks().delete(
48+
project=cloud_config.project,
49+
zone='us-central1-f',
50+
disk='new-encrypted-disk').execute()

0 commit comments

Comments
 (0)