getSecret example

$setup = $manifest->getSetup();
        $metadata = $manifest->getMetadata();
        $appName = $metadata->getName();

        if (!$setup) {
            throw AppException::registrationFailed(
                $appName,
                sprintf('No setup for registration provided in manifest for app "%s".', $metadata->getName())
            );
        }

        $privateSecret = $setup->getSecret();

        try {
            $shopId = $this->shopIdProvider->getShopId();
        } catch (AppUrlChangeDetectedException) {
            throw AppException::registrationFailed(
                $appName,
                'The app url changed. Please resolve how the apps should handle this change.'
            );
        }

        if ($privateSecret) {
            
$bus = $this->createMock(MessageBusInterface::class);
        $bus->expects(static::once())
            ->method('dispatch')
            ->with(static::callback(function DWebhookEventMessage $message) use ($payload$appId$webhookId$shopwareVersion) {
                $actualPayload = $message->getPayload();
                static::assertArrayHasKey('eventId', $actualPayload['source']);
                unset($actualPayload['source']['eventId']);
                static::assertEquals($payload$actualPayload);
                static::assertEquals($appId$message->getAppId());
                static::assertEquals($webhookId$message->getWebhookId());
                static::assertEquals($shopwareVersion$message->getShopwareVersion());
                static::assertEquals('s3cr3t', $message->getSecret());
                static::assertEquals(Defaults::LANGUAGE_SYSTEM, $message->getLanguageId());
                static::assertEquals('en-GB', $message->getUserLocale());

                return true;
            }))
            ->willReturn(new Envelope(new WebhookEventMessage($webhookEventId$payload$appId$webhookId, '6.4', 'http://test.com', 's3cr3t', Defaults::LANGUAGE_SYSTEM, 'en-GB')));

        $webhookDispatcher = new WebhookDispatcher(
            $this->getContainer()->get('event_dispatcher'),
            $this->getContainer()->get(Connection::class),
            $client,
            
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
use Symfony\Component\Security\Core\User\UserInterface;

class RememberMeTokenTest extends TestCase
{
    public function testConstructor()
    {
        $user = $this->getUser();
        $token = new RememberMeToken($user, 'fookey', 'foo');

        $this->assertEquals('fookey', $token->getFirewallName());
        $this->assertEquals('foo', $token->getSecret());
        $this->assertEquals(['ROLE_FOO']$token->getRoleNames());
        $this->assertSame($user$token->getUser());
    }

    public function testConstructorSecretCannotBeEmptyString()
    {
        $this->expectException(\InvalidArgumentException::class);
        new RememberMeToken(
            $this->getUser(),
            '',
            ''
        );
class VonageRequestParserTest extends AbstractRequestParserTestCase
{
    public function testMissingAuthorizationTokenThrows()
    {
        $request = $this->createRequest('{}');
        $request->headers->remove('Authorization');
        $parser = $this->createRequestParser();

        $this->expectException(RejectWebhookException::class);
        $this->expectExceptionMessage('Missing "Authorization" header');

        $parser->parse($request$this->getSecret());
    }

    public function testInvalidAuthorizationTokenThrows()
    {
        $request = $this->createRequest('{}');
        $request->headers->set('Authorization', 'Invalid Header');
        $parser = $this->createRequestParser();

        $this->expectException(RejectWebhookException::class);
        $this->expectExceptionMessage('Signature is wrong');

        
$registrationRequest = $this->getPastRequest(0);

        $setup = $manifest->getSetup();
        static::assertNotNull($setup);

        $uriWithoutQuery = $registrationRequest->getUri()->withQuery('');
        static::assertEquals($setup->getRegistrationUrl()(string) $uriWithoutQuery);
        static::assertNotEmpty($registrationRequest->getHeaderLine('sw-version'));
        static::assertNotEmpty($registrationRequest->getHeaderLine(AuthMiddleware::SHOPWARE_USER_LANGUAGE));
        static::assertNotEmpty($registrationRequest->getHeaderLine(AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE));

        $secret = $setup->getSecret();
        static::assertNotNull($secret);

        $this->assertRequestIsSigned($registrationRequest$secret);

        $app = $this->fetchApp($id);

        static::assertEquals(TestAppServer::APP_SECRET, $app->getAppSecret());

        static::assertEquals(2, $this->getRequestCount());

        $confirmationReq = $this->getPastRequest(1);
        
        if ($message->getLanguageId() && $message->getUserLocale()) {
            $headers = array_merge($headers[AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE => $message->getLanguageId(), AuthMiddleware::SHOPWARE_USER_LANGUAGE => $message->getUserLocale()]);
        }

        $requestContent = [
            'headers' => $headers,
            'body' => $jsonPayload,
            'connect_timeout' => self::CONNECT_TIMEOUT,
            'timeout' => self::TIMEOUT,
        ];

        if ($message->getSecret()) {
            $requestContent[AuthMiddleware::APP_REQUEST_TYPE] = [
                AuthMiddleware::APP_SECRET => $message->getSecret(),
            ];
        }

        $context = Context::createDefaultContext();

        $this->webhookEventLogRepository->update([
            [
                'id' => $message->getWebhookEventId(),
                'deliveryStatus' => WebhookEventLogDefinition::STATUS_RUNNING,
                
private readonly HttpClientInterface $client,
        private readonly RequestConfiguratorInterface $headers,
        private readonly RequestConfiguratorInterface $body,
        private readonly RequestConfiguratorInterface $signer,
    ) {
    }

    public function send(Subscriber $subscriber, RemoteEvent $event): void
    {
        $options = new HttpOptions();

        $this->headers->configure($event$subscriber->getSecret()$options);
        $this->body->configure($event$subscriber->getSecret()$options);
        $this->signer->configure($event$subscriber->getSecret()$options);

        $this->client->request('POST', $subscriber->getUrl()$options->toArray());
    }
}
'foo' => 'bar',
            'source' => [
                'url' => 'https://example.com',
                'appVersion' => $webhookEntity->getApp()?->getVersion(),
                'shopId' => 'foobar',
                'action' => $event->getName(),
            ],
        ]$payload);

        static::assertEquals($message->getLanguageId(), Defaults::LANGUAGE_SYSTEM);
        static::assertEquals($message->getAppId()$webhookEntity->getApp()?->getId());
        static::assertEquals($message->getSecret()$webhookEntity->getApp()?->getAppSecret());
        static::assertEquals($message->getShopwareVersion(), '0.0.0');
        static::assertEquals($message->getUrl(), 'https://foo.bar');
        static::assertEquals($message->getWebhookId()$webhookEntity->getId());
    }

    private function getWebhookDispatcher(bool $isAdminWorkerEnabled): WebhookDispatcher
    {
        return new WebhookDispatcher(
            $this->dispatcher,
            $this->connection,
            $this->client,
            

abstract class AbstractRequestParserTestCase extends TestCase
{
    /** * @dataProvider getPayloads */
    public function testParse(string $payload, RemoteEvent $expected)
    {
        $request = $this->createRequest($payload);
        $parser = $this->createRequestParser();
        $wh = $parser->parse($request$this->getSecret());
        $this->assertEquals($expected$wh);
    }

    public static function getPayloads(): iterable
    {
        $currentDir = \dirname((new \ReflectionClass(static::class))->getFileName());
        foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($currentDir.'/Fixtures', \RecursiveDirectoryIterator::SKIP_DOTS)) as $file) {
            $filename = str_replace($currentDir.'/Fixtures/', '', $file->getPathname());
            if (static::getFixtureExtension() !== pathinfo($filename, \PATHINFO_EXTENSION)) {
                continue;
            }

            
Home | Imprint | This part of the site doesn't use cookies.