예제 #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;
 }
예제 #2
0
 public function test requestCertificate triggers a new challenge for extra domains()
 {
     $dummyDomain = uniqid();
     $dummyAlternativeDomain = uniqid();
     $mockCsr = $this->prophesize(CSR::class);
     $dummyDomainKeyPair = $this->prophesize(KeyPair::class)->reveal();
     $dummyCertificate = $this->prophesize(Certificate::class)->reveal();
     $dummyMetadata = new CertificateMetadata($dummyDomain, null, true, null, [$dummyDomain]);
     $mockCsr->getSubjectAlternativeNames()->willReturn([$dummyDomain, $dummyAlternativeDomain]);
     $configuration = new DomainConfiguration($dummyDomain, $mockCsr->reveal());
     $this->mockCertificateRepository->hasCertificate($configuration)->willReturn(true);
     $this->mockCertificateRepository->loadCertificate($configuration)->willReturn($dummyMetadata);
     $this->mockChallenger->challengeDomains([$dummyAlternativeDomain])->shouldBeCalled();
     $mockKeyPairProvider = $this->prophesize(KeyPairProvider::class);
     $this->mockKeyPairFactory->createKeyPairProvider($dummyDomain)->shouldBeCalled()->willReturn($mockKeyPairProvider);
     $mockKeyPairProvider->getOrCreateKeyPair()->shouldBeCalled()->willReturn($dummyDomainKeyPair);
     $this->mockClient->requestCertificate($dummyDomain, $dummyDomainKeyPair, $mockCsr->reveal())->shouldBeCalled()->willReturn($dummyCertificate);
     $result = $this->service->requestCertificate($configuration);
     $this->assertSame($dummyCertificate, $result);
 }
예제 #3
0
 /**
  * @expectedException \Exception
  */
 public function test challengeDomain triggers rejected event()
 {
     $dummyDomain = uniqid();
     $dummyChallenge = $this->prophesize(Challenge::class)->reveal();
     $this->mockClient->requestChallenge($dummyDomain)->shouldBeCalled()->willReturn($dummyChallenge);
     $this->mockClient->checkChallenge($dummyChallenge)->shouldBeCalled()->willThrow(new \Exception());
     $this->mockDispatcher->dispatch('acme_php.challenge.requested', Argument::that(function ($item) use($dummyChallenge) {
         $this->assertInstanceOf(ChallengeEvent::class, $item);
         $this->assertSame($dummyChallenge, $item->getChallenge());
         return true;
     }))->shouldBeCalled();
     $this->mockDispatcher->dispatch('acme_php.challenge.accepted', Argument::any())->shouldNotBeCalled();
     $this->mockDispatcher->dispatch('acme_php.challenge.rejected', Argument::that(function ($item) use($dummyChallenge) {
         $this->assertInstanceOf(ChallengeEvent::class, $item);
         $this->assertSame($dummyChallenge, $item->getChallenge());
         return true;
     }))->shouldBeCalled();
     $this->mockDispatcher->dispatch('acme_php.challenge.checked', Argument::that(function ($item) use($dummyChallenge) {
         $this->assertInstanceOf(ChallengeEvent::class, $item);
         $this->assertSame($dummyChallenge, $item->getChallenge());
         return true;
     }))->shouldBeCalled();
     $this->service->challengeDomain($dummyDomain);
 }