Remove OAuth provider unit tests

This commit is contained in:
Prem Palanisamy committed 2026-06-04 05:52:04 +01:00
1 parent dede00a186
commit f5a9cd90ef
2 files changed
-136

No files matched your search

@@ -1,59 +0,0 @@
<?php
namespace Utopia\Tests\Unit\Destinations;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Utopia\Database\Database as UtopiaDatabase;
use Utopia\Database\Document as UtopiaDocument;
use Utopia\Migration\Destinations\Appwrite as AppwriteDestination;
use Utopia\Migration\Destinations\OnDuplicate;
class AppwriteOAuth2SecretTest extends TestCase
{
public function testJsonSecretMergesAndPreservesExistingKeys(): void
{
$existing = \json_encode(['clientSecret' => 'KEEP']);
$merged = $this->invokeMergeJsonSecret($existing, ['tenant' => 'contoso']);
$this->assertSame(
['clientSecret' => 'KEEP', 'tenant' => 'contoso'],
\json_decode($merged, true),
);
}
public function testJsonSecretPreservesExistingWhenNoFieldsAreMigrated(): void
{
$existing = \json_encode(['p8' => 'PRIVATE']);
$this->assertSame($existing, $this->invokeMergeJsonSecret($existing, []));
}
public function testJsonSecretTreatsNonArrayExistingAsEmpty(): void
{
$merged = $this->invokeMergeJsonSecret('5', ['endpoint' => 'https://idp.example']);
$this->assertSame(['endpoint' => 'https://idp.example'], \json_decode($merged, true));
}
private function invokeMergeJsonSecret(string $existing, array $fields): string
{
$destination = new AppwriteDestination(
project: 'destination-project',
endpoint: 'http://example.test/v1',
key: 'test-key',
dbForProject: $this->createStub(UtopiaDatabase::class),
getDatabasesDB: fn (UtopiaDocument $database): UtopiaDatabase => $this->createStub(UtopiaDatabase::class),
collectionStructure: ['attributes' => [], 'indexes' => []],
dbForPlatform: $this->createStub(UtopiaDatabase::class),
projectInternalId: '1',
onDuplicate: OnDuplicate::Fail,
);
$method = (new ReflectionClass(AppwriteDestination::class))->getMethod('mergeJsonSecret');
/** @var string $value */
$value = $method->invoke($destination, $existing, $fields);
return $value;
}
}
@@ -1,77 +0,0 @@
<?php
namespace Utopia\Tests\Unit\General;
use PHPUnit\Framework\TestCase;
use Utopia\Migration\Resources\Auth\OAuth2\OAuth2Provider;
class OAuth2ProviderTest extends TestCase
{
public function testRoutesGoogleFieldsFromDescriptor(): void
{
$provider = OAuth2Provider::fromArray('google', [
'id' => 'project-google',
'enabled' => true,
'clientId' => 'google-client',
'prompt' => ['consent', 'select_account'],
'clientSecret' => 'secret-must-not-migrate',
]);
$this->assertInstanceOf(OAuth2Provider::class, $provider);
$this->assertSame('google-client', $provider->getDestinationAppId());
$this->assertSame(['prompt' => ['consent', 'select_account']], $provider->getDestinationSecretFields());
$this->assertArrayNotHasKey('clientSecret', $provider->getSettings());
$this->assertTrue($provider->isConfigured());
}
public function testRoutesAppleFieldsToDestinationSecretNames(): void
{
$provider = OAuth2Provider::fromArray('apple', [
'id' => 'project-apple',
'enabled' => false,
'serviceId' => 'service-id',
'keyId' => 'KEY123',
'teamId' => 'TEAM456',
'p8File' => 'secret-must-not-migrate',
]);
$this->assertInstanceOf(OAuth2Provider::class, $provider);
$this->assertSame('service-id', $provider->getDestinationAppId());
$this->assertSame(['keyID' => 'KEY123', 'teamID' => 'TEAM456'], $provider->getDestinationSecretFields());
$this->assertArrayNotHasKey('p8File', $provider->getSettings());
$this->assertTrue($provider->isConfigured());
}
public function testUnknownProviderReturnsNull(): void
{
$this->assertNull(OAuth2Provider::fromArray('unknown', [
'id' => 'project-unknown',
'enabled' => true,
'clientId' => 'client',
]));
}
public function testConfiguredWhenEnabledEvenWithoutAppId(): void
{
$provider = OAuth2Provider::fromArray('github', [
'id' => 'project-github',
'enabled' => true,
'clientId' => '',
]);
$this->assertInstanceOf(OAuth2Provider::class, $provider);
$this->assertTrue($provider->isConfigured());
}
public function testSkipsDisabledProviderWithoutAppId(): void
{
$provider = OAuth2Provider::fromArray('github', [
'id' => 'project-github',
'enabled' => false,
'clientId' => '',
]);
$this->assertInstanceOf(OAuth2Provider::class, $provider);
$this->assertFalse($provider->isConfigured());
}
}