diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index cb71818df3..45970cd29d 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -4315,7 +4315,7 @@ App::post('/v1/account/targets/push') $device = $detector->getDevice(); - $sessionId = Auth::sessionVerify($user->getAttribute('sessions'), Auth::$secret); + $sessionId = Auth::sessionVerify($user->getAttribute('sessions', []), Auth::$secret); $session = $dbForProject->getDocument('sessions', $sessionId); try { @@ -4384,7 +4384,9 @@ App::put('/v1/account/targets/:targetId/push') } if ($identifier) { - $target->setAttribute('identifier', $identifier); + $target + ->setAttribute('identifier', $identifier) + ->setAttribute('expired', false); } $detector = new Detector($request->getUserAgent()); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index f0378ed0e3..3dffded6f6 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -1503,7 +1503,9 @@ App::patch('/v1/users/:userId/targets/:targetId') throw new Exception(Exception::PROVIDER_INCORRECT_TYPE); } - $target->setAttribute('identifier', $identifier); + $target + ->setAttribute('identifier', $identifier) + ->setAttribute('expired', false); } if ($providerId) { @@ -1517,8 +1519,9 @@ App::patch('/v1/users/:userId/targets/:targetId') throw new Exception(Exception::PROVIDER_INCORRECT_TYPE); } - $target->setAttribute('providerId', $provider->getId()); - $target->setAttribute('providerInternalId', $provider->getInternalId()); + $target + ->setAttribute('providerId', $provider->getId()) + ->setAttribute('providerInternalId', $provider->getInternalId()); } if ($name) { diff --git a/src/Appwrite/Utopia/Response/Model/Target.php b/src/Appwrite/Utopia/Response/Model/Target.php index d180b6c4c4..530749e006 100644 --- a/src/Appwrite/Utopia/Response/Model/Target.php +++ b/src/Appwrite/Utopia/Response/Model/Target.php @@ -32,7 +32,7 @@ class Target extends Model 'type' => self::TYPE_STRING, 'description' => 'Target Name.', 'default' => '', - 'example' => 'Aegon apple token', + 'example' => 'Apple iPhone 12', ]) ->addRule('userId', [ 'type' => self::TYPE_STRING, @@ -58,6 +58,12 @@ class Target extends Model 'description' => 'The target identifier.', 'default' => '', 'example' => 'token', + ]) + ->addRule('expired', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Is the target expired.', + 'default' => false, + 'example' => false, ]); } diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 244f84b161..cca27cc3be 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -2695,4 +2695,45 @@ class AccountCustomClientTest extends Scope return $data; } + + public function testCreatePushTarget(): void + { + $response = $this->client->call(Client::METHOD_POST, '/account/targets/push', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'] + ], $this->getHeaders()), [ + 'targetId' => ID::unique(), + 'identifier' => 'test-identifier', + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertEquals('test-identifier', $response['body']['identifier']); + } + + public function testUpdatePushTarget(): void + { + $response = $this->client->call(Client::METHOD_POST, '/account/targets/push', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'targetId' => ID::unique(), + 'identifier' => 'test-identifier-2', + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertEquals('test-identifier-2', $response['body']['identifier']); + + $response = $this->client->call(Client::METHOD_PUT, '/account/targets/'. $response['body']['$id'] .'/push', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'identifier' => 'test-identifier-updated', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('test-identifier-updated', $response['body']['identifier']); + $this->assertEquals(false, $response['body']['expired']); + } } diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index 8360af542e..9d6a04abe6 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -455,7 +455,7 @@ class HealthCustomServerTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals('/CN=www.google.com', $response['body']['name']); $this->assertEquals('www.google.com', $response['body']['subjectSN']); - $this->assertStringContainsString('Google Trust Services', $response['body']['issuerOrganisation']); + $this->assertContains($response['body']['issuerOrganisation'], ['Let\'s Encrypt', 'Google Trust Services']); $this->assertIsInt($response['body']['validFrom']); $this->assertIsInt($response['body']['validTo']); @@ -467,7 +467,7 @@ class HealthCustomServerTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals('/CN=appwrite.io', $response['body']['name']); $this->assertEquals('appwrite.io', $response['body']['subjectSN']); - $this->assertEquals("Let's Encrypt", $response['body']['issuerOrganisation']); + $this->assertContains($response['body']['issuerOrganisation'], ['Let\'s Encrypt', 'Google Trust Services']); $this->assertIsInt($response['body']['validFrom']); $this->assertIsInt($response['body']['validTo']); diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index d9105e0790..bd0a8ef937 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -1498,6 +1498,7 @@ trait UsersBase ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals('random-email1@mail.org', $response['body']['identifier']); + $this->assertEquals(false, $response['body']['expired']); return $response['body']; } @@ -1510,6 +1511,7 @@ trait UsersBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); + $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(3, \count($response['body']['targets'])); }