Repository navigation
FreeScout: Keep administrators to the proxy #996
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
Open
obenland
wants to merge
4
commits into
WordPress:trunk
Choose a base branch
from
obenland:add/freescout-admin-proxy
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
01614a7
FreeScout: Keep administrators to the proxy
obenland 9a6d8a0
FreeScout: Drop the load balancer note from the proxy docs
obenland b1f1624
FreeScout: Drop the obvious from the proxy docs
obenland 56d1809
FreeScout: Show why administrators were logged out on the password form
obenland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
167 changes: 167 additions & 0 deletions
167
freescout.wordpress.net/Modules/WPOrgSSO/tests/ProxyTest.php
This file contains hidden or 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,167 @@ | ||
| <?php | ||
| /** | ||
| * Tests for keeping administrators to the proxy. | ||
| * | ||
| * @package WordPressdotorg\FreeScout\WPOrgSSO | ||
| */ | ||
|
|
||
| declare( strict_types = 1 ); | ||
|
|
||
| namespace Modules\WPOrgSSO\Tests; | ||
|
|
||
| use App\User; | ||
| use Modules\WPOrgSSO\Entities\Account; | ||
| use Modules\WPOrgSSO\Providers\WPOrgSSOServiceProvider; | ||
|
|
||
| require_once __DIR__ . '/SsoTestCase.php'; | ||
|
|
||
| /** | ||
| * Covers logging administrators out of requests that don't come through the proxy. | ||
| */ | ||
| final class ProxyTest extends SsoTestCase { | ||
|
|
||
| /** | ||
| * Administrator connected to the "rita" account. | ||
| * | ||
| * @var User | ||
| */ | ||
| private $admin; | ||
|
|
||
| /** | ||
| * Requires the proxy, and creates a connected administrator. | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function setUp(): void { | ||
| parent::setUp(); | ||
|
|
||
| config( array( 'wporgsso.require_proxy' => true ) ); | ||
|
|
||
| $this->admin = $this->create_user( User::ROLE_ADMIN ); | ||
| Account::connect( (int) $this->admin->id, 'rita' ); | ||
| } | ||
|
|
||
| /** | ||
| * Marks the following requests as proxied, or not, like nginx does. | ||
| * | ||
| * @param string $proxied The param's value. | ||
| * @return $this | ||
| */ | ||
| private function proxied( string $proxied ): self { | ||
| return $this->withServerVariables( array( WPOrgSSOServiceProvider::SERVER_PROXIED_REQUEST => $proxied ) ); | ||
| } | ||
|
|
||
| /** | ||
| * A proxied administrator stays logged in. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_keeps_proxied_administrators(): void { | ||
| $this->proxied( '1' )->actingAs( $this->admin )->get( route( 'dashboard' ) )->assertStatus( 200 ); | ||
|
|
||
| $this->assertAuthenticatedAs( $this->admin ); | ||
| } | ||
|
|
||
| /** | ||
| * An administrator outside the proxy is logged out, and told why. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_logs_out_administrators_outside_the_proxy(): void { | ||
| $this->proxied( '0' )->actingAs( $this->admin )->get( route( 'dashboard' ) )->assertRedirect( route( 'login' ) ); | ||
|
|
||
| $this->assertGuest(); | ||
| $this->assertSame( 'Administrators can only use the helpdesk through the proxy.', session( WPOrgSSOServiceProvider::SESSION_ERROR ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Until WordPress.org is enforced, core's password form tells the administrator why, too. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_explains_the_logout_on_the_password_form(): void { | ||
| config( array( 'wporgsso.idp.cert' => '' ) ); | ||
|
|
||
| $this->proxied( '0' )->actingAs( $this->admin )->get( route( 'dashboard' ) )->assertRedirect( route( 'login' ) ); | ||
|
|
||
| // Core escapes old('email'), which is null on a first visit; PHP 8 deprecates that, and tests turn it into an exception. | ||
| $form = (string) $this->withSession( array( '_old_input' => array( 'email' => '' ) ) )->get( route( 'login' ) )->getContent(); | ||
|
|
||
| $this->assertStringContainsString( 'name="password"', $form ); | ||
| $this->assertStringContainsString( 'Administrators can only use the helpdesk through the proxy.', $form ); | ||
| } | ||
|
|
||
| /** | ||
| * Logging in through WordPress.org from outside the proxy doesn't get an administrator in either. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_logs_out_administrators_after_logging_in_outside_the_proxy(): void { | ||
| $this->proxied( '0' ); | ||
| $this->complete( $this->post_to_acs( $this->start_login( 'rita' ) ) )->assertRedirect( route( 'dashboard' ) ); | ||
|
|
||
| $this->get( route( 'dashboard' ) )->assertRedirect( route( 'login' ) ); | ||
| $this->assertGuest(); | ||
| } | ||
|
|
||
| /** | ||
| * Polls from outside the proxy get a 401, like other ended sessions. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_answers_polls_outside_the_proxy_with_a_401(): void { | ||
| $this->proxied( '0' )->actingAs( $this->admin )->getJson( route( 'dashboard' ) )->assertStatus( 401 ); | ||
| } | ||
|
|
||
| /** | ||
| * Without the param, nobody counts as proxied. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_logs_out_administrators_without_the_param(): void { | ||
| $this->actingAs( $this->admin )->get( route( 'dashboard' ) )->assertRedirect( route( 'login' ) ); | ||
|
|
||
| $this->assertGuest(); | ||
| } | ||
|
|
||
| /** | ||
| * A header of the same name doesn't count: only nginx sets the param. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_ignores_the_header(): void { | ||
| $this->proxied( '0' ) | ||
| ->withHeaders( array( 'WPORG-PROXIED-REQUEST' => '1' ) ) | ||
| ->actingAs( $this->admin ) | ||
| ->get( route( 'dashboard' ) ) | ||
| ->assertRedirect( route( 'login' ) ); | ||
|
|
||
| $this->assertGuest(); | ||
| } | ||
|
|
||
| /** | ||
| * Agents don't need the proxy. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_agents_need_no_proxy(): void { | ||
| $agent = $this->create_user( User::ROLE_USER ); | ||
|
|
||
| $this->proxied( '0' )->actingAs( $agent )->get( route( 'dashboard' ) )->assertStatus( 200 ); | ||
|
|
||
| $this->assertAuthenticatedAs( $agent ); | ||
| } | ||
|
|
||
| /** | ||
| * Until it's required, administrators don't need the proxy. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_does_nothing_until_required(): void { | ||
| config( array( 'wporgsso.require_proxy' => false ) ); | ||
|
|
||
| $this->proxied( '0' )->actingAs( $this->admin )->get( route( 'dashboard' ) )->assertStatus( 200 ); | ||
|
|
||
| $this->assertAuthenticatedAs( $this->admin ); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.