Esempio n. 1
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;
 }
Esempio n. 2
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);
 }