Completed
Push — develop ( b5844e...e46df6 )
by Florent
02:33
created

FlattenedTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
c 3
b 0
f 0
lcom 1
cbo 5
dl 0
loc 34
rs 10
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
use Jose\Factory\DecrypterFactory;
13
use Jose\Loader;
14
use Jose\Object\JWEInterface;
15
use Jose\Object\JWSInterface;
16
use Jose\Test\TestCase;
17
18
/**
19
 * Class FlattenedTest.
20
 *
21
 * @group Functional
22
 */
23
class FlattenedTest extends TestCase
24
{
25
    /**
26
     * @see https://tools.ietf.org/html/rfc7516#appendix-A.5
27
     */
28
    public function testLoadFlattenedJWE()
29
    {
30
        $decrypter = DecrypterFactory::createDecrypter(['A128KW', 'A128CBC-HS256'], ['DEF']);
31
32
        $loaded = Loader::load('{"protected":"eyJlbmMiOiJBMTI4Q0JDLUhTMjU2In0","unprotected":{"jku":"https://server.example.com/keys.jwks"},"header":{"alg":"A128KW","kid":"7"},"encrypted_key":"6KB707dM9YTIgHtLvtgWQ8mKwboJW3of9locizkDTHzBC2IlrT1oOQ","iv":"AxY8DCtDaGlsbGljb3RoZQ","ciphertext":"KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY","tag":"Mz-VPPyU4RlcuYv1IwIvzw"}');
33
34
        $this->assertInstanceOf(JWEInterface::class, $loaded);
35
        $this->assertEquals('A128KW', $loaded->getRecipient(0)->getHeader('alg'));
36
        $this->assertEquals('A128CBC-HS256', $loaded->getSharedProtectedHeader('enc'));
37
        $this->assertNull($loaded->getPayload());
38
39
        $decrypter->decryptUsingKeySet($loaded, $this->getSymmetricKeySet(), $index);
40
41
        $this->assertEquals(0, $index);
42
        $this->assertEquals('Live long and prosper.', $loaded->getPayload());
43
    }
44
45
    /**
46
     * @see https://tools.ietf.org/html/rfc7516#appendix-A.5
47
     */
48
    public function testLoadFlattenedJWS()
49
    {
50
        $loaded = Loader::load('{"payload":"eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ","protected":"eyJhbGciOiJFUzI1NiJ9","header":{"kid":"e9bc097a-ce51-4036-9562-d2ade882db0d"},"signature":"DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q"}');
51
52
        $this->assertInstanceOf(JWSInterface::class, $loaded);
53
        $this->assertEquals('ES256', $loaded->getSignature(0)->getProtectedHeader('alg'));
54
        $this->assertEquals(['iss' => 'joe', 'exp' => 1300819380, 'http://example.com/is_root' => true], $loaded->getPayload());
55
    }
56
}
57