From 47f01b3c3c98821603f3612511d713cf51a6a14c Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 9 Jul 2025 00:52:52 +0200 Subject: [PATCH] Fix: mglnr should be a string --- src/Api.php | 4 ++-- src/Authentication/Auth.php | 8 ++++---- src/Authentication/Authenticator.php | 4 ++-- src/Authentication/FakeCookie.php | 12 ++++++------ src/Authentication/MainCookie.php | 6 +++--- src/Fakes/LoginFake.php | 2 +- src/Nami.php | 2 +- tests/TestCase.php | 6 +++--- tests/Unit/BausteinTest.php | 8 ++++---- tests/Unit/GroupsTest.php | 20 ++++++++++---------- tests/Unit/LoginTest.php | 18 +++++++++--------- 11 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/Api.php b/src/Api.php index 94f21aa..d1cd48c 100644 --- a/src/Api.php +++ b/src/Api.php @@ -128,14 +128,14 @@ class Api } } - public function login(int $mglnr, string $password): self + public function login(string $mglnr, string $password): self { $this->authenticator->login($mglnr, $password); return $this; } - public function freshLogin(int $mglnr, string $password): self + public function freshLogin(string $mglnr, string $password): self { $this->authenticator->purge($mglnr); diff --git a/src/Authentication/Auth.php b/src/Authentication/Auth.php index 9e9fd84..0f7c0e4 100644 --- a/src/Authentication/Auth.php +++ b/src/Authentication/Auth.php @@ -6,10 +6,10 @@ use Illuminate\Support\Facades\Facade; /** * @method static void assertNotLoggedIn() - * @method static void success(int $mglnr, string $password) - * @method static void fails(int $mglnr, string $password) - * @method static void assertLoggedInWith(int $mglnr, string $password) - * @method static void assertNotLoggedInWith(int $mglnr, string $password) + * @method static void success(string $mglnr, string $password) + * @method static void fails(string $mglnr, string $password) + * @method static void assertLoggedInWith(string $mglnr, string $password) + * @method static void assertNotLoggedInWith(string $mglnr, string $password) * @method static void assertLoggedIn() */ class Auth extends Facade diff --git a/src/Authentication/Authenticator.php b/src/Authentication/Authenticator.php index e192a84..c219d44 100644 --- a/src/Authentication/Authenticator.php +++ b/src/Authentication/Authenticator.php @@ -8,9 +8,9 @@ abstract class Authenticator { protected static string $path = __DIR__ . '/../../.cookies'; - abstract public function login(int $mglnr, string $password): self; + abstract public function login(string $mglnr, string $password): self; - abstract public function purge(int $mglnr): void; + abstract public function purge(string $mglnr): void; abstract public function http(): PendingRequest; diff --git a/src/Authentication/FakeCookie.php b/src/Authentication/FakeCookie.php index 201537d..2a9a7de 100644 --- a/src/Authentication/FakeCookie.php +++ b/src/Authentication/FakeCookie.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\Assert; use Zoomyboy\LaravelNami\LoginException; /** - * @template Account of array{mglnr: int, password: string} + * @template Account of array{mglnr: string, password: string} */ class FakeCookie extends Authenticator { @@ -20,7 +20,7 @@ class FakeCookie extends Authenticator /** * @return self */ - public function login(int $mglnr, string $password): self + public function login(string $mglnr, string $password): self { $authenticated = collect($this->validAccounts)->search( fn ($account) => $account['mglnr'] === $mglnr && $account['password'] === $password @@ -52,18 +52,18 @@ class FakeCookie extends Authenticator * Reisters an account that can successfully login with * the given password. */ - public function success(int $mglnr, string $password): void + public function success(string $mglnr, string $password): void { $this->validAccounts[] = ['mglnr' => $mglnr, 'password' => $password]; } - public function assertLoggedInWith(int $mglnr, string $password): void + public function assertLoggedInWith(string $mglnr, string $password): void { Assert::assertSame($mglnr, data_get($this->authenticated, 'mglnr')); Assert::assertSame($password, data_get($this->authenticated, 'password')); } - public function assertNotLoggedInWith(int $mglnr, string $password): void + public function assertNotLoggedInWith(string $mglnr, string $password): void { Assert::assertTrue( $mglnr !== data_get($this->authenticated, 'mglnr') @@ -72,7 +72,7 @@ class FakeCookie extends Authenticator ); } - public function purge(int $mglnr): void + public function purge(string $mglnr): void { } diff --git a/src/Authentication/MainCookie.php b/src/Authentication/MainCookie.php index f953b07..3f24cf7 100644 --- a/src/Authentication/MainCookie.php +++ b/src/Authentication/MainCookie.php @@ -12,10 +12,10 @@ class MainCookie extends Authenticator { private CookieJar $cookie; private string $url = 'https://nami.dpsg.de'; - private int $mglnr; + private string $mglnr; private string $password; - public function login(int $mglnr, string $password): self + public function login(string $mglnr, string $password): self { $this->mglnr = $mglnr; $this->password = $password; @@ -46,7 +46,7 @@ class MainCookie extends Authenticator return $this; } - public function purge(int $mglnr): void + public function purge(string $mglnr): void { $this->mglnr = $mglnr; while ($this->file()) { diff --git a/src/Fakes/LoginFake.php b/src/Fakes/LoginFake.php index ae9f5fe..096bcd4 100644 --- a/src/Fakes/LoginFake.php +++ b/src/Fakes/LoginFake.php @@ -39,7 +39,7 @@ class LoginFake extends Fake }); } - public function assertSent(int $mglnr, string $password): void + public function assertSent(string $mglnr, string $password): void { Http::assertSent(function ($request) use ($mglnr, $password) { return $request->url() === 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' diff --git a/src/Nami.php b/src/Nami.php index fbebc36..981c159 100644 --- a/src/Nami.php +++ b/src/Nami.php @@ -5,7 +5,7 @@ namespace Zoomyboy\LaravelNami; use Illuminate\Support\Facades\Facade; /** - * @method static \Zoomyboy\LaravelNami\Api login(int $mglnr, string $password) + * @method static \Zoomyboy\LaravelNami\Api login(string $mglnr, string $password) * @method static bool isLoggedIn() * @method static \Zoomyboy\LaravelNami\Api fake() */ diff --git a/tests/TestCase.php b/tests/TestCase.php index 3bd2dff..61cc7af 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -40,16 +40,16 @@ class TestCase extends \Orchestra\Testbench\TestCase public function login(): Api { Auth::fake(); - Auth::success(12345, 'secret'); + Auth::success('12345', 'secret'); - return Nami::login(12345, 'secret'); + return Nami::login('12345', 'secret'); } public function loginWithWrongCredentials(): Api { Auth::fake(); - return Nami::login(12345, 'wrong'); + return Nami::login('12345', 'wrong'); } protected function clearCookies(): void diff --git a/tests/Unit/BausteinTest.php b/tests/Unit/BausteinTest.php index efdba40..988b1dc 100644 --- a/tests/Unit/BausteinTest.php +++ b/tests/Unit/BausteinTest.php @@ -19,10 +19,10 @@ class BausteinTest extends TestCase public function testGetAllCourses(): void { - Auth::success(12345, 'secret'); + Auth::success('12345', 'secret'); app(BausteinFake::class)->fetches([['id' => 788, 'descriptor' => 'abc']]); - $courses = Nami::login(12345, 'secret')->courses(); + $courses = Nami::login('12345', 'secret')->courses(); $this->assertCount(1, $courses); @@ -33,9 +33,9 @@ class BausteinTest extends TestCase public function testThrowExceptionWhenBausteinFetchingFails(): void { $this->expectException(NotSuccessfulException::class); - Auth::success(12345, 'secret'); + Auth::success('12345', 'secret'); app(BausteinFake::class)->failsToFetch(); - Nami::login(12345, 'secret')->courses(); + Nami::login('12345', 'secret')->courses(); } } diff --git a/tests/Unit/GroupsTest.php b/tests/Unit/GroupsTest.php index c153b7d..08f9ba5 100644 --- a/tests/Unit/GroupsTest.php +++ b/tests/Unit/GroupsTest.php @@ -22,12 +22,12 @@ class GroupsTest extends TestCase public function testGetGroups(): void { - Auth::success(12345, 'secret'); + Auth::success('12345', 'secret'); app(GroupFake::class)->fetches(null, [ 1234 => ['name' => 'testgroup'], ]); - $group = Nami::login(12345, 'secret')->group(1234); + $group = Nami::login('12345', 'secret')->group(1234); $this->assertInstanceOf(Group::class, $group); $this->assertEquals('testgroup', $group->name); @@ -39,14 +39,14 @@ class GroupsTest extends TestCase public function testGetSubgroups(): void { - Auth::success(12345, 'secret'); + Auth::success('12345', 'secret'); app(GroupFake::class)->fetches(null, [ 1234 => ['name' => 'testgroup'], ])->fetches(1234, [ 555 => ['name' => 'ABC'], ]); - $group = Nami::login(12345, 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null]))->first(); + $group = Nami::login('12345', 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null]))->first(); $this->assertEquals('ABC', $group->name); $this->assertEquals(555, $group->id); @@ -64,30 +64,30 @@ class GroupsTest extends TestCase public function testThrowsExceptionWhenGroupFetchFailed(): void { $this->expectException(NotSuccessfulException::class); - Auth::success(12345, 'secret'); + Auth::success('12345', 'secret'); app(GroupFake::class)->failsToFetch(null); - Nami::login(12345, 'secret')->group(1234); + Nami::login('12345', 'secret')->group(1234); } public function testThrowsExceptionWhenSubgroupFetchFailed(): void { $this->expectException(NotSuccessfulException::class); - Auth::success(12345, 'secret'); + Auth::success('12345', 'secret'); app(GroupFake::class)->fetches(null, [ 1234 => ['name' => 'testgroup'], ]); app(GroupFake::class)->failsToFetch(1234); - Nami::login(12345, 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null])); + Nami::login('12345', 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null])); } public function testItDoesntReturnGroupWhenNoJsonIsReturned(): void { $this->expectException(NoJsonReceivedException::class); - Auth::success(12345, 'secret'); + Auth::success('12345', 'secret'); app(GroupFake::class)->failsToFetchWithoutJson(null); - Nami::login(12345, 'secret')->group(1234); + Nami::login('12345', 'secret')->group(1234); } } diff --git a/tests/Unit/LoginTest.php b/tests/Unit/LoginTest.php index 59f3d76..75539d7 100644 --- a/tests/Unit/LoginTest.php +++ b/tests/Unit/LoginTest.php @@ -24,19 +24,19 @@ class LoginTest extends TestCase { app(LoginFake::class)->succeeds('lala-testsession'); - app(MainCookie::class)->login(12345, 'secret'); + app(MainCookie::class)->login('12345', 'secret'); Http::assertSentCount(1); $cookie = file_get_contents(__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt'); $this->assertEquals('lala-testsession.srv-nami06', $cookie); - app(LoginFake::class)->assertSent(12345, 'secret'); + app(LoginFake::class)->assertSent('12345', 'secret'); } public function testItThrowsExceptionWhenLoginFails(): void { app(LoginFake::class)->fails('::token::'); $this->expectException(LoginException::class); - app(MainCookie::class)->login(12345, 'secret'); + app(MainCookie::class)->login('12345', 'secret'); } public function testItDoesntSaveCookieWhenLoginFails(): void @@ -44,7 +44,7 @@ class LoginTest extends TestCase app(LoginFake::class)->fails('::token::'); try { - app(MainCookie::class)->login(12345, 'secret'); + app(MainCookie::class)->login('12345', 'secret'); } catch (LoginException $e) { } @@ -57,7 +57,7 @@ class LoginTest extends TestCase app(CourseFake::class)->fetches(103, []); file_put_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->subMinutes(5)->timestamp . '.txt', 'cook-testsession.srv-nami06'); - Nami::login(90100, 'secret'); + Nami::login('90100', 'secret'); Http::assertSentCount(0); $this->assertFileExists(__DIR__ . '/../../.cookies_test/90100_' . now()->subMinutes(5)->timestamp . '.txt'); @@ -70,7 +70,7 @@ class LoginTest extends TestCase app(LoginFake::class)->succeeds('newlogin'); file_put_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->subHour()->timestamp . '.txt', 'oldlogin-testsession.srv-nami06'); - Nami::login(90100, 'secret'); + Nami::login('90100', 'secret'); Http::assertSentCount(1); $cookie = file_get_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->timestamp . '.txt'); @@ -84,9 +84,9 @@ class LoginTest extends TestCase app(CourseFake::class)->fetches(103, []); app(LoginFake::class)->succeeds('newlogin'); file_put_contents(__DIR__ . '/../../.cookies_test/11111_' . now()->timestamp . '.txt', 'oldlogin-testsession.srv-nami06'); - app(Authenticator::class)->login(12345, 'secret'); + app(Authenticator::class)->login('12345', 'secret'); - app(LoginFake::class)->assertSent(12345, 'secret'); + app(LoginFake::class)->assertSent('12345', 'secret'); $this->assertFileExists(__DIR__ . '/../../.cookies_test/11111_' . now()->timestamp . '.txt'); $this->assertFileExists(__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt'); } @@ -94,7 +94,7 @@ class LoginTest extends TestCase public function testItRefreshesLogin(): void { app(LoginFake::class)->succeeds('newlogin'); - $auth = app(Authenticator::class)->login(12345, 'secret'); + $auth = app(Authenticator::class)->login('12345', 'secret'); rename( __DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt', __DIR__ . '/../../.cookies_test/12345_' . now()->subMinutes(51)->timestamp . '.txt'