def test_create_3072_key():
    # create a test parameter
    provider = DSAKeyProvider()
    name = '/test/parameter-%s' % uuid.uuid4()
    request = Request('Create', name)
    request['ResourceProperties']['Description'] = 'A large private key'
    request['ResourceProperties']['KeySize'] = '3072'
    response = provider.handle(request, {})
    assert response['Status'] == 'SUCCESS', response['Reason']
    assert provider.is_valid_cfn_response(), response['Reason']
    assert 'PhysicalResourceId' in response
    physical_resource_id = response['PhysicalResourceId']

    assert 'Data' in response
    assert 'Arn' in response['Data']
    assert 'PublicKey' in response['Data']
    assert 'PublicKeyPEM' in response['Data']
    assert 'Hash' in response['Data']
    assert response['Data']['Arn'] == physical_resource_id
    assert response['Data']['Hash'] == hashlib.md5(response['Data']['PublicKey'].encode('ascii')).hexdigest()

    public_key = load_pem_public_key(response['Data']['PublicKeyPEM'].encode('ascii'), backend=default_backend())
    assert public_key.key_size == 3072

    # delete the parameter
    request = Request('Delete', name, physical_resource_id)
    response = handler(request, {})
    assert response['Status'] == 'SUCCESS', response['Reason']
Пример #2
0
def test_create_3072_key():
    # create a test parameter
    provider = DSAKeyProvider()
    name = "/test/parameter-%s" % uuid.uuid4()
    request = Request("Create", name)
    request["ResourceProperties"]["Description"] = "A large private key"
    request["ResourceProperties"]["KeySize"] = "3072"
    response = provider.handle(request, {})
    assert response["Status"] == "SUCCESS", response["Reason"]
    assert provider.is_valid_cfn_response(), response["Reason"]
    assert "PhysicalResourceId" in response
    physical_resource_id = response["PhysicalResourceId"]

    assert "Data" in response
    assert "Arn" in response["Data"]
    assert "PublicKey" in response["Data"]
    assert "PublicKeyPEM" in response["Data"]
    assert "Hash" in response["Data"]
    assert response["Data"]["Arn"] == physical_resource_id
    assert (response["Data"]["Hash"] == hashlib.md5(
        response["Data"]["PublicKey"].encode("ascii")).hexdigest())

    public_key = load_pem_public_key(
        response["Data"]["PublicKeyPEM"].encode("ascii"),
        backend=default_backend())
    assert public_key.key_size == 3072

    # delete the parameter
    request = Request("Delete", name, physical_resource_id)
    response = handler(request, {})
    assert response["Status"] == "SUCCESS", response["Reason"]
def test_create():
    # create a test parameter
    provider = DSAKeyProvider()
    name = '/test/parameter-%s' % uuid.uuid4()
    request = Request('Create', name)
    request['ResourceProperties']['Description'] = 'A ppretty private key'
    response = provider.handle(request, {})
    assert response['Status'] == 'SUCCESS', response['Reason']
    assert provider.is_valid_cfn_response(), response['Reason']
    assert 'PhysicalResourceId' in response
    physical_resource_id = response['PhysicalResourceId']

    assert 'Data' in response
    assert 'Arn' in response['Data']
    assert 'PublicKey' in response['Data']
    assert 'Hash' in response['Data']
    assert 'Version' in response['Data']
    assert response['Data']['Arn'] == physical_resource_id
    assert response['Data']['Hash'] == hashlib.md5(
        response['Data']['PublicKey']).hexdigest()
    assert response['Data']['Version'] == 1

    public_key = load_pem_public_key(response['Data']['PublicKeyPEM'],
                                     backend=default_backend())
    assert public_key.key_size == 2048

    request['RequestType'] = 'Update'
    request['ResourceProperties']['RefreshOnUpdate'] = True
    request['PhysicalResourceId'] = physical_resource_id
    response = provider.handle(request, {})
    assert response['Status'] == 'SUCCESS', response['Reason']
    assert response['Data']['Hash'] == hashlib.md5(
        response['Data']['PublicKey']).hexdigest()
    assert response['Data']['Version'] == 2

    # delete the parameters
    request = Request('Delete', name, physical_resource_id)
    response = handler(request, {})
    assert response['Status'] == 'SUCCESS', response['Reason']