Completed
Push — v2.0.x ( 11273c...f488cd )
by Florent
04:53 queued 01:28
created

FlattenedTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 2
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\Test\TestCase;
15
16
/**
17
 * Class FlattenedTest.
18
 */
19
class FlattenedTest extends TestCase
20
{
21
    /**
22
     * @see https://tools.ietf.org/html/rfc7516#appendix-A.5
23
     */
24
    public function testLoadFlattenedJWE()
25
    {
26
        $decrypter = DecrypterFactory::createDecrypter(['A128KW', 'A128CBC-HS256'], ['DEF'], $this->getCheckers());
27
28
        $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"}');
29
30
        $this->assertInstanceOf('Jose\Object\JWEInterface', $loaded);
31
        $this->assertEquals('A128KW', $loaded->getRecipient(0)->getHeader('alg'));
32
        $this->assertEquals('A128CBC-HS256', $loaded->getSharedProtectedHeader('enc'));
33
        $this->assertNull($loaded->getPayload());
34
35
        $result = $decrypter->decryptUsingKeySet($loaded, $this->getSymmetricKeySet());
36
37
        $this->assertTrue($result);
38
        $this->assertEquals('Live long and prosper.', $loaded->getPayload());
39
    }
40
41
    /**
42
     * @see https://tools.ietf.org/html/rfc7516#appendix-A.5
43
     */
44
    public function testLoadFlattenedJWS()
45
    {
46
        $loaded = Loader::load('{"payload":"eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ","protected":"eyJhbGciOiJFUzI1NiJ9","header":{"kid":"e9bc097a-ce51-4036-9562-d2ade882db0d"},"signature":"DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q"}');
47
48
        $this->assertInstanceOf('Jose\Object\JWSInterface', $loaded);
49
        $this->assertEquals('ES256', $loaded->getSignature(0)->getProtectedHeader('alg'));
50
        $this->assertEquals(['iss' => 'joe', 'exp' => 1300819380, 'http://example.com/is_root' => true], $loaded->getPayload());
51
    }
52
}
53