From 51d1a38f0f408259444a7c0cdf4bb67b31be24f4 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 24 Jan 2024 18:24:48 +0530 Subject: [PATCH] Added test case --- .env | 2 +- app/controllers/shared/api.php | 2 +- tests/e2e/Services/Account/AccountBase.php | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 877a8daac..3ba90d873 100644 --- a/.env +++ b/.env @@ -103,4 +103,4 @@ _APP_ASSISTANT_OPENAI_API_KEY= _APP_MESSAGE_SMS_TEST_DSN= _APP_MESSAGE_EMAIL_TEST_DSN= _APP_MESSAGE_PUSH_TEST_DSN= -_APP_RESTRICTED_COUNTRIES= \ No newline at end of file +_APP_RESTRICTED_COUNTRIES=AQ \ No newline at end of file diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index d87d69a22..c5a4d2345 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -601,7 +601,7 @@ App::init() ->action(function (Request $request, Reader $geodb) { if (!empty(app::getEnv('_APP_RESTRICTED_COUNTRIES', ''))) { $countries = explode(',', App::getEnv('_APP_RESTRICTED_COUNTRIES', '')); - $record = $geodb->get($request->getHeader('x-forwarded-for')); + $record = $geodb->get($request->getIP()); $country = $record['country']['iso_code']; $countryName = $record['country']['names']['en']; if (in_array($country, $countries)) { diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 70a13b2d4..e228d7293 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -43,6 +43,20 @@ trait AccountBase /** * Test for FAILURE */ + $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-forwarded-for' => '103.152.127.250' + ]), [ + 'userId' => ID::unique(), + 'email' => $email, + 'password' => $password, + 'name' => $name, + ]); + + $this->assertEquals(401, $response['headers']['status-code']); + $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json',