Fix: mglnr should be a string
This commit is contained in:
parent
35bed01848
commit
47f01b3c3c
|
@ -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);
|
$this->authenticator->login($mglnr, $password);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function freshLogin(int $mglnr, string $password): self
|
public function freshLogin(string $mglnr, string $password): self
|
||||||
{
|
{
|
||||||
$this->authenticator->purge($mglnr);
|
$this->authenticator->purge($mglnr);
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,10 @@ use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method static void assertNotLoggedIn()
|
* @method static void assertNotLoggedIn()
|
||||||
* @method static void success(int $mglnr, string $password)
|
* @method static void success(string $mglnr, string $password)
|
||||||
* @method static void fails(int $mglnr, string $password)
|
* @method static void fails(string $mglnr, string $password)
|
||||||
* @method static void assertLoggedInWith(int $mglnr, string $password)
|
* @method static void assertLoggedInWith(string $mglnr, string $password)
|
||||||
* @method static void assertNotLoggedInWith(int $mglnr, string $password)
|
* @method static void assertNotLoggedInWith(string $mglnr, string $password)
|
||||||
* @method static void assertLoggedIn()
|
* @method static void assertLoggedIn()
|
||||||
*/
|
*/
|
||||||
class Auth extends Facade
|
class Auth extends Facade
|
||||||
|
|
|
@ -8,9 +8,9 @@ abstract class Authenticator
|
||||||
{
|
{
|
||||||
protected static string $path = __DIR__ . '/../../.cookies';
|
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;
|
abstract public function http(): PendingRequest;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use PHPUnit\Framework\Assert;
|
||||||
use Zoomyboy\LaravelNami\LoginException;
|
use Zoomyboy\LaravelNami\LoginException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template Account of array{mglnr: int, password: string}
|
* @template Account of array{mglnr: string, password: string}
|
||||||
*/
|
*/
|
||||||
class FakeCookie extends Authenticator
|
class FakeCookie extends Authenticator
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ class FakeCookie extends Authenticator
|
||||||
/**
|
/**
|
||||||
* @return self<Account>
|
* @return self<Account>
|
||||||
*/
|
*/
|
||||||
public function login(int $mglnr, string $password): self
|
public function login(string $mglnr, string $password): self
|
||||||
{
|
{
|
||||||
$authenticated = collect($this->validAccounts)->search(
|
$authenticated = collect($this->validAccounts)->search(
|
||||||
fn ($account) => $account['mglnr'] === $mglnr && $account['password'] === $password
|
fn ($account) => $account['mglnr'] === $mglnr && $account['password'] === $password
|
||||||
|
@ -52,18 +52,18 @@ class FakeCookie extends Authenticator
|
||||||
* Reisters an account that can successfully login with
|
* Reisters an account that can successfully login with
|
||||||
* the given password.
|
* 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];
|
$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($mglnr, data_get($this->authenticated, 'mglnr'));
|
||||||
Assert::assertSame($password, data_get($this->authenticated, 'password'));
|
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(
|
Assert::assertTrue(
|
||||||
$mglnr !== data_get($this->authenticated, 'mglnr')
|
$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
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,10 @@ class MainCookie extends Authenticator
|
||||||
{
|
{
|
||||||
private CookieJar $cookie;
|
private CookieJar $cookie;
|
||||||
private string $url = 'https://nami.dpsg.de';
|
private string $url = 'https://nami.dpsg.de';
|
||||||
private int $mglnr;
|
private string $mglnr;
|
||||||
private string $password;
|
private string $password;
|
||||||
|
|
||||||
public function login(int $mglnr, string $password): self
|
public function login(string $mglnr, string $password): self
|
||||||
{
|
{
|
||||||
$this->mglnr = $mglnr;
|
$this->mglnr = $mglnr;
|
||||||
$this->password = $password;
|
$this->password = $password;
|
||||||
|
@ -46,7 +46,7 @@ class MainCookie extends Authenticator
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function purge(int $mglnr): void
|
public function purge(string $mglnr): void
|
||||||
{
|
{
|
||||||
$this->mglnr = $mglnr;
|
$this->mglnr = $mglnr;
|
||||||
while ($this->file()) {
|
while ($this->file()) {
|
||||||
|
|
|
@ -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) {
|
Http::assertSent(function ($request) use ($mglnr, $password) {
|
||||||
return $request->url() === 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup'
|
return $request->url() === 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup'
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace Zoomyboy\LaravelNami;
|
||||||
use Illuminate\Support\Facades\Facade;
|
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 bool isLoggedIn()
|
||||||
* @method static \Zoomyboy\LaravelNami\Api fake()
|
* @method static \Zoomyboy\LaravelNami\Api fake()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -40,16 +40,16 @@ class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
public function login(): Api
|
public function login(): Api
|
||||||
{
|
{
|
||||||
Auth::fake();
|
Auth::fake();
|
||||||
Auth::success(12345, 'secret');
|
Auth::success('12345', 'secret');
|
||||||
|
|
||||||
return Nami::login(12345, 'secret');
|
return Nami::login('12345', 'secret');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loginWithWrongCredentials(): Api
|
public function loginWithWrongCredentials(): Api
|
||||||
{
|
{
|
||||||
Auth::fake();
|
Auth::fake();
|
||||||
|
|
||||||
return Nami::login(12345, 'wrong');
|
return Nami::login('12345', 'wrong');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function clearCookies(): void
|
protected function clearCookies(): void
|
||||||
|
|
|
@ -19,10 +19,10 @@ class BausteinTest extends TestCase
|
||||||
|
|
||||||
public function testGetAllCourses(): void
|
public function testGetAllCourses(): void
|
||||||
{
|
{
|
||||||
Auth::success(12345, 'secret');
|
Auth::success('12345', 'secret');
|
||||||
app(BausteinFake::class)->fetches([['id' => 788, 'descriptor' => 'abc']]);
|
app(BausteinFake::class)->fetches([['id' => 788, 'descriptor' => 'abc']]);
|
||||||
|
|
||||||
$courses = Nami::login(12345, 'secret')->courses();
|
$courses = Nami::login('12345', 'secret')->courses();
|
||||||
|
|
||||||
$this->assertCount(1, $courses);
|
$this->assertCount(1, $courses);
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ class BausteinTest extends TestCase
|
||||||
public function testThrowExceptionWhenBausteinFetchingFails(): void
|
public function testThrowExceptionWhenBausteinFetchingFails(): void
|
||||||
{
|
{
|
||||||
$this->expectException(NotSuccessfulException::class);
|
$this->expectException(NotSuccessfulException::class);
|
||||||
Auth::success(12345, 'secret');
|
Auth::success('12345', 'secret');
|
||||||
app(BausteinFake::class)->failsToFetch();
|
app(BausteinFake::class)->failsToFetch();
|
||||||
|
|
||||||
Nami::login(12345, 'secret')->courses();
|
Nami::login('12345', 'secret')->courses();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,12 @@ class GroupsTest extends TestCase
|
||||||
|
|
||||||
public function testGetGroups(): void
|
public function testGetGroups(): void
|
||||||
{
|
{
|
||||||
Auth::success(12345, 'secret');
|
Auth::success('12345', 'secret');
|
||||||
app(GroupFake::class)->fetches(null, [
|
app(GroupFake::class)->fetches(null, [
|
||||||
1234 => ['name' => 'testgroup'],
|
1234 => ['name' => 'testgroup'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$group = Nami::login(12345, 'secret')->group(1234);
|
$group = Nami::login('12345', 'secret')->group(1234);
|
||||||
|
|
||||||
$this->assertInstanceOf(Group::class, $group);
|
$this->assertInstanceOf(Group::class, $group);
|
||||||
$this->assertEquals('testgroup', $group->name);
|
$this->assertEquals('testgroup', $group->name);
|
||||||
|
@ -39,14 +39,14 @@ class GroupsTest extends TestCase
|
||||||
|
|
||||||
public function testGetSubgroups(): void
|
public function testGetSubgroups(): void
|
||||||
{
|
{
|
||||||
Auth::success(12345, 'secret');
|
Auth::success('12345', 'secret');
|
||||||
app(GroupFake::class)->fetches(null, [
|
app(GroupFake::class)->fetches(null, [
|
||||||
1234 => ['name' => 'testgroup'],
|
1234 => ['name' => 'testgroup'],
|
||||||
])->fetches(1234, [
|
])->fetches(1234, [
|
||||||
555 => ['name' => 'ABC'],
|
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('ABC', $group->name);
|
||||||
$this->assertEquals(555, $group->id);
|
$this->assertEquals(555, $group->id);
|
||||||
|
@ -64,30 +64,30 @@ class GroupsTest extends TestCase
|
||||||
public function testThrowsExceptionWhenGroupFetchFailed(): void
|
public function testThrowsExceptionWhenGroupFetchFailed(): void
|
||||||
{
|
{
|
||||||
$this->expectException(NotSuccessfulException::class);
|
$this->expectException(NotSuccessfulException::class);
|
||||||
Auth::success(12345, 'secret');
|
Auth::success('12345', 'secret');
|
||||||
app(GroupFake::class)->failsToFetch(null);
|
app(GroupFake::class)->failsToFetch(null);
|
||||||
|
|
||||||
Nami::login(12345, 'secret')->group(1234);
|
Nami::login('12345', 'secret')->group(1234);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testThrowsExceptionWhenSubgroupFetchFailed(): void
|
public function testThrowsExceptionWhenSubgroupFetchFailed(): void
|
||||||
{
|
{
|
||||||
$this->expectException(NotSuccessfulException::class);
|
$this->expectException(NotSuccessfulException::class);
|
||||||
Auth::success(12345, 'secret');
|
Auth::success('12345', 'secret');
|
||||||
app(GroupFake::class)->fetches(null, [
|
app(GroupFake::class)->fetches(null, [
|
||||||
1234 => ['name' => 'testgroup'],
|
1234 => ['name' => 'testgroup'],
|
||||||
]);
|
]);
|
||||||
app(GroupFake::class)->failsToFetch(1234);
|
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
|
public function testItDoesntReturnGroupWhenNoJsonIsReturned(): void
|
||||||
{
|
{
|
||||||
$this->expectException(NoJsonReceivedException::class);
|
$this->expectException(NoJsonReceivedException::class);
|
||||||
Auth::success(12345, 'secret');
|
Auth::success('12345', 'secret');
|
||||||
app(GroupFake::class)->failsToFetchWithoutJson(null);
|
app(GroupFake::class)->failsToFetchWithoutJson(null);
|
||||||
|
|
||||||
Nami::login(12345, 'secret')->group(1234);
|
Nami::login('12345', 'secret')->group(1234);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,19 +24,19 @@ class LoginTest extends TestCase
|
||||||
{
|
{
|
||||||
app(LoginFake::class)->succeeds('lala-testsession');
|
app(LoginFake::class)->succeeds('lala-testsession');
|
||||||
|
|
||||||
app(MainCookie::class)->login(12345, 'secret');
|
app(MainCookie::class)->login('12345', 'secret');
|
||||||
|
|
||||||
Http::assertSentCount(1);
|
Http::assertSentCount(1);
|
||||||
$cookie = file_get_contents(__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt');
|
$cookie = file_get_contents(__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt');
|
||||||
$this->assertEquals('lala-testsession.srv-nami06', $cookie);
|
$this->assertEquals('lala-testsession.srv-nami06', $cookie);
|
||||||
app(LoginFake::class)->assertSent(12345, 'secret');
|
app(LoginFake::class)->assertSent('12345', 'secret');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItThrowsExceptionWhenLoginFails(): void
|
public function testItThrowsExceptionWhenLoginFails(): void
|
||||||
{
|
{
|
||||||
app(LoginFake::class)->fails('::token::');
|
app(LoginFake::class)->fails('::token::');
|
||||||
$this->expectException(LoginException::class);
|
$this->expectException(LoginException::class);
|
||||||
app(MainCookie::class)->login(12345, 'secret');
|
app(MainCookie::class)->login('12345', 'secret');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItDoesntSaveCookieWhenLoginFails(): void
|
public function testItDoesntSaveCookieWhenLoginFails(): void
|
||||||
|
@ -44,7 +44,7 @@ class LoginTest extends TestCase
|
||||||
app(LoginFake::class)->fails('::token::');
|
app(LoginFake::class)->fails('::token::');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
app(MainCookie::class)->login(12345, 'secret');
|
app(MainCookie::class)->login('12345', 'secret');
|
||||||
} catch (LoginException $e) {
|
} catch (LoginException $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class LoginTest extends TestCase
|
||||||
app(CourseFake::class)->fetches(103, []);
|
app(CourseFake::class)->fetches(103, []);
|
||||||
file_put_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->subMinutes(5)->timestamp . '.txt', 'cook-testsession.srv-nami06');
|
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);
|
Http::assertSentCount(0);
|
||||||
$this->assertFileExists(__DIR__ . '/../../.cookies_test/90100_' . now()->subMinutes(5)->timestamp . '.txt');
|
$this->assertFileExists(__DIR__ . '/../../.cookies_test/90100_' . now()->subMinutes(5)->timestamp . '.txt');
|
||||||
|
@ -70,7 +70,7 @@ class LoginTest extends TestCase
|
||||||
app(LoginFake::class)->succeeds('newlogin');
|
app(LoginFake::class)->succeeds('newlogin');
|
||||||
file_put_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->subHour()->timestamp . '.txt', 'oldlogin-testsession.srv-nami06');
|
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);
|
Http::assertSentCount(1);
|
||||||
$cookie = file_get_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->timestamp . '.txt');
|
$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(CourseFake::class)->fetches(103, []);
|
||||||
app(LoginFake::class)->succeeds('newlogin');
|
app(LoginFake::class)->succeeds('newlogin');
|
||||||
file_put_contents(__DIR__ . '/../../.cookies_test/11111_' . now()->timestamp . '.txt', 'oldlogin-testsession.srv-nami06');
|
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/11111_' . now()->timestamp . '.txt');
|
||||||
$this->assertFileExists(__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt');
|
$this->assertFileExists(__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt');
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ class LoginTest extends TestCase
|
||||||
public function testItRefreshesLogin(): void
|
public function testItRefreshesLogin(): void
|
||||||
{
|
{
|
||||||
app(LoginFake::class)->succeeds('newlogin');
|
app(LoginFake::class)->succeeds('newlogin');
|
||||||
$auth = app(Authenticator::class)->login(12345, 'secret');
|
$auth = app(Authenticator::class)->login('12345', 'secret');
|
||||||
rename(
|
rename(
|
||||||
__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt',
|
__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt',
|
||||||
__DIR__ . '/../../.cookies_test/12345_' . now()->subMinutes(51)->timestamp . '.txt'
|
__DIR__ . '/../../.cookies_test/12345_' . now()->subMinutes(51)->timestamp . '.txt'
|
||||||
|
|
Loading…
Reference in New Issue