Separate Redis database for testing in Laravel - testing

I'm using Redis to store user-defined config for my Laravel app. I want to know how can I separate the Redis database is being used while testing from the one that is going to be used in for production? That's because I need to flush Redis before each test case and I don't want this to touch my data in main (production) Redis database.

You can use a different Redis database. In your config/database.php:
'default' => [
[
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],
],
You can set a different REDIS_DB in your .env.testing (e.g. REDIS_DB=1)

Related

Does Amazon SES support plus addressing?

I successfully send many emails through Amazon SES... however a handful of them fail due to containing the plus character (plus addressing).
Here's how the emails are sent:
"Key" => "MyKey",
"Secret" => "MySecret",
"Region" => "us-east-1",
"Service" => "email",
"Host" => "email.us-east-1.amazonaws.com",
"Params" => [
"Action" => "SendEmail",
"Destination.ToAddresses.member.1" => "someone+testing#gmail.com",
"Message.Subject.Data" => urlencode("Test Message"),
"Message.Body.Html.Data" => urlencode("<p>Hello, this is a test.</p>"),
"Source" => urlencode("sender#example.com")
The response from Amazon SES is:
InvalidParameterValue
Local address contains control or whitespace
I know I can strip the "+testing" from the address, but don't believe that's the right thing to do. I'm unable to find anything in Amazon's documentation that mentions support for plus addressing or how to escape the plus character.
Has anyone else solved this?
In the AWS addresses with + are possible. The + characters are sth called VERP - Variable Envelope Return Path -> which work exactly as they are supposed to work (https://docs.aws.amazon.com/ses/latest/dg/send-email-concepts-email-format.html)
Are you sure that none of the other part use some strange characters?
You can try changing the encoding to UTF-8: Here is some example for that for SES. https://docs.aws.amazon.com/ses/latest/dg/send-email-raw.html

Connecting to MSSQL server using Cpanel

I am currently in the process of moving over my locally made laravel application to the web. I am using cpanel for shared hosting. Currently my app used three different databases. The normal MySQL database, a microsoft azure database, and a microsoft sql server database. Currently I am able to connect to 2 of the three databases as I cant connect to the MSSQL database. When I attempt to connect to the database I get the following error:
[ODBC Driver 17 for SQL Server]Login timeout expired (SQL: SELECT * FROM tblGlue)
I know that something is going wrong before it tries to authenticate the user as I can change my username or a password to a non-existent user and I get the same error. When I connected to my azure database I had to use the stored procedure sp_set_firewall_rule to allow the IP of my website to access the databse. Is there something like this that I have to do for MSSQL as that's the only thing I can think of that's different. Here is the configuration for the database.
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
'host' => "xxxx",
'port' => "1433",
'database' => "TEAM",
'username' => "xxxx",
'password' => "xxxxx",
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
Also when I run DB::connection("sqlsrv")->getDatabaseName() I get a good result. However DB::connection("sqlsrv")->getPdo() gives the same error.
I'm thinking that the server is blocking the IP of my website somehow. Any ideas on how I can fix this. Any help is greatly appreciated!
Avoid to use Select * and return just needed rows. Try increasing the connection timeout value. I recommend using a connection timeout of at least 30 seconds.
Use parameter login_timeout.
'mssql' => [
'driver' => 'sqlsrv',
'host' => 'CDBSQLSERVER',
'database' => 'MyDatabase',
'username' => 'XXXX',
'password' => 'XXXX',
'charset' => 'utf8',
'prefix' => '',
'login_timeout' => YOUR_TIMEOUT
]
Further you can Verify or copy the connection string for your database from the Azure portal.
Use UID in place of username.
Your client can assist in a diagnosis by logging all errors it encounters. You might be able to correlate the log entries with error data that SQL Database logs itself internally.

CakePHP4 - Authentication - How to change default userModel?

I'm following this tutorial to set up Authentication https://book.cakephp.org/authentication/2/en/index.html with CakePHP4.
The table where my users are stored is not called "users" so when I try to log in it gives me this error:
Base table or view not found: 1146 Table 'databasename.users'
Where can I specify the userModel? In which file should it be set up? How?
You have to configure the respective resolver accordingly, in this case the ORM resolver.
Resolvers are used by identifiers, which accept resolver configuration via the resolver option. So for example for the password identifier, you could do it like this:
$service->loadIdentifier('Authentication.Password', [
'resolver' => [
'className' => 'Authentication.Orm',
'userModel' => 'YourCustomModelName',
],
// ....
]);
Note that it's necessary to pass the class name too when passing an array of resolver configuration, as the default configuration is just a string (the resolver class name), so it will not merge with the defaults, but overwrite them!
See also
Authentication Cookbook > Identifiers
Authentication Cookbook > Identifiers > Identity resolvers

Rights modules uses a different application instance

I'm developing a Yii application which uses several modules including Rights module for access control. They all are residing in the same "modules" folder and configured in the same config/main.php file. And application has only one entry script.
However I noticed that Rights module uses a different app session while all other modules uses another app session. Because of this reason user session is not shared with Rights.
Has anyone encounter such issue with yii modules? please help. Thanks!
my config file:
'rights'=>array(
'debug' => true,
'superuserName' => 'Super Administrator', // Name of the role with super user privileges.
'authenticatedName' => 'Customer', // Name of the authenticated user role.
'userIdColumn' => 'id', // Name of the user id column in the database.
'userNameColumn' => 'username', // Name of the user name column in the database.
'enableBizRule' => true, // Whether to enable authorization item business rules.
'enableBizRuleData' => true, // Whether to enable data for business rules.
'displayDescription' => false, // Whether to use item description instead of name.
'flashSuccessKey' => 'success', // Key to use for setting success flash messages.
'flashErrorKey' => 'error', // Key to use for setting error flash messages.
//'baseUrl' =>'/rights', // Base URL for Rights. Change if module is nested.
//'layout' => 'rights.views.layouts.main', // Layout to use for displaying Rights.
//'appLayout' => 'application.views.layouts.main', // Application layout.
//'cssFile' => 'rights.css', // Style sheet file to use for Rights.
'install' => false, // Whether to enable installer.
),
After trying for two days I found the solution.
I noticed that it uses two different key prefixes (stateKeyPrefix) in system. One for Rights and another one for other modules. This can be configured to use single key prefix in main config file.
'user'=>array(
'class'=>'RWebUser',
'allowAutoLogin'=>true, // enable cookie-based authentication
'stateKeyPrefix'=>'f298d9729c7408c3d406db95a9639204', // some random value
),
Hope this will help someone with the same issue.

For every request a new session is getting generated in Yii application

I know I am either skipping something or configured session incorrectly but Yii sessions are not working for me. I have spent a lot of time in debugging and searching but it doesn't result in any concrete answer.
As described in documentation as well as tutorials over internet I have configured my application session as follows:
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
'session' => array (
'sessionName' => 'Site Session',
'class'=>'CHttpSession',
'useTransparentSessionID' =>($_POST['PHPSESSID']) ? true : false,
'autoStart' => 'true',
'cookieMode' => 'allow',
'timeout' => 300
),
However each time I am sending a request to server, I get a new session object. I have verified same via echo "Session id: ".Yii::app()->session->sessionID;, every time it gives me different id. Also variables which I have added in session previously are not accessible due to this behaviour.
Kindly provide some pointers, I have spent more than 4 hours in debugging and looking for a solution. Tons of thanks for any pointers in advance.
Thanks
~Tarun
It could well be just that you have a space in your sessions name.
I've just done a quick test on my working Yii instance, changed the session name to have a space in it, and the cookie value for the session seems to change every time.
Please read php session name documentation at this url http://php.net/manual/en/function.session-name.php
It clearly mentions that session name should contain only alphanumerical characters. That too it should contain at least one alphabet(session name cannot have all its characters as digits also). Otherwise a new session id is generated every time.
chrome 44 and chrome 47's bug , update it to 51,It's ok.
Just a note cause I ran into this issue in Yii2. I had a constant COOKIE_DOMAIN that was set via php-fpm config and it was for the wrong domain name, causing the session to reset. Make sure this is set to ".example.com" (including the . at the start to support all your hostnames)
'components'=>[
'session' => [
'class' => 'yii\web\DbSession',
'cookieParams' => [
'path' => '/',
'domain' => COOKIE_DOMAIN, // <<<--- check this
'secure' => true,
],
'writeCallback' => function($session){
return [
'user_id' => Yii::$app->user->id
];
},
'sessionTable' => 'session', // session table name. Defaults to 'session'.
],
...
]