-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
508 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: "Run Tests" | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'src/**' | ||
- 'tests/**' | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
env: | ||
APP_ENV: test | ||
|
||
jobs: | ||
tests: | ||
name: "Tests" | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: "Checkout" | ||
uses: "actions/checkout@v3" | ||
|
||
- name: "Install PHP" | ||
uses: "shivammathur/setup-php@v2" | ||
with: | ||
coverage: "none" | ||
extensions: "intl, zip, redis" | ||
php-version: "8.1" | ||
tools: composer | ||
|
||
- name: "Install dependencies" | ||
uses: "ramsey/composer-install@v2" | ||
with: | ||
composer-options: "--ansi --no-interaction" | ||
|
||
- name: Start Redis | ||
uses: supercharge/[email protected] | ||
with: | ||
redis-version: 6 | ||
|
||
- name: "Run tests" | ||
run: "composer tests" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packeton\Tests\Functional\Controller; | ||
|
||
use Packeton\Tests\Phpunit\PacketonTestTrait; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
class BaseAclControllerTest extends WebTestCase | ||
{ | ||
use PacketonTestTrait; | ||
|
||
#[DataProvider('aclUserUrlProvider')] | ||
public function testACLAccess(string $user, string $url, int $code): void | ||
{ | ||
$client = static::createClient(); | ||
|
||
$user = $this->getUser($user); | ||
$client->loginUser($user); | ||
|
||
$client->request('GET', $url); | ||
static::assertResponseStatusCodeSame($code); | ||
} | ||
|
||
#[DataProvider('adminUrlProvider')] | ||
public function testAdminAccess(string $url): void | ||
{ | ||
$client = static::createClient(); | ||
|
||
$admin = $this->getUser('admin'); | ||
|
||
$client->loginUser($admin); | ||
|
||
$client->request('GET', $url); | ||
static::assertResponseIsSuccessful(); | ||
} | ||
|
||
public function testAnonymousAccess(): void | ||
{ | ||
$client = static::createClient(); | ||
$client->request('GET', '/'); | ||
static::assertResponseRedirects(); | ||
} | ||
|
||
public static function aclUserUrlProvider(): array | ||
{ | ||
return [ | ||
['dev', '/', 200], | ||
['dev', '/', 200], | ||
['dev', '/packages/okvpn/cron-bundle', 200], | ||
['dev', '/packages/okvpn/satis-api', 200], | ||
['dev', '/packages/okvpn/cron-bundle/stats', 200], | ||
['dev', '/packages/submit', 200], | ||
['dev', '/groups', 403], | ||
|
||
['user1', '/', 200], | ||
['user1', '/profile', 200], | ||
['user1', '/packages/okvpn/cron-bundle', 200], | ||
['user1', '/packages/okvpn/satis-api', 404], | ||
['user1', '/about', 403], | ||
|
||
['user2', '/packages/okvpn/satis-api', 200], | ||
]; | ||
} | ||
|
||
public static function adminUrlProvider(): array | ||
{ | ||
return [ | ||
['/'], | ||
['/packages/okvpn/cron-bundle'], | ||
['/packages/okvpn/cron-bundle/stats'], | ||
['/packages/submit'], | ||
['/users/'], | ||
['/users/dev'], | ||
['/users/dev/update'], | ||
['/groups'], | ||
['/groups/1/update'], | ||
['/users/sshkey'], | ||
['/profile'], | ||
['/statistics'], | ||
['/explore'], | ||
['/about'], | ||
['/users/admin/packages'], | ||
['/users/admin/favorites'], | ||
['/apidoc'], | ||
['/proxies'], | ||
['/feeds/'], | ||
['/feeds/releases.rss'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace Packeton\Tests\Functional\Controller; | ||
|
||
use Packeton\Tests\Phpunit\PacketonTestTrait; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
class ProviderControllerTest extends WebTestCase | ||
{ | ||
use PacketonTestTrait; | ||
|
||
public function testRootPackages(): void | ||
{ | ||
$client = static::createClient(); | ||
|
||
$client->request('GET', '/packages.json'); | ||
static::assertResponseStatusCodeSame(401); | ||
|
||
$this->basicLogin('admin', $client); | ||
$client->request('GET', '/packages.json'); | ||
static::assertResponseStatusCodeSame(200);; | ||
} | ||
|
||
#[DataProvider('aclUserProvider')] | ||
public function testAvailablePackages(string $user, int $count): void | ||
{ | ||
$client = static::createClient(); | ||
|
||
$this->basicLogin($user, $client); | ||
$client->request('GET', '/packages.json'); | ||
|
||
$content = $this->getJsonResponse($client); | ||
static::assertCount($count, $content['available-packages']); | ||
} | ||
|
||
public function testV2Packages(): void | ||
{ | ||
$client = static::createClient(); | ||
|
||
$this->basicLogin('admin', $client); | ||
|
||
$client->request('GET', '/p2/okvpn/cron-bundle.json'); | ||
$content = $this->getJsonResponse($client); | ||
static::assertNotEmpty($content['packages']['okvpn/cron-bundle']); | ||
|
||
$client->request('GET', '/p2/okvpn/cron-bundle~dev.json'); | ||
$content = $this->getJsonResponse($client); | ||
static::assertNotEmpty($content['packages']['okvpn/cron-bundle']); | ||
|
||
$client->request('GET', '/p2/okvpn/cron-bundle222.json'); | ||
static::assertResponseStatusCodeSame(404); | ||
} | ||
|
||
public function testV2CustomerPackages(): void | ||
{ | ||
$client = static::createClient(); | ||
|
||
$this->basicLogin('user1', $client); | ||
|
||
$client->request('GET', '/p2/okvpn/cron-bundle.json'); | ||
$content = $this->getJsonResponse($client); | ||
static::assertNotEmpty($content['packages']['okvpn/cron-bundle']); | ||
|
||
$client->request('GET', '/p2/okvpn/cron-bundle~dev.json'); | ||
$content = $this->getJsonResponse($client); | ||
static::assertNotEmpty($content['packages']['okvpn/cron-bundle']); | ||
|
||
$client->request('GET', '/p2/okvpn/satis-api.json'); | ||
static::assertResponseStatusCodeSame(404); | ||
} | ||
|
||
public function testProviderIncludesV1(): void | ||
{ | ||
$client = static::createClient(); | ||
|
||
$this->basicLogin('admin', $client); | ||
|
||
$server = ['HTTP_USER_AGENT' => 'Composer/1.10.2 (Windows NT; 10.0; PHP 8.1.0)']; | ||
$client->request('GET', '/packages.json', server: $server); | ||
$content = $this->getJsonResponse($client); | ||
static::assertNotEmpty($content['provider-includes']); | ||
|
||
$hash = reset($content['provider-includes'])['sha256']; | ||
$client->request('GET', "/p/providers$$hash.json", server: $server); | ||
static::assertEquals($hash, hash('sha256', $client->getResponse()->getContent())); | ||
|
||
$content = $this->getJsonResponse($client); | ||
static::assertNotEmpty($content['providers']); | ||
|
||
$hash = $content['providers']['okvpn/cron-bundle']['sha256']; | ||
$client->request('GET', "/p/okvpn/cron-bundle$$hash.json", server: $server); | ||
static::assertEquals($hash, hash('sha256', $client->getResponse()->getContent())); | ||
|
||
$content = $this->getJsonResponse($client); | ||
static::assertNotEmpty($content['packages']); | ||
static::assertNotEmpty($content['packages']['okvpn/cron-bundle']); | ||
$versions = array_column($content['packages']['okvpn/cron-bundle'], 'version_normalized'); | ||
static::assertTrue(in_array('9999999-dev', $versions)); | ||
} | ||
|
||
public static function aclUserProvider(): array | ||
{ | ||
return [ | ||
['admin', 3], | ||
['dev', 3], | ||
['user1', 1], | ||
['user2', 3], | ||
]; | ||
} | ||
} |
Oops, something went wrong.