fix(tests): round-trip encrypt OpenRouter test key via real Encryption class
This commit is contained in:
@@ -18,13 +18,21 @@ class OpenRouterImageProviderTest extends BaseTestCase {
|
|||||||
protected function setUp(): void {
|
protected function setUp(): void {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
// Generate valid encrypted API key using the real Encryption class.
|
||||||
|
// BaseTestCase stubs wp_salt() to return a deterministic value,
|
||||||
|
// so encrypt/decrypt round-trips correctly in tests.
|
||||||
|
$encrypted_key = \PRAutoBlogger_Encryption::encrypt( 'sk-or-test-key-123' );
|
||||||
|
|
||||||
// Provide a valid encrypted API key.
|
// Provide a valid encrypted API key.
|
||||||
Functions\when( 'get_option' )->alias( function ( $key, $default = false ) {
|
Functions\when( 'get_option' )->alias( function ( $key, $default = false ) use ( $encrypted_key ) {
|
||||||
static $options = [
|
static $options = [];
|
||||||
'prautoblogger_openrouter_api_key' => 'enc:fake-encrypted-key',
|
if ( empty( $options ) ) {
|
||||||
'prautoblogger_image_model' => 'black-forest-labs/flux-2-pro',
|
$options = [
|
||||||
'prautoblogger_ai_gateway_base_url' => '',
|
'prautoblogger_openrouter_api_key' => $encrypted_key,
|
||||||
];
|
'prautoblogger_image_model' => 'black-forest-labs/flux-2-pro',
|
||||||
|
'prautoblogger_ai_gateway_base_url' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
return $options[ $key ] ?? $default;
|
return $options[ $key ] ?? $default;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
@@ -33,17 +41,6 @@ class OpenRouterImageProviderTest extends BaseTestCase {
|
|||||||
} );
|
} );
|
||||||
Functions\when( 'esc_html' )->returnArg();
|
Functions\when( 'esc_html' )->returnArg();
|
||||||
Functions\when( 'esc_html__' )->returnArg();
|
Functions\when( 'esc_html__' )->returnArg();
|
||||||
|
|
||||||
// Mock encryption: decrypt returns a valid sk-or- key.
|
|
||||||
if ( ! class_exists( 'PRAutoBlogger_Encryption' ) ) {
|
|
||||||
eval( '
|
|
||||||
class PRAutoBlogger_Encryption {
|
|
||||||
public static function is_encrypted( $v ) { return 0 === strpos( $v, "enc:" ); }
|
|
||||||
public static function decrypt( $v ) { return "sk-or-test-key-123"; }
|
|
||||||
public static function encrypt( $v ) { return "enc:" . $v; }
|
|
||||||
}
|
|
||||||
' );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Provider name matches expected identifier. */
|
/** Provider name matches expected identifier. */
|
||||||
|
|||||||
Reference in New Issue
Block a user