public function testLoginExpires() { if (getenv('TRAVIS') == 'true') { $this->markTestSkipped('Can not reliably test this on travis-ci.'); } $appConfig = ['components' => ['user' => ['identityClass' => UserIdentity::className(), 'authTimeout' => 10], 'authManager' => ['class' => PhpManager::className(), 'itemFile' => '@runtime/user_test_rbac_items.php', 'assignmentFile' => '@runtime/user_test_rbac_assignments.php', 'ruleFile' => '@runtime/user_test_rbac_rules.php']]]; $this->mockWebApplication($appConfig); $am = Yii::$app->authManager; $am->removeAll(); $am->add($role = $am->createPermission('rUser')); $am->add($perm = $am->createPermission('doSomething')); $am->addChild($role, $perm); $am->assign($role, 'user1'); Yii::$app->session->removeAll(); static::$time = \time(); Yii::$app->user->login(UserIdentity::findIdentity('user1')); // print_r(Yii::$app->session); // print_r($_SESSION); $this->mockWebApplication($appConfig); $this->assertFalse(Yii::$app->user->isGuest); $this->assertTrue(Yii::$app->user->can('doSomething')); static::$time += 5; $this->mockWebApplication($appConfig); $this->assertFalse(Yii::$app->user->isGuest); $this->assertTrue(Yii::$app->user->can('doSomething')); static::$time += 11; $this->mockWebApplication($appConfig); $this->assertTrue(Yii::$app->user->isGuest); $this->assertFalse(Yii::$app->user->can('doSomething')); }
/** * @inheritdoc */ protected function setUp() { parent::setUp(); file_put_contents($this->itemFile, file_get_contents(__DIR__ . '/data/_rbac/items.php')); file_put_contents($this->assignmentFile, file_get_contents(__DIR__ . '/data/_rbac/assignments.php')); file_put_contents($this->ruleFile, file_get_contents(__DIR__ . '/data/_rbac/rules.php')); $this->mockWebApplication(['components' => ['authManager' => ['class' => \yii\rbac\PhpManager::className(), 'itemFile' => $this->itemFile, 'assignmentFile' => $this->assignmentFile, 'ruleFile' => $this->ruleFile]]]); $this->itemController = new ItemController('item', Yii::$app); $this->itemController->detachBehavior('verbs'); }
<?php $params = (require __DIR__ . '/params.php'); $config = ['aliases' => ['@uploadedFilesDir' => '@app/uploadedFiles'], 'id' => 'basic', 'basePath' => dirname(__DIR__), 'timeZone' => 'GMT', 'bootstrap' => ['log'], 'components' => ['request' => ['cookieValidationKey' => 'nz4H_EKn2VnYkbIaXL4ucu1TmDiif-gw'], 'cache' => ['class' => 'yii\\caching\\FileCache'], 'user' => ['identityClass' => 'app\\models\\UserRecord', 'enableAutoLogin' => true], 'errorHandler' => ['errorAction' => 'site/error'], 'mailer' => ['class' => 'yii\\swiftmailer\\Mailer', 'useFileTransport' => true], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'db' => require __DIR__ . '/db.php', 'dbSqlite' => ['class' => 'yii\\db\\Connection', 'dsn' => 'sqlite:' . dirname(__DIR__) . PATH_SEPARATOR . '..' . PATH_SEPARATOR . 'web' . PATH_SEPARATOR . 'sqlite.db'], 'urlManager' => ['enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => ['newws/index' => 'newws/index', 'newws/<year:\\d{4}>/items-list' => 'newws/items-list', ['pattern' => 'newws/<category:\\w+>/items-list', 'route' => 'newws/items-list', 'defaults' => ['category' => 'shopping']], ['pattern' => '<lang:\\w+>/<controller>/<action>', 'route' => '<controller>/<action>'], ['class' => 'app\\components\\NewwsUrlRule']]], 'authManager' => ['class' => \yii\rbac\PhpManager::className()]], 'params' => $params]; if (YII_ENV_DEV) { // configuration adjustments for 'dev' environment $config['bootstrap'][] = 'debug'; $config['modules']['debug'] = ['class' => 'yii\\debug\\Module']; $config['bootstrap'][] = 'gii'; $config['modules']['gii'] = ['class' => 'yii\\gii\\Module', 'allowedIPs' => ['*']]; } return $config;