Skip to content
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

SSO: switch from module codebase to Connection package, part 3 #37153

Merged
merged 26 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
51be1c0
SSO: remove references to Jetpack class
jeherve May 1, 2024
83a29ad
Switch to modern display of notice and add missing i18n wrapping
jeherve May 1, 2024
7054189
Load SSO feature from the Connection package
jeherve May 1, 2024
3b7fafa
Switch to Connection package for all SSO references
jeherve May 1, 2024
feb2bb4
Deprecate all module classes and methods
jeherve May 1, 2024
914d1d3
Remove module test
jeherve May 1, 2024
b544238
Remove test reference too
jeherve May 1, 2024
18dbc04
Remove one more test directory (multisite)
jeherve May 1, 2024
c17a41e
Update Phan config
jeherve May 1, 2024
d05c401
Move SSO callables to the Connection package
jeherve May 1, 2024
c2294ed
Add deprecated class back
jeherve May 1, 2024
4e3492f
Remove deprecated private methods
jeherve May 1, 2024
7745ce8
Remove private properties and methods
jeherve May 1, 2024
9ecff27
Merge remote-tracking branch 'origin/trunk' into update/sso-use-package
jeherve May 1, 2024
836745c
Merge remote-tracking branch 'origin/trunk' into update/sso-use-package
jeherve May 9, 2024
d1571de
Move user generation to Utils class
jeherve May 9, 2024
0ea30ae
Try fixing tests
jeherve May 9, 2024
6980c07
Revert "Try fixing tests"
jeherve May 10, 2024
65a375a
Merge remote-tracking branch 'origin/trunk' into update/sso-use-package
jeherve May 10, 2024
b204864
Bump versions
jeherve May 10, 2024
f4a1a59
Ensure the SSO module is used in tests
jeherve May 10, 2024
c562446
Merge remote-tracking branch 'origin/trunk' into update/sso-use-package
jeherve May 10, 2024
6c9ade7
Add new SSO XML-RPC method
jeherve May 10, 2024
5fc7741
Merge remote-tracking branch 'origin/trunk' into update/sso-use-package
jeherve May 10, 2024
1e7a3f6
Merge branch 'trunk' into update/sso-use-package
fgiannar May 14, 2024
a4402bc
Jetpack Connection: Bump package version
fgiannar May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/packages/connection/changelog/update-sso-use-package
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

SSO: do not rely on the Jetpack class anymore.
12 changes: 7 additions & 5 deletions projects/packages/connection/src/sso/class-force-2fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ public function plugins_loaded() {
$this->role = apply_filters( 'jetpack_force_2fa_cap', 'manage_options' );

// Bail if Jetpack SSO is not active
if (
! class_exists( 'Jetpack' )
|| ! ( new Modules() )->is_active( 'sso' )
) {
if ( ! ( new Modules() )->is_active( 'sso' ) ) {
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
return;
}
Expand All @@ -75,7 +72,12 @@ public function admin_notice() {
* @module SSO
*/
if ( apply_filters( 'jetpack_force_2fa_dependency_notice', true ) && current_user_can( $this->role ) ) {
printf( '<div class="%1$s"><p>%2$s</p></div>', 'notice notice-warning', 'Jetpack Force 2FA requires Jetpack and the Jetpack SSO module.' );
wp_admin_notice(
esc_html__( 'Jetpack Force 2FA requires Jetpack’s SSO feature.', 'jetpack-connection' ),
array(
'type' => 'warning',
)
);
}
}

Expand Down
8 changes: 0 additions & 8 deletions projects/packages/connection/src/sso/class-sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ private function __construct() {

self::$instance = $this;

/*
* This feature currently relies on the Jetpack plugin.
* Bail if Jetpack isn't installed.
*/
if ( ! class_exists( 'Jetpack' ) ) {
return;
}

add_action( 'admin_init', array( $this, 'maybe_authorize_user_after_sso' ), 1 );
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'login_init', array( $this, 'login_init' ) );
Expand Down
12 changes: 4 additions & 8 deletions projects/plugins/jetpack/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
*/
return [
// # Issue statistics:
// PhanTypeMismatchArgument : 550+ occurrences
// PhanTypeMismatchArgument : 540+ occurrences
// PhanTypeMismatchArgumentProbablyReal : 300+ occurrences
// PhanPluginDuplicateConditionalNullCoalescing : 290+ occurrences
// PhanUndeclaredMethod : 270+ occurrences
// PhanNoopNew : 210+ occurrences
// PhanNoopNew : 200+ occurrences
// PhanTypeMismatchReturn : 160+ occurrences
// PhanTypeMismatchReturnProbablyReal : 150+ occurrences
// PhanDeprecatedFunction : 140+ occurrences
Expand All @@ -38,11 +38,11 @@
// PhanPluginSimplifyExpressionBool : 25+ occurrences
// PhanTypeMismatchDefault : 25+ occurrences
// PhanTypeMissingReturn : 25+ occurrences
// PhanTypeSuspiciousNonTraversableForeach : 25+ occurrences
// PhanUndeclaredFunction : 25+ occurrences
// PhanTypeArraySuspicious : 20+ occurrences
// PhanTypeMismatchArgumentNullableInternal : 20+ occurrences
// PhanTypeMismatchDimFetch : 20+ occurrences
// PhanTypeSuspiciousNonTraversableForeach : 20+ occurrences
// PhanPluginDuplicateExpressionAssignmentOperation : 15+ occurrences
// PhanPluginMixedKeyNoKey : 15+ occurrences
// PhanSuspiciousMagicConstant : 15+ occurrences
Expand All @@ -66,7 +66,6 @@
// PhanUndeclaredVariableDim : 6 occurrences
// PhanImpossibleCondition : 5 occurrences
// PhanNonClassMethodCall : 5 occurrences
// PhanPluginUnreachableCode : 5 occurrences
// PhanTypeMismatchDimAssignment : 5 occurrences
// PhanTypeSuspiciousStringExpression : 5 occurrences
// PhanAccessMethodInternal : 4 occurrences
Expand All @@ -80,6 +79,7 @@
// PhanTypeInvalidRightOperandOfNumericOp : 4 occurrences
// PhanDeprecatedFunctionInternal : 3 occurrences
// PhanDeprecatedTrait : 3 occurrences
// PhanPluginUnreachableCode : 3 occurrences
// PhanTypeConversionFromArray : 3 occurrences
// PhanTypeMismatchArgumentReal : 3 occurrences
// PhanTypeObjectUnsetDeclaredProperty : 3 occurrences
Expand Down Expand Up @@ -467,10 +467,6 @@
'modules/sitemaps/sitemap-librarian.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturnProbablyReal'],
'modules/sitemaps/sitemap-logger.php' => ['PhanTypeMismatchProperty'],
'modules/sitemaps/sitemaps.php' => ['PhanNoopNew', 'PhanTypeMismatchArgument'],
'modules/sso.php' => ['PhanNoopNew', 'PhanRedundantCondition', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'],
'modules/sso/class-jetpack-force-2fa.php' => ['PhanDeprecatedFunction'],
'modules/sso/class.jetpack-sso-helpers.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturn'],
'modules/sso/class.jetpack-sso-user-admin.php' => ['PhanPluginUnreachableCode', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal'],
'modules/stats.php' => ['PhanDeprecatedFunction', 'PhanPossiblyUndeclaredVariable', 'PhanRedundantCondition', 'PhanSuspiciousMagicConstant', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnNullable', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeMissingReturn'],
'modules/subscriptions.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeSuspiciousNonTraversableForeach'],
'modules/subscriptions/subscribe-modal/class-jetpack-subscribe-modal.php' => ['PhanTypeMismatchReturnNullable'],
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/update-sso-use-package
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

SSO: switch to loading feature from the Connection package.
24 changes: 9 additions & 15 deletions projects/plugins/jetpack/class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Connection\Rest_Authentication as Connection_Rest_Authentication;
use Automattic\Jetpack\Connection\Secrets;
use Automattic\Jetpack\Connection\SSO\Helpers;
use Automattic\Jetpack\Connection\Tokens;
use Automattic\Jetpack\Connection\Webhooks\Authorize_Redirect;
use Automattic\Jetpack\Constants;
Expand Down Expand Up @@ -1082,24 +1083,17 @@ public function filter_sync_callable_whitelist( $callables ) {

// Jetpack Functions.
$jetpack_callables = array(
'single_user_site' => array( 'Jetpack', 'is_single_user_site' ),
'updates' => array( 'Jetpack', 'get_updates' ),
'available_jetpack_blocks' => array( 'Jetpack_Gutenberg', 'get_availability' ), // Includes both Gutenberg blocks *and* plugins.
'single_user_site' => array( 'Jetpack', 'is_single_user_site' ),
'updates' => array( 'Jetpack', 'get_updates' ),
'available_jetpack_blocks' => array( 'Jetpack_Gutenberg', 'get_availability' ), // Includes both Gutenberg blocks *and* plugins.
'sso_is_two_step_required' => array( Helpers::class, 'is_two_step_required' ), // SSO feature related.
jeherve marked this conversation as resolved.
Show resolved Hide resolved
'sso_should_hide_login_form' => array( Helpers::class, 'should_hide_login_form' ), // SSO feature related.
'sso_match_by_email' => array( Helpers::class, 'match_by_email' ), // SSO feature related.
'sso_new_user_override' => array( Helpers::class, 'new_user_override' ), // SSO feature related.
'sso_bypass_default_login_form' => array( Helpers::class, 'bypass_login_forward_wpcom' ), // SSO feature related.
);
$callables = array_merge( $callables, $jetpack_callables );

// Jetpack_SSO_Helpers.
if ( include_once JETPACK__PLUGIN_DIR . 'modules/sso/class.jetpack-sso-helpers.php' ) {
$sso_helpers = array(
'sso_is_two_step_required' => array( 'Jetpack_SSO_Helpers', 'is_two_step_required' ),
'sso_should_hide_login_form' => array( 'Jetpack_SSO_Helpers', 'should_hide_login_form' ),
'sso_match_by_email' => array( 'Jetpack_SSO_Helpers', 'match_by_email' ),
'sso_new_user_override' => array( 'Jetpack_SSO_Helpers', 'new_user_override' ),
'sso_bypass_default_login_form' => array( 'Jetpack_SSO_Helpers', 'bypass_login_forward_wpcom' ),
);
$callables = array_merge( $callables, $sso_helpers );
}

return $callables;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName

use Automattic\Jetpack\Connection\SSO\Helpers;
use Automattic\Jetpack\Constants;

/**
Expand Down Expand Up @@ -76,7 +77,7 @@ public function create_or_get_user() {
$this->user_data->url = isset( $this->user_data->URL ) ? $this->user_data->URL : '';
$this->user_data->display_name = $this->user_data->name;
$this->user_data->description = '';
$user = Jetpack_SSO_Helpers::generate_user( $this->user_data );
$user = Helpers::generate_user( $this->user_data );
jeherve marked this conversation as resolved.
Show resolved Hide resolved
}

if ( is_multisite() ) {
Expand Down
Loading
Loading