From 3acc7e137a4f224a7b8accd8bb51a1506d43713b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20R=C3=B6sch?= Date: Tue, 8 Feb 2022 09:52:47 +0100 Subject: [PATCH] Fix Issue#20 - "Secret fields are displayed in plain text" * Added phpunit to GH actions. * [TASK] Adapt php-cs-fixer version to resolve composer package requirements * Allow mautic/core-lib: 3.2, so the plugin is installable with composer. --- .github/workflows/ci.yaml | 7 ++- .gitignore | 2 + Form/Type/ConfigType.php | 5 +- Tests/Form/Type/ConfigTypeTest.php | 74 ++++++++++++++++++++++++++++++ composer.json | 22 +++++++-- phpunit.xml.dist | 21 +++++++++ 6 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 Tests/Form/Type/ConfigTypeTest.php create mode 100644 phpunit.xml.dist diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f19cf80..9bc03b5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,6 +20,9 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} - tools: php-cs-fixer:3.5 + - name: Composer install + run: composer install - name: Check PHP CS - run: php-cs-fixer fix --config .php-cs-fixer.php --dry-run --using-cache no --show-progress dots -v + run: ./vendor/bin/php-cs-fixer fix --config .php-cs-fixer.php --dry-run --using-cache no --show-progress dots -v + - name: Test + run: ./vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 69f9fdb..70dde01 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea .php-cs-fixer.cache +.phpunit.result.cache composer.lock +vendor diff --git a/Form/Type/ConfigType.php b/Form/Type/ConfigType.php index c03160d..8fcf6a7 100644 --- a/Form/Type/ConfigType.php +++ b/Form/Type/ConfigType.php @@ -4,6 +4,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; +use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; @@ -39,7 +40,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]); - $builder->add('triggerdialog_masSecret', TextType::class, [ + $builder->add('triggerdialog_masSecret', PasswordType::class, [ 'label' => 'plugin.triggerdialog.form.masSecret', 'label_attr' => [ 'class' => 'control-label', @@ -63,7 +64,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]); - $builder->add('triggerdialog_rest_password', TextType::class, [ + $builder->add('triggerdialog_rest_password', PasswordType::class, [ 'label' => 'plugin.triggerdialog.form.rest.password', 'label_attr' => [ 'class' => 'control-label', diff --git a/Tests/Form/Type/ConfigTypeTest.php b/Tests/Form/Type/ConfigTypeTest.php new file mode 100644 index 0000000..0b14497 --- /dev/null +++ b/Tests/Form/Type/ConfigTypeTest.php @@ -0,0 +1,74 @@ + '123', + 'triggerdialog_masClientId' => 'masClientId', + 'triggerdialog_masSecret' => 'masSecret', + 'triggerdialog_rest_user' => 'rest_user', + 'triggerdialog_rest_password' => 'rest_password', + ]; + + $form = $this->factory->create(ConfigType::class, $dataToForm); + $view = $form->createView(); + + self::assertSame('123', $view->children['triggerdialog_masId']->vars['value']); + self::assertSame('masClientId', $view->children['triggerdialog_masClientId']->vars['value']); + self::assertSame('', $view->children['triggerdialog_masSecret']->vars['value']); + self::assertSame('rest_user', $view->children['triggerdialog_rest_user']->vars['value']); + self::assertSame('', $view->children['triggerdialog_rest_password']->vars['value']); + } + + public function testFieldsAreSaved(): void + { + $dataToForm = [ + 'triggerdialog_masId' => '123', + 'triggerdialog_masClientId' => 'masClientId', + 'triggerdialog_masSecret' => 'masSecret', + 'triggerdialog_rest_user' => 'rest_user', + 'triggerdialog_rest_password' => 'rest_password', + ]; + + $form = $this->factory->create(ConfigType::class, $dataToForm); + + $formData = [ + 'triggerdialog_masId' => '321', + 'triggerdialog_masClientId' => 'masClientId_1', + 'triggerdialog_masSecret' => 'masSecret_1', + 'triggerdialog_rest_user' => 'rest_user_1', + 'triggerdialog_rest_password' => 'rest_password_1', + ]; + + $form->submit($formData); + + $formData['triggerdialog_masId'] = (int) $formData['triggerdialog_masId']; + + self::assertTrue($form->isSynchronized()); + + self::assertSame($formData, $form->getData()); + self::assertTrue($form->isValid()); + } +} diff --git a/composer.json b/composer.json index 6e893bf..4b9753b 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ "license": "GPL-3.0-or-later", "type": "mautic-plugin", "homepage": "https://www.Leuchtfeuer.com", + "minimum-stability": "dev", "authors": [ { "name": "Florian Wessels", @@ -16,7 +17,15 @@ "ext-json": "*", "ext-simplexml": "*", "ext-openssl": "*", - "firebase/php-jwt": "^5.0" + "firebase/php-jwt": "^5.0", + "mautic/core-lib": "^3.2|^4.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.4", + "phpunit/phpunit": "^9.5.0" + }, + "extra": { + "install-directory-name": "MauticTriggerdialogBundle" }, "support": { "issues": "https://github.com/Leuchtfeuer/mautic-deutschepost/issues", @@ -28,12 +37,15 @@ }, "autoload": { "psr-4": { - "MauticPlugin\\MauticTriggerdialogBundle\\": "/" + "MauticPlugin\\MauticTriggerdialogBundle\\": "" } }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^3.5" - }, + "repositories": [ + { + "type": "git", + "url": "https://github.com/dennisameling/FOSOAuthServerBundle.git" + } + ], "scripts": { "cs-fix": "./vendor/bin/php-cs-fixer fix --config .php-cs-fixer.php --using-cache no --show-progress dots -v" } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..e05baee --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,21 @@ + + + + + + * + + + Assets + Config + Tests + vendor + + + + + Tests + + +