Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| WebAuthnManageForm | |
0.00% |
0 / 40 |
|
0.00% |
0 / 6 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getHTML | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getButtons | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| onSuccess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| onSubmit | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDescriptors | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\OATHAuth\HTMLForm; |
| 4 | |
| 5 | use MediaWiki\Context\IContextSource; |
| 6 | use MediaWiki\Extension\OATHAuth\HTMLField\NoJsInfoField; |
| 7 | use MediaWiki\Extension\OATHAuth\HTMLField\RegisteredKeyLayout; |
| 8 | use MediaWiki\Extension\OATHAuth\Module\IModule; |
| 9 | use MediaWiki\Extension\OATHAuth\Module\WebAuthn; |
| 10 | use MediaWiki\Extension\OATHAuth\OATHAuthModuleRegistry; |
| 11 | use MediaWiki\Extension\OATHAuth\OATHUser; |
| 12 | use MediaWiki\Extension\OATHAuth\OATHUserRepository; |
| 13 | use MediaWiki\SpecialPage\SpecialPage; |
| 14 | use MediaWiki\Status\Status; |
| 15 | use OOUI\ButtonWidget; |
| 16 | |
| 17 | /** |
| 18 | * @property WebAuthn $module |
| 19 | */ |
| 20 | class WebAuthnManageForm extends OATHAuthOOUIHTMLForm { |
| 21 | |
| 22 | /** @inheritDoc */ |
| 23 | public function __construct( |
| 24 | OATHUser $oathUser, |
| 25 | OATHUserRepository $oathRepo, |
| 26 | IModule $module, |
| 27 | IContextSource $context, |
| 28 | OATHAuthModuleRegistry $moduleRegistry |
| 29 | ) { |
| 30 | parent::__construct( $oathUser, $oathRepo, $module, $context, $moduleRegistry ); |
| 31 | |
| 32 | $this->setId( 'webauthn-manage-form' ); |
| 33 | $this->suppressDefaultSubmit(); |
| 34 | |
| 35 | $this->panelPadded = false; |
| 36 | $this->panelFramed = false; |
| 37 | } |
| 38 | |
| 39 | /** @inheritDoc */ |
| 40 | public function getHTML( $submitResult ) { |
| 41 | $this->getOutput()->addModules( 'ext.webauthn.manage' ); |
| 42 | return parent::getHTML( $submitResult ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @return ButtonWidget |
| 47 | */ |
| 48 | public function getButtons() { |
| 49 | return new ButtonWidget( [ |
| 50 | 'id' => 'button_add_key', |
| 51 | 'flags' => [ 'progressive', 'primary' ], |
| 52 | 'disabled' => true, |
| 53 | 'label' => wfMessage( 'oathauth-webauthn-ui-add-key' )->plain(), |
| 54 | 'href' => SpecialPage::getTitleFor( 'OATHManage' )->getLocalURL( [ |
| 55 | 'module' => 'webauthn', |
| 56 | 'action' => WebAuthn::ACTION_ADD_KEY |
| 57 | ] ), |
| 58 | 'infusable' => true |
| 59 | ] ); |
| 60 | } |
| 61 | |
| 62 | public function onSuccess(): void { |
| 63 | // Not used - redirect is handled client-side after API call |
| 64 | } |
| 65 | |
| 66 | public function onSubmit( array $formData ): Status|bool|array|string { |
| 67 | // This is handled client-side via API |
| 68 | return [ 'oathauth-webauthn-javascript-required' ]; |
| 69 | } |
| 70 | |
| 71 | protected function getDescriptors(): array { |
| 72 | $oathUser = $this->oathRepo->findByUser( $this->getUser() ); |
| 73 | $keys = WebAuthn::getWebAuthnKeys( $oathUser ); |
| 74 | |
| 75 | $registeredKeys = []; |
| 76 | foreach ( $keys as $idx => $key ) { |
| 77 | $registeredKeys["reg_key_$idx"] = [ |
| 78 | 'type' => 'null', |
| 79 | 'default' => [ |
| 80 | 'name' => $key->getFriendlyName(), |
| 81 | 'signCount' => $key->getSignCounter() |
| 82 | ], |
| 83 | 'raw' => true, |
| 84 | 'class' => RegisteredKeyLayout::class, |
| 85 | 'section' => 'webauthn-registered-keys-section-name' |
| 86 | ]; |
| 87 | } |
| 88 | |
| 89 | return [ |
| 90 | 'nojs' => [ |
| 91 | 'class' => NoJsInfoField::class, |
| 92 | 'section' => 'webauthn-registered-keys-section-name', |
| 93 | ], |
| 94 | ] + $registeredKeys; |
| 95 | } |
| 96 | } |