parent
e947ac63b5
commit
673bfc7477
@ -0,0 +1,54 @@ |
||||
-----BEGIN RSA PRIVATE KEY----- |
||||
Proc-Type: 4,ENCRYPTED |
||||
DEK-Info: AES-256-CBC,1D5840ABD70AE2EC6C39CE34371077B4 |
||||
|
||||
PMEyq3rbj/MhAsgmMwH7RQg+XJFCimnDxi8rQz9Y8cc2Ew193FOLBd19s6UUv4mT |
||||
KLxALDIicIEvOsHcL6GX181a9k0lUD2o6CjFOa6289J9KJjR2S25RJB9t3ucWLXz |
||||
kYMwVst43WIy8y2aLOICh9+fzxFjDyBNSue4NYThYWPyWI4jx+BaH6fUN67aSBqC |
||||
gDK0gXKWB3ES3viUF8JT6CVOPth5ikm7Ec0tAdFO/RyOT1sc3sl7ZYMk0li1ZH0b |
||||
/w12NkWSwgZ/Aa2nJttDiYPy7P4ulCyIdOPb83QnRK1FTwDg4ArzDW63DNhA9I50 |
||||
SrzCC6owasGxABK93Rl6+60HsBcuvUFurlTO359JCFuLxneLRCV85xf5b69Gkmhs |
||||
nkZ4Jgl94EVwm9SMU6whAxl78t/EEo3IW2NtzQApz3Ug0MZe3O3+SKkDVHmHFEw2 |
||||
4x1WddluM3H0tAeqHdSG6wlzvR68RAkF4MlNQmUvIVtqHOHhmrycyB/ZVIGrgIgG |
||||
HzMsAiLhxPG98RgbwJA3iDYK8fVahAZOccc20MZWrGYJb7xntMlhdsvh+uV3+Jk+ |
||||
IF6ROPIKOEgE7fZv+abgfNmxkypOwFxkfCdEW+bMQajQ+eUET/CghxpPJN7TKBZB |
||||
8jJOdTpk4Oo/xkDsgRb+Pfcgy215cVpKyt4PdCEIWB2km84I8Pbx0xJCb6fsFzpN |
||||
gHZi2ScR0+5BXJHc3d+LUo1IvVWbIjURR7ePmRyXbRLAqIXlDLsH1/o0yGgvJTJg |
||||
eBMqSFn4htg6IOrIMd+rxQbD5nmotNyZTpNylgm53Nu3VqH42BoRfelQ5m0Kv6oQ |
||||
nlWrT1QtzewK5NOaBsnh51mtxYcjM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z3qHPIHmupaUHraqqpFQIN98KDSsab92Xj9WnSftRN4wOVoL |
||||
PERb5DbCLf6Z6IgCM/2NDMbs0mSOMjJgF3mzXZFfRKqodku32kX4FhkczvB0J6xF |
||||
FD5AVx/IEfDSIhDC/V2W6aKmB69oCzK+MA3oZP//U3XKePAjM67RGmoV6z05EV0h |
||||
BDRQ6O51VY/c8g/cUme2N4Uo+HPRmBb3CyFV1x78ZYFG9XvclsIKfBtk5E64E7qA |
||||
9nr/huUKXB4UEOQiLYWXxOiEMmipJnQut+AS4yMiwJybmiF9B38zNO3MPzgd+mBD |
||||
-----END RSA PRIVATE KEY----- |
@ -0,0 +1,14 @@ |
||||
-----BEGIN PUBLIC KEY----- |
||||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqLjExtq7xWdyCQaRUZCx |
||||
3pS7vRZlqMdVPv/4kDB1zgVRIEfPIjKA9iwQNS/R3CYLg6m69TBRPpedujEWyeVm |
||||
/YGrTG2o7V9Pf95qnL73fR00fOtlTsc30y2BN1HG5HHe5hwwk1dZRrVyPu9n0Hib |
||||
36en+A/ZKhtL7Ikrrxwh7SYxfNVx902DabhrZSuJhocIZvQlL3Ci9MueGAPGMSy8 |
||||
MnY+J4XDmxb1c2DaLn7Bo/sWRZ9+j+H4uJwEjM/+duVFjWMekvflarePcMUB+rmy |
||||
qiS/8cp4/ak2gCmg8eCx5FK5EO5IaE++Q7aI4F12c13mHi9BnN6B1/nHnLX78672 |
||||
9sjvgKWvjn1vcxBmyQERR3Ja4IbC/CZ8d+5nI4Oo9pvo53zsHVVh3PWlQxu753Yy |
||||
9aeaesHN3Cn5ZIdhWdCA7j3X+vlkALa1m6YBFlftStfQutiKr1OE4VFhvyenhTrz |
||||
sFO0tkDtUsCzIxd6wJxTVujkikd1ybkGD8KFXBsTv6d3L90wScSRHyAR7wbmgZWK |
||||
s6do8M+mvd+MMFZk+vBDSBo9ER7OvblqfcsOONr+OA3DlDimsmfggkzvXzeY3qG8 |
||||
sBmF1IFycy/W+sl8m2/m2+OR+SFu0vFg2fgkAYQWIQaCkmJhxz9WEqbnXveDoajR |
||||
JuQr1AtxAWiggPbVJLKJbLECAwEAAQ== |
||||
-----END PUBLIC KEY----- |
@ -0,0 +1,5 @@ |
||||
lexik_jwt_authentication: |
||||
secret_key: '%kernel.project_dir%/config/jwt-test/private-test.pem' |
||||
public_key: '%kernel.project_dir%/config/jwt-test/public-test.pem' |
||||
pass_phrase: 'test' |
||||
token_ttl: 3600 |
@ -0,0 +1,83 @@ |
||||
<?php |
||||
namespace Chamilo\Tests; |
||||
|
||||
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase; |
||||
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client; |
||||
use Hautelook\AliceBundle\PhpUnit\RefreshDatabaseTrait; |
||||
|
||||
abstract class AbstractApiTest extends ApiTestCase |
||||
{ |
||||
private $token; |
||||
private $clientWithCredentials; |
||||
|
||||
//use RefreshDatabaseTrait; |
||||
|
||||
public function setUp(): void |
||||
{ |
||||
self::bootKernel(); |
||||
} |
||||
|
||||
protected function getClientWithGuiCredentials($username, $password): Client |
||||
{ |
||||
$params = [ |
||||
'username' => $username, |
||||
'password' => $password, |
||||
]; |
||||
|
||||
$response = static::createClient()->request( |
||||
'POST', |
||||
'/api/authentication_token', |
||||
[ |
||||
'headers' => ['Content-Type' => 'application/json'], |
||||
'body' => json_encode($params), |
||||
] |
||||
); |
||||
|
||||
$this->assertResponseIsSuccessful(); |
||||
$data = json_decode($response->getContent()); |
||||
//$this->token = $data->access_token; |
||||
|
||||
$this->assertEquals('admin', $data->username); |
||||
|
||||
return $response; |
||||
} |
||||
|
||||
protected function createClientWithCredentials($token = null): Client |
||||
{ |
||||
$token = $token ?: $this->getToken(); |
||||
|
||||
return static::createClient([], ['headers' => ['authorization' => 'Bearer '.$token]]); |
||||
} |
||||
|
||||
/** |
||||
* Use credentials with token. |
||||
*/ |
||||
protected function getToken($body = []): string |
||||
{ |
||||
if ($this->token) { |
||||
return $this->token; |
||||
} |
||||
|
||||
$response = static::createClient()->request( |
||||
'POST', |
||||
'/api/authentication_token', |
||||
[ |
||||
/*'body' => $body ?: [ |
||||
'username' => 'admin', |
||||
'password' => 'admin', |
||||
],*/ |
||||
'headers' => ['Content-Type' => 'application/json'], |
||||
'body' => json_encode([ |
||||
'username' => 'admin', |
||||
'password' => 'admin', |
||||
]) |
||||
], |
||||
); |
||||
|
||||
$this->assertResponseIsSuccessful(); |
||||
$data = json_decode($response->getContent()); |
||||
$this->token = $data->token; |
||||
|
||||
return $data->token; |
||||
} |
||||
} |
@ -0,0 +1,93 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\Tests\CourseBundle\Repository; |
||||
|
||||
use Chamilo\CoreBundle\Entity\AccessUrl; |
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository; |
||||
use Chamilo\CoreBundle\Repository\Node\CourseRepository; |
||||
use Chamilo\CoreBundle\Repository\Node\UserRepository; |
||||
use Chamilo\CourseBundle\Entity\CDocument; |
||||
use Chamilo\Tests\AbstractApiTest; |
||||
|
||||
class CDocumentRepositoryTest extends AbstractApiTest |
||||
{ |
||||
/*public function testLoginAsUserWithToken() |
||||
{ |
||||
|
||||
$this->createClientWithCredentials($token)->request('GET', '/account/edit'); |
||||
$this->assertResponseStatusCodeSame('200'); |
||||
}*/ |
||||
|
||||
public function testGetDocuments() |
||||
{ |
||||
$token = $this->getToken([]); |
||||
$response = $this->createClientWithCredentials($token)->request('GET', '/api/documents'); |
||||
$this->assertResponseIsSuccessful(); |
||||
|
||||
// Asserts that the returned content type is JSON-LD (the default) |
||||
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); |
||||
|
||||
// Asserts that the returned JSON is a superset of this one |
||||
$this->assertJsonContains([ |
||||
'@context' => '/api/contexts/Documents', |
||||
'@id' => '/api/documents', |
||||
'@type' => 'hydra:Collection', |
||||
'hydra:totalItems' => 0, |
||||
/*'hydra:view' => [ |
||||
'@id' => '/api/documents?page=1', |
||||
'@type' => 'hydra:PartialCollectionView', |
||||
],*/ |
||||
]); |
||||
|
||||
$this->assertCount(0, $response->toArray()['hydra:member']); |
||||
$this->assertMatchesResourceCollectionJsonSchema(CDocument::class); |
||||
} |
||||
|
||||
public function testCreateFolder(): void |
||||
{ |
||||
$userRepository = self::getContainer()->get(UserRepository::class); |
||||
$urlRepo = self::getContainer()->get(AccessUrlRepository::class); |
||||
$courseRepo = self::getContainer()->get(CourseRepository::class); |
||||
|
||||
// Get admin. |
||||
$admin = $userRepository->findByUsername('admin'); |
||||
// Get access url. |
||||
$accessUrl = $urlRepo->findOneBy(['url' => AccessUrl::DEFAULT_ACCESS_URL]); |
||||
|
||||
// Create course. @todo move in a function? |
||||
$course = (new Course()) |
||||
->setTitle('Test course') |
||||
->setCode('test_course') |
||||
->addAccessUrl($accessUrl) |
||||
->setCreator($admin) |
||||
; |
||||
$courseRepo->create($course); |
||||
|
||||
// Create folder. |
||||
$resourceLinkList = [ |
||||
'cid' => $course->getId(), |
||||
'visibility' => 2, |
||||
]; |
||||
|
||||
$token = $this->getToken([]); |
||||
$response = $this->createClientWithCredentials($token)->request( |
||||
'POST', |
||||
'/api/documents', |
||||
[ |
||||
'json' => [ |
||||
'title' => 'folder1', |
||||
'parentResourceNodeId' => $course->getResourceNode()->getId(), |
||||
'resourceLinkList' => json_encode($resourceLinkList), |
||||
], |
||||
] |
||||
); |
||||
|
||||
$this->assertResponseIsSuccessful(); |
||||
|
||||
$this->assertResponseStatusCodeSame(201); |
||||
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); |
||||
} |
||||
} |
@ -1,8 +0,0 @@ |
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
||||
<head> |
||||
</head> |
||||
<body> |
||||
<br /> |
||||
</body> |
||||
</html> |
Loading…
Reference in new issue