2023-09-03 14:59:09 +00:00
|
|
|
import os
|
2023-11-30 15:55:51 +00:00
|
|
|
from unittest import SkipTest, mock
|
|
|
|
|
|
|
|
import boto3
|
2022-12-22 10:57:19 +00:00
|
|
|
|
2023-09-03 14:59:09 +00:00
|
|
|
from moto import mock_ec2, settings
|
2023-11-30 15:55:51 +00:00
|
|
|
from tests import EXAMPLE_AMI_PARAVIRTUAL, EXAMPLE_AMI_WINDOWS
|
2022-12-22 10:57:19 +00:00
|
|
|
|
|
|
|
|
2023-09-03 14:59:09 +00:00
|
|
|
# The default AMIs are not loaded for our test case, to speed things up
|
|
|
|
# But we do need it for this specific test (and others in this file..)
|
|
|
|
@mock.patch.dict(os.environ, {"MOTO_EC2_LOAD_DEFAULT_AMIS": "true"})
|
2022-12-22 10:57:19 +00:00
|
|
|
@mock_ec2
|
|
|
|
def test_get_password_data():
|
2023-09-03 14:59:09 +00:00
|
|
|
if settings.TEST_SERVER_MODE:
|
|
|
|
raise SkipTest("Can't set environment variables in ServerMode")
|
2022-12-22 10:57:19 +00:00
|
|
|
client = boto3.client("ec2", region_name="us-east-1")
|
|
|
|
|
|
|
|
# Ensure non-windows instances return empty password data
|
|
|
|
instance_id = client.run_instances(
|
|
|
|
ImageId=EXAMPLE_AMI_PARAVIRTUAL, MinCount=1, MaxCount=1
|
|
|
|
)["Instances"][0]["InstanceId"]
|
|
|
|
resp = client.get_password_data(InstanceId=instance_id)
|
2023-07-17 09:31:05 +00:00
|
|
|
assert resp["InstanceId"] == instance_id
|
|
|
|
assert resp["PasswordData"] == ""
|
2022-12-22 10:57:19 +00:00
|
|
|
|
|
|
|
# Ensure Windows instances
|
|
|
|
instance_id = client.run_instances(
|
|
|
|
ImageId=EXAMPLE_AMI_WINDOWS, MinCount=1, MaxCount=1
|
|
|
|
)["Instances"][0]["InstanceId"]
|
|
|
|
resp = client.get_password_data(InstanceId=instance_id)
|
2023-07-17 09:31:05 +00:00
|
|
|
assert resp["InstanceId"] == instance_id
|
|
|
|
assert len(resp["PasswordData"]) == 128
|