yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

Incorrect behaviour in DbManager #13501

Closed StalkAlex closed 7 years ago

StalkAlex commented 7 years ago

What steps will reproduce the problem?

Trying to create permission

$permission = $auth->createPermission('test');
$permission->ruleName = 'TestRule';
$auth->add($permission)

data of rule is O:24:"app\rules\TestRule":3:{s:4:"name";s:14:"TestOnly";s:9:"createdAt";i:1485582849;s:9:"updatedAt";i:1485582849;}

What do you get instead?

Error

PHP Warning 'yii\base\ErrorException' with message 'unserialize() expects parameter 1 to be string, resource given'

in /vagrant/vendor/yiisoft/yii2/rbac/DbManager.php:634

Here's screen. As it seen data variable isn't sting anymore but resource stream. test

Additional info

Q A
Yii version 2.0.11
PHP version 7.1.1
Operating system CentOS 7
Database PostgreSQL 9.6
StalkAlex commented 7 years ago

There is no such bug in 2.0.10, so it's not db related problem. If issue will be confirmed, may this be fixed in 2.0.11.2? It looks serious.

samdark commented 7 years ago

Probably. Can you find out which commit breaks it using git bisect?

StalkAlex commented 7 years ago

Yep. I'll check.

StalkAlex commented 7 years ago

@samdark found commit that causes this bug https://github.com/yiisoft/yii2/commit/23790272dc561aacf2070cbbda396f49e44cbb7d

cebe commented 7 years ago

To fix it a check should be added that will read all data from the stream. possibly via http://php.net/manual/en/function.stream-get-contents.php

StalkAlex commented 7 years ago

@cebe Like this? https://github.com/StalkAlex/yii2/commit/5a76ef110e99d377b1f79a2b814656da45a7b610 Checked in own project, it worked. I could make PR.

samdark commented 7 years ago

Looks OK.

cebe commented 7 years ago

There is now a 2.0.11.2 release including this fix. https://github.com/yiisoft/yii2/blob/2.0.11.2/framework/CHANGELOG.md#20112-february-08-2017

StalkAlex commented 7 years ago

Good news, thanks!

simonevallana commented 7 years ago

This problem remain also in the 2.0.11.2 version in the method loadFromCache() in DbManager class (line 990). Could you fix it? Thank you

samdark commented 7 years ago

@simonevallana it's fixed in 2.0.12 which isn't released yet.

simonevallana commented 7 years ago

@samdark Perfect, thank you.

cebe commented 7 years ago

turns out RBAC tests do not cover pgsql and sqlite, even though they suggest they should.

cebe commented 7 years ago

fixed by fa4d762..67b9a57