Skip to content

Commit

Permalink
Merge pull request #18 from sima-land/auth-response-code
Browse files Browse the repository at this point in the history
#17 fix auth response code
  • Loading branch information
pelmennoteam authored Aug 9, 2022
2 parents 0278eef + dbaf960 commit 71a6972
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Rest/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private function auth()
"regulation" => $this->regulation
];
$response = $client->request('POST', $this->createUrl('signin'), $options);
if ($response->getStatusCode() != 204) {
if ($response->getStatusCode() != 200) {
throw new \Exception($response->getReasonPhrase(), $response->getStatusCode());
}
$headerAuth = $response->getHeader("Authorization");
Expand Down
10 changes: 7 additions & 3 deletions tests/Rest/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SimaLand\API\Rest\Client;
use SimaLand\API\Rest\Request;
use SimaLand\API\Tests\BaseCase;
use GuzzleHttp\Psr7\Utils;

class ClientTest extends BaseCase
{
Expand Down Expand Up @@ -96,17 +97,20 @@ public function testGetToken()
$tokenPath = TEST_DIR . 'output';
$fileToken = $tokenPath . "/token.txt";
file_put_contents($fileToken, 'token');
$jsonToken = <<<JSON
{"token": "$token"}
JSON;

$this->setGuzzleHttpResponse(new Response(401, [], 'Unauthorized'));
$this->setGuzzleHttpResponse(new Response(204, ['Authorization' => [$token]], null));
$this->setGuzzleHttpResponse(new Response(200, [], 'ok'));
$this->setGuzzleHttpResponse((new Response(200, ['Authorization' => [$token]], null)));
$this->setGuzzleHttpResponse(new Response(200, [], Utils::streamFor($jsonToken)));

$client = $this->getClient();
$oldTokenPath = $client->tokenPath;
$client->tokenPath = $tokenPath;
$response = $client->get('user');
$client->tokenPath = $oldTokenPath;
$this->assertEquals('ok', $response->getBody()->getContents());
$this->assertEquals($jsonToken, $response->getBody()->getContents());
$this->assertEquals($token, file_get_contents($fileToken));
@unlink($fileToken);
}
Expand Down

0 comments on commit 71a6972

Please sign in to comment.