public function test createKeyPairProvider injects the logger()
 {
     $dummyDomain = uniqid();
     $dummyStorage = $this->prophesize(KeyPairStorage::class)->reveal();
     $dummyLogger = $this->prophesize(LoggerInterface::class)->reveal();
     $this->mockStorageFactory->createKeyPairStorage($dummyDomain)->shouldBeCalled()->willReturn($dummyStorage);
     $this->service->setLogger($dummyLogger);
     $provider = $this->service->createKeyPairProvider($dummyDomain);
     $reflection = new \ReflectionObject($provider);
     $loggerProperty = $reflection->getProperty('logger');
     $loggerProperty->setAccessible(true);
     $this->assertSame($dummyLogger, $loggerProperty->getValue($provider));
 }
Example #2
0
 /**
  * Request a new certificate for the given configuration.
  *
  * @param DomainConfiguration $configuration
  *
  * @return Certificate
  */
 public function requestCertificate(DomainConfiguration $configuration)
 {
     $domains = array_merge([$configuration->getDomain()], (array) $configuration->getCSR()->getSubjectAlternativeNames());
     $challengedDomains = [];
     if ($this->certificateRepository->hasCertificate($configuration)) {
         $metadata = $this->certificateRepository->loadCertificate($configuration);
         $challengedDomains = array_merge([$configuration->getDomain()], $metadata->getSubjectAlternativeNames());
     }
     $unchallengedDomains = array_values(array_diff($domains, $challengedDomains));
     if (count($unchallengedDomains)) {
         $this->challenger->challengeDomains($unchallengedDomains);
     }
     $domain = $configuration->getDomain();
     $domainKeyPair = $this->keyPairFactory->createKeyPairProvider($domain)->getOrCreateKeyPair();
     $certificate = $this->client->requestCertificate($domain, $domainKeyPair, $configuration->getCSR());
     $this->dispatcher->dispatch(AcmePhpBundleEvents::CERTIFICATE_REQUESTED, new CertificateEvent($configuration, $certificate, $domainKeyPair));
     $this->logger->notice('Certificate for domain {domain} requested', ['domain' => $configuration->getDomain()]);
     return $certificate;
 }
Example #3
0
 public function test requestCertificate trigger event()
 {
     $dummyDomain = uniqid();
     $dummyCsr = $this->prophesize(CSR::class)->reveal();
     $dummyDomainKeyPair = $this->prophesize(KeyPair::class)->reveal();
     $dummyCertificate = $this->prophesize(Certificate::class)->reveal();
     $dummyMetadata = new CertificateMetadata($dummyDomain, null, true, null, [$dummyDomain]);
     $configuration = new DomainConfiguration($dummyDomain, $dummyCsr);
     $this->mockCertificateRepository->hasCertificate($configuration)->willReturn(true);
     $this->mockCertificateRepository->loadCertificate($configuration)->willReturn($dummyMetadata);
     $mockKeyPairProvider = $this->prophesize(KeyPairProvider::class);
     $this->mockKeyPairFactory->createKeyPairProvider($dummyDomain)->shouldBeCalled()->willReturn($mockKeyPairProvider);
     $mockKeyPairProvider->getOrCreateKeyPair()->shouldBeCalled()->willReturn($dummyDomainKeyPair);
     $this->mockClient->requestCertificate($dummyDomain, $dummyDomainKeyPair, $dummyCsr)->shouldBeCalled()->willReturn($dummyCertificate);
     $this->mockDispatcher->dispatch('acme_php.certificate.requested', Argument::that(function ($item) use($dummyCertificate) {
         return $item instanceof CertificateEvent && $item->getCertificate() === $dummyCertificate;
     }))->shouldBeCalled();
     $this->service->requestCertificate($configuration);
 }