Merge pull request #7671 from appwrite/feat-fix-1.5.x-migrations

Feat fix 1.5.x migrations
This commit is contained in:
Christy Jacob 2024-02-27 19:29:37 +05:30 committed by GitHub
commit 6a2fb82a27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 112 additions and 2 deletions

View file

@ -252,6 +252,14 @@ class V20 extends Migration
Console::warning("'totpBackup' from {$id}: {$th->getMessage()}");
}
// Create challenges attribute
try {
$this->createAttributeFromCollection($this->projectDB, $id, 'challenges');
$this->projectDB->purgeCachedCollection($id);
} catch (Throwable $th) {
Console::warning("'challenges' from {$id}: {$th->getMessage()}");
}
break;
case 'projects':
// Rename providers authProviders to oAuthProviders
@ -543,9 +551,11 @@ class V20 extends Migration
$document->setAttribute('expire', $expire);
$factors = match ($document->getAttribute('provider')) {
Auth::SESSION_PROVIDER_ANONYMOUS => ['anonymous'],
Auth::SESSION_PROVIDER_EMAIL => ['password'],
Auth::SESSION_PROVIDER_PHONE => ['phone'],
default => ['password'],
Auth::SESSION_PROVIDER_ANONYMOUS => ['anonymous'],
Auth::SESSION_PROVIDER_TOKEN => ['token'],
default => ['email'],
};
$document->setAttribute('factors', $factors);

View file

@ -22,6 +22,15 @@ class V17 extends Filter
case Response::MODEL_TOKEN:
$parsedResponse = $this->parseToken($parsedResponse);
break;
case Response::MODEL_MEMBERSHIP:
$parsedResponse = $this->parseMembership($parsedResponse);
break;
case Response::MODEL_SESSION:
$parsedResponse = $this->parseSession($parsedResponse);
break;
case Response::MODEL_WEBHOOK:
$parsedResponse = $this->parseWebhook($parsedResponse);
break;
}
return $parsedResponse;
@ -30,6 +39,8 @@ class V17 extends Filter
protected function parseUser(array $content)
{
unset($content['targets']);
unset($content['mfa']);
unset($content['totp']);
return $content;
}
@ -45,4 +56,25 @@ class V17 extends Filter
unset($content['phrase']);
return $content;
}
protected function parseMembership(array $content)
{
unset($content['mfa']);
return $content;
}
protected function parseSession(array $content)
{
unset($content['factors']);
unset($content['secret']);
return $content;
}
protected function parseWebhook(array $content)
{
unset($content['enabled']);
unset($content['logs']);
unset($content['attempts']);
return $content;
}
}

View file

@ -73,6 +73,8 @@ class V17Test extends TestCase
'remove targets' => [
[
'targets' => 'test',
'mfa' => 'test',
'totp' => 'test',
],
[
],
@ -116,4 +118,70 @@ class V17Test extends TestCase
$this->assertEquals($expected, $result);
}
public function membershipProvider(): array
{
return [
'remove mfa' => [
[
'mfa' => 'test',
],
[
],
],
];
}
/**
* @dataProvider membershipProvider
*/
public function testMembership(array $content, array $expected): void
{
$model = Response::MODEL_MEMBERSHIP;
$result = $this->filter->parse($content, $model);
$this->assertEquals($expected, $result);
}
public function sessionProvider(): array
{
return [
'remove factors and secrets' => [
[
'factors' => 'test',
'secret' => 'test',
],
[
],
]
];
}
/**
* @dataProvider sessionProvider
*/
public function testSession(array $content, array $expected): void
{
$model = Response::MODEL_SESSION;
$result = $this->filter->parse($content, $model);
$this->assertEquals($expected, $result);
}
public function webhookProvider(): array
{
return [
'remove webhook additions' => [
[
'enabled' => true,
'logs' => ['test', 'test'],
'attempts' => 1
],
[
],
],
];
}
}