Skip to content
Merged
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
37 changes: 25 additions & 12 deletions CERTInext.IntegrationTests/DcvLifecycleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,33 @@ public async Task EnrollWithoutDcv_DoesNotInvokeDnsProvider()
{
IntegrationSkip.IfNotConfigured(_fixture);

// Use a plugin backed by the real client but DcvEnabled=false
var plugin = BuildPlugin(dcvEnabled: false);
// Route plugin/client logs to the test output (before the plugin is constructed), so the CA's
// answer to the V1 order is visible.
var restoreLogging = TestOutputLogging.RouteTo(_output);
EnrollmentResult result;
try
{
// Use a plugin backed by the real client but DcvEnabled=false
var plugin = BuildPlugin(dcvEnabled: false);

var result = await plugin.Enroll(
csr: GenerateCsrPem(IntegrationTestData.DcvTestDomain),
subject: $"CN={IntegrationTestData.DcvTestDomain}",
san: new Dictionary<string, string[]>
{
["dns"] = new[] { IntegrationTestData.DcvTestDomain }
},
productInfo: IntegrationTestData.DvSslProductInfo(_fixture.Config.DefaultProductCode),
requestFormat: RequestFormat.PKCS10,
enrollmentType: EnrollmentType.New);
result = await plugin.Enroll(
csr: GenerateCsrPem(IntegrationTestData.DcvTestDomain),
subject: $"CN={IntegrationTestData.DcvTestDomain}",
san: new Dictionary<string, string[]>
{
["dns"] = new[] { IntegrationTestData.DcvTestDomain }
},
productInfo: IntegrationTestData.DvSslProductInfo(_fixture.Config.DefaultProductCode),
requestFormat: RequestFormat.PKCS10,
enrollmentType: EnrollmentType.New);
}
finally
{
restoreLogging();
}

_output.WriteLine($"RESULT: CARequestID={result?.CARequestID ?? "(none)"}, Status={result?.Status}, " +
$"Message={result?.StatusMessage}");
result.Should().NotBeNull();
}

Expand Down
2 changes: 1 addition & 1 deletion CERTInext.IntegrationTests/INTEGRATION_TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ matching flag in your shell. These flags are deliberately **not** read from `~/.
| `CERTINEXT_V2_LIFECYCLE_DV_UCC=1`, `_OV=1`, `_OV_UCC=1`, `_EV=1`, `_WILDCARD_DV=1`, `_RENEW_REISSUE=1` | The matching `V2FullLifecycleTests` method; the OV and OV UCC tests also need `CERTINEXT_ORG_NUMBER`, and the EV test needs its own pre-vetted `CERTINEXT_EV_ORG_NUMBER` |
| `CERTINEXT_V2_LIFECYCLE_FRESH_DCV=1` | `V2FreshDomainDcvLifecycleTests` (also needs Cloudflare and `CERTINEXT_V2_FRESH_DCV_PARENT`, the parent domain that fresh subdomains are created under) |
| `CERTINEXT_V2_INLINE_CSR=0` | Not a test gate: runs the V2 enrollment tests (`V2LifecycleTests`, `V2FullLifecycleTests`, `V2DcvLifecycleTests`, `V2FreshDomainDcvLifecycleTests`, `PrivatePkiV2LiveTests`) with the `V2InlineCsr` connector setting off (SSL/TLS two-call: create, then submit CSR). Unset runs the default single-call flow; run the suite once in each mode. Private PKI stays two-call either way |
| `CERTINEXT_PRIVATE_PKI_LIVE=1` | `PrivatePkiV2LiveTests.PrivatePki_V2_EnrollIntranetSsl_ThenRevoke_Live`; override the product code and CN with `CERTINEXT_PRIVATE_PKI_PRODUCT_CODE` and `CERTINEXT_PRIVATE_PKI_CN` |
| `CERTINEXT_PRIVATE_PKI_LIVE=1` | `PrivatePkiV2LiveTests.PrivatePki_V2_EnrollIntranetSsl_ThenRevoke_Live`; override the product code and CN with `CERTINEXT_PRIVATE_PKI_PRODUCT_CODE` and `CERTINEXT_PRIVATE_PKI_CN`, the variant with `CERTINEXT_PRIVATE_PKI_VARIANT`, and set `CERTINEXT_PRIVATE_PKI_LEAVE_PENDING=1` (process env) to leave an unissued order pending for manual approval |
| `CERTINEXT_V2_OPS_TESTS=1` | `V2OrderWindowSweepTests` — see below |

Further variables select existing orders for specific tests: `CERTINEXT_PENDING_ORDER_ID`
Expand Down
23 changes: 20 additions & 3 deletions CERTInext.IntegrationTests/PrivatePkiV2LiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,30 @@ namespace Keyfactor.Extensions.CAPlugin.CERTInext.IntegrationTests
/// from ~/.env_certinext_v2 by <see cref="V2EnvHelper"/>, same as <see cref="V2LifecycleTests"/>.
/// </summary>
[Collection(PrivatePkiV2LiveCollection.Name)]
public class PrivatePkiV2LiveTests : IClassFixture<IntegrationTestFixture>
public class PrivatePkiV2LiveTests : IClassFixture<IntegrationTestFixture>, IDisposable
{
private const string OptInFlag = "CERTINEXT_PRIVATE_PKI_LIVE";
private const string IpSan = "10.0.0.50";

private readonly IntegrationTestFixture _fixture;
private readonly ITestOutputHelper _output;
private readonly Action _restoreLogging;

private readonly bool _optedIn;
private readonly string _v2ApiUrl;
private readonly string _v2ClientId;
private readonly string _v2ClientSecret;
private readonly string _productCode;
private readonly string _cnOverride;
private readonly string _variant;
private readonly bool _leavePending;
private readonly bool _v2CredsPresent;

public PrivatePkiV2LiveTests(IntegrationTestFixture fixture, ITestOutputHelper output)
{
_fixture = fixture;
_output = output;
_restoreLogging = TestOutputLogging.RouteTo(output);

// Read the opt-in flag from the real process environment BEFORE promoting the V2 env
// file, so leaving the flag in ~/.env_certinext_v2 cannot arm this order-placing test.
Expand All @@ -83,12 +87,17 @@ public PrivatePkiV2LiveTests(IntegrationTestFixture fixture, ITestOutputHelper o
_v2ClientSecret = V2EnvHelper.GetEnv(env, "CERTINEXT_CLIENT_SECRET");
_productCode = V2EnvHelper.GetEnv(env, "CERTINEXT_PRIVATE_PKI_PRODUCT_CODE", "149");
_cnOverride = V2EnvHelper.GetEnv(env, "CERTINEXT_PRIVATE_PKI_CN");
_variant = V2EnvHelper.GetEnv(env, "CERTINEXT_PRIVATE_PKI_VARIANT", Constants.ApiV2.PrivatePkiVariantIntranetSsl);
// Read from the process environment, like the opt-in flag: leaves a pending order for manual portal approval.
_leavePending = Environment.GetEnvironmentVariable("CERTINEXT_PRIVATE_PKI_LEAVE_PENDING")?.Trim() == "1";

_v2CredsPresent = !string.IsNullOrWhiteSpace(_v2ApiUrl)
&& !string.IsNullOrWhiteSpace(_v2ClientId)
&& !string.IsNullOrWhiteSpace(_v2ClientSecret);
}

public void Dispose() => _restoreLogging();

/// <summary>
/// V2 config for the private-pki order: mirrors <c>V2LifecycleTests.BuildV2Config</c> (V2
/// mode, no V1-only fields, requestor placeholders) with DCV disabled. Private PKI has no DCV
Expand Down Expand Up @@ -202,7 +211,7 @@ public async Task PrivatePki_V2_EnrollIntranetSsl_ThenRevoke_Live()
ProductParameters = new Dictionary<string, string>
{
[Constants.EnrollmentParam.ProductFamily] = "private-pki",
[Constants.EnrollmentParam.ProductVariant] = Constants.ApiV2.PrivatePkiVariantIntranetSsl,
[Constants.EnrollmentParam.ProductVariant] = _variant,
[Constants.EnrollmentParam.ProductCode] = _productCode,
}
};
Expand All @@ -214,7 +223,7 @@ public async Task PrivatePki_V2_EnrollIntranetSsl_ThenRevoke_Live()
};

_output.WriteLine("=== private-pki live enrollment (ONE order, no retries) ===");
_output.WriteLine($"Family=private-pki, Variant={Constants.ApiV2.PrivatePkiVariantIntranetSsl}, ProductCode={_productCode}");
_output.WriteLine($"Family=private-pki, Variant={_variant}, ProductCode={_productCode}");
_output.WriteLine($"CN={cn}, SANs: dnsname=[{cn}], ipaddress=[{IpSan}]");

string orderId = null;
Expand Down Expand Up @@ -323,6 +332,14 @@ private async Task CleanupAsync(CERTInextCAPlugin plugin, CERTInextClient client
return;
}

if (!issued && _leavePending)
{
_output.WriteLine($"CERTINEXT_PRIVATE_PKI_LEAVE_PENDING=1: leaving order {orderId} pending for manual approval. " +
"Revoke it once issued (scripts/v2/revoke-private-pki.sh), or cancel it with " +
"POST /private-pki-certificates/{id}/cancel and a non-empty \"reason\".");
return;
}

bool cleanedUp = false;
if (issued)
{
Expand Down
99 changes: 95 additions & 4 deletions CERTInext.IntegrationTests/V2WildcardSanShapeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
// and limitations under the License.
//
// Wildcard-in-the-SAN-only enrollments (issue 0099): the CSR's CN is the apex and the wildcard is
// only in the SAN set. CERTInext's wrapper decides "wildcard" from certificate.domain alone, so the
// plugin must send the wildcard as the domain. These probes place real sandbox orders and record
// what CERTInext accepts and which product it resolves; gated by CERTINEXT_V2_WILDCARD_SAN_PROBE=1.
// only in the SAN set. The plugin keeps the CN as certificate.domain and sends the wildcard in
// additionalDomains, with no X-Product-Code unless the template sets ProductCode. These probes
// place real sandbox orders and record what CERTInext accepts and which product it resolves; gated
// by CERTINEXT_V2_WILDCARD_SAN_PROBE=1.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Keyfactor.AnyGateway.Extensions;
using Keyfactor.Extensions.CAPlugin.CERTInext.API.V2;
using Keyfactor.Extensions.CAPlugin.CERTInext.Client;
using Keyfactor.PKI.Enums.EJBCA;
using Org.BouncyCastle.Asn1;
Expand Down Expand Up @@ -106,7 +108,8 @@ private static string GenerateCsrPem(string commonName, IReadOnlyList<string> dn

/// <summary>
/// Read-only: lists the account's live catalog entries with their productTypeID, so a run
/// shows which Wildcard UCC products (typeID 21 DV / 22 OV) the plugin can resolve to.
/// shows the account's product codes and productTypeIDs. Informational only: the plugin doesn't check a
/// template ProductCode against the catalog.
/// </summary>
[SkippableFact]
public async Task Catalog_ListsProductTypeIds()
Expand Down Expand Up @@ -203,5 +206,93 @@ await V2OrderCleanup.RevokeOrCancelAsync(
}
}
}

public static IEnumerable<object[]> RawShapes() => new[]
{
// shape, additionalDomains mode: "omit" | "wildcard" (the plugin's body)
new object[] { "R1-noHeader-wildcardOnlyInCsr", "omit" },
new object[] { "R2-noHeader-wildcardInAdditionalDomains", "wildcard" },
};

/// <summary>
/// Bypasses the plugin and posts the create body directly: no X-Product-Code, CSR inline with
/// CN = apex and SANs apex + <c>*.apex</c>, <c>domain</c> = apex. Only <c>additionalDomains</c>
/// varies, to tell whether CERTInext resolves a wildcard product from the CSR alone (as a
/// customer script that leaves the product to CERTInext appears to). Records the outcome,
/// <c>resolvedProductCode</c> and the raw Track Order body; cleans up a placed order.
/// </summary>
[SkippableTheory]
[MemberData(nameof(RawShapes))]
public async Task Probe_Raw_ApexCn_WildcardSan(string shape, string additionalDomainsMode)
{
Skip.If(!_enabled, "CERTINEXT_USE_V2_API not set or V2 credentials not configured — skipping.");
Skip.If(Environment.GetEnvironmentVariable("CERTINEXT_V2_WILDCARD_SAN_PROBE") != "1",
"CERTINEXT_V2_WILDCARD_SAN_PROBE=1 not set — this places real wildcard DV sandbox orders. Skipping.");

string ts = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff");
string apex = $"wcraw-{ts}.{_v2Domain}";
string wildcard = "*." + apex;
var config = BuildV2Config();

var request = new V2CreateSslOrderRequest
{
ProductVariant = Constants.ApiV2.ProductVariantDv,
EmailNotifications = Constants.ApiV2.EmailNotificationsConsentOnly,
Requestor = new V2Requestor
{
Name = config.RequestorName, Email = config.RequestorEmail,
Phone = "+10000000000", Designation = "IT Administrator"
},
Csr = GenerateCsrPem(apex, new[] { apex, wildcard }),
Certificate = new V2CertificateParams
{
Domain = apex,
AdditionalDomains = additionalDomainsMode == "wildcard" ? new List<string> { wildcard } : null
},
Subscription = new V2SubscriptionParams { ValidityYears = 1 },
Agreement = new V2AgreementParams { SignerName = config.RequestorName, SignerPlace = config.SignerPlace },
Remarks = "Keyfactor plugin wildcard-SAN raw probe."
};

_output.WriteLine($"SHAPE {shape}: CN={apex}, CSR SANs=[{apex}, {wildcard}], domain={apex}, " +
$"additionalDomains={(request.Certificate.AdditionalDomains == null ? "(omitted)" : wildcard)}, " +
"X-Product-Code=(none)");

using var client = new CERTInextClient(config);
string orderId = null;
try
{
V2CreateOrderResponse created;
try
{
created = await client.PlaceOrderV2Async(Constants.ApiV2.FamilySsl, null, request);
}
catch (Exception ex)
{
_output.WriteLine($"RESULT {shape}: REJECTED {ex.GetType().Name}: {ex.Message}");
return;
}

orderId = string.IsNullOrWhiteSpace(created.OrderId) ? null : created.OrderId;
_output.WriteLine($"RESULT {shape}: OrderId={orderId ?? "(none)"}, Status={created.Status}, " +
$"ResolvedProductCode={created.ResolvedProductCode ?? "(not reported)"}");

if (orderId != null)
{
var (status, _, body) = await client.ProbeV2GetAsync($"{Constants.ApiV2.SslCertificatesPath}/{orderId}");
string masked = System.Text.RegularExpressions.Regex.Replace(
body ?? string.Empty, @"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}", "<email>");
_output.WriteLine($"TRACK {shape}: HTTP {status} {masked}");
}
}
finally
{
if (orderId != null)
{
await V2OrderCleanup.RevokeOrCancelAsync(
client, orderId, "V2 wildcard-SAN raw probe cleanup.", _output.WriteLine);
}
}
}
}
}
Loading