Passed
Push — master ( 36be2d...32b990 )
by Carlos
02:58
created

ClientCredentialsCest::accessTokenRequestInvalid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 15
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
use Codeception\Util\HttpCode;
4
use roaresearch\yii2\oauth2server\fixtures\OauthClientsFixture;
5
6
/**
7
 * @author Christopher CM <[email protected]>
8
 */
9
class ClientCredentialsCest
10
{
11
    public function fixtures(ApiTester $I): void
12
    {
13
        $I->haveFixtures([
14
            'clients' => OauthClientsFixture::class,
15
        ]);
16
    }
17
18
    /**
19
     * @depends fixtures
20
     */
21
    public function accessTokenRequestValid(ApiTester $I): void
22
    {
23
        $I->wantTo('Request a new access token.');
24
        $I->amHttpAuthenticated('testclient', 'testpass');
25
26
        $I->sendPOST('/oauth2/token', [
27
            'grant_type' => 'client_credentials',
28
        ]);
29
30
        $I->seeResponseCodeIs(HttpCode::OK);
31
        $I->seeResponseIsJson();
32
        $I->seeResponseMatchesJsonType([
33
            'access_token' => 'string:regex(/[0-9a-f]{40}/)',
34
        ]);
35
    }
36
37
    /**
38
     * @depends fixtures
39
     */
40
    public function accessTokenRequestInvalid(ApiTester $I): void
41
    {
42
        $I->wantTo('Request a new access token with invalid credentials.');
43
        $I->amHttpAuthenticated('testclient', 'wrongpass');
44
45
        $I->sendPOST('/oauth2/token', [
46
            'grant_type' => 'client_credentials',
47
        ]);
48
49
        $I->seeResponseCodeIs(HttpCode::BAD_REQUEST);
50
        $I->seeResponseIsJson();
51
52
        $I->seeResponseMatchesJsonType([
53
            'name' => 'string',
54
            'message' => 'string',
55
        ]);
56
    }
57
}
58