From 18dafdbecdb904b902b299ed713873fd66aeb0c9 Mon Sep 17 00:00:00 2001 From: Achmad Hadi Kurnia Date: Mon, 18 Sep 2023 03:07:52 +0700 Subject: [PATCH 1/5] Add get data test --- src/Commands/GetData.php | 4 ++-- tests/CommandTest.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Commands/GetData.php b/src/Commands/GetData.php index a24cbd6..3146aab 100644 --- a/src/Commands/GetData.php +++ b/src/Commands/GetData.php @@ -3,7 +3,7 @@ namespace Kanekescom\Siasn\Api\Commands; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Http; +use Kanekescom\Siasn\Api\Facades\Siasn; class GetData extends Command { @@ -27,6 +27,6 @@ class GetData extends Command */ public function handle() { - $this->info(json_encode(Http::siasn()->get($this->argument('endpoint'))->object(), JSON_PRETTY_PRINT)); + $this->info(json_encode(Siasn::get($this->argument('endpoint'))->object(), JSON_PRETTY_PRINT)); } } diff --git a/tests/CommandTest.php b/tests/CommandTest.php index dd6dd31..98bcec3 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -65,4 +65,10 @@ public function can_forget_token() $this->assertNull(cache('sso-token')); $this->assertNull(cache('ws-token')); } + + /** @test */ + public function can_get_data() + { + $this->artisan('siasn:get ' . env('SIASN_GET_ENDPOINT_TEST'))->assertSuccessful(); + } } From 01f11238d77c56d7f193a5645714ab700a2fc60b Mon Sep 17 00:00:00 2001 From: Achmad Hadi Kurnia Date: Mon, 18 Sep 2023 08:05:13 +0700 Subject: [PATCH 2/5] Update composer branch alias --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index fde0ba5..11a81a2 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,9 @@ "aliases": { "Siasn": "Kanekescom\\Siasn\\Api\\Facades\\Siasn" } + }, + "branch-alias": { + "dev-main": "dev-main" } }, "scripts": { From 8a111cecd6e05f88ed63a973e9cead640b068ab2 Mon Sep 17 00:00:00 2001 From: Achmad Hadi Kurnia Date: Mon, 18 Sep 2023 09:34:29 +0700 Subject: [PATCH 3/5] Remove unused file --- src/Exceptions/InvalidCredentialsException.php | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 src/Exceptions/InvalidCredentialsException.php diff --git a/src/Exceptions/InvalidCredentialsException.php b/src/Exceptions/InvalidCredentialsException.php deleted file mode 100644 index c66bed9..0000000 --- a/src/Exceptions/InvalidCredentialsException.php +++ /dev/null @@ -1,10 +0,0 @@ - Date: Mon, 18 Sep 2023 09:34:48 +0700 Subject: [PATCH 4/5] Reorder variable --- src/Siasn.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Siasn.php b/src/Siasn.php index 7681516..c23a7c2 100644 --- a/src/Siasn.php +++ b/src/Siasn.php @@ -11,8 +11,8 @@ class Siasn public function __construct() { - $wsToken = Token::getWsToken(); $ssoToken = Token::getSsoToken(); + $wsToken = Token::getWsToken(); $this->request = Http::retry(3, 100) ->withOptions([ From 2aaae07d133a5e6a824dd14a6ec80f84afd39802 Mon Sep 17 00:00:00 2001 From: Achmad Hadi Kurnia Date: Mon, 18 Sep 2023 10:06:27 +0700 Subject: [PATCH 5/5] Fix bugs token class --- src/Credentials/Token.php | 18 ++++++++++++++++-- tests/CommandTest.php | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Credentials/Token.php b/src/Credentials/Token.php index 5f311b7..68fef40 100644 --- a/src/Credentials/Token.php +++ b/src/Credentials/Token.php @@ -2,6 +2,8 @@ namespace Kanekescom\Siasn\Api\Credentials; +use Kanekescom\Siasn\Api\Exceptions\InvalidSsoCredentialsException; +use Kanekescom\Siasn\Api\Exceptions\InvalidWsCredentialsException; use Kanekescom\Siasn\Api\SiasnConfig; class Token @@ -12,7 +14,13 @@ class Token public static function getSsoToken() { return cache()->remember('sso-token', SiasnConfig::getSsoTokenAge(), function () { - return Sso::getToken()->object(); + $ssoToken = Sso::getToken()->object(); + + if (blank(optional($ssoToken)->token_type) || blank(optional($ssoToken)->access_token)) { + throw new InvalidSsoCredentialsException('Invalid SSO user credentials.'); + } + + return $ssoToken; }); } @@ -22,7 +30,13 @@ public static function getSsoToken() public static function getWsToken() { return cache()->remember('ws-token', SiasnConfig::getWsTokenAge(), function () { - return Ws::getToken()->object(); + $wsToken = Ws::getToken()->object(); + + if (blank(optional($wsToken)->access_token)) { + throw new InvalidWsCredentialsException('Invalid WS user credentials.'); + } + + return $wsToken; }); } } diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 98bcec3..1e902f0 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -69,6 +69,6 @@ public function can_forget_token() /** @test */ public function can_get_data() { - $this->artisan('siasn:get ' . env('SIASN_GET_ENDPOINT_TEST'))->assertSuccessful(); + $this->artisan('siasn:get '.env('SIASN_GET_ENDPOINT_TEST'))->assertSuccessful(); } }