server/src/tests/Libraries/Handle/HandleClientTest.php
changeset 153 338bcc78d431
child 326 226d5b17a119
equal deleted inserted replaced
152:dd6b3adde73b 153:338bcc78d431
       
     1 <?php
       
     2 
       
     3 use Illuminate\Foundation\Testing\WithoutMiddleware;
       
     4 use Illuminate\Foundation\Testing\DatabaseMigrations;
       
     5 use Illuminate\Foundation\Testing\DatabaseTransactions;
       
     6 
       
     7 use GuzzleHttp\Client;
       
     8 use GuzzleHttp\Middleware;
       
     9 use GuzzleHttp\Handler\MockHandler;
       
    10 use GuzzleHttp\HandlerStack;
       
    11 use GuzzleHttp\Psr7\Response;
       
    12 use GuzzleHttp\Psr7\Request;
       
    13 use GuzzleHttp\Exception\RequestException;
       
    14 
       
    15 use CorpusParole\Libraries\Handle\HandleClient;
       
    16 
       
    17 class HandleClientTest extends TestCase
       
    18 {
       
    19     const CERT_PEM = <<<EOT
       
    20 -----BEGIN PRIVATE KEY-----
       
    21 MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDxemvFVLJTkXl65rTnzSPLtJaP
       
    22 NacGD/SYxnhE1l98F6lj/JQaEH094GWGsCWf41XkZOZYMAZEGIDqdmr6vZjhW7zNjGXCA83PMb+r
       
    23 p/BOHuq+O5OQaHy9kI2kbNgfqbm+IzP9vrxTXmsVh4N/mCtfygq/uw8S0z0T5G1O9VoJ3mfBQ6dK
       
    24 fjqUlHtcp2JPt8gDJQ0a8npQysFOeuX+cVV/KW+M1o53xzIOlufudD0dHV9AK9o/4NHQpCgG0Izl
       
    25 6vcpNqRvotzEov03ID586gUw744ViLPqtOvxM54ac6X2ZKjjwhzGPFL6/A/BqPKQg2xExMbRxquN
       
    26 E50MZFSL7AVNAgMBAAECggEBAIgWXAIbl1wtUe8HcdBo9dFpdqhCrlxmRYyL3V++CJXgp9/nined
       
    27 71cdzVm4j5up/M/4ZTAx8HYT8SMxlVy12SC4GJEmnHpYtnYcLU7KGE2OcvC+loz9tb8HZivSA4Lk
       
    28 nf8fy78m7O92+JZrhpoz4c3cCW7ANuB/F57MTyX+c7229zEsiALhURc3Vib6rWUfq3AJBWOEYKoa
       
    29 SLLQozi8UJoFODXwC9LDMaxgioNSaU+aj0W0haR/31HRvMQt+Zy1aYYAeuWHT940D6Wgp38ZLMqd
       
    30 uj22EY64WhcVfv8lQbIb6jOoZqMIj9erGfWlbGlVxoMhUTGQi0sKmyjFBvClwgECgYEA/Am+vCOf
       
    31 WbHKvGd8G8zWk1VRHpJg4huxqn/i18OuYWdojXgfC/HDR4JKIbl/XP+r0HSudTg4vrusZYGrMGZR
       
    32 rD82tPDTj24cAI+mfsSNInm6VE4v3eMlEkAcPvqo+qgV5FXU1qFMW5c02vTqOyC/Swjr4YRkP/H7
       
    33 XhI8T+C6zkECgYEA9UYuSH4ZOehYEDtSXYK4R5NjhjM38a/bulJ8rUBZ8vtA1UACAkoGYXbPukzE
       
    34 GkEnihuFFDtW7KEY35q2ATj5zV1n1Eh3kfJ7TURl0hNva63jf/uNIXbS0JaFBh8/0N0tkJYrwCOH
       
    35 aKjAcaMs6OEMuqiLeJX/lpGdCLy+bdikjA0CgYEAjb0NPtDptI9/7CRmb1vq8EBytjartXzNlY0G
       
    36 DUFGuBBng+ehzh3QLE7hUcX4ElzWSwzTb6iGgP0aHpulojpog+2o3mjxESBjLw2aHIB8vn6mgvLV
       
    37 iHtNRc44FFLy5MPSS+7ZGzrqrjeCygAiGc54xcHmpZTGrA9xxZ2LvYAsjgECgYBHpKtKQ4MM1iA7
       
    38 BYjmhZNcXOH6RiW2M/8Dqqp+VMixX9CtOZgcoRDCEVlV+qxhWty4y5cQtNCMJ/ZDAkbdjo3w/bKh
       
    39 YFWEzQZVKIBxX3nxQwar0IeF2dZ0VTMf+arDUIfJrwOyiO45lOk5iEdK8smsECVFINNaYMg00CTz
       
    40 ow9VVQKBgFDCVC97xsu5lOl6nd9mSu2GL+6hzpWPIZDD2SwMs6Vkkj33UhqyqziCOFKmRTF5oON+
       
    41 ew2EGVPukWZsYXNH0KLwdJ7q0QKEONGPMxVNURkHR9cJ8ScaZkiZ6Zh0MT3S3kTak+A5pzo3eS4H
       
    42 LhgZ72DZ0ABBEGoMfaVh8fJHZKcm
       
    43 -----END PRIVATE KEY-----
       
    44 -----BEGIN CERTIFICATE-----
       
    45 MIIDVTCCAj2gAwIBAgIJAMa/cIGB8QEVMA0GCSqGSIb3DQEBCwUAMCUxIzAhBgNV
       
    46 BAMUGjMwMDoxMTI4MC4xMDAvQ09SUFVTX0FETUlOMB4XDTE2MDQxODEyMDg1M1oX
       
    47 DTE2MDUxODEyMDg1M1owJTEjMCEGA1UEAxQaMzAwOjExMjgwLjEwMC9DT1JQVVNf
       
    48 QURNSU4wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDxemvFVLJTkXl6
       
    49 5rTnzSPLtJaPNacGD/SYxnhE1l98F6lj/JQaEH094GWGsCWf41XkZOZYMAZEGIDq
       
    50 dmr6vZjhW7zNjGXCA83PMb+rp/BOHuq+O5OQaHy9kI2kbNgfqbm+IzP9vrxTXmsV
       
    51 h4N/mCtfygq/uw8S0z0T5G1O9VoJ3mfBQ6dKfjqUlHtcp2JPt8gDJQ0a8npQysFO
       
    52 euX+cVV/KW+M1o53xzIOlufudD0dHV9AK9o/4NHQpCgG0Izl6vcpNqRvotzEov03
       
    53 ID586gUw744ViLPqtOvxM54ac6X2ZKjjwhzGPFL6/A/BqPKQg2xExMbRxquNE50M
       
    54 ZFSL7AVNAgMBAAGjgYcwgYQwHQYDVR0OBBYEFLycwnSTnQGcssXGrj8TGn2rSAgD
       
    55 MFUGA1UdIwROMEyAFLycwnSTnQGcssXGrj8TGn2rSAgDoSmkJzAlMSMwIQYDVQQD
       
    56 FBozMDA6MTEyODAuMTAwL0NPUlBVU19BRE1JToIJAMa/cIGB8QEVMAwGA1UdEwQF
       
    57 MAMBAf8wDQYJKoZIhvcNAQELBQADggEBAGcQGNpACyRBwBQ/iXy7RxLSGdhvbGmh
       
    58 bikNjBYJVAnYSZjIY2keF1BnhJvaqWHiixoeXC0J9gmN+caZ/WcCyW7xie7fBbn2
       
    59 FYYJDUj1ik4hD7Cptvd+YwNu2ZjGOKoOqVghGaZSL5cWcfYNYfwv3gQVj05CG6oq
       
    60 pHHeD5QJw/o/2LYJuFRymPA2AG96mjUSH2gCsqnSxPudfJYVVzjlkWbehIt8ss8l
       
    61 SdSJqhGvvC5G6x9WhVC3qw56n65+g1FIbhFCXddG/1WGmSfmE8hwlvaOoYgynQGD
       
    62 BNpIg6V6Mo5EZWnBOuyK26xy4BgXiQCdJPejLGmmzSAUXNAQx47R7VI=
       
    63 -----END CERTIFICATE-----
       
    64 EOT;
       
    65 
       
    66     const DSA_PEM = <<<EOT
       
    67 -----BEGIN PRIVATE KEY-----
       
    68 MIICXAIBADCCAjUGByqGSM44BAEwggIoAoIBAQCPeTXZuarpv6vtiHrPSVG28y7FnjuvNxjo6sSW
       
    69 Hz79NgbnQ1GpxBgzObgJ58KuHFObp0dbhdARrbi0eYd1SYRpXKwOjxSzNggooi/6JxEKPWKpk0U0
       
    70 CaD+aWxGWPhL3SCBnDcJoBBXsZWtzQAjPbpUhLYpH51kjviDRIZ3l5zsBLQ0pqwudemYXeI9sCkv
       
    71 wRGMn/qdgYHnM423krcw17njSVkvaAmYchU5Feo9a4tGU8YzRY+AOzKkwuDycpAlbk4/ijsIOKHE
       
    72 UOThjBopo33fXqFD3ktm/wSQPtXPFiPhWNSHxgjpfyEc2B3KI8tuOAdl+CLjQr5ITAV2OTlgHNZn
       
    73 Ah0AuvaWpoV499/e5/pnyXfHhe8ysjO65YDAvNVpXQKCAQAWplxYIEhQcE51AqOXVwQNNNo6NHjB
       
    74 VNTkpcAtJC7gT5bmHkvQkEq9rI837rHgnzGC0jyQQ8tkL4gAQWDt+coJsyB2p5wypifyRz6Rh5ui
       
    75 xOdEvSCBVEy1W4AsNo0fqD7UielOD6BojjJCilx4xHjGjQUntxyaOrsLC+EsRGiWOefTznTbEBpl
       
    76 qiuH9kxoJts+xy9LVZmDS7TtsC98kOmkltOlXVNb6/xF1PYZ9j897buHOSXC8iTgdzEpbaiH7B5H
       
    77 SPh++1/et1SEMWsiMt7lU92vAhErDR8C2jCXMiT+J67ai51LKSLZuovjntnhA6Y8UoELxoi34u1D
       
    78 FuHvF9veBB4CHHTW1E//VJ4Ms6LhUNp9nY8IgcxN6upRxLvE+uE=
       
    79 -----END PRIVATE KEY-----
       
    80 EOT;
       
    81 
       
    82     const RSA_PEM = <<<EOT
       
    83 -----BEGIN PRIVATE KEY-----
       
    84 MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDxemvFVLJTkXl65rTnzSPLtJaP
       
    85 NacGD/SYxnhE1l98F6lj/JQaEH094GWGsCWf41XkZOZYMAZEGIDqdmr6vZjhW7zNjGXCA83PMb+r
       
    86 p/BOHuq+O5OQaHy9kI2kbNgfqbm+IzP9vrxTXmsVh4N/mCtfygq/uw8S0z0T5G1O9VoJ3mfBQ6dK
       
    87 fjqUlHtcp2JPt8gDJQ0a8npQysFOeuX+cVV/KW+M1o53xzIOlufudD0dHV9AK9o/4NHQpCgG0Izl
       
    88 6vcpNqRvotzEov03ID586gUw744ViLPqtOvxM54ac6X2ZKjjwhzGPFL6/A/BqPKQg2xExMbRxquN
       
    89 E50MZFSL7AVNAgMBAAECggEBAIgWXAIbl1wtUe8HcdBo9dFpdqhCrlxmRYyL3V++CJXgp9/nined
       
    90 71cdzVm4j5up/M/4ZTAx8HYT8SMxlVy12SC4GJEmnHpYtnYcLU7KGE2OcvC+loz9tb8HZivSA4Lk
       
    91 nf8fy78m7O92+JZrhpoz4c3cCW7ANuB/F57MTyX+c7229zEsiALhURc3Vib6rWUfq3AJBWOEYKoa
       
    92 SLLQozi8UJoFODXwC9LDMaxgioNSaU+aj0W0haR/31HRvMQt+Zy1aYYAeuWHT940D6Wgp38ZLMqd
       
    93 uj22EY64WhcVfv8lQbIb6jOoZqMIj9erGfWlbGlVxoMhUTGQi0sKmyjFBvClwgECgYEA/Am+vCOf
       
    94 WbHKvGd8G8zWk1VRHpJg4huxqn/i18OuYWdojXgfC/HDR4JKIbl/XP+r0HSudTg4vrusZYGrMGZR
       
    95 rD82tPDTj24cAI+mfsSNInm6VE4v3eMlEkAcPvqo+qgV5FXU1qFMW5c02vTqOyC/Swjr4YRkP/H7
       
    96 XhI8T+C6zkECgYEA9UYuSH4ZOehYEDtSXYK4R5NjhjM38a/bulJ8rUBZ8vtA1UACAkoGYXbPukzE
       
    97 GkEnihuFFDtW7KEY35q2ATj5zV1n1Eh3kfJ7TURl0hNva63jf/uNIXbS0JaFBh8/0N0tkJYrwCOH
       
    98 aKjAcaMs6OEMuqiLeJX/lpGdCLy+bdikjA0CgYEAjb0NPtDptI9/7CRmb1vq8EBytjartXzNlY0G
       
    99 DUFGuBBng+ehzh3QLE7hUcX4ElzWSwzTb6iGgP0aHpulojpog+2o3mjxESBjLw2aHIB8vn6mgvLV
       
   100 iHtNRc44FFLy5MPSS+7ZGzrqrjeCygAiGc54xcHmpZTGrA9xxZ2LvYAsjgECgYBHpKtKQ4MM1iA7
       
   101 BYjmhZNcXOH6RiW2M/8Dqqp+VMixX9CtOZgcoRDCEVlV+qxhWty4y5cQtNCMJ/ZDAkbdjo3w/bKh
       
   102 YFWEzQZVKIBxX3nxQwar0IeF2dZ0VTMf+arDUIfJrwOyiO45lOk5iEdK8smsECVFINNaYMg00CTz
       
   103 ow9VVQKBgFDCVC97xsu5lOl6nd9mSu2GL+6hzpWPIZDD2SwMs6Vkkj33UhqyqziCOFKmRTF5oON+
       
   104 ew2EGVPukWZsYXNH0KLwdJ7q0QKEONGPMxVNURkHR9cJ8ScaZkiZ6Zh0MT3S3kTak+A5pzo3eS4H
       
   105 LhgZ72DZ0ABBEGoMfaVh8fJHZKcm
       
   106 -----END PRIVATE KEY-----
       
   107 
       
   108 EOT;
       
   109 
       
   110     public function setUp() {
       
   111         parent::setUp();
       
   112 
       
   113         // $this->markTestSkipped('Not ready yet');
       
   114 
       
   115         $this->certTmpPath = tempnam("/tmp", "CERT_TEST");
       
   116         file_put_contents($this->certTmpPath, HandleClientTest::CERT_PEM);
       
   117 
       
   118     }
       
   119 
       
   120     public function tearDown() {
       
   121         unlink($this->certTmpPath);
       
   122 
       
   123         parent::tearDown();
       
   124     }
       
   125 
       
   126     private function initClient($respArray) {
       
   127 
       
   128         $this->history = [];
       
   129 
       
   130         $mock = new MockHandler($respArray);
       
   131         $handler = HandlerStack::create($mock);
       
   132 
       
   133         $history = Middleware::history($this->history);
       
   134 
       
   135         $handler->push($history);
       
   136 
       
   137         $this->httpClient = new Client(['handler' => $handler]);
       
   138 
       
   139     }
       
   140 
       
   141 
       
   142     /**
       
   143      * Test Pagination with DSA key.
       
   144      *
       
   145      * @return void
       
   146      */
       
   147     public function testPaginateDSA()
       
   148     {
       
   149         $responses = [
       
   150             new Response(201,
       
   151                          [ 'Location' => '/api/sessions/this',
       
   152                            'Content-Type' => 'application/json;charset=UTF-8',
       
   153                            'Vary' => "Accept-Encoding"
       
   154                          ],
       
   155                          "{\"sessionId\":\"fo79koatgsdyfjkx4c6p3l0c\",\"nonce\":\"10hYzYGE5vf0a1F9eWfk6g==\"}"
       
   156             ),
       
   157             new Response(200,
       
   158                          [ 'Location' => '/api/sessions/this',
       
   159                            'Content-Type' => 'application/json;charset=UTF-8'
       
   160                          ],
       
   161                          "{\"sessionId\":\"fo79koatgsdyfjkx4c6p3l0c\",\"nonce\":\"10hYzYGE5vf0a1F9eWfk6g==\",\"authenticated\":true,\"id\":\"300:11280.101/CORPUS_ADMIN_DSA\"}"
       
   162             ),
       
   163             new Response(200,
       
   164                          [ 'Location' => '/api/sessions/this',
       
   165                            'Content-Type' => 'application/json;charset=UTF-8'
       
   166                          ],
       
   167                          "{\"responseCode\":1,\"prefix\":\"11280.101\",\"totalCount\":\"2\",\"page\":0,\"pageSize\":15,\"handles\":[\"11280.101/CORPUS_ADMIN\",\"11280.101/CORPUS_ADMIN_DSA\"]}"
       
   168             )
       
   169 
       
   170         ];
       
   171         $this->initClient($responses);
       
   172 
       
   173         $handleClient = new HandleClient(HandleClientTest::DSA_PEM, null, "300:11281.100/CORPUS_ADMIN_DSA", "172.16.1.6", 8000, $this->httpClient);
       
   174 
       
   175         $pagination = $handleClient->paginateAll('11280.101');
       
   176 
       
   177         $this->assertNotNull($pagination);
       
   178 
       
   179         $this->assertInstanceOf("Illuminate\Pagination\LengthAwarePaginator", $pagination, "Must be a LengthAwarePaginator");
       
   180 
       
   181         $this->assertEquals(2, $pagination->count(), "Must have only one handle");
       
   182         $this->assertEquals(2, $pagination->total(), "Total is one");
       
   183 
       
   184         $handles = iterator_to_array($pagination);
       
   185         $this->assertEquals(['11280.101/CORPUS_ADMIN','11280.101/CORPUS_ADMIN_DSA'], $handles, "Same handles");
       
   186 
       
   187         $this->assertCount(3, $this->history, "Must have 3 transactions");
       
   188 
       
   189     }
       
   190 
       
   191 
       
   192     /**
       
   193      * Test Pagination with RSA key.
       
   194      *
       
   195      * @return void
       
   196      */
       
   197     public function testPaginateRSA()
       
   198     {
       
   199         $responses = [
       
   200             new Response(201,
       
   201                          [ 'Location' => '/api/sessions/this',
       
   202                            'Content-Type' => 'application/json;charset=UTF-8',
       
   203                            'Vary' => "Accept-Encoding"
       
   204                          ],
       
   205                          "{\"sessionId\":\"fo79koatgsdyfjkx4c6p3l0c\",\"nonce\":\"10hYzYGE5vf0a1F9eWfk6g==\"}"
       
   206             ),
       
   207             new Response(200,
       
   208                          [ 'Location' => '/api/sessions/this',
       
   209                            'Content-Type' => 'application/json;charset=UTF-8'
       
   210                          ],
       
   211                          "{\"sessionId\":\"fo79koatgsdyfjkx4c6p3l0c\",\"nonce\":\"10hYzYGE5vf0a1F9eWfk6g==\",\"authenticated\":true,\"id\":\"300:11280.101/CORPUS_ADMIN\"}"
       
   212             ),
       
   213             new Response(200,
       
   214                          [ 'Location' => '/api/sessions/this',
       
   215                            'Content-Type' => 'application/json;charset=UTF-8'
       
   216                          ],
       
   217                          "{\"responseCode\":1,\"prefix\":\"11280.101\",\"totalCount\":\"2\",\"page\":0,\"pageSize\":15,\"handles\":[\"11280.101/CORPUS_ADMIN\",\"11280.101/CORPUS_ADMIN_DSA\"]}"
       
   218             )
       
   219 
       
   220         ];
       
   221         $this->initClient($responses);
       
   222 
       
   223         $handleClient = new HandleClient(HandleClientTest::RSA_PEM, null, "300:11280.101/CORPUS_ADMIN", "172.16.1.6", 8000, $this->httpClient);
       
   224 
       
   225         $pagination = $handleClient->paginateAll('11280.101');
       
   226 
       
   227         $this->assertNotNull($pagination);
       
   228 
       
   229         $this->assertInstanceOf("Illuminate\Pagination\LengthAwarePaginator", $pagination, "Must be a LengthAwarePaginator");
       
   230 
       
   231         $this->assertEquals(2, $pagination->count(), "Must have only 2 handle");
       
   232         $this->assertEquals(2, $pagination->total(), "Total is 2");
       
   233 
       
   234         $handles = iterator_to_array($pagination);
       
   235         $this->assertEquals(['11280.101/CORPUS_ADMIN', '11280.101/CORPUS_ADMIN_DSA'], $handles, "Same handles");
       
   236 
       
   237         $this->assertCount(3, $this->history, "Must have 3 transactions");
       
   238 
       
   239     }
       
   240 
       
   241     /**
       
   242      * Test Pagination with Client Certificate.
       
   243      *
       
   244      * @return void
       
   245      */
       
   246     public function testPaginateCert()
       
   247     {
       
   248 
       
   249         $responses = [
       
   250             new Response(200,
       
   251                          [ 'Location' => '/api/sessions/this',
       
   252                            'Content-Type' => 'application/json;charset=UTF-8'
       
   253                          ],
       
   254                          "{\"responseCode\":1,\"prefix\":\"11280.101\",\"totalCount\":\"2\",\"page\":0,\"pageSize\":15,\"handles\":[\"11280.101/CORPUS_ADMIN\",\"11280.101/CORPUS_ADMIN_DSA\"]}"
       
   255             )
       
   256         ];
       
   257 
       
   258 
       
   259         $this->initClient($responses);
       
   260 
       
   261         $handleClient = new HandleClient($this->certTmpPath, null, "300:11280.101/CORPUS_ADMIN", "172.16.1.6", 8000, $this->httpClient);
       
   262 
       
   263         $pagination = $handleClient->paginateAll('11280.101');
       
   264 
       
   265         $this->assertNotNull($pagination);
       
   266 
       
   267         $this->assertInstanceOf("Illuminate\Pagination\LengthAwarePaginator", $pagination, "Must be a LengthAwarePaginator");
       
   268 
       
   269         $this->assertEquals(2, $pagination->count(), "Must have only 2 handle");
       
   270         $this->assertEquals(2, $pagination->total(), "Total is 2");
       
   271         $this->assertFalse($pagination->hasPages(), "Do not have a page");
       
   272 
       
   273         $handles = iterator_to_array($pagination);
       
   274         $this->assertEquals(['11280.101/CORPUS_ADMIN', '11280.101/CORPUS_ADMIN_DSA'], $handles, "Same handles");
       
   275 
       
   276         $this->assertCount(1, $this->history, "Must have 1 transactions");
       
   277 
       
   278     }
       
   279 
       
   280 
       
   281     /**
       
   282      * Test Pagination with Client Certificate.
       
   283      *
       
   284      * @return void
       
   285      */
       
   286     public function testPaginateFirstPageCert()
       
   287     {
       
   288 
       
   289         $responses = [
       
   290             new Response(200,
       
   291                          [ 'Location' => '/api/sessions/this',
       
   292                            'Content-Type' => 'application/json;charset=UTF-8'
       
   293                          ],
       
   294                          "{\"responseCode\":1,\"prefix\":\"11280.101\",\"totalCount\":\"12\",\"page\":0,\"pageSize\":5,\"handles\":[\"11280.101/TEST1\",\"11280.101/TEST2\",\"11280.101/TEST3\",\"11280.101/TEST4\",\"11280.101/TEST5\"]}"
       
   295             )
       
   296         ];
       
   297 
       
   298 
       
   299         $this->initClient($responses);
       
   300 
       
   301         $handleClient = new HandleClient($this->certTmpPath, null, "300:11280.101/CORPUS_ADMIN", "172.16.1.6", 8000, $this->httpClient);
       
   302 
       
   303         $pagination = $handleClient->paginateAll('11280.101', 5);
       
   304 
       
   305         $this->assertNotNull($pagination);
       
   306 
       
   307         $this->assertInstanceOf("Illuminate\Pagination\LengthAwarePaginator", $pagination, "Must be a LengthAwarePaginator");
       
   308 
       
   309         $this->assertEquals(5, $pagination->count(), "Must have only 5 handle");
       
   310         $this->assertEquals(5, $pagination->perPage(), "Per page is 5");
       
   311         $this->assertEquals(12, $pagination->total(), "Total is 12");
       
   312         $this->assertEquals(1, $pagination->currentPage(), "Current page is 1");
       
   313         $this->assertEquals(3, $pagination->lastPage(), "Last page is 3");
       
   314         $this->assertTrue($pagination->hasMorePages(), "Must have more page");
       
   315         $this->assertTrue($pagination->hasPages(), "Have at least page");
       
   316         $this->assertEquals(1, $pagination->firstItem(), "First item is 1");
       
   317         $this->assertEquals(5, $pagination->lastItem(), "First item is 4");
       
   318 
       
   319         $handles = iterator_to_array($pagination);
       
   320         $this->assertEquals(['11280.101/TEST1', '11280.101/TEST2', '11280.101/TEST3', '11280.101/TEST4', '11280.101/TEST5'], $handles, "Same handles");
       
   321 
       
   322 
       
   323     }
       
   324 
       
   325     /**
       
   326      * Test Pagination with Client Certificate.
       
   327      *
       
   328      * @return void
       
   329      */
       
   330     public function testPaginateNextPageCert()
       
   331     {
       
   332 
       
   333         $responses = [
       
   334             new Response(200,
       
   335                          [ 'Location' => '/api/sessions/this',
       
   336                            'Content-Type' => 'application/json;charset=UTF-8'
       
   337                          ],
       
   338                          "{\"responseCode\":1,\"prefix\":\"11280.101\",\"totalCount\":\"12\",\"page\":1,\"pageSize\":5,\"handles\":[\"11280.101/TEST6\",\"11280.101/TEST7\",\"11280.101/TEST8\",\"11280.101/TEST9\",\"11280.101/TEST10\"]}"
       
   339             )
       
   340         ];
       
   341 
       
   342 
       
   343         $this->initClient($responses);
       
   344 
       
   345         $handleClient = new HandleClient($this->certTmpPath, null, "300:11280.101/CORPUS_ADMIN", "172.16.1.6", 8000, $this->httpClient);
       
   346 
       
   347         $pagination = $handleClient->paginateAll('11280.101', 5, 'page', 2);
       
   348 
       
   349         $this->assertNotNull($pagination);
       
   350 
       
   351         $this->assertInstanceOf("Illuminate\Pagination\LengthAwarePaginator", $pagination, "Must be a LengthAwarePaginator");
       
   352 
       
   353         $this->assertEquals(5, $pagination->count(), "Must have only 5 handle");
       
   354         $this->assertEquals(5, $pagination->perPage(), "Per page is 5");
       
   355         $this->assertEquals(12, $pagination->total(), "Total is 12");
       
   356         $this->assertEquals(2, $pagination->currentPage(), "Current page is 2");
       
   357         $this->assertEquals(3, $pagination->lastPage(), "Last page is 3");
       
   358         $this->assertTrue($pagination->hasPages(), "Have at least page");
       
   359         $this->assertTrue($pagination->hasMorePages(), "Must have more page");
       
   360         $this->assertEquals(6, $pagination->firstItem(), "First item is 1");
       
   361         $this->assertEquals(10, $pagination->lastItem(), "First item is 4");
       
   362 
       
   363         $handles = iterator_to_array($pagination);
       
   364         $this->assertEquals(['11280.101/TEST6', '11280.101/TEST7', '11280.101/TEST8', '11280.101/TEST9', '11280.101/TEST10'], $handles, "Same handles");
       
   365 
       
   366 
       
   367     }
       
   368 
       
   369     /**
       
   370      * Test Pagination with Client Certificate.
       
   371      *
       
   372      * @return void
       
   373      */
       
   374     public function testPaginateLastPageCert()
       
   375     {
       
   376 
       
   377         $responses = [
       
   378             new Response(200,
       
   379                          [ 'Location' => '/api/sessions/this',
       
   380                            'Content-Type' => 'application/json;charset=UTF-8'
       
   381                          ],
       
   382                          "{\"responseCode\":1,\"prefix\":\"11280.101\",\"totalCount\":\"12\",\"page\":2,\"pageSize\":5,\"handles\":[\"11280.101/TEST11\",\"11280.101/TEST12\"]}"
       
   383             )
       
   384         ];
       
   385 
       
   386 
       
   387         $this->initClient($responses);
       
   388 
       
   389         $handleClient = new HandleClient($this->certTmpPath, null, "300:11280.101/CORPUS_ADMIN", "172.16.1.6", 8000, $this->httpClient);
       
   390 
       
   391         $pagination = $handleClient->paginateAll('11280.101', 5, 'page', 3);
       
   392 
       
   393         $this->assertNotNull($pagination);
       
   394 
       
   395         $this->assertInstanceOf("Illuminate\Pagination\LengthAwarePaginator", $pagination, "Must be a LengthAwarePaginator");
       
   396 
       
   397         $this->assertEquals(2, $pagination->count(), "Must have only 2 handle");
       
   398         $this->assertEquals(5, $pagination->perPage(), "Per page is 5");
       
   399         $this->assertEquals(12, $pagination->total(), "Total is 12");
       
   400         $this->assertEquals(3, $pagination->currentPage(), "Current page is 3");
       
   401         $this->assertEquals(3, $pagination->lastPage(), "Last page is 3");
       
   402         $this->assertFalse($pagination->hasMorePages(), "Must have more page");
       
   403         $this->assertTrue($pagination->hasPages(), "Have at least page");
       
   404         $this->assertEquals(11, $pagination->firstItem(), "First item is 1");
       
   405         $this->assertEquals(12, $pagination->lastItem(), "First item is 4");
       
   406 
       
   407         $handles = iterator_to_array($pagination);
       
   408         $this->assertEquals(['11280.101/TEST11', '11280.101/TEST12'], $handles, "Same handles");
       
   409 
       
   410 
       
   411     }
       
   412 
       
   413 
       
   414 }