public function test onCertificateRequested persists the certificate()
 {
     $dummyConfiguration = $this->prophesize(DomainConfiguration::class)->reveal();
     $dummyCertificate = $this->prophesize(Certificate::class)->reveal();
     $dummyDomainKeyPair = $this->prophesize(KeyPair::class)->reveal();
     $event = new CertificateEvent($dummyConfiguration, $dummyCertificate, $dummyDomainKeyPair);
     $this->mockRepository->persistCertificate($dummyConfiguration, $dummyCertificate, $dummyDomainKeyPair)->shouldBeCalled();
     $this->service->onCertificateRequested($event);
 }
Beispiel #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;
 }
 public function test loadCertificate use parsers to parse certificate file content()
 {
     $dummyDomain = uniqid();
     $dummyCsr = $this->prophesize(CSR::class)->reveal();
     $dummyCertificate = $this->prophesize(Certificate::class)->reveal();
     $dummyDomainKeyPair = $this->prophesize(KeyPair::class)->reveal();
     $dummyCertificateFileContent = uniqid();
     $dummyCertificateMetadata = new CertificateMetadata($dummyDomain, uniqid(), (bool) rand(0, 1), uniqid(), [uniqid()]);
     $dummyCertificateFileName = uniqid();
     $configuration = new DomainConfiguration($dummyDomain, $dummyCsr);
     $mockStorage = $this->prophesize(CertificateStorage::class);
     $this->mockStorageFactory->createCertificateStorage($dummyDomain)->willReturn($mockStorage->reveal());
     $this->mockCertificateFormatter->getName()->willReturn($dummyCertificateFileName);
     $this->mockCertificateParser->parse($dummyCertificateFileContent)->shouldBeCalled()->willReturn($dummyCertificateMetadata);
     $mockStorage->loadCertificateFile($dummyCertificateFileName)->shouldBeCalled()->willReturn($dummyCertificateFileContent);
     $result = $this->service->loadCertificate($configuration, $dummyCertificate, $dummyDomainKeyPair);
     $this->assertSame(var_export($dummyCertificateMetadata, true), var_export($result, true));
 }
 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);
 }
 /**
  * Triggered when a certificate is requested.
  *
  * @param CertificateEvent $event
  */
 public function onCertificateRequested(CertificateEvent $event)
 {
     $this->certificateRepository->persistCertificate($event->getDomainConfiguration(), $event->getCertificate(), $event->getDomainKeyPair());
 }