X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=ext%2Fauthx%2Ftests%2Fphpunit%2FCivi%2FAuthx%2FAllFlowsTest.php;h=e7792914f41681b2bd970d9957796d114ad9127e;hb=ee4d3a2dbfa8fa1a7705d9a27e8bb735fb8439f1;hp=d2e2ea5f61a274eeeeae95eedb3f8786c443327b;hpb=15acadd111ff13aa1550767b5f14f0fcd502fccc;p=civicrm-core.git diff --git a/ext/authx/tests/phpunit/Civi/Authx/AllFlowsTest.php b/ext/authx/tests/phpunit/Civi/Authx/AllFlowsTest.php index d2e2ea5f61..e7792914f4 100644 --- a/ext/authx/tests/phpunit/Civi/Authx/AllFlowsTest.php +++ b/ext/authx/tests/phpunit/Civi/Authx/AllFlowsTest.php @@ -423,6 +423,46 @@ class AllFlowsTest extends \PHPUnit\Framework\TestCase implements EndToEndInterf $this->assertEquals($actualSteps, $planSteps); } + /** + * Civi's test suite includes middleware that will add JWT tokens to outgoing requests. + * + * This test tries a few permutations with different principals ("demo", "Lebowski"), + * different identifier fields (authx_user, authx_contact_id), and different + * flows (param/header/xheader). + * + * @throws \CiviCRM_API3_Exception + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function testJwtMiddleware() { + // HTTP GET with a specific user. Choose flow automatically. + $response = $this->createGuzzle()->get('civicrm/authx/id', [ + 'authx_user' => $GLOBALS['_CV']['DEMO_USER'], + ]); + $this->assertMyContact($this->getDemoCID(), $this->getDemoUID(), 'jwt', 'param', $response); + + // HTTP GET with a specific contact. Choose flow automatically. + $response = $this->createGuzzle()->get('civicrm/authx/id', [ + 'authx_contact_id' => $this->getDemoCID(), + ]); + $this->assertMyContact($this->getDemoCID(), $this->getDemoUID(), 'jwt', 'param', $response); + + // HTTP POST with a specific contact. Per-client default. + $response = $this->createGuzzle([ + 'authx_contact_id' => $this->getLebowskiCID(), + ])->post('civicrm/authx/id'); + $this->assertMyContact($this->getLebowskiCID(), NULL, 'jwt', 'param', $response); + + // Using explicit flow options... + foreach (['param', 'xheader', 'header'] as $flowType) { + \Civi::settings()->set("authx_{$flowType}_cred", ['jwt']); + $response = $this->createGuzzle()->get('civicrm/authx/id', [ + 'authx_contact_id' => $this->getDemoCID(), + 'authx_flow' => $flowType, + ]); + $this->assertMyContact($this->getDemoCID(), $this->getDemoUID(), 'jwt', $flowType, $response); + } + } + /** * Filter a request, applying the given authentication options *