Skip to content

Commit faeaf27

Browse files
committed
gito1
1 parent 7fe4087 commit faeaf27

File tree

6 files changed

+102
-3
lines changed

6 files changed

+102
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
compassman - Company's Password Manager
1+
Compassman - Company's Password Manager
22
=======================================
33

44
Compassman is an application that allows sharing of passwords by many users.

config/packages/security.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ security:
2727
- { path: ^/admin/logout, roles: IS_AUTHENTICATED_ANONYMOUSLY }
2828
- { path: ^/admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
2929
- { path: ^/admin, roles: ROLE_ADMIN }
30-
- { path: ^/access_entry, roles: ROLE_USER }
30+
- { path: ^/access_entry, roles: IS_AUTHENTICATED_ANONYMOUSLY }
3131
- { path: ^/access, roles: ROLE_USER }
3232
- { path: ^/profile, roles: ROLE_USER }

src/Form/UserType.php

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function configureOptions(OptionsResolver $resolver)
2424
{
2525
$resolver->setDefaults([
2626
'data_class' => User::class,
27+
2728
]);
2829
}
2930
}

templates/user/_delete_form.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<form method="post" action="{{ path('user_delete', {'id': user.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
22
<input type="hidden" name="_method" value="DELETE">
3-
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ user.id) }}">
3+
44
<button class="btn btn-danger">Delete</button>
55
</form>

tests/ComPassManWebTestCase.php

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace App\Tests;
4+
5+
use Doctrine\ORM\EntityManager;
6+
use App\Entity\User;
7+
use Symfony\Bundle\FrameworkBundle\Client;
8+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
9+
use Symfony\Component\BrowserKit\Cookie;
10+
use Symfony\Component\HttpFoundation\Session\Session;
11+
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
12+
13+
class ComPassManWebTestCase extends WebTestCase
14+
{
15+
/** @var Client $client */
16+
protected $client = null;
17+
18+
/** @var EntityManager $entityManager */
19+
protected $entityManager;
20+
21+
/** @var Session $session */
22+
protected $session;
23+
24+
protected $parameters = [
25+
'test_user_id' => null,
26+
'firewall_name' => 'main',
27+
'firewall_context' => 'main'
28+
];
29+
30+
/** @var null|User */
31+
protected $user = null;
32+
33+
public function setUp()
34+
{
35+
$this->client = static::createClient();
36+
$this->client->followRedirects(true);
37+
$this->client->setMaxRedirects(10);
38+
$this->client->disableReboot();
39+
40+
$this->session = $this->client->getContainer()->get('session');
41+
42+
$this->entityManager = $this->client->getContainer()->get('doctrine.orm.entity_manager');
43+
//dump($this->entityManager);
44+
$this->entityManager->beginTransaction();
45+
46+
$this->parameters['test_user_id'] = static::$kernel->getContainer()->getParameter('test_user_id');
47+
$user = $this->entityManager->getRepository(User::class)->find($this->parameters['test_user_id']);
48+
$this->user = $user;
49+
}
50+
51+
protected function logIn()
52+
{
53+
$session = $this->session;
54+
55+
$userId = $this->parameters['test_user_id'];
56+
$user = $this->entityManager->getRepository(User::class)->find($userId);
57+
58+
$token = new UsernamePasswordToken($user, null, $this->parameters['firewall_name'], ['ROLE_SUPER_ADMIN']);
59+
$session->set('_security_' . $this->parameters['firewall_context'], serialize($token));
60+
$session->save();
61+
62+
$cookie = new Cookie($session->getName(), $session->getId());
63+
$this->client->getCookieJar()->set($cookie);
64+
65+
$this->user = $user;
66+
}
67+
68+
protected function tearDown()
69+
{
70+
$this->entityManager->rollback();
71+
parent::tearDown();
72+
73+
$this->entityManager->close();
74+
$this->entityManager = null;
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Tests\Controller;
4+
5+
use App\Tests\ComPassManWebTestCase;
6+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
7+
8+
class AccessEntryControllerTest extends WebTestCase
9+
{
10+
public function testIndex1()
11+
{
12+
$client = static::createClient();
13+
14+
$client->request('GET', '/access_entry/', [], [], [
15+
'PHP_AUTH_USER' => 'test',
16+
'PHP_AUTH_PW' => 'test',
17+
]);
18+
19+
$this->assertEquals(200, $client->getResponse()->getStatusCode());
20+
}
21+
22+
}

0 commit comments

Comments
 (0)