Skip to content

Commit

Permalink
Add tests for refreshing via claims
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jan 28, 2024
1 parent 7de1f99 commit 5a30c15
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/test/php/web/frontend/unittest/HtmxFlowTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use lang\IllegalStateException;
use test\{Assert, Test};
use web\auth\Flow;
use web\auth\{Authorization, Flow};
use web\frontend\HtmxFlow;
use web\io\{TestInput, TestOutput};
use web\{Request, Response};
Expand Down Expand Up @@ -49,4 +49,24 @@ public function authenticate($request, $response, $session) {
Assert::equals(401, $res->status());
Assert::equals('authenticationexpired', $res->headers()['HX-Trigger']);
}

#[Test]
public function delegates_refreshing() {
$flow= new HtmxFlow(new class() extends Flow {
public function refresh($claims) {
return newinstance(Authorization::class, [], [
'claims' => function() use($claims) { return ['token' => 'new'] + $claims; }
]);
}

public function authenticate($request, $response, $session) {
// NOOP
}
});

Assert::equals(
['token' => 'new', 'refresh' => '6100'],
$flow->refresh(['token' => 'old', 'refresh' => '6100'])->claims()
);
}
}

0 comments on commit 5a30c15

Please sign in to comment.