Skip to content

Commit

Permalink
Adding test for customer-supplied disk encryption key. Fixes #281 (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott committed May 11, 2016
1 parent d5cffb7 commit a3d36ed
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions compute/encryption/generate_wrapped_rsa_key_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,40 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import generate_wrapped_rsa_key
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials


def test_main():
generate_wrapped_rsa_key.main(None)


def test_create_disk(cloud_config):
credentials = GoogleCredentials.get_application_default()
compute = discovery.build('compute', 'beta', credentials=credentials)

# Generate the key.
key_bytes = os.urandom(32)
google_public_key = generate_wrapped_rsa_key.get_google_public_cert_key()
wrapped_rsa_key = generate_wrapped_rsa_key.wrap_rsa_key(
google_public_key, key_bytes)

# Create the disk, if the encryption key is invalid, this will raise.
compute.disks().insert(
project=cloud_config.project,
zone='us-central1-f',
body={
'name': 'new-encrypted-disk',
'diskEncryptionKey': {
'rsaEncryptedKey': wrapped_rsa_key.decode('utf-8')
}
}).execute()

# Delete the disk.
compute.disks().delete(
project=cloud_config.project,
zone='us-central1-f',
disk='new-encrypted-disk').execute()

0 comments on commit a3d36ed

Please sign in to comment.