You are here

public function WebhooksTest::testSignature in Webhooks 8

Test webhook signature.

File

tests/src/Functional/WebhooksTest.php, line 256

Class

WebhooksTest
Test description.

Namespace

Drupal\Tests\webhooks\Functional

Code

public function testSignature() {
  $webhook_config = WebhookConfig::load(self::WEBHOOK_ID_OUTGOING_VERIFIED);
  $webhook = new Webhook($this->payload);
  $this->webhookService
    ->send($webhook_config, $webhook);

  // Make sure the secret has been set.
  $this
    ->assertEqual($webhook_config
    ->getSecret(), self::WEBHOOK_SECRET);
  $webhook_receive = $this->state
    ->get('onWebhookReceive');

  // This succeeds if the webhook has been verified and accepted.
  $this
    ->assertEqual($webhook_receive, TRUE);

  /** @var \Drupal\webhooks\Webhook $webhook_received */
  $webhook_received = $this->state
    ->get('onWebhookReceive_webhook');

  // Verify signature.
  $this
    ->assertEqual($webhook_received
    ->getSignature(), $webhook
    ->getSignature());
}