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
|
|
|
'success' => true, |
23
|
|
|
'data' => [ |
24
|
|
|
'configuration' => [ |
25
|
|
|
'title' => 'Test config', |
26
|
|
|
'url' => 'test_url', |
27
|
|
|
] |
28
|
|
|
] |
29
|
|
|
]); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function addIncompleteConfig(ApiTester $I) |
33
|
|
|
{ |
34
|
|
|
$I->wantTo('create incomplete db configuration'); |
35
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
36
|
|
|
$I->sendPOST('/config', [ |
37
|
|
|
'title' => 'Test config', |
38
|
|
|
'dbname' => 'test', |
39
|
|
|
]); |
40
|
|
|
$I->seeResponseCodeIs(HttpCode::BAD_REQUEST); |
41
|
|
|
$I->seeResponseContainsJson([ |
42
|
|
|
'success' => false, |
43
|
|
|
'data' => [ |
44
|
|
|
'validation' => [ |
45
|
|
|
[ |
46
|
|
|
'field' => 'user', |
47
|
|
|
] |
48
|
|
|
] |
49
|
|
|
] |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function addCompleteNonUrlConfig(ApiTester $I) |
54
|
|
|
{ |
55
|
|
|
$I->wantTo('create incomplete db configuration'); |
56
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
57
|
|
|
$I->sendPOST('/config', [ |
58
|
|
|
'title' => 'Test config', |
59
|
|
|
'dbname' => 'test', |
60
|
|
|
'user' => 'test-user', |
61
|
|
|
'password' => 'test-pwd', |
62
|
|
|
'port' => '3306', |
63
|
|
|
'host' => 'localhost', |
64
|
|
|
'driver' => 'pdo_mysql' |
65
|
|
|
]); |
66
|
|
|
$I->seeResponseCodeIs(HttpCode::OK); |
67
|
|
|
$I->seeResponseContainsJson([ |
68
|
|
|
'success' => true, |
69
|
|
|
'data' => [ |
70
|
|
|
'configuration' => [ |
71
|
|
|
'title' => 'Test config', |
72
|
|
|
'dbname' => 'test', |
73
|
|
|
'user' => 'test-user', |
74
|
|
|
'password' => ObscuredStrategy::OBSCURED_STRING, |
75
|
|
|
'port' => '3306', |
76
|
|
|
'host' => 'localhost', |
77
|
|
|
'driver' => 'pdo_mysql' |
78
|
|
|
] |
79
|
|
|
] |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function mutateExitingRecord(ApiTester $I): void |
84
|
|
|
{ |
85
|
|
|
$I->wantTo('attempt to mutate existing record by providing ID'); |
86
|
|
|
$I->haveHttpHeader('Content-Type', 'application/json'); |
87
|
|
|
$I->sendPOST('/config', [ |
88
|
|
|
'title' => 'Test config', |
89
|
|
|
'url' => 'test_url', |
90
|
|
|
]); |
91
|
|
|
|
92
|
|
|
$entities = $I->grabEntitiesFromRepository(DbConfiguration::class); |
93
|
|
|
$lastId = (end($entities))->getId(); |
94
|
|
|
|
95
|
|
|
$I->sendPOST('/config', [ |
96
|
|
|
'id' => $lastId, |
97
|
|
|
'title' => 'Test config infected', |
98
|
|
|
'url' => 'test_url_compromised', |
99
|
|
|
]); |
100
|
|
|
|
101
|
|
|
$entities = $I->grabEntitiesFromRepository(DbConfiguration::class); |
102
|
|
|
$newLastId = (end($entities))->getId(); |
103
|
|
|
|
104
|
|
|
$I->assertNotEquals($lastId, $newLastId); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|