$this->formatMessage( $ret, 'label', $field['label'] );
$this->formatMessage( $ret, 'help', $field['help'] );
$ret['optional'] = !empty( $field['optional'] );
+ $ret['sensitive'] = !empty( $field['sensitive'] );
$retFields[$name] = $ret;
}
* - label: (Message) Text suitable for a label in an HTML form
* - help: (Message) Text suitable as a description of what the field is
* - optional: (bool) If set and truthy, the field may be left empty
+ * - sensitive: (bool) If set and truthy, the field is considered sensitive. Code using the
+ * request should avoid exposing the value of the field.
*
* @return array As above
*/
$options['optional'] = !empty( $options['optional'] );
}
+ $options['sensitive'] = !empty( $options['sensitive'] );
+
if ( !array_key_exists( $name, $merged ) ) {
$merged[$name] = $options;
} elseif ( $merged[$name]['type'] !== $options['type'] ) {
}
$merged[$name]['optional'] = $merged[$name]['optional'] && $options['optional'];
+ $merged[$name]['sensitive'] = $merged[$name]['sensitive'] || $options['sensitive'];
// No way to merge 'value', 'image', 'help', or 'label', so just use
// the value from the first request.
'type' => 'password',
'label' => wfMessage( $passwordLabel ),
'help' => wfMessage( 'authmanager-password-help' ),
+ 'sensitive' => true,
],
];
'type' => 'password',
'label' => wfMessage( $retypeLabel ),
'help' => wfMessage( 'authmanager-retype-help' ),
+ 'sensitive' => true,
];
}
'type' => 'string',
'label' => $msg,
'help' => $msg,
+ 'sensitive' => true,
],
'string3' => [
'type' => 'string',
$expect = $req1->getFieldInfo();
foreach ( $expect as $name => &$options ) {
$options['optional'] = !empty( $options['optional'] );
+ $options['sensitive'] = !empty( $options['sensitive'] );
}
unset( $options );
$this->assertEquals( $expect, $fields );
$fields = AuthenticationRequest::mergeFieldInfo( [ $req1, $req2 ] );
$expect += $req2->getFieldInfo();
+ $expect['string1']['sensitive'] = true;
$expect['string2']['optional'] = false;
$expect['string3']['optional'] = false;
+ $expect['string3']['sensitive'] = false;
$expect['select']['options']['bar'] = $msg;
$this->assertEquals( $expect, $fields );
$fields = AuthenticationRequest::mergeFieldInfo( [ $req1, $req2 ] );
$expect += $req2->getFieldInfo();
$expect['string1']['optional'] = false;
+ $expect['string1']['sensitive'] = true;
$expect['string3']['optional'] = false;
$expect['select']['optional'] = false;
$expect['select']['options']['bar'] = $msg;
$fields = AuthenticationRequest::mergeFieldInfo( [ $req1, $req2 ] );
$expect = $req1->getFieldInfo() + $req2->getFieldInfo();
+ foreach ( $expect as $name => &$options ) {
+ $options['sensitive'] = !empty( $options['sensitive'] );
+ }
$expect['string1']['optional'] = false;
+ $expect['string1']['sensitive'] = true;
$expect['string2']['optional'] = true;
$expect['string3']['optional'] = true;
$expect['select']['optional'] = false;
if ( isset( $data['image'] ) ) {
$this->assertType( 'string', $data['image'], "Field $field, image" );
}
+ if ( isset( $data['sensitive'] ) ) {
+ $this->assertType( 'bool', $data['sensitive'], "Field $field, sensitive" );
+ }
+ if ( $data['type'] === 'password' ) {
+ $this->assertTrue( !empty( $data['sensitive'] ),
+ "Field $field, password field must be sensitive" );
+ }
switch ( $data['type'] ) {
case 'string':