. */ namespace Tests\Feature; use App\Password; use DateTimeImmutable; use Lcobucci\Clock\FrozenClock; use Lcobucci\JWT\Builder; use Lcobucci\JWT\JwtFacade; use Lcobucci\JWT\Signer\Key\InMemory; use Lcobucci\JWT\Signer\Rsa\Sha256; class AccountAlstomTest extends AccountJWTAuthenticationTest { public function setUp(): void { parent::setUp(); } public function testAlstomProvisioning() { # JWT is disabled if Sodium is not loaded if (!extension_loaded('sodium')) return; $password = Password::factory()->create(); //$domain = 'sip_provisioning.example.com'; $bearer = 'authz_server="https://sso.test/", realm="sip.test.org"'; //\App\Space::where('domain', $password->account->domain)->update(['host' => $domain]); //config()->set('app.sip_domain', $domain); config()->set('services.jwt.rsa_public_key_pem', $this->serverPublicKeyPem); $this->get($this->route)->assertStatus(400); // Accounts to provision $passwordAccount1 = Password::factory()->create(); $passwordAccount2 = Password::factory()->create(); $clock = new FrozenClock(new DateTimeImmutable()); config()->set('services.jwt.sip_identifier', 'sip_identity'); $token = (new JwtFacade(null, $clock))->issue( new Sha256(), InMemory::plainText($this->serverPrivateKeyPem), static fn( Builder $builder, DateTimeImmutable $issuedAt ): Builder => $builder ->withClaim( 'sip_identity', 'sip:' . $password->account->username . '@' . $password->account->domain ) ->withClaim( 'matching_accounts', [ 'sip:' . $passwordAccount1->account->identifier, 'sip:' . $passwordAccount2->account->identifier ] ) ); $this->withHeaders([ 'Authorization' => 'Bearer ' . $token->toString(), 'x-linphone-provisioning' => true, ]) ->get($this->accountRoute) ->assertStatus(200) ->assertSee($passwordAccount1->account->username) ->assertSee($passwordAccount1->account->passwords()->first()->ha1); // Non existing accounts $token = (new JwtFacade(null, $clock))->issue( new Sha256(), InMemory::plainText($this->serverPrivateKeyPem), static fn( Builder $builder, DateTimeImmutable $issuedAt ): Builder => $builder ->withClaim( 'sip_identity', 'sip:' . $password->account->username . '@' . $password->account->domain ) ->withClaim( 'matching_accounts', [ 'sip:' . $passwordAccount1->account->identifier, 'sip:' . $passwordAccount2->account->identifier, 'sip:other@account.com' ] ) ); $this->withHeaders([ 'Authorization' => 'Bearer ' . $token->toString(), 'x-linphone-provisioning' => true, ]) ->get($this->accountRoute) ->assertStatus(400) ->dump(); } }