From 0f11c249b9450f8611581fec156b3e9692f9e803 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 22 Oct 2024 14:07:32 +1300 Subject: [PATCH 1/8] Update messaging for FCM response fix --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 9079512e60..5c7d48373e 100644 --- a/composer.lock +++ b/composer.lock @@ -2124,16 +2124,16 @@ }, { "name": "utopia-php/messaging", - "version": "0.12.1", + "version": "0.12.2", "source": { "type": "git", "url": "https://github.com/utopia-php/messaging.git", - "reference": "b9dfafb5efc1d12cbee01d03dc98853ef026e35b" + "reference": "f6790fba1fcee12163d51c65d2c226a7856295d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/messaging/zipball/b9dfafb5efc1d12cbee01d03dc98853ef026e35b", - "reference": "b9dfafb5efc1d12cbee01d03dc98853ef026e35b", + "url": "https://api.github.com/repos/utopia-php/messaging/zipball/f6790fba1fcee12163d51c65d2c226a7856295d9", + "reference": "f6790fba1fcee12163d51c65d2c226a7856295d9", "shasum": "" }, "require": { @@ -2169,9 +2169,9 @@ ], "support": { "issues": "https://github.com/utopia-php/messaging/issues", - "source": "https://github.com/utopia-php/messaging/tree/0.12.1" + "source": "https://github.com/utopia-php/messaging/tree/0.12.2" }, - "time": "2024-10-09T08:17:07+00:00" + "time": "2024-10-22T01:02:20+00:00" }, { "name": "utopia-php/migration", From 99710e7b745af2d76b73c36b06daa05551aa5fca Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 22 Oct 2024 14:08:16 +1300 Subject: [PATCH 2/8] Force expired false if updating target identifier --- app/controllers/api/account.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index cb71818df3..de787358a7 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -4384,7 +4384,9 @@ App::put('/v1/account/targets/:targetId/push') } if ($identifier) { - $target->setAttribute('identifier', $identifier); + $target + ->setAttribute('identifier', $identifier) + ->setAtttibute('expired', false); } $detector = new Detector($request->getUserAgent()); From 8ab1600417ca607c38019599c7d9075f35cf99ac Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 22 Oct 2024 14:35:04 +1300 Subject: [PATCH 3/8] Update users API --- app/controllers/api/users.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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) { From 0a22292d1b81501aaa342565ee67dc2df0746929 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 22 Oct 2024 14:35:11 +1300 Subject: [PATCH 4/8] Update tests --- .../Account/AccountCustomClientTest.php | 44 +++++++++++++++++++ tests/e2e/Services/Users/UsersBase.php | 1 + 2 files changed, 45 insertions(+) diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 244f84b161..88dcf0e1e6 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -2695,4 +2695,48 @@ class AccountCustomClientTest extends Scope return $data; } + + public function testCreatePushTarget(): void + { + $response = $this->client->call(Client::METHOD_POST, '/account/push/targets', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + '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/push/targets', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + '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']); + + $response = $this->client->call(Client::METHOD_PATCH, '/account/push/targets/' . $response['body']['$id'], [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + '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/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index d9105e0790..693a935a69 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']; } From 1ed3dee13569a05c46090088640562026b447cff Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 22 Oct 2024 14:54:34 +1300 Subject: [PATCH 5/8] Fix tests --- app/controllers/api/account.php | 4 ++-- src/Appwrite/Utopia/Response/Model/Target.php | 8 ++++++- .../Account/AccountCustomClientTest.php | 21 ++++++++----------- tests/e2e/Services/Users/UsersBase.php | 1 + 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index de787358a7..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 { @@ -4386,7 +4386,7 @@ App::put('/v1/account/targets/:targetId/push') if ($identifier) { $target ->setAttribute('identifier', $identifier) - ->setAtttibute('expired', false); + ->setAttribute('expired', false); } $detector = new Detector($request->getUserAgent()); 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 88dcf0e1e6..cca27cc3be 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -2698,11 +2698,10 @@ class AccountCustomClientTest extends Scope public function testCreatePushTarget(): void { - $response = $this->client->call(Client::METHOD_POST, '/account/push/targets', [ + $response = $this->client->call(Client::METHOD_POST, '/account/targets/push', \array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ], [ + 'x-appwrite-project' => $this->getProject()['$id'] + ], $this->getHeaders()), [ 'targetId' => ID::unique(), 'identifier' => 'test-identifier', ]); @@ -2714,24 +2713,22 @@ class AccountCustomClientTest extends Scope public function testUpdatePushTarget(): void { - $response = $this->client->call(Client::METHOD_POST, '/account/push/targets', [ + $response = $this->client->call(Client::METHOD_POST, '/account/targets/push', \array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ], [ + ], $this->getHeaders()), [ 'targetId' => ID::unique(), - 'identifier' => 'test-identifier', + 'identifier' => 'test-identifier-2', ]); $this->assertEquals(201, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals('test-identifier', $response['body']['identifier']); + $this->assertEquals('test-identifier-2', $response['body']['identifier']); - $response = $this->client->call(Client::METHOD_PATCH, '/account/push/targets/' . $response['body']['$id'], [ + $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'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ], [ + ], $this->getHeaders()), [ 'identifier' => 'test-identifier-updated', ]); diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index 693a935a69..bd0a8ef937 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -1511,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'])); } From 58658f335a2cb6e0f8ec4bfd7de09c926f9f812e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 22 Oct 2024 19:18:48 +1300 Subject: [PATCH 6/8] Fix health cert test --- tests/e2e/Services/Health/HealthCustomServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index 8360af542e..4199eeb927 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->assertEquals('Let\'s Encrypt', $response['body']['issuerOrganisation']); $this->assertIsInt($response['body']['validFrom']); $this->assertIsInt($response['body']['validTo']); From f203800dd95295945b01e040f3d8a9240d696582 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 22 Oct 2024 19:52:38 +1300 Subject: [PATCH 7/8] Fix tests --- tests/e2e/Services/Health/HealthCustomServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index 4199eeb927..96751bd45b 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->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']); From 6403048acd7b222c8dabad137f2dccb276fcc3dc Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 22 Oct 2024 20:00:24 +1300 Subject: [PATCH 8/8] Fix tests --- tests/e2e/Services/Health/HealthCustomServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index 96751bd45b..9d6a04abe6 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -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']);