1- // Copyright 2024 Keyfactor
1+ // Copyright 2026 Keyfactor
22//
33// Licensed under the Apache License, Version 2.0 (the "License");
44// you may not use this file except in compliance with the License.
@@ -28,6 +28,15 @@ namespace Keyfactor.Extensions.CAPlugin.GoDaddyTests;
2828
2929public class GoDaddyCAPluginTests
3030{
31+ private static readonly DateTimeOffset NotBefore = DateTimeOffset . Now . AddDays ( - 100 ) ;
32+ private static readonly DateTimeOffset ReissueNotAfter = DateTimeOffset . Now . AddDays ( 365 ) ;
33+ private static readonly DateTimeOffset RenewalNotAfter = DateTimeOffset . Now . AddDays ( 59 ) ;
34+
35+ private const string TestSubject = "CN=Test Subject" ;
36+ private static readonly string TestCsr = GenerateCSR ( TestSubject ) ;
37+ private static readonly X509Certificate2 FakeReissueCertificate = FakeGoDaddyClient . GenerateSelfSignedCertificate ( RSA . Create ( 2048 ) , "CN=Test Cert" , NotBefore , ReissueNotAfter ) ;
38+ private static readonly X509Certificate2 FakeRenewalCertificate = FakeGoDaddyClient . GenerateSelfSignedCertificate ( RSA . Create ( 2048 ) , "CN=Test Cert" , NotBefore , RenewalNotAfter ) ;
39+
3140 ILogger _logger { get ; set ; }
3241
3342 public GoDaddyCAPluginTests ( )
@@ -253,7 +262,7 @@ public void GoDaddyCAPlugin_ValidateProductInfo_EV_InvalidParameters_ReturnFailu
253262 [ InlineData ( "UCC_DV_SSL" ) ]
254263 [ InlineData ( "UCC_EV_SSL" ) ]
255264 [ InlineData ( "UCC_OV_SSL" ) ]
256- public void GoDaddyCAPlugin_Enroll_ReturnSuccess ( string productID )
265+ public async Task GoDaddyCAPlugin_Enroll_ReturnSuccess ( string productID )
257266 {
258267 // Arrange
259268 FakeGoDaddyClient fakeClient = new FakeGoDaddyClient ( ) ;
@@ -267,10 +276,6 @@ public void GoDaddyCAPlugin_Enroll_ReturnSuccess(string productID)
267276 Client = fakeClient
268277 } ;
269278 plugin . Initialize ( configProvider , certificateDataReader ) ;
270-
271- // CSR
272- string subject = "CN=Test Subject" ;
273- string csrString = GenerateCSR ( subject ) ;
274279
275280 Dictionary < string , string [ ] > sans = new ( ) ;
276281
@@ -307,10 +312,10 @@ public void GoDaddyCAPlugin_Enroll_ReturnSuccess(string productID)
307312 EnrollmentType type = EnrollmentType . New ;
308313
309314 // Act
310- EnrollmentResult result = plugin . Enroll ( csrString , subject , sans , productInfo , format , type ) . Result ;
315+ EnrollmentResult result = await plugin . Enroll ( TestCsr , TestSubject , sans , productInfo , format , type ) ;
311316
312317 // Assert
313- Assert . Equal ( result . Status , ( int ) EndEntityStatus . GENERATED ) ;
318+ Assert . Equal ( ( int ) EndEntityStatus . GENERATED , result . Status ) ;
314319 }
315320
316321 [ Theory ]
@@ -324,12 +329,13 @@ public void GoDaddyCAPlugin_Enroll_ReturnSuccess(string productID)
324329 [ InlineData ( "UCC_DV_SSL" ) ]
325330 [ InlineData ( "UCC_EV_SSL" ) ]
326331 [ InlineData ( "UCC_OV_SSL" ) ]
327- public void GoDaddyCAPlugin_Renew_ReturnSuccess ( string productID )
332+ public async Task GoDaddyCAPlugin_Renew_ReturnSuccess ( string productID )
328333 {
329334 // Arrange
330- DateTime enrollmentNotBefore = DateTime . UtcNow . AddDays ( - 5 ) ;
331- DateTime enrollmentNotAfter = DateTime . UtcNow . AddDays ( 20 ) ;
332- X509Certificate2 fakeCertificate = FakeGoDaddyClient . GenerateSelfSignedCertificate ( RSA . Create ( 2048 ) , "CN=Test Cert" , enrollmentNotBefore , enrollmentNotAfter ) ;
335+
336+ // Renewal is only available 60 days prior to expiration of the previous certificate and 30 days after the
337+ // expiration of the previous certificate.
338+
333339 string fakeCaRequestId = Guid . NewGuid ( ) . ToString ( ) ;
334340
335341 FakeGoDaddyClient fakeClient = new FakeGoDaddyClient ( )
@@ -339,20 +345,14 @@ public void GoDaddyCAPlugin_Renew_ReturnSuccess(string productID)
339345 { fakeCaRequestId , new AnyCAPluginCertificate
340346 {
341347 CARequestID = fakeCaRequestId ,
342- Certificate = fakeCertificate . ExportCertificatePem ( ) ,
348+ Certificate = FakeRenewalCertificate . ExportCertificatePem ( ) ,
343349 Status = 123 ,
344350 ProductID = productID ,
345351 }
346352 }
347353 }
348354 } ;
349355
350- // Renewal is only available 60 days prior to expiration of the previous certificate and 30 days after the
351- // expiration of the previous certificate.
352-
353- fakeClient . EnrollmentNotBefore = enrollmentNotBefore ;
354- fakeClient . EnrollmentNotAfter = enrollmentNotAfter ;
355-
356356 BlockingCollection < AnyCAPluginCertificate > certificates = new BlockingCollection < AnyCAPluginCertificate > ( ) ;
357357
358358 IAnyCAPluginConfigProvider configProvider = new FakeCaConfigProvider ( new Config ( ) ) ;
@@ -364,10 +364,6 @@ public void GoDaddyCAPlugin_Renew_ReturnSuccess(string productID)
364364 } ;
365365 plugin . Initialize ( configProvider , certificateDataReader ) ;
366366
367- // CSR
368- string subject = "CN=Test Subject" ;
369- string csrString = GenerateCSR ( subject ) ;
370-
371367 Dictionary < string , string [ ] > sans = new ( ) ;
372368
373369 EnrollmentProductInfo productInfo = new EnrollmentProductInfo
@@ -394,7 +390,7 @@ public void GoDaddyCAPlugin_Renew_ReturnSuccess(string productID)
394390 { EnrollmentConfigConstants . JobTitle , "Software Engineer" } ,
395391 { EnrollmentConfigConstants . RegistrationAgent , "Agent" } ,
396392 { EnrollmentConfigConstants . RegistrationNumber , "REG-12345" } ,
397- { "PriorCertSN" , fakeCertificate . SerialNumber }
393+ { "PriorCertSN" , FakeRenewalCertificate . SerialNumber }
398394 }
399395 } ;
400396
@@ -404,12 +400,12 @@ public void GoDaddyCAPlugin_Renew_ReturnSuccess(string productID)
404400 EnrollmentType type = EnrollmentType . Renew ;
405401
406402 // Act
407- EnrollmentResult result = plugin . Enroll ( csrString , subject , sans , productInfo , format , type ) . Result ;
403+ EnrollmentResult result = await plugin . Enroll ( TestCsr , TestSubject , sans , productInfo , format , type ) ;
408404
409405 // Assert
410- Assert . Equal ( result . Status , ( int ) EndEntityStatus . GENERATED ) ;
411- Assert . Equal ( result . StatusMessage , $ "Certificate with ID { fakeCaRequestId } has been renewed") ;
412- Assert . Equal ( result . CARequestID , fakeCaRequestId ) ;
406+ Assert . Equal ( ( int ) EndEntityStatus . GENERATED , result . Status ) ;
407+ Assert . Equal ( $ "Certificate with ID { fakeCaRequestId } has been renewed", result . StatusMessage ) ;
408+ Assert . Equal ( fakeCaRequestId , result . CARequestID ) ;
413409 }
414410
415411 [ Theory ]
@@ -423,12 +419,12 @@ public void GoDaddyCAPlugin_Renew_ReturnSuccess(string productID)
423419 [ InlineData ( "UCC_DV_SSL" ) ]
424420 [ InlineData ( "UCC_EV_SSL" ) ]
425421 [ InlineData ( "UCC_OV_SSL" ) ]
426- public void GoDaddyCAPlugin_Reissue_ReturnSuccess ( string productID )
422+ public async Task GoDaddyCAPlugin_Reissue_ReturnSuccess ( string productID )
427423 {
428424 // Arrange
429- DateTime enrollmentNotBefore = DateTime . UtcNow . AddDays ( - 100 ) ;
430- DateTime enrollmentNotAfter = DateTime . UtcNow . AddDays ( 365 ) ;
431- X509Certificate2 fakeCertificate = FakeGoDaddyClient . GenerateSelfSignedCertificate ( RSA . Create ( 2048 ) , "CN=Test Cert" , enrollmentNotBefore , enrollmentNotAfter ) ;
425+ // DateTime enrollmentNotBefore = DateTime.UtcNow.AddDays(-100);
426+ // DateTime enrollmentNotAfter = DateTime.UtcNow.AddDays(365);
427+ // X509Certificate2 fakeCertificate = FakeGoDaddyClient.GenerateSelfSignedCertificate(RSA.Create(2048), "CN=Test Cert", enrollmentNotBefore, enrollmentNotAfter);
432428 string fakeCaRequestId = Guid . NewGuid ( ) . ToString ( ) ;
433429
434430 FakeGoDaddyClient fakeClient = new FakeGoDaddyClient ( )
@@ -438,20 +434,14 @@ public void GoDaddyCAPlugin_Reissue_ReturnSuccess(string productID)
438434 { fakeCaRequestId , new AnyCAPluginCertificate
439435 {
440436 CARequestID = fakeCaRequestId ,
441- Certificate = fakeCertificate . ExportCertificatePem ( ) ,
437+ Certificate = FakeReissueCertificate . ExportCertificatePem ( ) ,
442438 Status = 123 ,
443439 ProductID = productID ,
444440 }
445441 }
446442 }
447443 } ;
448444
449- // Renewal is only available 60 days prior to expiration of the previous certificate and 30 days after the
450- // expiration of the previous certificate.
451-
452- fakeClient . EnrollmentNotBefore = enrollmentNotBefore ;
453- fakeClient . EnrollmentNotAfter = enrollmentNotAfter ;
454-
455445 BlockingCollection < AnyCAPluginCertificate > certificates = new BlockingCollection < AnyCAPluginCertificate > ( ) ;
456446
457447 IAnyCAPluginConfigProvider configProvider = new FakeCaConfigProvider ( new Config ( ) ) ;
@@ -463,10 +453,6 @@ public void GoDaddyCAPlugin_Reissue_ReturnSuccess(string productID)
463453 } ;
464454 plugin . Initialize ( configProvider , certificateDataReader ) ;
465455
466- // CSR
467- string subject = "CN=Test Subject" ;
468- string csrString = GenerateCSR ( subject ) ;
469-
470456 Dictionary < string , string [ ] > sans = new ( ) ;
471457
472458 EnrollmentProductInfo productInfo = new EnrollmentProductInfo
@@ -493,7 +479,7 @@ public void GoDaddyCAPlugin_Reissue_ReturnSuccess(string productID)
493479 { EnrollmentConfigConstants . JobTitle , "Software Engineer" } ,
494480 { EnrollmentConfigConstants . RegistrationAgent , "Agent" } ,
495481 { EnrollmentConfigConstants . RegistrationNumber , "REG-12345" } ,
496- { "PriorCertSN" , fakeCertificate . SerialNumber }
482+ { "PriorCertSN" , FakeReissueCertificate . SerialNumber }
497483 }
498484 } ;
499485
@@ -503,12 +489,12 @@ public void GoDaddyCAPlugin_Reissue_ReturnSuccess(string productID)
503489 EnrollmentType type = EnrollmentType . Renew ;
504490
505491 // Act
506- EnrollmentResult result = plugin . Enroll ( csrString , subject , sans , productInfo , format , type ) . Result ;
492+ EnrollmentResult result = await plugin . Enroll ( TestCsr , TestSubject , sans , productInfo , format , type ) ;
507493
508494 // Assert
509- Assert . Equal ( result . Status , ( int ) EndEntityStatus . GENERATED ) ;
510- Assert . Equal ( result . StatusMessage , $ "Certificate with ID { fakeCaRequestId } has been reissued") ;
511- Assert . Equal ( result . CARequestID , fakeCaRequestId ) ;
495+ Assert . Equal ( ( int ) EndEntityStatus . GENERATED , result . Status ) ;
496+ Assert . Equal ( $ "Certificate with ID { fakeCaRequestId } has been reissued", result . StatusMessage ) ;
497+ Assert . Equal ( fakeCaRequestId , result . CARequestID ) ;
512498 }
513499
514500 [ IntegrationTestingFact ]
0 commit comments