1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace codecept\configuration; |
4
|
|
|
|
5
|
|
|
use codecept\ApiTester; |
6
|
|
|
use Codeception\Util\HttpCode; |
7
|
|
|
use SlayerBirden\DataFlowServer\Db\Entities\DbConfiguration; |
8
|
|
|
use SlayerBirden\DataFlowServer\Doctrine\Hydrator\Strategy\ObscuredStrategy; |
9
|
|
|
|
10
|
|
|
class AddConfigCest |
11
|
|
|
{ |
12
|
|
|
public function addConfiguration(ApiTester $I) |
13
|
|
|
{ |
14
|
|
|
$I->wantTo('create db configuration'); |
15
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
16
|
|
|
$I->sendPOST('/config', [ |
17
|
|
|
'title' => 'Test config', |
18
|
|
|
'url' => 'test_url', |
19
|
|
|
]); |
20
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
21
|
|
|
$I->seeResponseContainsJson([ |
22
|
|
|
'data' => [ |
23
|
|
|
'configuration' => [ |
24
|
|
|
'title' => 'Test config', |
25
|
|
|
'url' => 'test_url', |
26
|
|
|
] |
27
|
|
|
] |
28
|
|
|
]); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function addIncompleteConfig(ApiTester $I) |
32
|
|
|
{ |
33
|
|
|
$I->wantTo('create incomplete db configuration'); |
34
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
35
|
|
|
$I->sendPOST('/config', [ |
36
|
|
|
'title' => 'Test config', |
37
|
|
|
'dbname' => 'test', |
38
|
|
|
]); |
39
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function addCompleteNonUrlConfig(ApiTester $I) |
43
|
|
|
{ |
44
|
|
|
$I->wantTo('create complete non url db configuration'); |
45
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
46
|
|
|
$I->sendPOST('/config', [ |
47
|
|
|
'title' => 'Test config', |
48
|
|
|
'dbname' => 'test', |
49
|
|
|
'user' => 'test-user', |
50
|
|
|
'password' => 'test-pwd', |
51
|
|
|
'port' => '3306', |
52
|
|
|
'host' => 'localhost', |
53
|
|
|
'driver' => 'pdo_mysql' |
54
|
|
|
]); |
55
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
56
|
|
|
$I->seeResponseContainsJson([ |
57
|
|
|
'data' => [ |
58
|
|
|
'configuration' => [ |
59
|
|
|
'title' => 'Test config', |
60
|
|
|
'dbname' => 'test', |
61
|
|
|
'user' => 'test-user', |
62
|
|
|
'password' => ObscuredStrategy::OBSCURED_STRING, |
63
|
|
|
'port' => '3306', |
64
|
|
|
'host' => 'localhost', |
65
|
|
|
'driver' => 'pdo_mysql' |
66
|
|
|
] |
67
|
|
|
] |
68
|
|
|
]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function mutateExitingRecord(ApiTester $I): void |
72
|
|
|
{ |
73
|
|
|
$I->wantTo('attempt to mutate existing record by providing ID'); |
74
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
75
|
|
|
$I->sendPOST('/config', [ |
76
|
|
|
'title' => 'Test config', |
77
|
|
|
'url' => 'test_url', |
78
|
|
|
]); |
79
|
|
|
|
80
|
|
|
$entities = $I->grabEntitiesFromRepository(DbConfiguration::class); |
81
|
|
|
$lastId = (end($entities))->getId(); |
82
|
|
|
|
83
|
|
|
$I->sendPOST('/config', [ |
84
|
|
|
'id' => $lastId, |
85
|
|
|
'title' => 'Test config infected', |
86
|
|
|
'url' => 'test_url_compromised', |
87
|
|
|
]); |
88
|
|
|
|
89
|
|
|
$entities = $I->grabEntitiesFromRepository(DbConfiguration::class); |
90
|
|
|
$newLastId = (end($entities))->getId(); |
91
|
|
|
|
92
|
|
|
$I->assertNotEquals($lastId, $newLastId); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|