Skip to content

Commit

Permalink
Fix Issue#20 - "Secret fields are displayed in plain text"
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
elbebass authored Feb 8, 2022
1 parent 45d3d4a commit 3acc7e1
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 9 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
.php-cs-fixer.cache
.phpunit.result.cache
composer.lock
vendor
5 changes: 3 additions & 2 deletions Form/Type/ConfigType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
74 changes: 74 additions & 0 deletions Tests/Form/Type/ConfigTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace MauticPlugin\MauticTriggerdialogBundle\Tests\Form\Type;

use MauticPlugin\MauticTriggerdialogBundle\Form\Type\ConfigType;
use Symfony\Component\Form\PreloadedExtension;
use Symfony\Component\Form\Test\TypeTestCase;

class ConfigTypeTest extends TypeTestCase
{
/**
* @return PreloadedExtension[]
*/
protected function getExtensions(): array
{
$type = new ConfigType();

return [
new PreloadedExtension([$type], []),
];
}

public function testFieldsAreNotFilledIn(): 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);
$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());
}
}
22 changes: 17 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"
}
Expand Down
21 changes: 21 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false"
bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>*</directory>
</include>
<exclude>
<directory>Assets</directory>
<directory>Config</directory>
<directory>Tests</directory>
<directory>vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="unit">
<directory>Tests</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit 3acc7e1

Please sign in to comment.