Compare commits
9 Commits
af626f5d3a
...
0dd2c64c38
Author | SHA1 | Date |
---|---|---|
|
0dd2c64c38 | |
|
cf50705d5a | |
|
5802ccf332 | |
|
e897d37dbd | |
|
6fd6e9ead5 | |
|
8125e664b1 | |
|
95985a00e5 | |
|
8e0c56641a | |
|
b558766cdc |
45
src/Api.php
45
src/Api.php
|
@ -72,8 +72,9 @@ class Api
|
|||
{
|
||||
$this->assertLoggedIn();
|
||||
|
||||
return app(Paginator::class)->startResult(100,
|
||||
fn ($page, $start) => $this->http()->get($this->url.'/ica/rest/nami/search-multi/result-list?searchedValues='.rawurlencode(json_encode((object) $payload) ?: '{}').'&page='.$page.'&start='.$start.'&limit=100'),
|
||||
return app(Paginator::class)->startResult(
|
||||
100,
|
||||
fn ($page, $start) => $this->http()->get($this->url . '/ica/rest/nami/search-multi/result-list?searchedValues=' . rawurlencode(json_encode((object) $payload) ?: '{}') . '&page=' . $page . '&start=' . $start . '&limit=100'),
|
||||
function ($response) {
|
||||
if (true !== $response->json()['success']) {
|
||||
$this->exception(NotSuccessfulException::class, 'Search failed', '', $response->json(), []);
|
||||
|
@ -105,7 +106,7 @@ class Api
|
|||
public function pageSearch(array $payload, int $page, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$start = ($page - 1) * $perPage;
|
||||
$response = $this->http()->get($this->url.'/ica/rest/nami/search-multi/result-list?searchedValues='.rawurlencode(json_encode((object) $payload) ?: '{}').'&page='.$page.'&start='.$start.'&limit='.$perPage);
|
||||
$response = $this->http()->get($this->url . '/ica/rest/nami/search-multi/result-list?searchedValues=' . rawurlencode(json_encode((object) $payload) ?: '{}') . '&page=' . $page . '&start=' . $start . '&limit=' . $perPage);
|
||||
$items = array_map(fn ($member) => MemberEntry::from($member), $response->json()['data']);
|
||||
|
||||
return new LengthAwarePaginator($items, $response->json('totalEntries'), $perPage, $page, []);
|
||||
|
@ -114,11 +115,11 @@ class Api
|
|||
public function deleteMember(int $id): void
|
||||
{
|
||||
$this->assertLoggedIn();
|
||||
$url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/mglschaft-beenden';
|
||||
$url = $this->url . '/ica/rest/nami/mitglied/filtered-for-navigation/mglschaft-beenden';
|
||||
$payload = [
|
||||
'id' => $id,
|
||||
'isConfirmed' => 'true',
|
||||
'beendenZumDatum' => now()->subDays(1)->format('Y-m-d').' 00:00:00',
|
||||
'beendenZumDatum' => now()->subDays(1)->format('Y-m-d') . ' 00:00:00',
|
||||
];
|
||||
$response = $this->http()->asForm()->post($url, $payload);
|
||||
|
||||
|
@ -153,13 +154,13 @@ class Api
|
|||
$existing = $this->rawMember($member->groupId, $member->id);
|
||||
$payload = array_merge($existing, $member->toNami());
|
||||
$payload['kontoverbindung'] = json_encode(data_get($payload, 'kontoverbindung', []));
|
||||
$url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->groupId.'/'.$member->id;
|
||||
$url = $this->url . '/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/' . $member->groupId . '/' . $member->id;
|
||||
$response = $this->http()->put($url, $payload);
|
||||
$this->assertOk($response, $url, 'Update failed');
|
||||
|
||||
return $response->json()['data']['id'];
|
||||
} else {
|
||||
$url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->groupId;
|
||||
$url = $this->url . '/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/' . $member->groupId;
|
||||
$response = $this->http()->post($url, [
|
||||
...$member->toNami(),
|
||||
'ersteTaetigkeitId' => $firstActivity,
|
||||
|
@ -177,10 +178,10 @@ class Api
|
|||
{
|
||||
$this->assertLoggedIn();
|
||||
if ($data->id) {
|
||||
$url = $this->url."/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}/{$data->id}";
|
||||
$url = $this->url . "/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}/{$data->id}";
|
||||
$response = $this->http()->put($url, $data->toNami());
|
||||
} else {
|
||||
$url = $this->url."/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}";
|
||||
$url = $this->url . "/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/{$memberId}";
|
||||
$response = $this->http()->post($url, $data->toNami());
|
||||
}
|
||||
if (true !== data_get($response->json(), 'success')) {
|
||||
|
@ -204,7 +205,7 @@ class Api
|
|||
|
||||
return $this
|
||||
->fetchCollection(
|
||||
'/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/'.$memberId.'/flist',
|
||||
'/ica/rest/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/' . $memberId . '/flist',
|
||||
'Membership fetch failed'
|
||||
)
|
||||
->map(fn ($membership) => MembershipEntry::from($membership));
|
||||
|
@ -234,7 +235,7 @@ class Api
|
|||
$this->assertLoggedIn();
|
||||
|
||||
return $this->fetchCollection(
|
||||
'/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/'.$activity->id,
|
||||
'/ica/rest/nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/' . $activity->id,
|
||||
'Fetch subactivities failed'
|
||||
)->map(fn ($subactivity) => Subactivity::from($subactivity));
|
||||
}
|
||||
|
@ -286,11 +287,11 @@ class Api
|
|||
public function createCourse(int $memberId, array $payload): int
|
||||
{
|
||||
$this->assertLoggedIn();
|
||||
$url = $this->url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}";
|
||||
$url = $this->url . "/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}";
|
||||
$payload = [
|
||||
'bausteinId' => $payload['course_id'],
|
||||
'vstgName' => $payload['event_name'],
|
||||
'vstgTag' => Carbon::parse($payload['completed_at'])->format('Y-m-d').'T00:00:00',
|
||||
'vstgTag' => Carbon::parse($payload['completed_at'])->format('Y-m-d') . 'T00:00:00',
|
||||
'veranstalter' => $payload['organizer'],
|
||||
];
|
||||
$response = $this->http()->post($url, $payload);
|
||||
|
@ -308,11 +309,11 @@ class Api
|
|||
public function updateCourse(int $memberId, int $courseId, array $payload): void
|
||||
{
|
||||
$this->assertLoggedIn();
|
||||
$url = $this->url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}";
|
||||
$url = $this->url . "/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}";
|
||||
$payload = [
|
||||
'bausteinId' => $payload['course_id'],
|
||||
'vstgName' => $payload['event_name'],
|
||||
'vstgTag' => Carbon::parse($payload['completed_at'])->format('Y-m-d').'T00:00:00',
|
||||
'vstgTag' => Carbon::parse($payload['completed_at'])->format('Y-m-d') . 'T00:00:00',
|
||||
'veranstalter' => $payload['organizer'],
|
||||
];
|
||||
$response = $this->http()->put($url, $payload);
|
||||
|
@ -325,7 +326,7 @@ class Api
|
|||
public function deleteCourse(int $memberId, int $courseId): void
|
||||
{
|
||||
$this->assertLoggedIn();
|
||||
$url = $this->url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}";
|
||||
$url = $this->url . "/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}";
|
||||
$response = $this->http()->delete($url);
|
||||
|
||||
if (null !== $response->json() && true !== data_get($response->json(), 'success')) {
|
||||
|
@ -357,7 +358,7 @@ class Api
|
|||
$this->assertLoggedIn();
|
||||
|
||||
return $this->fetchCollection(
|
||||
'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/'.($parentGroup ? $parentGroup->id : 'root'),
|
||||
'/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/' . ($parentGroup ? $parentGroup->id : 'root'),
|
||||
'Group fetch failed'
|
||||
)->map(fn ($group) => Group::from([...$group, 'parentId' => $parentGroup ? $parentGroup->id : null]));
|
||||
}
|
||||
|
@ -466,8 +467,8 @@ class Api
|
|||
$this->assertLoggedIn();
|
||||
|
||||
return $this->fetchData(
|
||||
'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId,
|
||||
'Fetch von Mitglied '.$memberId.' in Gruppe '.$groupId.' fehlgeschlagen'
|
||||
'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/' . $groupId . '/' . $memberId,
|
||||
'Fetch von Mitglied ' . $memberId . ' in Gruppe ' . $groupId . ' fehlgeschlagen'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -485,7 +486,7 @@ class Api
|
|||
*/
|
||||
private function fetchCollection(string $url, string $error): Collection
|
||||
{
|
||||
$response = $this->http()->get($this->url.$url);
|
||||
$response = $this->http()->get($this->url . $url);
|
||||
|
||||
$this->assertOk($response, $url, $error);
|
||||
/** @var array<int, mixed> */
|
||||
|
@ -499,7 +500,7 @@ class Api
|
|||
*/
|
||||
private function fetchData(string $url, string $error): array
|
||||
{
|
||||
$response = $this->http()->get($this->url.$url);
|
||||
$response = $this->http()->get($this->url . $url);
|
||||
|
||||
$this->assertOk($response, $url, $error);
|
||||
|
||||
|
@ -511,7 +512,7 @@ class Api
|
|||
$response = $this->http()->withHeaders([
|
||||
'content-type' => 'application/json',
|
||||
'accept' => 'application/json',
|
||||
])->delete($this->url.$url);
|
||||
])->delete($this->url . $url);
|
||||
|
||||
$this->assertOk($response, $url, $error);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ use Illuminate\Http\Client\PendingRequest;
|
|||
|
||||
abstract class Authenticator
|
||||
{
|
||||
protected static string $path = __DIR__ . '/../../.cookies';
|
||||
|
||||
abstract public function login(int $mglnr, string $password): self;
|
||||
|
||||
abstract public function purge(): void;
|
||||
|
@ -16,8 +18,6 @@ abstract class Authenticator
|
|||
|
||||
abstract public function refresh(): void;
|
||||
|
||||
protected static string $path = __DIR__.'/../../.cookies';
|
||||
|
||||
public static function setPath(string $path): void
|
||||
{
|
||||
static::$path = $path;
|
||||
|
|
|
@ -12,8 +12,8 @@ class MainCookie extends Authenticator
|
|||
{
|
||||
private CookieJar $cookie;
|
||||
private string $url = 'https://nami.dpsg.de';
|
||||
private ?int $mglnr = null;
|
||||
private ?string $password = null;
|
||||
private int $mglnr;
|
||||
private string $password;
|
||||
|
||||
public function login(int $mglnr, string $password): self
|
||||
{
|
||||
|
@ -28,8 +28,7 @@ class MainCookie extends Authenticator
|
|||
unlink($file);
|
||||
}
|
||||
|
||||
$this->http()->get($this->url.'/ica/pages/login.jsp');
|
||||
$response = $this->http()->asForm()->post($this->url.'/ica/rest/nami/auth/manual/sessionStartup', [
|
||||
$response = $this->http()->asForm()->post($this->url . '/ica/rest/nami/auth/manual/sessionStartup', [
|
||||
'Login' => 'API',
|
||||
'redirectTo' => './app.jsp',
|
||||
'username' => $mglnr,
|
||||
|
@ -65,9 +64,7 @@ class MainCookie extends Authenticator
|
|||
|
||||
public function refresh(): void
|
||||
{
|
||||
if ($this->mglnr && $this->password) {
|
||||
$this->login($this->mglnr, $this->password);
|
||||
}
|
||||
$this->login($this->mglnr, $this->password);
|
||||
}
|
||||
|
||||
public function http(): PendingRequest
|
||||
|
@ -77,12 +74,12 @@ class MainCookie extends Authenticator
|
|||
|
||||
private function newFileName(): string
|
||||
{
|
||||
return parent::$path.'/'.time().'.txt';
|
||||
return parent::$path . '/' . $this->mglnr . '_' . now()->timestamp . '.txt';
|
||||
}
|
||||
|
||||
private function isExpired(): bool
|
||||
{
|
||||
$lastLoginTime = Carbon::createFromTimestamp(pathinfo($this->file(), PATHINFO_FILENAME));
|
||||
$lastLoginTime = Carbon::createFromTimestamp(str(pathinfo($this->file(), PATHINFO_FILENAME))->replace($this->mglnr . '_', '')->toString());
|
||||
|
||||
return $lastLoginTime->addMinutes(50)->isPast();
|
||||
}
|
||||
|
@ -94,7 +91,7 @@ class MainCookie extends Authenticator
|
|||
*/
|
||||
private function file(): ?string
|
||||
{
|
||||
$files = glob(parent::$path.'/*');
|
||||
$files = glob(parent::$path . '/' . $this->mglnr . '_*');
|
||||
|
||||
if (!count($files)) {
|
||||
return null;
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami\Fakes;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class LoginFake extends Fake
|
||||
{
|
||||
public function succeeds(string $token): void
|
||||
{
|
||||
$this->fakeLogin($token, 0);
|
||||
}
|
||||
|
||||
public function fails(string $token): void
|
||||
{
|
||||
$this->fakeLogin($token, 500);
|
||||
}
|
||||
|
||||
protected function fakeLogin(string $token, int $statusCode): void
|
||||
{
|
||||
Http::fake(function ($request) use ($token, $statusCode) {
|
||||
if ($request->url() !== 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup') {
|
||||
return;
|
||||
}
|
||||
|
||||
return Http::response(json_encode([
|
||||
"servicePrefix" => null,
|
||||
"methodCall" => null,
|
||||
"response" => null,
|
||||
"statusCode" => $statusCode,
|
||||
"statusMessage" => "",
|
||||
"apiSessionName" => "JSESSIONID",
|
||||
"apiSessionToken" => $token,
|
||||
"minorNumber" => 2,
|
||||
"majorNumber" => 1,
|
||||
]), 200, [
|
||||
'Set-Cookie' => 'JSESSIONID=' . $token . '.srv-nami06; path=/ica; secure; HttpOnly; Max-Age=9000; Expires=Sat, 24-Feb-2024 01:18:00 GMT'
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function assertSent(int $mglnr, string $password): void
|
||||
{
|
||||
Http::assertSent(function ($request) use ($mglnr, $password) {
|
||||
return $request->url() === 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup'
|
||||
&& $request->header('Content-Type')[0] === 'application/x-www-form-urlencoded'
|
||||
&& $request['Login'] === 'API'
|
||||
&& $request['redirectTo'] === './app.jsp'
|
||||
&& $request['username'] === $mglnr
|
||||
&& $request['password'] === $password;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ class SearchFake extends Fake
|
|||
public function fetchFails(int $page, int $start, int $perPage, ?string $error = 'wrong message'): void
|
||||
{
|
||||
Http::fake(function ($request) use ($error, $page, $start, $perPage) {
|
||||
if ($request->url() === 'https://nami.dpsg.de/ica/rest/nami/search-multi/result-list?searchedValues='.rawurlencode('{}').'&page='.$page.'&start='.$start.'&limit='.$perPage) {
|
||||
if ($request->url() === 'https://nami.dpsg.de/ica/rest/nami/search-multi/result-list?searchedValues=' . rawurlencode('{}') . '&page=' . $page . '&start=' . $start . '&limit=' . $perPage) {
|
||||
return $this->errorResponse($error);
|
||||
}
|
||||
});
|
||||
|
@ -23,7 +23,7 @@ class SearchFake extends Fake
|
|||
public function fetches(int $page, int $start, int $perPage, array $data): void
|
||||
{
|
||||
Http::fake(function ($request) use ($page, $start, $data, $perPage) {
|
||||
if (Str::endsWith($request->url(), '&page='.$page.'&start='.$start.'&limit='.$perPage)) {
|
||||
if (Str::endsWith($request->url(), '&page=' . $page . '&start=' . $start . '&limit=' . $perPage)) {
|
||||
return $this->collection(collect($data));
|
||||
}
|
||||
});
|
||||
|
@ -35,7 +35,7 @@ class SearchFake extends Fake
|
|||
public function assertFetched(int $page, int $start, int $perPage, array $data): void
|
||||
{
|
||||
Http::assertSent(function ($request) use ($page, $start, $perPage, $data) {
|
||||
return $request->url() === 'https://nami.dpsg.de/ica/rest/nami/search-multi/result-list?searchedValues='.rawurlencode(json_encode((object) $data)).'&page='.$page.'&start='.$start.'&limit='.$perPage;
|
||||
return $request->url() === 'https://nami.dpsg.de/ica/rest/nami/search-multi/result-list?searchedValues=' . rawurlencode(json_encode((object) $data)) . '&page=' . $page . '&start=' . $start . '&limit=' . $perPage;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,13 +69,6 @@ class CourseTest extends TestCase
|
|||
$this->login()->coursesOf(11111);
|
||||
}
|
||||
|
||||
public function testItNeedsLoginToGetCourses(): void
|
||||
{
|
||||
$this->expectException(NotAuthenticatedException::class);
|
||||
|
||||
Nami::coursesOf(11111);
|
||||
}
|
||||
|
||||
public function testStoreACourse(): void
|
||||
{
|
||||
app(CourseFake::class)->createsSuccessfully(123, 999);
|
||||
|
@ -94,17 +87,6 @@ class CourseTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function testNeedsLoginToStoreACourse(): void
|
||||
{
|
||||
$this->expectException(NotAuthenticatedException::class);
|
||||
Nami::createCourse(123, [
|
||||
'event_name' => '::event::',
|
||||
'completed_at' => '2021-01-02 00:00:00',
|
||||
'organizer' => '::org::',
|
||||
'course_id' => 456,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testUpdateACourse(): void
|
||||
{
|
||||
app(CourseFake::class)->updatesSuccessfully(123, 999);
|
||||
|
@ -140,17 +122,6 @@ class CourseTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function testItNeedsValidCredentialsToStoreACourse(): void
|
||||
{
|
||||
$this->expectException(NotAuthenticatedException::class);
|
||||
Nami::createCourse(123, [
|
||||
'event_name' => '::event::',
|
||||
'completed_at' => '2021-01-02 00:00:00',
|
||||
'organizer' => '::org::',
|
||||
'course_id' => 456,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testItThrowsLoginExceptionWhenFetchingWithWrongCredentials(): void
|
||||
{
|
||||
$this->expectException(LoginException::class);
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami\Tests\Unit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Zoomyboy\LaravelNami\Authentication\Authenticator;
|
||||
use Zoomyboy\LaravelNami\Authentication\MainCookie;
|
||||
use Zoomyboy\LaravelNami\Fakes\CourseFake;
|
||||
use Zoomyboy\LaravelNami\Fakes\LoginFake;
|
||||
use Zoomyboy\LaravelNami\LoginException;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\Tests\TestCase;
|
||||
|
||||
class LoginTest extends TestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Carbon::setTestNow(Carbon::parse('2024-02-23 23:48:00'));
|
||||
}
|
||||
|
||||
public function testItLoggsInAndSavesCookie(): void
|
||||
{
|
||||
app(LoginFake::class)->succeeds('lala-testsession');
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
public function testItThrowsExceptionWhenLoginFails(): void
|
||||
{
|
||||
app(LoginFake::class)->fails('::token::');
|
||||
$this->expectException(LoginException::class);
|
||||
app(MainCookie::class)->login(12345, 'secret');
|
||||
}
|
||||
|
||||
public function testItDoesntSaveCookieWhenLoginFails(): void
|
||||
{
|
||||
app(LoginFake::class)->fails('::token::');
|
||||
|
||||
try {
|
||||
app(MainCookie::class)->login(12345, 'secret');
|
||||
} catch (LoginException $e) {
|
||||
}
|
||||
|
||||
Http::assertSentCount(1);
|
||||
$this->assertEmpty(glob(__DIR__ . '/../../.cookies_test/*'));
|
||||
}
|
||||
|
||||
public function testItDoesntResetCookieWhenAlreadyLoggedIn(): void
|
||||
{
|
||||
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');
|
||||
|
||||
Http::assertSentCount(0);
|
||||
$this->assertFileExists(__DIR__ . '/../../.cookies_test/90100_' . now()->subMinutes(5)->timestamp . '.txt');
|
||||
$this->assertCount(1, glob(__DIR__ . '/../../.cookies_test/*'));
|
||||
}
|
||||
|
||||
public function testItIgnoresExpiredCookie(): void
|
||||
{
|
||||
app(CourseFake::class)->fetches(103, []);
|
||||
app(LoginFake::class)->succeeds('newlogin');
|
||||
file_put_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->subHour()->timestamp . '.txt', 'oldlogin-testsession.srv-nami06');
|
||||
|
||||
Nami::login(90100, 'secret');
|
||||
|
||||
Http::assertSentCount(1);
|
||||
$cookie = file_get_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->timestamp . '.txt');
|
||||
$this->assertEquals('newlogin.srv-nami06', $cookie);
|
||||
$this->assertFileExists(__DIR__ . '/../../.cookies_test/90100_' . now()->timestamp . '.txt');
|
||||
$this->assertCount(1, glob(__DIR__ . '/../../.cookies_test/*'));
|
||||
}
|
||||
|
||||
public function testItDoesntUseOtherCookieForLogin(): void
|
||||
{
|
||||
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(LoginFake::class)->assertSent(12345, 'secret');
|
||||
$this->assertFileExists(__DIR__ . '/../../.cookies_test/11111_' . now()->timestamp . '.txt');
|
||||
$this->assertFileExists(__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt');
|
||||
}
|
||||
|
||||
public function testItRefreshesLogin(): void
|
||||
{
|
||||
app(LoginFake::class)->succeeds('newlogin');
|
||||
$auth = app(Authenticator::class)->login(12345, 'secret');
|
||||
rename(
|
||||
__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt',
|
||||
__DIR__ . '/../../.cookies_test/12345_' . now()->subMinutes(51)->timestamp . '.txt'
|
||||
);
|
||||
$auth->refresh();
|
||||
Http::assertSentCount(2);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue