

Nextrek
@ 461
Nextrek / Android / SmartCharging / endPoints / nightly / fb_SDK / tests / Entities / SignedRequestTest.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
<?php use Facebook\Entities\SignedRequest; class SignedRequestTest extends PHPUnit_Framework_TestCase { public $appSecret = 'foo_app_secret'; public $rawSignedRequest = 'U0_O1MqqNKUt32633zAkdd2Ce-jGVgRgJeRauyx_zC8=.eyJvYXV0aF90b2tlbiI6ImZvb190b2tlbiIsImFsZ29yaXRobSI6IkhNQUMtU0hBMjU2IiwiaXNzdWVkX2F0IjozMjEsImNvZGUiOiJmb29fY29kZSIsInN0YXRlIjoiZm9vX3N0YXRlIiwidXNlcl9pZCI6MTIzLCJmb28iOiJiYXIifQ=='; public $payloadData = array( 'oauth_token' => 'foo_token', 'algorithm' => 'HMAC-SHA256', 'issued_at' => 321, 'code' => 'foo_code', 'state' => 'foo_state', 'user_id' => 123, 'foo' => 'bar', ); public function testValidSignedRequestsWillPassFormattingValidation() { $sr = SignedRequest::make($this->payloadData, $this->appSecret); SignedRequest::validateFormat($sr); } /** * @expectedException \Facebook\FacebookSDKException */ public function testInvalidSignedRequestsWillFailFormattingValidation() { SignedRequest::validateFormat('invalid_signed_request'); } public function testSignatureAndPayloadCanBeSeparatedInSignedRequests() { list($sig, $payload) = SignedRequest::split('sig.payload'); $this->assertEquals('sig', $sig); $this->assertEquals('payload', $payload); } public function testBase64EncodingIsUrlSafe() { $encodedData = SignedRequest::base64UrlEncode('aijkoprstADIJKLOPQTUVX1256!)]-:;"<>?.|~'); $this->assertEquals('YWlqa29wcnN0QURJSktMT1BRVFVWWDEyNTYhKV0tOjsiPD4_Lnx-', $encodedData); } public function testAUrlSafeBase64EncodedStringCanBeDecoded() { $decodedData = SignedRequest::base64UrlDecode('YWlqa29wcnN0QURJSktMT1BRVFVWWDEyNTYhKV0tOjsiPD4/Lnx+'); $this->assertEquals('aijkoprstADIJKLOPQTUVX1256!)]-:;"<>?.|~', $decodedData); } public function testAValidEncodedSignatureCanBeDecoded() { $decodedSig = SignedRequest::decodeSignature('c2ln'); $this->assertEquals('sig', $decodedSig); } /** * @expectedException \Facebook\FacebookSDKException */ public function testAnImproperlyEncodedSignatureWillThrowAnException() { SignedRequest::decodeSignature('foo!'); } public function testAValidEncodedPayloadCanBeDecoded() { $decodedPayload = SignedRequest::decodePayload('WyJwYXlsb2FkIl0='); $this->assertEquals(array('payload'), $decodedPayload); } /** * @expectedException \Facebook\FacebookSDKException */ public function testAnImproperlyEncodedPayloadWillThrowAnException() { SignedRequest::decodePayload('foo!'); } public function testSignedRequestDataMustContainTheHmacSha256Algorithm() { SignedRequest::validateAlgorithm($this->payloadData); } /** * @expectedException \Facebook\FacebookSDKException */ public function testNonApprovedAlgorithmsWillThrowAnException() { $signedRequestData = $this->payloadData; $signedRequestData['algorithm'] = 'FOO-ALGORITHM'; SignedRequest::validateAlgorithm($signedRequestData); } public function testASignatureHashCanBeGeneratedFromBase64EncodedData() { $hashedSig = SignedRequest::hashSignature('WyJwYXlsb2FkIl0=', $this->appSecret); $expectedSig = base64_decode('bFofyO2sERX73y8uvuX26SLodv0mZ+Zk18d8b3zhD+s='); $this->assertEquals($expectedSig, $hashedSig); } public function testTwoBinaryStringsCanBeComparedForSignatureValidation() { $hashedSig = base64_decode('bFofyO2sERX73y8uvuX26SLodv0mZ+Zk18d8b3zhD+s='); SignedRequest::validateSignature($hashedSig, $hashedSig); } /** * @expectedException \Facebook\FacebookSDKException */ public function testNonSameBinaryStringsWillThrowAnExceptionForSignatureValidation() { $hashedSig1 = base64_decode('bFofyO2sERX73y8uvuX26SLodv0mZ+Zk18d8b3zhD+s='); $hashedSig2 = base64_decode('GJy4HzkRtCeZA0cJjdZJtGfovcdxgl/AERI20S4MY7c='); SignedRequest::validateSignature($hashedSig1, $hashedSig2); } public function testASignedRequestWillPassCsrfValidation() { SignedRequest::validateCsrf($this->payloadData, 'foo_state'); } /** * @expectedException \Facebook\FacebookSDKException */ public function testASignedRequestWithIncorrectCsrfDataWillThrowAnException() { SignedRequest::validateCsrf($this->payloadData, 'invalid_foo_state'); } public function testARawSignedRequestCanBeValidatedAndDecoded() { $payload = SignedRequest::parse($this->rawSignedRequest, 'foo_state', $this->appSecret); $this->assertEquals($this->payloadData, $payload); } public function testARawSignedRequestCanBeInjectedIntoTheConstructorToInstantiateANewEntity() { $signedRequest = new SignedRequest($this->rawSignedRequest, 'foo_state', $this->appSecret); $rawSignedRequest = $signedRequest->getRawSignedRequest(); $payloadData = $signedRequest->getPayload(); $userId = $signedRequest->getUserId(); $hasOAuthData = $signedRequest->hasOAuthData(); $this->assertInstanceOf('\Facebook\Entities\SignedRequest', $signedRequest); $this->assertEquals($this->rawSignedRequest, $rawSignedRequest); $this->assertEquals($this->payloadData, $payloadData); $this->assertEquals(123, $userId); $this->assertTrue($hasOAuthData); } } |
Commits for Nextrek/Android/SmartCharging/endPoints/nightly/fb_SDK/tests/Entities/SignedRequestTest.php
Revision | Author | Commited | Message |
---|---|---|---|
461 |
![]() |
Mon 03 Aug, 2015 10:04:56 +0000 | Aggiunto supporto login Facebook, logout utente e modifiche (solo lato repo) all’utente e al locale. |