Skip to content

Commit

Permalink
Ci backend tests (#9)
Browse files Browse the repository at this point in the history
* [CI] Add selenium tests

* Avoid user self removing
  • Loading branch information
PapsOu authored May 23, 2018
1 parent 2a930cf commit fc9a231
Show file tree
Hide file tree
Showing 63 changed files with 1,208 additions and 604 deletions.
7 changes: 7 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ DBROOTPASSWORD=postgres24
DBNAME=db_pialab
DBUSER=user_pialab
DBPASSWORD=pass_pialab

TEST_SERVER_URL="http://localhost:8000"
TEST_URL=""
TEST_USER="[email protected]"
TEST_PASSWORD="ci"

CODECEPTCMD="bin/codecept run -vvv --debug --steps --no-interaction --xml --html"
###< librinfo CI ###

###> symfony/framework-bundle ###
Expand Down
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@

/composer.lock
.php_cs.cache

###> phpunit/phpunit ###
/phpunit.xml
###< phpunit/phpunit ###

###> symfony/phpunit-bridge ###
.phpunit
/phpunit.xml
###< symfony/phpunit-bridge ###

###> codeception/codeception ###
tests/*.suite.yml
tests/_output/*
!tests/_output/.gitkeep
tests/_support/_generated/*
!tests/_support/_generated/.gitkeep
###< codeception/codeception ###
21 changes: 20 additions & 1 deletion bin/ci-scripts/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,24 @@ else
exit 42
fi

echo "waiting for test creation"
export CODECEPTCMD

export TEST_SERVER_URL
export TEST_URL
export TEST_USER
export TEST_PASSWORD

if [ -n "$CODECEPTCMD" ]
then
CODECEPTGROUP=$@
if [ $# -eq 0 ]
then
CODECEPTGROUP="all" #"login" # all"
fi

for i in $CODECEPTGROUP
do
$CODECEPTCMD -g $i #--env=$CODECEPTENV
done
fi

5 changes: 4 additions & 1 deletion bin/ci-scripts/server_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ else
exit 42
fi

bin/console server:start --no-interaction
# get ip
currentip=$(hostname -i) # works only if the host name can be resolved

bin/console server:start $currentip:8000 --no-interaction

7 changes: 7 additions & 0 deletions bin/ci-scripts/set_env_with_etcd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ postgresuser=$($ETCDCTLCMD get /default/postgres/root/username --print-value-onl
postgrespass=$($ETCDCTLCMD get /default/postgres/root/password --print-value-only $ETCDENDPOINT)
# TODO add a check default cnx with psql

# get selenium default
SeleniumHost=$($ETCDCTLCMD get /default/selenium/hostname --print-value-only $ETCDENDPOINT)
$ETCDCTLCMD put $Prefix/selenium/hostname $SeleniumHost $ETCDENDPOINT

# set postgres env
$ETCDCTLCMD put $Prefix/postgres/hostname $postgreshost $ETCDENDPOINT
$ETCDCTLCMD put $Prefix/postgres/root/username $postgresuser $ETCDENDPOINT
Expand All @@ -63,6 +67,9 @@ $ETCDCTLCMD put $Prefix/postgres/default/password pia_pass_$Suffix $ETCDENDPOINT

# set symfony env
$ETCDCTLCMD put $Prefix/symfony/env $SYMFONYENV $ETCDENDPOINT
# get ip
currentip=$(hostname -i) # works only if the host name can be resolved
$ETCDCTLCMD put $Prefix/url/addr $currentip':8000' $ETCDENDPOINT

$ETCDCTLCMD get --prefix $Prefix $ETCDENDPOINT

Expand Down
1 change: 1 addition & 0 deletions bin/codecept
1 change: 1 addition & 0 deletions bin/phpunit
1 change: 1 addition & 0 deletions bin/simple-phpunit
13 changes: 13 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
params:
- .env
- env
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"white-october/pagerfanta-bundle": "^1.1"
},
"require-dev": {
"codeception/codeception": "^2.4",
"symfony/dotenv": "^4.0",
"symfony/phpunit-bridge": "^4.0",
"symfony/profiler-pack": "^1.0",
"symfony/web-server-bundle": "^4.0"
},
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions config/services_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
_defaults:
public: true

# If you need to access services in a test, create an alias
# and then fetch that alias from the container. As a convention,
# aliases are prefixed with test. For example:
#
# test.App\Service\MyService: '@App\Service\MyService'
7 changes: 7 additions & 0 deletions etc/confd/conf.d/acceptance.suite.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[template]
src = "acceptance.suite.yml.tmpl"
dest = "tests/acceptance.suite.yml"
keys = [
"/selenium/hostname",
"/url/addr",
]
1 change: 0 additions & 1 deletion etc/confd/conf.d/env.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ keys = [
"/postgres/default/dbname",
"/postgres/default/username",
"/postgres/default/password",

]
10 changes: 10 additions & 0 deletions etc/confd/templates/acceptance.suite.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class_name: WebGuy
modules:
enabled:
- WebDriver:
host: {{getv "/selenium/hostname"}}
port: 4444
url: 'http://{{getv "/url/addr"}}'
wait: 5
browser: 'firefox'
- \Helper\Acceptance
7 changes: 7 additions & 0 deletions etc/confd/templates/env.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ DBROOTPASSWORD={{getv "/postgres/root/password"}}
DBNAME={{getv "/postgres/default/dbname"}}
DBUSER={{getv "/postgres/default/username"}}
DBPASSWORD={{getv "/postgres/default/password"}}

TEST_SERVER_URL="http://127.0.0.1:8000"
TEST_URL=""
TEST_USER="[email protected]"
TEST_PASSWORD="pia42"

CODECEPTCMD="bin/codecept run -vvv --debug --steps --no-interaction --xml --html"
###< librinfo CI ###

###> symfony/framework-bundle ###
Expand Down
1 change: 1 addition & 0 deletions etc/pipeline.jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pipeline {

post {
always {
publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: false, reportDir: 'tests/_output/', reportFiles: 'report.html', reportName: 'Codeception Report', reportTitles: ''])
cleanWs()
}
}
Expand Down
31 changes: 31 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<env name="KERNEL_CLASS" value="App\Kernel" />
<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="1" />
<env name="APP_SECRET" value="s$cretf0rt3st" />
<env name="SHELL_VERBOSITY" value="-1" />
<!-- define your env variables for the test env here -->
</php>

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
100 changes: 50 additions & 50 deletions public/assets/css/semantic-superhero.min.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions public/assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ body .ui.bulleted.list>.item::before,
body ul.ui.list li::before {
content: '';
display: none;
}

body .table.responsive.wrapper {
overflow-y: auto;
}
Binary file added public/assets/img/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/img/pia-lab-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/img/pia-lab-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/img/pia-lab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/assets/img/pia-logo-small-white.png
Binary file not shown.
Binary file removed public/assets/img/pia-logo-small.png
Binary file not shown.
Binary file removed public/assets/img/pia-logo.png
Binary file not shown.
4 changes: 2 additions & 2 deletions public/assets/js/semantic.min.js

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions src/Auth/PasswordResettingListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PiaApi\Entity\Oauth\User;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

class PasswordResettingListener implements EventSubscriberInterface
{
Expand All @@ -31,10 +32,16 @@ class PasswordResettingListener implements EventSubscriberInterface
*/
protected $twig;

public function __construct(UrlGeneratorInterface $router, Environment $twig)
/**
* @var TokenStorageInterface
*/
protected $tokenStorage;

public function __construct(UrlGeneratorInterface $router, Environment $twig, TokenStorageInterface $tokenStorage)
{
$this->router = $router;
$this->twig = $twig;
$this->tokenStorage = $tokenStorage;
}

/**
Expand All @@ -43,7 +50,7 @@ public function __construct(UrlGeneratorInterface $router, Environment $twig)
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::RESETTING_RESET_SUCCESS => 'onPasswordResettingSuccess',
FOSUserEvents::RESETTING_RESET_SUCCESS => ['onPasswordResettingSuccess', -10],
);
}

Expand All @@ -54,6 +61,9 @@ public function onPasswordResettingSuccess(FormEvent $event)

$url = $user->getApplication()->getUrl();

$this->tokenStorage->setToken(null);
$event->getRequest()->getSession()->invalidate(); // This does not work. Maybe because of FOSUser original event listener...

if ($url === null || $url === '') {
// This case should never happen
$response = new Response('', 200);
Expand Down
7 changes: 4 additions & 3 deletions src/Controller/BackOffice/OauthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function manageApplicationsAction(Request $request)
}

/**
* @Route("/manageApplication/addApplication", name="manage_applications_add_application")
* @Route("/manageApplications/addApplication", name="manage_applications_add_application")
*
* @param Request $request
*/
Expand All @@ -79,6 +79,7 @@ public function addApplicationAction(Request $request)
$client = $this->fosOauthClientManager->createClient();
/* @var Client $client */
$client->setName($applicationData['name']);
$client->setUrl($applicationData['url']);
$client->setRedirectUris($applicationData['redirectUris']);
$client->setAllowedGrantTypes($applicationData['allowedGrantTypes']);
$this->fosOauthClientManager->updateClient($client);
Expand All @@ -93,7 +94,7 @@ public function addApplicationAction(Request $request)
}

/**
* @Route("/manageUsers/addApplication/{applicationId}", name="manage_applications_edit_application")
* @Route("/manageApplications/editApplication/{applicationId}", name="manage_applications_edit_application")
*
* @param Request $request
*/
Expand Down Expand Up @@ -129,7 +130,7 @@ public function editApplicationAction(Request $request)
}

/**
* @Route("/manageApplication/removeApplication/{applicationId}", name="manage_applications_remove_application")
* @Route("/manageApplications/removeApplication/{applicationId}", name="manage_applications_remove_application")
*
* @param Request $request
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Controller/BackOffice/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public function removeUserAction(Request $request)
throw new NotFoundHttpException(sprintf('User « %s » does not exist', $userId));
}

if ($user === $this->getUser()) {
throw new NotFoundHttpException('You cannot delete yourself !');
}

$form = $this->createForm(RemoveUserForm::class, $user, [
'action' => $this->generateUrl('manage_users_remove_user', ['userId' => $user->getId()]),
]);
Expand Down
Loading

0 comments on commit fc9a231

Please sign in to comment.