Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Support for SameSite cookie setting missing #3442

Closed
tangix opened this issue Aug 3, 2020 · 21 comments · Fixed by #3447
Closed

Bug: Support for SameSite cookie setting missing #3442

tangix opened this issue Aug 3, 2020 · 21 comments · Fixed by #3447
Labels
bug Verified issues on the current code behavior or pull requests that will fix them in progress

Comments

@tangix
Copy link
Contributor

tangix commented Aug 3, 2020

Describe the bug
Not possible to configure SameSite setting for cookies (session and CSRF).
The differences between PHP 7.2 and 7.3 makes this more difficult.
I now find myself in the situation that I need to be able to configure this setting and after migration to PHP 7.3 the hack with cookiePath = '/;samesite=none'; no longer works.

I could possible do some work on this, but I'd like to know if there are anything planned before I start working on a PR.

CodeIgniter 4 version
4.0.4

Affected module(s)
Sessions + ?

Expected behavior, and steps to reproduce if appropriate
It should be possible to configure SameSite settings for cookies.

@tangix tangix added the bug Verified issues on the current code behavior or pull requests that will fix them label Aug 3, 2020
@paulbalandan
Copy link
Member

This was opened in #2374 and a PR was made in #3037, but it was closed. Maybe you can check on that?

@tangix
Copy link
Contributor Author

tangix commented Aug 3, 2020

Hmmm - digging further into this I see that RFC about this is not (yet) approved - https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-05 August 8 2020 seems to be the dead-line.
However it seems like most browsers (and PHP 7.3) went ahead and implemented this already, so I'll try to add this.

@algobasket
Copy link

hey i need help my cookie doesn't store anything after redirect but if I comment the redirect (return redirect()->to('/browse'); )
the cookie store.
Please help

public function saveUserCookie()
{
$userCookie = json_encode(array(
'userId' => $this->session->get('userId'),
'display' => $this->session->get('display'),
'role' => $this->session->get('role'),
'email' => $this->session->get('email')
),true);
$userCookie = (string)$userCookie;
set_cookie('userCookie',$userCookie,'3600');
return redirect()->to('/browse');
}

@tangix
Copy link
Contributor Author

tangix commented Aug 4, 2020

return redirect()->to('/browse')->withCookies(); as described in the docs https://codeigniter4.github.io/userguide/general/common_functions.html?highlight=redirectresponse#redirect may work?

@algobasket
Copy link

return redirect()->to('/browse')->withCookies(); as described in the docs https://codeigniter4.github.io/userguide/general/common_functions.html?highlight=redirectresponse#redirect may work?

it say "Call to undefined method CodeIgniter\HTTP\RedirectResponse::withCookies() "

@lonnieezell
Copy link
Member

That function is available in version 4.0.4 only, so you need to upgrade CodeIgniter to the latest version.

@tangix
Copy link
Contributor Author

tangix commented Aug 4, 2020

I have been working on a PR for SameSite setting, but wrapping up I have some problems running the tests and I wonder if someone could help me out. Running phpunit it fails hard in the database tests:
I have pulled the latest changes from develop but still no go.

msa@verdandi CodeIgniter4 % ./vendor/bin/phpunit        
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

.............................................................   61 / 3391 (  1%)
.............................................................  122 / 3391 (  3%)
..............................SSSSSSSSSSEEEEEEEEE............  183 / 3391 (  5%)
.............................................................  244 / 3391 (  7%)
..EEE...........PHP Fatal error:  Cannot declare class Config\Database, because the name is already in use in /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/app/Config/Database.php on line 114
PHP Stack trace:
PHP   1. {main}() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/phpunit:61
PHP   3. PHPUnit\TextUI\Command->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/Command.php:163
PHP   4. PHPUnit\TextUI\TestRunner->doRun() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/Command.php:204
PHP   5. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:627
PHP   6. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
PHP   7. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
PHP   8. CommonFunctionsTest->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
PHP   9. PHPUnit\Framework\TestResult->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestCase.php:763
PHP  10. CommonFunctionsTest->runBare() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestResult.php:691
PHP  11. CommonFunctionsTest->runTest() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestCase.php:1035
PHP  12. CommonFunctionsTest->testModelExists() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestCase.php:1415
PHP  13. model() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/tests/system/CommonFunctionsTest.php:285
PHP  14. CodeIgniter\Database\ModelFactory::get() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Common.php:838
PHP  15. CodeIgniter\Database\ModelFactory::createClass() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Database/ModelFactory.php:40
PHP  16. Tests\Support\Models\JobModel->__construct() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Database/ModelFactory.php:76
PHP  17. CodeIgniter\Database\Config::connect() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Model.php:359
PHP  18. config() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Database/Config.php:91
PHP  19. CodeIgniter\Config\Config::get() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Common.php:223
PHP  20. CodeIgniter\Config\Config::createClass() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:83
PHP  21. class_exists() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
PHP  22. spl_autoload_call() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
PHP  23. CodeIgniter\Autoloader\Autoloader->loadClass() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
PHP  24. CodeIgniter\Autoloader\Autoloader->loadInNamespace() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Autoloader/Autoloader.php:258
PHP  25. CodeIgniter\Autoloader\Autoloader->requireFile() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Autoloader/Autoloader.php:285

Fatal error: Cannot declare class Config\Database, because the name is already in use in /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/app/Config/Database.php on line 114

Call Stack:
    0.0003     402984   1. {main}() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/phpunit:0
    0.0054    1001080   2. PHPUnit\TextUI\Command::main() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/phpunit:61
    0.0054    1001208   3. PHPUnit\TextUI\Command->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/Command.php:163
    0.5910   28450416   4. PHPUnit\TextUI\TestRunner->doRun() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/Command.php:204
    0.9559   30697200   5. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:627
    0.9793   30697392   6. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
   26.5235   56638280   7. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
   31.1940   59082392   8. CommonFunctionsTest->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
   31.1940   59082392   9. PHPUnit\Framework\TestResult->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestCase.php:763
   31.1942   59082520  10. CommonFunctionsTest->runBare() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestResult.php:691
   31.2215   59237856  11. CommonFunctionsTest->runTest() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestCase.php:1035
   31.2216   59238232  12. CommonFunctionsTest->testModelExists() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestCase.php:1415
   31.2216   59238232  13. model() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/tests/system/CommonFunctionsTest.php:285
   31.2216   59238232  14. CodeIgniter\Database\ModelFactory::get() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Common.php:838
   31.2216   59238296  15. CodeIgniter\Database\ModelFactory::createClass() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Database/ModelFactory.php:40
   31.2225   59245784  16. Tests\Support\Models\JobModel->__construct() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Database/ModelFactory.php:76
   31.2225   59245784  17. CodeIgniter\Database\Config::connect() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Model.php:359
   31.2225   59245784  18. config() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Database/Config.php:91
   31.2225   59245784  19. CodeIgniter\Config\Config::get() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Common.php:223
   31.2225   59245784  20. CodeIgniter\Config\Config::createClass() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:83
   31.2225   59245784  21. class_exists() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
   31.2225   59245824  22. spl_autoload_call() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
   31.2227   59245864  23. CodeIgniter\Autoloader\Autoloader->loadClass() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
   31.2227   59245864  24. CodeIgniter\Autoloader\Autoloader->loadInNamespace() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Autoloader/Autoloader.php:258
   31.2227   59246016  25. CodeIgniter\Autoloader\Autoloader->requireFile() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Autoloader/Autoloader.php:285

msa@verdandi CodeIgniter4 % php -v               
PHP 7.3.20 (cli) (built: Jul  9 2020 23:50:54) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.20, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.20, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.8.0, Copyright (c) 2002-2019, by Derick Rethans
msa@verdandi CodeIgniter4 % 

@paulbalandan
Copy link
Member

Did you change other tests?

Can you try this? phpunit -v --filter <test class name you are testing> to have phpunit run that specific test only

@tangix
Copy link
Contributor Author

tangix commented Aug 4, 2020

I am not sure what to put in test class name. The tests I have added to are in API, HTTP and Session and they all run fine. I have updated MockAppConfig and MockCLIConfig.

The tests failing are in CodeIgniter\Database\Live\SQLite\AlterTableTest::testDropForeignKeySuccess which I haven't touched. Could be my sqlite (installed via homebrew) that is flakey.

msa@verdandi CodeIgniter4 % ./vendor/bin/phpunit tests/system/API
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

...........................                                       27 / 27 (100%)

Time: 4.12 seconds, Memory: 30.00 MB

OK (27 tests, 76 assertions)

Generating code coverage report in Clover XML format ... ^[[A^C
msa@verdandi CodeIgniter4 % ./vendor/bin/phpunit tests/system/API
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

...........................                                       27 / 27 (100%)

Time: 4.12 seconds, Memory: 30.00 MB

OK (27 tests, 76 assertions)

Generating code coverage report in Clover XML format ... done [3.05 seconds]
msa@verdandi CodeIgniter4 % ./vendor/bin/phpunit tests/system/HTTP
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

...............................................................  63 / 489 ( 12%)
............................................................... 126 / 489 ( 25%)
............................................................... 189 / 489 ( 38%)
............................................................... 252 / 489 ( 51%)
............................................................... 315 / 489 ( 64%)
............................................................... 378 / 489 ( 77%)
............................................................... 441 / 489 ( 90%)
................................................                489 / 489 (100%)

Time: 1.16 minutes, Memory: 50.00 MB

OK (489 tests, 975 assertions)

Generating code coverage report in Clover XML format ... done [3.2 seconds]
msa@verdandi CodeIgniter4 % ./vendor/bin/phpunit tests/system/Session 
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

........................................                          40 / 40 (100%)

Time: 43.18 seconds, Memory: 18.00 MB

OK (40 tests, 90 assertions)

Generating code coverage report in Clover XML format ... done [5.88 seconds]

msa@verdandi CodeIgniter4 % ./vendor/bin/phpunit tests/system/Database 
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

...............................................................  63 / 543 ( 11%)
............................................................... 126 / 543 ( 23%)
............................................................... 189 / 543 ( 34%)
.......................................S.S..S.................. 252 / 543 ( 46%)
............................................................... 315 / 543 ( 58%)
..FFF.......................................................... 378 / 543 ( 69%)
............................................................... 441 / 543 ( 81%)
...................................FEF......................... 504 / 543 ( 92%)
...............F.......................                         543 / 543 (100%)

Time: 3.23 minutes, Memory: 80.00 MB

There was 1 error:

1) CodeIgniter\Database\Live\SQLite\AlterTableTest::testDropForeignKeySuccess
ErrorException: Undefined offset: 0

/Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/tests/system/Database/Live/SQLite/AlterTableTest.php:164

--

There were 6 failures:

1) CodeIgniter\Database\Live\MetadataTest::testListTables
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'db_migrations'
-    1 => 'db_user'
-    2 => 'db_job'
-    3 => 'db_misc'
-    4 => 'db_type_test'
-    5 => 'db_empty'
-    6 => 'db_secondary'
-    7 => 'db_stringifypkey'
+    0 => 'db_user'
+    1 => 'db_job'
+    2 => 'db_misc'
+    3 => 'db_type_test'
+    4 => 'db_empty'
+    5 => 'db_secondary'
+    6 => 'db_stringifypkey'
 )

/Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/tests/system/Database/Live/MetadataTest.php:43

2) CodeIgniter\Database\Live\MetadataTest::testListTablesConstrainPrefix
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'db_migrations'
-    1 => 'db_user'
-    2 => 'db_job'
-    3 => 'db_misc'
-    4 => 'db_type_test'
-    5 => 'db_empty'
-    6 => 'db_secondary'
-    7 => 'db_stringifypkey'
+    0 => 'db_user'
+    1 => 'db_job'
+    2 => 'db_misc'
+    3 => 'db_type_test'
+    4 => 'db_empty'
+    5 => 'db_secondary'
+    6 => 'db_stringifypkey'
 )

/Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/tests/system/Database/Live/MetadataTest.php:52

3) CodeIgniter\Database\Live\MetadataTest::testConstrainPrefixIgnoresOtherTables
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'db_migrations'
-    1 => 'db_user'
-    2 => 'db_job'
-    3 => 'db_misc'
-    4 => 'db_type_test'
-    5 => 'db_empty'
-    6 => 'db_secondary'
-    7 => 'db_stringifypkey'
+    0 => 'db_user'
+    1 => 'db_job'
+    2 => 'db_misc'
+    3 => 'db_type_test'
+    4 => 'db_empty'
+    5 => 'db_secondary'
+    6 => 'db_stringifypkey'
 )

/Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/tests/system/Database/Live/MetadataTest.php:83

4) CodeIgniter\Database\Live\SQLite\AlterTableTest::testModifyColumnSuccess
Failed asserting that false is true.

/Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/tests/system/Database/Live/SQLite/AlterTableTest.php:153

5) CodeIgniter\Database\Live\SQLite\AlterTableTest::testProcessCopiesOldData
Row was found in database
Failed asserting that false is true.

/Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Test/CIDatabaseTestCase.php:294
/Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/tests/system/Database/Live/SQLite/AlterTableTest.php:200

6) CodeIgniter\Database\MigrationRunnerTest::testLoadsDefaultDatabaseWhenNoneSpecified
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'/Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/writable/:memory:'
+':memory:'

/Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/tests/system/Database/Migrations/MigrationRunnerTest.php:42

ERRORS!
Tests: 543, Assertions: 991, Errors: 1, Failures: 6, Skipped: 3.

Generating code coverage report in Clover XML format ... done [4.5 seconds]

@paulbalandan
Copy link
Member

The test class name is the class name ending in Test, like MigrationRunnerTest.

@tangix
Copy link
Contributor Author

tangix commented Aug 4, 2020

OK, output:

msa@verdandi CodeIgniter4 % ./vendor/bin/phpunit -v --filter MigrationRunnerTest
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.2.32 with Xdebug 2.8.0
Configuration: /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/phpunit.xml.dist

PHP Fatal error:  Cannot declare class Config\Database, because the name is already in use in /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/app/Config/Database.php on line 114
PHP Stack trace:
PHP   1. {main}() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/phpunit:61
PHP   3. PHPUnit\TextUI\Command->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/Command.php:163
PHP   4. PHPUnit\TextUI\TestRunner->doRun() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/Command.php:204
PHP   5. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:627
PHP   6. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
PHP   7. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
PHP   8. CodeIgniter\Database\MigrationRunnerTest->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
PHP   9. PHPUnit\Framework\TestResult->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestCase.php:763
PHP  10. CodeIgniter\Database\MigrationRunnerTest->runBare() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestResult.php:691
PHP  11. CodeIgniter\Database\MigrationRunnerTest->setUp() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestCase.php:1031
PHP  12. CodeIgniter\Database\MigrationRunnerTest->setUp() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/tests/system/Database/Migrations/MigrationRunnerTest.php:22
PHP  13. CodeIgniter\Database\MigrationRunnerTest->loadDependencies() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Test/CIDatabaseTestCase.php:166
PHP  14. CodeIgniter\Database\Config::connect() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Test/CIDatabaseTestCase.php:133
PHP  15. config() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Database/Config.php:91
PHP  16. CodeIgniter\Config\Config::get() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Common.php:223
PHP  17. CodeIgniter\Config\Config::createClass() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:83
PHP  18. class_exists() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
PHP  19. spl_autoload_call() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
PHP  20. CodeIgniter\Autoloader\Autoloader->loadClass() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
PHP  21. CodeIgniter\Autoloader\Autoloader->loadInNamespace() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Autoloader/Autoloader.php:258
PHP  22. CodeIgniter\Autoloader\Autoloader->requireFile() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Autoloader/Autoloader.php:285


[ErrorException]

Cannot declare class Config\Database, because the name is already in use

at APPPATH/Config/Database.php:114

Backtrace:
  1    [internal function]
       CodeIgniter\Debug\Exceptions()->shutdownHandler()


Fatal error: Cannot declare class Config\Database, because the name is already in use in /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/app/Config/Database.php on line 114

Call Stack:
    0.0004     396048   1. {main}() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/phpunit:0
    0.0060     983104   2. PHPUnit\TextUI\Command::main() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/phpunit:61
    0.0060     983232   3. PHPUnit\TextUI\Command->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/Command.php:163
    0.6740   27772704   4. PHPUnit\TextUI\TestRunner->doRun() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/Command.php:204
    1.0775   29354208   5. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:627
    1.1992   29355088   6. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
    1.2153   29355968   7. PHPUnit\Framework\TestSuite->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
    1.2187   29460408   8. CodeIgniter\Database\MigrationRunnerTest->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
    1.2187   29460408   9. PHPUnit\Framework\TestResult->run() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestCase.php:763
    4.7374   43451664  10. CodeIgniter\Database\MigrationRunnerTest->runBare() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestResult.php:691
    4.7380   43469200  11. CodeIgniter\Database\MigrationRunnerTest->setUp() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/vendor/phpunit/phpunit/src/Framework/TestCase.php:1031
    4.7381   43469200  12. CodeIgniter\Database\MigrationRunnerTest->setUp() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/tests/system/Database/Migrations/MigrationRunnerTest.php:22
    4.7674   43694864  13. CodeIgniter\Database\MigrationRunnerTest->loadDependencies() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Test/CIDatabaseTestCase.php:166
    4.7674   43694864  14. CodeIgniter\Database\Config::connect() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Test/CIDatabaseTestCase.php:133
    4.7675   43694864  15. config() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Database/Config.php:91
    4.7675   43694864  16. CodeIgniter\Config\Config::get() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Common.php:223
    4.7675   43694864  17. CodeIgniter\Config\Config::createClass() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:83
    4.7675   43694864  18. class_exists() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
    4.7675   43694904  19. spl_autoload_call() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
    4.7675   43694944  20. CodeIgniter\Autoloader\Autoloader->loadClass() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Config/Config.php:122
    4.7675   43694944  21. CodeIgniter\Autoloader\Autoloader->loadInNamespace() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Autoloader/Autoloader.php:258
    4.7676   43695096  22. CodeIgniter\Autoloader\Autoloader->requireFile() /Users/msa/Tangix_Work/GitHub_Projects/CodeIgniter4/system/Autoloader/Autoloader.php:285

msa@verdandi CodeIgniter4 % 

@tangix
Copy link
Contributor Author

tangix commented Aug 4, 2020

Must be something in my setup or the database tests. I have just cloned the develop branch from github and it fails in the same way.

@paulbalandan
Copy link
Member

The failing tests are irrelevant in your case, I think. Maybe the Travis test will be the official judge for this.

@tangix
Copy link
Contributor Author

tangix commented Aug 4, 2020

The failing tests are irrelevant in your case, I think. Maybe the Travis test will be the official judge for this.

Yeah - thought so too, but that means I have to create the PR, right?

@paulbalandan
Copy link
Member

Yes, to have it officially tested.

@tangix
Copy link
Contributor Author

tangix commented Aug 4, 2020

...scary... ;-) I'll finish it up and create the PR.

@tangix
Copy link
Contributor Author

tangix commented Aug 4, 2020

Seems like session mock wasn't correct. Now all tests pass.

@InsiteFX
Copy link
Contributor

InsiteFX commented Aug 10, 2020

You all need to read this article I just found:

PHP 7.3 Same-site Cookies

This can now be set in the php ini file the above will show how to do it.

@michalsn
Copy link
Member

If you're referring to the ini_set option - it only applies to the session cookie.

Also, this article seems a bit outdated since setting custom cookies with None value requires now also the Secure flag to be set.

@InsiteFX
Copy link
Contributor

InsiteFX commented Aug 10, 2020

From what I read on PHP.net is that there is now an options array for the secure and other flags starting with php 7.3.0 the options associated array was added.

setcookie ( string $name [, string $value = "" [, array $options = [] ]] ) : bool

If the samesite element is omitted, no SameSite cookie attribute is set.

setcookie

Here is how the new associated array works.

`$arrCookieOptions = [
'expires' => time() + 60 * 60 * 24 * 30,
'path' => '/',
'domain' => '.example.com', // leading dot for compatibility or use subdomain
'secure' => true, // or false
'httponly' => true, // or false
'samesite' => 'None', // None || Lax || Strict
];

	setcookie('TestCookie', 'The Cookie Value', $arrCookieOptions);`

@michalsn
Copy link
Member

@InsiteFX We already use this option in #3447. Thanks for referencing php.net as I somehow missed this important feature:

If the samesite element is omitted, no SameSite cookie attribute is set.

michalsn pushed a commit that referenced this issue Aug 24, 2020
Add support for SameSite cookies #3442
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants