Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add ClouDNS provider extension, #257 #259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<ItemGroup>
<Compile Include="AwsRoute53ProviderTests.cs" />
<Compile Include="AwsS3ProviderTests.cs" />
<Compile Include="ClouDNSTests.cs" />
<Compile Include="CloudFlareTests.cs" />
<Compile Include="Config\BaseParams.cs" />
<Compile Include="Config\AwsR53HandlerParams.cs" />
Expand Down Expand Up @@ -95,6 +96,10 @@
<Project>{63ae964a-79a4-4c7d-a686-dd9b2389af3f}</Project>
<Name>ACMESharp.Providers.CloudFlare</Name>
</ProjectReference>
<ProjectReference Include="..\ACMESharp.Providers.ClouDNS\ACMESharp.Providers.ClouDNS.csproj">
<Project>{529518fe-9546-4ec1-8e1f-9bc9239f0c7e}</Project>
<Name>ACMESharp.Providers.ClouDNS</Name>
</ProjectReference>
<ProjectReference Include="..\ACMESharp.Providers.IIS\ACMESharp.Providers.IIS.csproj">
<Project>{944ec9bd-81a1-484e-ba29-360bc155bf51}</Project>
<Name>ACMESharp.Providers.IIS</Name>
Expand Down
148 changes: 148 additions & 0 deletions ACMESharp/ACMESharp.Providers-test/ClouDNSTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using ACMESharp.ACME;
using ACMESharp.Providers.ClouDNS;
using ACMESharp.Util;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ACMESharp.Providers
{
[TestClass]
public class ClouDNSTests
{
public static readonly IReadOnlyDictionary<string, object> EMPTY_PARAMS =
new Dictionary<string, object>()
{
["DomainName"] = "",
["AuthId"] = "",
["AuthPassword"] = "",
};

private static IReadOnlyDictionary<string, object> _handlerParams = EMPTY_PARAMS;

private static IReadOnlyDictionary<string, object> GetParams()
{
return _handlerParams;
}

[ClassInitialize]
public static void Init(TestContext tctx)
{
var file = new FileInfo("Config\\ClouDNSHandlerParams.json");
if (file.Exists)
{
using (var fs = new FileStream(file.FullName, FileMode.Open))
{
_handlerParams = JsonHelper.Load<Dictionary<string, object>>(fs);
}
}
}

public static ClouDNSChallengeHandlerProvider GetProvider()
{
return new ClouDNSChallengeHandlerProvider();
}

public static ClouDNSChallengeHandler GetHandler(Challenge challenge)
{
return (ClouDNSChallengeHandler)GetProvider().GetHandler(challenge, null);
}

public static ClouDNSHelper GetHelper()
{
var p = GetParams();
var h = new ClouDNSHelper(
(string)p["AuthId"],
(string)p["AuthPassword"],
(string)p["DomainName"]
);
return h;
}

[TestMethod]
public void TestParameterDescriptions()
{
var p = GetProvider();
var dp = p.DescribeParameters();

Assert.IsNotNull(dp);
Assert.IsTrue(dp.Any());
}

[TestMethod]
public void TestSupportedChallenges()
{
var p = GetProvider();

Assert.IsTrue(p.IsSupported(TestCommon.DNS_CHALLENGE));
Assert.IsFalse(p.IsSupported(TestCommon.HTTP_CHALLENGE));
Assert.IsFalse(p.IsSupported(TestCommon.TLS_SNI_CHALLENGE));
Assert.IsFalse(p.IsSupported(TestCommon.FAKE_CHALLENGE));
}

[TestMethod]
[ExpectedException(typeof(KeyNotFoundException))]
public void TestRequiredParams()
{
var p = GetProvider();
var c = TestCommon.DNS_CHALLENGE;
var h = p.GetHandler(c, new Dictionary<string, object>());
}

[TestMethod]
public void TestHandlerLifetime()
{
var p = GetProvider();
var c = TestCommon.DNS_CHALLENGE;
var h = p.GetHandler(c, GetParams());

Assert.IsNotNull(h);
Assert.IsFalse(h.IsDisposed);
h.Dispose();
Assert.IsTrue(h.IsDisposed);
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void TestHandlerDisposedAccess()
{
var p = GetProvider();
var c = TestCommon.DNS_CHALLENGE;
var h = p.GetHandler(c, GetParams());

h.Dispose();
h.Handle(null);
}

[TestMethod]
public void TestAddDnsRecord()
{
var h = GetHelper();
var rrName = "acmesharp-test." + GetParams()["DomainName"];
var rrValue = "testrr-" + DateTime.Now.ToString("yyyyMMddHHmmss #1");

h.AddOrUpdateDnsRecord(rrName, rrValue);
}

[TestMethod]
public void TestUpdateDnsRecord()
{
var h = GetHelper();
var rrName = "acmesharp-test." + GetParams()["DomainName"];
var rrValue = "testrr-" + DateTime.Now.ToString("yyyyMMddHHmmss #2");

h.AddOrUpdateDnsRecord(rrName, rrValue);
}

[TestMethod]
public void TestDeleteDnsRecord()
{
var h = GetHelper();
var rrName = "acmesharp-test." + GetParams()["DomainName"];

h.DeleteDnsRecord(rrName);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{529518FE-9546-4EC1-8E1F-9BC9239F0C7E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ACMESharp.Providers.ClouDNS</RootNamespace>
<AssemblyName>ACMESharp.Providers.ClouDNS</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\$(Configuration)\ACMESharp.Providers.ClouDNS\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\$(Configuration)\ACMESharp.Providers.ClouDNS\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\shared\SharedGlobalSuppressions.cs">
<Link>Properties\SharedGlobalSuppressions.cs</Link>
</Compile>
<Compile Include="ClouDNSChallengeHandler.cs" />
<Compile Include="ClouDNSChallengeHandlerProvider.cs" />
<Compile Include="ClouDNSHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Results\DnsRecord.cs" />
<Compile Include="Results\ZoneRecord.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ACMESharp\ACMESharp.csproj">
<Project>{d551234b-0a8d-4dee-8178-a81998df0edb}</Project>
<Name>ACMESharp</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="ACMESharp.Providers.ClouDNS.psd1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
112 changes: 112 additions & 0 deletions ACMESharp/ACMESharp.Providers.ClouDNS/ACMESharp.Providers.ClouDNS.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

## For a reference of this file's elements, see:
## https://technet.microsoft.com/library/hh849709.aspx
## https://technet.microsoft.com/en-us/library/dd878297(v=vs.85).aspx

## 64-bit:
## %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
## 32-bit:
## %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe

@{
## This is a manifest-only module so we don't define any root
#RootModule = ''

ModuleVersion = '0.8.0'
GUID = '7F6533CB-B35A-4E08-BD31-7561D0CC2A7B'

Author = 'https://github.com/ebekker'

CompanyName = 'https://github.com/ebekker/ACMESharp'

Copyright = '(c) 2017 Dave Crane. All rights reserved.'

Description = "ClouDNS Provider extension library for ACMESharp Client."

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
DefaultCommandPrefix = 'ACME'

## Minimum version of the Windows PowerShell engine required by this module
## This does not appear to be enforce for versions > 2.0 as per
## https://technet.microsoft.com/en-us/library/dd878297(v=vs.85).aspx
PowerShellVersion = '3.0'

DotNetFrameworkVersion = '4.5'

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('pki','ssl','tls','security','certificates','letsencrypt','acme','powershell','acmesharp','cloudns','acmesharp_ext')

# A URL to the license for this module.
LicenseUri = 'https://raw.githubusercontent.com/ebekker/ACMESharp/master/LICENSE'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/ebekker/ACMESharp'

# A URL to an icon representing this module.
IconUri = 'https://cdn.rawgit.com/ebekker/ACMESharp/master/artwork/ACMESharp-logo-square64.png'

# ReleaseNotes of this module
ReleaseNotes = 'Please see the release notes from the release distribution page: https://github.com/ebekker/ACMESharp/releases'

} # End of PSData hashtable

} # End of PrivateData hashtable

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @( ## FYI -- If one module uses the Hashtable spec, they all have to

## The minimum version of ACMESharp that supports our form of a Provider
## extension as a dynamically installed and *enabled* POSH Extension Module
, @{ModuleName="ACMESharp";ModuleVersion="0.8.2"}
)


############################################################
## Unused manifest elements reserved for possible future use
############################################################

# HelpInfo URI of this module for updateable help
# HelpInfoURI = ''

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module
# FunctionsToExport = '*'

# Cmdlets to export from this module
# CmdletsToExport = '*'

# Variables to export from this module
# VariablesToExport = '*'

# Aliases to export from this module
# AliasesToExport = '*'

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

}
Loading