mirror of https://github.com/MISP/MISP
new: [Warninglists] things are completely broken, need to start with TableTests
parent
37d332808b
commit
f76346df9b
|
@ -10,3 +10,6 @@
|
|||
[submodule "libraries/misp-taxonomies"]
|
||||
path = libraries/misp-taxonomies
|
||||
url = https://github.com/MISP/misp-taxonomies
|
||||
[submodule "libraries/misp-warninglists"]
|
||||
path = libraries/misp-warninglists
|
||||
url = https://github.com/MISP/misp-warninglists
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 2c7d29985ef77b568c0cfe3f035414db61f8b74c
|
|
@ -3,14 +3,18 @@ namespace App\Controller\Component\Navigation;
|
|||
|
||||
class NoticelistsNavigation extends BaseNavigation
|
||||
{
|
||||
function addRoutes()
|
||||
public function addRoutes()
|
||||
{
|
||||
$this->bcf->addRoute('Noticelists', 'update', [
|
||||
'label' => __('Update Noticelists'),
|
||||
'url' => '/noticelists/update',
|
||||
'icon' => 'circle-up',
|
||||
'isPOST' => true,
|
||||
]);
|
||||
$this->bcf->addRoute(
|
||||
'Noticelists',
|
||||
'update',
|
||||
[
|
||||
'label' => __('Update Noticelists'),
|
||||
'url' => '/noticelists/update',
|
||||
'icon' => 'circle-up',
|
||||
'isPOST' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function addActions()
|
||||
|
|
|
@ -64,7 +64,7 @@ $fields = [
|
|||
'type' => 'boolean',
|
||||
'pill' => true
|
||||
],
|
||||
|
||||
|
||||
];
|
||||
echo $this->element(
|
||||
'/genericElements/SingleViews/single_view',
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
echo $this->element(
|
||||
'genericElements/SingleViews/single_view',
|
||||
[
|
||||
'title' => __('Warninglist View'),
|
||||
'data' => $entity,
|
||||
'fields' => [
|
||||
[
|
||||
'key' => __('ID'),
|
||||
'path' => 'id'
|
||||
],
|
||||
[
|
||||
'key' => __('Name'),
|
||||
'path' => 'name'
|
||||
],
|
||||
[
|
||||
'key' => __('Description'),
|
||||
'path' => 'description'
|
||||
],
|
||||
[
|
||||
'key' => __('Version'),
|
||||
'path' => 'version'
|
||||
],
|
||||
[
|
||||
'key' => __('Category'),
|
||||
'path' => 'category',
|
||||
'function' => function (array|\App\Model\Entity\Warninglist $row) use ($possibleCategories) {
|
||||
return $possibleCategories[$row['category']];
|
||||
}
|
||||
],
|
||||
[
|
||||
'key' => __('Type'),
|
||||
'path' => 'type'
|
||||
],
|
||||
[
|
||||
'key' => __('Accepted attribute types'),
|
||||
'path' => 'type' // FIXME
|
||||
]
|
||||
],
|
||||
'children' => [
|
||||
[
|
||||
'url' => '/warninglists/preview_entries/{{0}}',
|
||||
'url_params' => ['id'],
|
||||
'title' => __('Values'),
|
||||
'elementId' => 'preview_entries_container'
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
// $types = implode(', ', array_column($warninglist['WarninglistType'], 'type'));
|
||||
// $table_data = [
|
||||
// ['key' => __('ID'), 'value' => $entity['id']],
|
||||
// ['key' => __('Name'), 'value' => $entity['name']],
|
||||
// ['key' => __('Description'), 'value' => $entity['description']],
|
||||
// ['key' => __('Version'), 'value' => $entity['version']],
|
||||
// ['key' => __('Category'), 'value' => $possibleCategories[$entity['category']]],
|
||||
// ['key' => __('Type'), 'value' => $entity['type']],
|
||||
// ['key' => __('Accepted attribute types'), 'value' => $types],
|
||||
// [
|
||||
// 'key' => __('Enabled'),
|
||||
// 'boolean' => $entity['enabled'],
|
||||
// 'html' => $me['Role']['perm_warninglist'] ? sprintf(
|
||||
// ' <a href="%s/warninglists/enableWarninglist/%s%s" title="%s">%s</a>',
|
||||
// $baseurl,
|
||||
// h($warninglist['Warninglist']['id']),
|
||||
// $entity['enabled'] ? '' : '/1',
|
||||
// $entity['enabled'] ? __('Disable') : __('Enable'),
|
||||
// $entity['enabled'] ? __('Disable') : __('Enable')
|
||||
// ) : '',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// $values = [];
|
||||
// foreach ($warninglist['WarninglistEntry'] as $entry) {
|
||||
// $value = '<span class="warninglist-value">' . h($entry['value']) . '</span>';
|
||||
// if ($entry['comment']) {
|
||||
// $value .= ' <span class="warninglist-comment"># ' . h($entry['comment']) . '</span>';
|
||||
// }
|
||||
// $values[] = $value;
|
||||
// }
|
||||
|
||||
// echo '<div class="warninglist view">';
|
||||
// echo sprintf(
|
||||
// '<div class="row-fluid"><div class="span8" style="margin:0;">%s</div></div><h4>%s</h4>',
|
||||
// sprintf(
|
||||
// '<h2>%s</h2>%s',
|
||||
// h($warninglist['Warninglist']['name']),
|
||||
// $this->element('genericElements/viewMetaTable', ['table_data' => $table_data])
|
||||
// ),
|
||||
// __('Values')
|
||||
// );
|
||||
// echo implode('<br>', $values);
|
||||
// echo '</div>';
|
||||
// echo $this->element(
|
||||
// '/genericElements/SideMenu/side_menu',
|
||||
// [
|
||||
// 'menuList' => 'warninglist',
|
||||
// 'menuItem' => 'view',
|
||||
// 'id' => $entity['id'],
|
||||
// 'isDefault' => $entity['default'] == 1,
|
||||
// ]
|
||||
// );
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Model\Table;
|
||||
|
||||
use App\Model\Table\WarninglistsTable;
|
||||
use App\Test\Fixture\OrganisationsFixture;
|
||||
use App\Test\Fixture\UsersFixture;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* App\Model\Table\WarninglistsTable Test Case
|
||||
*/
|
||||
class WarninglistsTableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var \App\Model\Table\WarninglistsTable
|
||||
*/
|
||||
protected $Warninglists;
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fixtures = [
|
||||
'app.Warninglists',
|
||||
'app.WarninglistEntries',
|
||||
'app.Users',
|
||||
'app.Organisations',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$config = $this->getTableLocator()->exists('Warninglists') ? [] : ['className' => WarninglistsTable::class];
|
||||
$this->Warninglists = $this->getTableLocator()->get('Warninglists', $config);
|
||||
|
||||
$this->user = [
|
||||
'id' => UsersFixture::USER_REGULAR_USER_ID,
|
||||
'org_id' => OrganisationsFixture::ORGANISATION_A_ID,
|
||||
'email' => UsersFixture::USER_REGULAR_USER_EMAIL,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->Warninglists);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test initialize method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInitialize(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidationDefault(): void
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
|
||||
public function testParseFreetext(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$items = [];
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$items[] = $faker->domainName() . " #" . $faker->sentence();
|
||||
}
|
||||
$items[] = ""; // empty to verify trim
|
||||
$items[] = " # "; // empty to verify trim
|
||||
$freetext = implode("\n", $items);
|
||||
$result = WarninglistsTable::parseFreetext($freetext);
|
||||
$this->assertEquals(count($result), 10);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue