-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #547 from TonisOrmisson/fix-profile-open
Fixes #546: all profiles publicly viewable to anyone by default
- Loading branch information
Showing
7 changed files
with
191 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,8 @@ | |
'user_id' => 1, | ||
'name' => 'John Doe', | ||
], | ||
'seconduser' => [ | ||
'user_id' => 9, | ||
'name' => 'John Doe 2', | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,4 +87,30 @@ | |
'confirmed_at' => $time, | ||
'gdpr_consent' => false, | ||
], | ||
'admin' => [ | ||
'id' => 8, | ||
'username' => 'admin', | ||
'email' => '[email protected]', | ||
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui', | ||
'auth_key' => '39HU0m5lpjWtqstFVGFjj6lFb7UZDeRq', | ||
'auth_tf_key' => '', | ||
'auth_tf_enabled' => false, | ||
'created_at' => $time, | ||
'updated_at' => $time, | ||
'confirmed_at' => $time, | ||
'gdpr_consent' => false, | ||
], | ||
'seconduser' => [ | ||
'id' => 9, | ||
'username' => 'seconduser', | ||
'email' => '[email protected]', | ||
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui', | ||
'auth_key' => '776960890cec5ac53525f0e910716f5a', | ||
'auth_tf_key' => '', | ||
'auth_tf_enabled' => false, | ||
'created_at' => $time, | ||
'updated_at' => $time, | ||
'confirmed_at' => $time, | ||
'gdpr_consent' => false, | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
/** | ||
* @var Codeception\Scenario | ||
*/ | ||
|
||
use tests\_fixtures\ProfileFixture; | ||
use tests\_fixtures\UserFixture; | ||
|
||
|
||
$I = new FunctionalTester($scenario); | ||
$I->haveFixtures([ | ||
'user' => UserFixture::class, | ||
'profile' => ProfileFixture::class | ||
]); | ||
$user = $I->grabFixture('user', 'user'); | ||
$secondUser = $I->grabFixture('user', 'seconduser'); | ||
$adminUser = $I->grabFixture('user', 'admin'); | ||
$I->wantTo('Ensure that profile profile pages are shown only to when user has correct permissions and else forbidden'); | ||
|
||
Yii::$app->getModule('user')->profileVisibility = \Da\User\Controller\ProfileController::PROFILE_VISIBILITY_OWNER; | ||
Yii::$app->getModule('user')->administrators = ['admin']; | ||
|
||
$I->amLoggedInAs($user); | ||
$I->amGoingTo('try to open users own profile page'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $user->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->dontSee('Forbidden'); | ||
$I->see('Joined on'); | ||
|
||
$I->amGoingTo('Profile visibility::OWNER: try to open another users profile page'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $secondUser->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->see('Forbidden'); | ||
$I->dontSee('Joined on'); | ||
|
||
Yii::$app->user->logout(); | ||
$I->amGoingTo('Profile visibility::OWNER: try to open users profile page as guest'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $user->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->see('Forbidden'); | ||
$I->dontSee('Joined on'); | ||
|
||
|
||
Yii::$app->getModule('user')->profileVisibility = \Da\User\Controller\ProfileController::PROFILE_VISIBILITY_ADMIN; | ||
$I->amLoggedInAs($user); | ||
$I->amGoingTo('Profile visibility::PROFILE_VISIBILITY_ADMIN: try to open users own profile page'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $user->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->dontSee('Forbidden'); | ||
$I->see('Joined on'); | ||
|
||
$I->amGoingTo('Profile visibility::PROFILE_VISIBILITY_ADMIN: try to open another users profile page as regular user'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $secondUser->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->see('Forbidden'); | ||
$I->dontSee('Joined on'); | ||
|
||
$I->amLoggedInAs($adminUser); | ||
$I->amGoingTo('Profile visibility::PROFILE_VISIBILITY_ADMIN: try to open another users profile page as admin'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $user->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->dontSee('Forbidden'); | ||
$I->see('Joined on'); | ||
|
||
Yii::$app->user->logout(); | ||
$I->amGoingTo('Profile visibility::PROFILE_VISIBILITY_ADMIN: try to open users profile page as guest'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $user->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->see('Forbidden'); | ||
$I->dontSee('Joined on'); | ||
|
||
|
||
Yii::$app->getModule('user')->profileVisibility = \Da\User\Controller\ProfileController::PROFILE_VISIBILITY_USERS; | ||
$I->amLoggedInAs($user); | ||
$I->amGoingTo('Profile visibility::PROFILE_VISIBILITY_USERS: try to open users own profile page'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $user->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->dontSee('Forbidden'); | ||
$I->see('Joined on'); | ||
|
||
$I->amGoingTo('Profile visibility::PROFILE_VISIBILITY_USERS: try to open another users profile page as regular user'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $secondUser->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->dontSee('Forbidden'); | ||
$I->see('Joined on'); | ||
|
||
$I->amLoggedInAs($adminUser); | ||
$I->amGoingTo('Profile visibility::PROFILE_VISIBILITY_USERS: try to open another users profile page as admin'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $user->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->dontSee('Forbidden'); | ||
$I->see('Joined on'); | ||
|
||
Yii::$app->user->logout(); | ||
$I->amGoingTo('Profile visibility::PROFILE_VISIBILITY_USERS: try to open users profile page as guest'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $user->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->see('Forbidden'); | ||
$I->dontSee('Joined on'); | ||
|
||
Yii::$app->getModule('user')->profileVisibility = \Da\User\Controller\ProfileController::PROFILE_VISIBILITY_PUBLIC; | ||
|
||
Yii::$app->user->logout(); | ||
$I->amGoingTo('Profile visibility::PROFILE_VISIBILITY_PUBLIC: try to open users profile page as guest'); | ||
$I->amOnRoute('/user/profile/show', ['id' => $user->id]); | ||
$I->expectTo('See the profile page'); | ||
$I->dontSee('Forbidden'); | ||
$I->see('Joined on'); | ||
|