Mod auth
This commit is contained in:
parent
b557d471a0
commit
8de7dcae24
|
@ -543,12 +543,12 @@
|
|||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
]
|
||||
],
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
|
@ -824,16 +824,16 @@
|
|||
},
|
||||
{
|
||||
"name": "laravel/framework",
|
||||
"version": "v8.83.0",
|
||||
"version": "v8.83.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/framework.git",
|
||||
"reference": "29bc8779103909ebc428478b339ee6fa8703e193"
|
||||
"reference": "bddba117f8bce2f3c9875ca1ca375a96350d0f4d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/29bc8779103909ebc428478b339ee6fa8703e193",
|
||||
"reference": "29bc8779103909ebc428478b339ee6fa8703e193",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/bddba117f8bce2f3c9875ca1ca375a96350d0f4d",
|
||||
"reference": "bddba117f8bce2f3c9875ca1ca375a96350d0f4d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -993,20 +993,20 @@
|
|||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"time": "2022-02-08T15:44:51+00:00"
|
||||
"time": "2022-02-15T15:05:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/serializable-closure",
|
||||
"version": "v1.1.0",
|
||||
"version": "v1.1.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/serializable-closure.git",
|
||||
"reference": "65c9faf50d567b65d81764a44526545689e3fe63"
|
||||
"reference": "9e4b005daa20b0c161f3845040046dc9ddc1d74e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/65c9faf50d567b65d81764a44526545689e3fe63",
|
||||
"reference": "65c9faf50d567b65d81764a44526545689e3fe63",
|
||||
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/9e4b005daa20b0c161f3845040046dc9ddc1d74e",
|
||||
"reference": "9e4b005daa20b0c161f3845040046dc9ddc1d74e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1052,20 +1052,20 @@
|
|||
"issues": "https://github.com/laravel/serializable-closure/issues",
|
||||
"source": "https://github.com/laravel/serializable-closure"
|
||||
},
|
||||
"time": "2022-02-01T16:29:39+00:00"
|
||||
"time": "2022-02-11T19:23:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/ui",
|
||||
"version": "v3.4.3",
|
||||
"version": "v3.4.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/ui.git",
|
||||
"reference": "64a0f43492c00780b2261c56cd7007a4f370d95b"
|
||||
"reference": "1596de849ecafc0bcc891389da939012b67f9d5c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/ui/zipball/64a0f43492c00780b2261c56cd7007a4f370d95b",
|
||||
"reference": "64a0f43492c00780b2261c56cd7007a4f370d95b",
|
||||
"url": "https://api.github.com/repos/laravel/ui/zipball/1596de849ecafc0bcc891389da939012b67f9d5c",
|
||||
"reference": "1596de849ecafc0bcc891389da939012b67f9d5c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1111,22 +1111,22 @@
|
|||
"ui"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/laravel/ui/tree/v3.4.3"
|
||||
"source": "https://github.com/laravel/ui/tree/v3.4.4"
|
||||
},
|
||||
"time": "2022-02-08T14:19:32+00:00"
|
||||
"time": "2022-02-10T22:38:33+00:00"
|
||||
},
|
||||
{
|
||||
"name": "league/commonmark",
|
||||
"version": "2.2.1",
|
||||
"version": "2.2.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thephpleague/commonmark.git",
|
||||
"reference": "f8afb78f087777b040e0ab8a6b6ca93f6fc3f18a"
|
||||
"reference": "13d7751377732637814f0cda0e3f6d3243f9f769"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/f8afb78f087777b040e0ab8a6b6ca93f6fc3f18a",
|
||||
"reference": "f8afb78f087777b040e0ab8a6b6ca93f6fc3f18a",
|
||||
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/13d7751377732637814f0cda0e3f6d3243f9f769",
|
||||
"reference": "13d7751377732637814f0cda0e3f6d3243f9f769",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1217,7 +1217,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-01-25T14:37:33+00:00"
|
||||
"time": "2022-02-13T15:00:57+00:00"
|
||||
},
|
||||
{
|
||||
"name": "league/config",
|
||||
|
@ -1552,16 +1552,16 @@
|
|||
},
|
||||
{
|
||||
"name": "nesbot/carbon",
|
||||
"version": "2.56.0",
|
||||
"version": "2.57.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/briannesbitt/Carbon.git",
|
||||
"reference": "626ec8cbb724cd3c3400c3ed8f730545b744e3f4"
|
||||
"reference": "4a54375c21eea4811dbd1149fe6b246517554e78"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/626ec8cbb724cd3c3400c3ed8f730545b744e3f4",
|
||||
"reference": "626ec8cbb724cd3c3400c3ed8f730545b744e3f4",
|
||||
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/4a54375c21eea4811dbd1149fe6b246517554e78",
|
||||
"reference": "4a54375c21eea4811dbd1149fe6b246517554e78",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1644,7 +1644,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-01-21T17:08:38+00:00"
|
||||
"time": "2022-02-13T18:13:33+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nette/schema",
|
||||
|
@ -3834,12 +3834,12 @@
|
|||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
|
@ -6352,16 +6352,16 @@
|
|||
},
|
||||
{
|
||||
"name": "phar-io/version",
|
||||
"version": "3.1.1",
|
||||
"version": "3.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phar-io/version.git",
|
||||
"reference": "15a90844ad40f127afd244c0cad228de2a80052a"
|
||||
"reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phar-io/version/zipball/15a90844ad40f127afd244c0cad228de2a80052a",
|
||||
"reference": "15a90844ad40f127afd244c0cad228de2a80052a",
|
||||
"url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74",
|
||||
"reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -6397,9 +6397,9 @@
|
|||
"description": "Library for handling version information and constraints",
|
||||
"support": {
|
||||
"issues": "https://github.com/phar-io/version/issues",
|
||||
"source": "https://github.com/phar-io/version/tree/3.1.1"
|
||||
"source": "https://github.com/phar-io/version/tree/3.2.1"
|
||||
},
|
||||
"time": "2022-02-07T21:56:48+00:00"
|
||||
"time": "2022-02-21T01:04:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpdocumentor/reflection-common",
|
||||
|
@ -6694,16 +6694,16 @@
|
|||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
"version": "9.2.10",
|
||||
"version": "9.2.11",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
|
||||
"reference": "d5850aaf931743067f4bfc1ae4cbd06468400687"
|
||||
"reference": "665a1ac0a763c51afc30d6d130dac0813092b17f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d5850aaf931743067f4bfc1ae4cbd06468400687",
|
||||
"reference": "d5850aaf931743067f4bfc1ae4cbd06468400687",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/665a1ac0a763c51afc30d6d130dac0813092b17f",
|
||||
"reference": "665a1ac0a763c51afc30d6d130dac0813092b17f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -6759,7 +6759,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
|
||||
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.10"
|
||||
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.11"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -6767,7 +6767,7 @@
|
|||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2021-12-05T09:12:13+00:00"
|
||||
"time": "2022-02-18T12:46:09+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-file-iterator",
|
||||
|
@ -7012,16 +7012,16 @@
|
|||
},
|
||||
{
|
||||
"name": "phpunit/phpunit",
|
||||
"version": "9.5.13",
|
||||
"version": "9.5.14",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||
"reference": "597cb647654ede35e43b137926dfdfef0fb11743"
|
||||
"reference": "1883687169c017d6ae37c58883ca3994cfc34189"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/597cb647654ede35e43b137926dfdfef0fb11743",
|
||||
"reference": "597cb647654ede35e43b137926dfdfef0fb11743",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1883687169c017d6ae37c58883ca3994cfc34189",
|
||||
"reference": "1883687169c017d6ae37c58883ca3994cfc34189",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -7099,7 +7099,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.13"
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.14"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -7111,7 +7111,7 @@
|
|||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2022-01-24T07:33:35+00:00"
|
||||
"time": "2022-02-18T12:54:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "pimple/pimple",
|
||||
|
@ -7168,23 +7168,23 @@
|
|||
},
|
||||
{
|
||||
"name": "react/promise",
|
||||
"version": "v2.8.0",
|
||||
"version": "v2.9.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/reactphp/promise.git",
|
||||
"reference": "f3cff96a19736714524ca0dd1d4130de73dbbbc4"
|
||||
"reference": "234f8fd1023c9158e2314fa9d7d0e6a83db42910"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/reactphp/promise/zipball/f3cff96a19736714524ca0dd1d4130de73dbbbc4",
|
||||
"reference": "f3cff96a19736714524ca0dd1d4130de73dbbbc4",
|
||||
"url": "https://api.github.com/repos/reactphp/promise/zipball/234f8fd1023c9158e2314fa9d7d0e6a83db42910",
|
||||
"reference": "234f8fd1023c9158e2314fa9d7d0e6a83db42910",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.0 || ^6.5 || ^5.7 || ^4.8.36"
|
||||
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.36"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
|
@ -7202,7 +7202,23 @@
|
|||
"authors": [
|
||||
{
|
||||
"name": "Jan Sorgalla",
|
||||
"email": "jsorgalla@gmail.com"
|
||||
"email": "jsorgalla@gmail.com",
|
||||
"homepage": "https://sorgalla.com/"
|
||||
},
|
||||
{
|
||||
"name": "Christian Lück",
|
||||
"email": "christian@clue.engineering",
|
||||
"homepage": "https://clue.engineering/"
|
||||
},
|
||||
{
|
||||
"name": "Cees-Jan Kiewiet",
|
||||
"email": "reactphp@ceesjankiewiet.nl",
|
||||
"homepage": "https://wyrihaximus.net/"
|
||||
},
|
||||
{
|
||||
"name": "Chris Boden",
|
||||
"email": "cboden@gmail.com",
|
||||
"homepage": "https://cboden.dev/"
|
||||
}
|
||||
],
|
||||
"description": "A lightweight implementation of CommonJS Promises/A for PHP",
|
||||
|
@ -7212,9 +7228,19 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/reactphp/promise/issues",
|
||||
"source": "https://github.com/reactphp/promise/tree/v2.8.0"
|
||||
"source": "https://github.com/reactphp/promise/tree/v2.9.0"
|
||||
},
|
||||
"time": "2020-05-12T15:16:56+00:00"
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/WyriHaximus",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/clue",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2022-02-11T10:27:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/cli-parser",
|
||||
|
@ -7722,16 +7748,16 @@
|
|||
},
|
||||
{
|
||||
"name": "sebastian/global-state",
|
||||
"version": "5.0.4",
|
||||
"version": "5.0.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/global-state.git",
|
||||
"reference": "19c519631c5a511b7ed0ad64a6713fdb3fd25fe4"
|
||||
"reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/19c519631c5a511b7ed0ad64a6713fdb3fd25fe4",
|
||||
"reference": "19c519631c5a511b7ed0ad64a6713fdb3fd25fe4",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2",
|
||||
"reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -7774,7 +7800,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/global-state/issues",
|
||||
"source": "https://github.com/sebastianbergmann/global-state/tree/5.0.4"
|
||||
"source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -7782,7 +7808,7 @@
|
|||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2022-02-10T07:01:19+00:00"
|
||||
"time": "2022-02-14T08:28:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/lines-of-code",
|
||||
|
@ -8355,16 +8381,16 @@
|
|||
},
|
||||
{
|
||||
"name": "spatie/laravel-ray",
|
||||
"version": "1.29.1",
|
||||
"version": "1.29.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/spatie/laravel-ray.git",
|
||||
"reference": "96e51dfbbb6fe108d6c0430b8a644ec6cf581583"
|
||||
"reference": "440cda76812a7770e6684d19683444c608e135e4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/spatie/laravel-ray/zipball/96e51dfbbb6fe108d6c0430b8a644ec6cf581583",
|
||||
"reference": "96e51dfbbb6fe108d6c0430b8a644ec6cf581583",
|
||||
"url": "https://api.github.com/repos/spatie/laravel-ray/zipball/440cda76812a7770e6684d19683444c608e135e4",
|
||||
"reference": "440cda76812a7770e6684d19683444c608e135e4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -8389,6 +8415,9 @@
|
|||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.29.x-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Spatie\\LaravelRay\\RayServiceProvider"
|
||||
|
@ -8420,7 +8449,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/spatie/laravel-ray/issues",
|
||||
"source": "https://github.com/spatie/laravel-ray/tree/1.29.1"
|
||||
"source": "https://github.com/spatie/laravel-ray/tree/1.29.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -8432,7 +8461,7 @@
|
|||
"type": "other"
|
||||
}
|
||||
],
|
||||
"time": "2022-02-09T12:59:05+00:00"
|
||||
"time": "2022-02-15T14:52:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "spatie/macroable",
|
||||
|
@ -9019,5 +9048,5 @@
|
|||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.0.0"
|
||||
"plugin-api-version": "2.1.0"
|
||||
}
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
namespace Zoomyboy\LaravelNami\Authentication;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Cookie\FileCookieJar;
|
||||
use GuzzleHttp\Cookie\CookieJar;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
|
||||
class MainCookie extends Authenticator {
|
||||
|
||||
private FileCookieJar $cookie;
|
||||
private CookieJar $cookie;
|
||||
private string $url = 'https://nami.dpsg.de';
|
||||
private ?int $mglnr = null;
|
||||
private ?string $password = null;
|
||||
|
@ -28,7 +28,6 @@ class MainCookie extends Authenticator {
|
|||
unlink($file);
|
||||
}
|
||||
|
||||
$cookieFile = $this->newFileName();
|
||||
$this->http()->get($this->url.'/ica/pages/login.jsp');
|
||||
$response = $this->http()->asForm()->post($this->url.'/ica/rest/nami/auth/manual/sessionStartup', [
|
||||
'Login' => 'API',
|
||||
|
@ -43,7 +42,7 @@ class MainCookie extends Authenticator {
|
|||
throw $e;
|
||||
}
|
||||
|
||||
$this->cookie->save($cookieFile);
|
||||
file_put_contents($this->newFileName(), $this->cookie->getCookieByName('JSESSIONID')->getValue());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -78,7 +77,7 @@ class MainCookie extends Authenticator {
|
|||
{
|
||||
$lastLoginTime = Carbon::createFromTimestamp(pathinfo($this->file(), PATHINFO_FILENAME));
|
||||
|
||||
return $lastLoginTime->addMinutes(50)->isPast();
|
||||
return $lastLoginTime->addMinutes(3)->isPast();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,13 +99,19 @@ class MainCookie extends Authenticator {
|
|||
/**
|
||||
* Loads the cookie for a new request
|
||||
*
|
||||
* @return FileCookieJar
|
||||
* @return CookieJar
|
||||
*/
|
||||
private function load(): FileCookieJar
|
||||
private function load(): CookieJar
|
||||
{
|
||||
$cookieFile = $this->file() ?: $this->newFileName();
|
||||
if ($this->file()) {
|
||||
$data = file_get_contents($this->file());
|
||||
|
||||
return $this->cookie = new FileCookieJar($cookieFile, true);
|
||||
return $this->cookie = CookieJar::fromArray([
|
||||
'JSESSIONID' => $data,
|
||||
], 'nami.dpsg.de');
|
||||
}
|
||||
|
||||
return $this->cookie = new CookieJar();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class NamiServiceProvider extends ServiceProvider
|
|||
}
|
||||
|
||||
public function register() {
|
||||
$this->app->bind(Authenticator::class, function() {
|
||||
$this->app->singleton(Authenticator::class, function() {
|
||||
return app(MainCookie::class);
|
||||
});
|
||||
$this->app->bind('nami.api', function() {
|
||||
|
|
|
@ -1,179 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Authentication\Auth;
|
||||
use Zoomyboy\LaravelNami\Fakes\CourseFake;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
|
||||
class LoginTest extends TestCase
|
||||
{
|
||||
|
||||
public string $successJson = '{"servicePrefix":null,"methodCall":null,"response":null,"statusCode":0,"statusMessage":"","apiSessionName":"JSESSIONID","apiSessionToken":"ILBY--L4pZEjSKa39tCemens","minorNumber":2,"majorNumber":1}';
|
||||
public string $bruteJson = '{"servicePrefix":null,"methodCall":null,"response":null,"statusCode":3000,"statusMessage":"Die höchste Anzahl von Login-Versuchen wurde erreicht. Ihr Konto ist für 15 Minuten gesperrt worden. Nach Ablauf dieser Zeitspanne wird ihr Zugang wieder freigegeben.","apiSessionName":"JSESSIONID","apiSessionToken":"tGlSpMMij9ruHfeiUYjO7SD2","minorNumber":0,"majorNumber":0}';
|
||||
public string $wrongCredentialsJson = '{"servicePrefix":null,"methodCall":null,"response":null,"statusCode":3000,"statusMessage":"Benutzer nicht gefunden oder Passwort falsch.","apiSessionName":"JSESSIONID","apiSessionToken":"v7lrjgPBbXInJR57qJzVIJ05","minorNumber":0,"majorNumber":0}';
|
||||
|
||||
public function test_first_successful_login(): void
|
||||
{
|
||||
Http::fake($this->fakeSuccessfulLogin());
|
||||
|
||||
Nami::login(12345, 'secret');
|
||||
|
||||
Http::assertSentCount(2);
|
||||
Http::assertSent(fn ($request) => $request->url() == 'https://nami.dpsg.de/ica/pages/login.jsp');
|
||||
Http::assertSent(fn ($request) => $request->url() == 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup'
|
||||
&& $request['username'] == '12345' && $request['password'] == 'secret'
|
||||
&& $request['redirectTo'] == './app.jsp' && $request['Login'] == 'API'
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_throws_exception_when_login_failed(): void
|
||||
{
|
||||
Http::fake($this->fakeFailedLogin());
|
||||
|
||||
try {
|
||||
Nami::login(12345, 'wrongpassword');
|
||||
} catch (LoginException $e) {
|
||||
$this->assertEquals(LoginException::WRONG_CREDENTIALS, $e->reason);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_first_login_fails_because_of_bruteforce_protection(): void
|
||||
{
|
||||
Http::fake($this->fakeBruteforceFailure());
|
||||
|
||||
try {
|
||||
Nami::login(12345, 'secret');
|
||||
} catch (LoginException $e) {
|
||||
$this->assertEquals(LoginException::TOO_MANY_FAILED_LOGINS, $e->reason);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_store_cookie_after_login(): void
|
||||
{
|
||||
Http::fake($this->fakeSuccessfulLogin());
|
||||
|
||||
Nami::login(12345, 'secret');
|
||||
|
||||
$this->assertFileExists(__DIR__.'/../../.cookies_test/'.time().'.txt');
|
||||
}
|
||||
|
||||
public function test_dont_login_if_cookie_exists(): void
|
||||
{
|
||||
touch(__DIR__.'/../../.cookies_test/'.time().'.txt');
|
||||
|
||||
Nami::login(12345, 'secret');
|
||||
|
||||
Http::assertSentCount(0);
|
||||
}
|
||||
|
||||
public function test_delete_expired_cookie_before_login(): void
|
||||
{
|
||||
$lastLogin = now()->subHours(2)->timestamp;
|
||||
touch(__DIR__."/../../.cookies_test/{$lastLogin}.txt");
|
||||
Http::fake($this->fakeSuccessfulLogin());
|
||||
|
||||
Nami::login(12345, 'secret');
|
||||
|
||||
Http::assertSentCount(2);
|
||||
$this->assertFileDoesNotExist(__DIR__."/../../.cookies_test/{$lastLogin}.txt");
|
||||
}
|
||||
|
||||
public function test_login_once_if_cookie_is_expired(): void
|
||||
{
|
||||
$lastLogin = now()->subHour()->subMinutes(10)->timestamp;
|
||||
touch(__DIR__."/../../.cookies_test/{$lastLogin}.txt");
|
||||
Http::fake($this->fakeSuccessfulLogin());
|
||||
|
||||
Nami::login(12345, 'secret');
|
||||
Nami::login(12345, 'secret');
|
||||
|
||||
Http::assertSentCount(2);
|
||||
}
|
||||
|
||||
public function test_it_refreshes_login_when_a_cookie_of_an_existing_api_is_expired(): void
|
||||
{
|
||||
app(CourseFake::class)->forMember(11111, []);
|
||||
Http::fake($this->fakeSuccessfulLoginForever());
|
||||
$api = Nami::login(12345, 'secret');
|
||||
$this->clearCookies();
|
||||
$lastLogin = now()->subHours(2)->timestamp;
|
||||
touch(__DIR__."/../../.cookies_test/{$lastLogin}.txt");
|
||||
|
||||
$courses = $api->coursesFor(11111);
|
||||
$this->assertCount(0, $courses);
|
||||
}
|
||||
|
||||
public function test_it_fakes_login(): void
|
||||
{
|
||||
Auth::fake();
|
||||
Auth::success(12345, 'secret');
|
||||
Auth::assertNotLoggedIn();
|
||||
|
||||
Nami::login(12345, 'secret');
|
||||
|
||||
Auth::assertLoggedInWith(12345, 'secret');
|
||||
Auth::assertLoggedIn();
|
||||
Auth::assertNotLoggedInWith(12345, 'wrong');
|
||||
Http::assertSentCount(0);
|
||||
}
|
||||
|
||||
public function test_it_fakes_failed_login(): void
|
||||
{
|
||||
Auth::fake();
|
||||
Auth::failed(12345, 'wrong');
|
||||
$this->expectException(LoginException::class);
|
||||
|
||||
Nami::login(12345, 'wrong');
|
||||
|
||||
Http::assertSentCount(0);
|
||||
Auth::assertNotLoggedIn();
|
||||
}
|
||||
|
||||
public function test_it_fakes_login_state(): void
|
||||
{
|
||||
Auth::fake();
|
||||
Auth::success(12345, 'secret');
|
||||
$this->assertFalse(Nami::isLoggedIn());
|
||||
|
||||
Nami::login(12345, 'secret');
|
||||
|
||||
$this->assertTrue(Nami::isLoggedIn());
|
||||
}
|
||||
|
||||
private function fakeSuccessfulLogin(): array
|
||||
{
|
||||
return [
|
||||
'https://nami.dpsg.de/ica/pages/login.jsp' => Http::sequence()->push('<html></html>', 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::sequence()->push($this->successJson, 200),
|
||||
];
|
||||
}
|
||||
|
||||
private function fakeSuccessfulLoginForever(): array
|
||||
{
|
||||
return [
|
||||
'https://nami.dpsg.de/ica/pages/login.jsp' => Http::response('<html></html>', 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::response($this->successJson, 200),
|
||||
];
|
||||
}
|
||||
|
||||
private function fakeFailedLogin(): array
|
||||
{
|
||||
return [
|
||||
'https://nami.dpsg.de/ica/pages/login.jsp' => Http::sequence()->push('<html></html>', 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::sequence()->push($this->wrongCredentialsJson, 200)
|
||||
];
|
||||
}
|
||||
|
||||
private function fakeBruteforceFailure(): array
|
||||
{
|
||||
return [
|
||||
'https://nami.dpsg.de/ica/pages/login.jsp' => Http::sequence()->push('<html></html>', 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::sequence()->push($this->bruteJson, 200)
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue