Skip to content

Commit

Permalink
Fixes #13445: Add mc_login() for login and to return user data.
Browse files Browse the repository at this point in the history
  • Loading branch information
vboctor committed Jun 12, 2012
1 parent f39ad8c commit ae27eae
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
28 changes: 28 additions & 0 deletions api/soap/mantisconnect.php
Expand Up @@ -94,6 +94,20 @@
)
);

### UserData
$l_oServer->wsdl->addComplexType(
'UserData',
'complexType',
'struct',
'all',
'',
array(
'account_data' => array( 'name' => 'account_data', 'type' => 'tns:AccountData', 'minOccurs' => '0'),
'access_level' => array( 'name' => 'global_access_level', 'type' => 'xsd:integer', 'minOccurs' => '0'),
'timezone' => array( 'name' => 'timezone', 'type' => 'xsd:string', 'minOccurs' => '0'),
)
);

### AccountDataArray
$l_oServer->wsdl->addComplexType(
'AccountDataArray',
Expand Down Expand Up @@ -665,6 +679,20 @@
### PUBLIC METHODS (defined in mc_enum_api.php)
###

### mc_login
$l_oServer->register( 'mc_login',
array(
'username' => 'xsd:string',
'password' => 'xsd:string'
),
array(
'return' => 'tns:UserData'
),
$t_namespace,
false, false, false,
'Log the user in and get their information.'
);

### mc_enum_status
$l_oServer->register( 'mc_enum_status',
array(
Expand Down
32 changes: 31 additions & 1 deletion api/soap/mc_api.php
Expand Up @@ -16,7 +16,37 @@ function mc_version() {
return MANTIS_VERSION;
}

# Checks if MantisBT installation is marked as offline by the administrator.
/**
* Attempts to login the user.
* If logged in successfully, return user information.
* If failed to login in, then throw a fault.
*/
function mc_login( $p_username, $p_password ) {
$t_user_id = mci_check_login( $p_username, $p_password );
if ( $t_user_id === false ) {
return mci_soap_fault_login_failed();
}

return mci_user_get( $p_username, $p_password, $t_user_id );
}

/**
* Given an id, this method returns the user.
* When calling this method make sure that the caller has the right to retrieve
* information about the target user.
*/
function mci_user_get( $p_username, $p_password, $p_user_id ) {
$t_user_data = array();

// if user doesn't exist, then mci_account_get_array_by_id() will throw.
$t_user_data['account_data'] = mci_account_get_array_by_id( $p_user_id );
$t_user_data['access_level'] = access_get_global_level( $p_user_id );
$t_user_data['timezone'] = user_pref_get_pref( $p_user_id, 'timezone' );

return $t_user_data;
}

# access_ if MantisBT installation is marked as offline by the administrator.
# true: offline, false: online
function mci_is_mantis_offline() {
$t_offline_file = dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'mantis_offline.php';
Expand Down
46 changes: 46 additions & 0 deletions tests/soap/LoginTest.php
Expand Up @@ -31,6 +31,25 @@ class LoginTest extends SoapBase {
private $dummyUser = 'no';
private $dummyPassword = 'user';

public function testLoginFailed() {
try {
$this->client->mc_login( $this->dummyUser , $this->dummyPassword );
$this->fail( "Should have failed." );
} catch ( SoapFault $e) {
$this->assertIsLoginFailure( $e );
}
}

public function testLoginSuccessfully() {
$t_user_data = $this->client->mc_login( $this->userName, $this->password );

$this->assertEquals( $this->userName, $t_user_data->account_data->name, 'name' );
$this->assertEquals( $this->userId, $t_user_data->account_data->id, 'id' );
$this->assertEquals( $this->email, $t_user_data->account_data->email, 'email' );
$this->assertEquals( false, empty( $t_user_data->timezone ), 'timezone' );
$this->assertEquals( 90, (integer)$t_user_data->access_level, 'access_level' );
}

public function testGetIssueGetLoginFailed() {
try {
$this->client->mc_issue_get( $this->dummyUser , $this->dummyPassword, 1 );
Expand Down Expand Up @@ -76,6 +95,33 @@ public function testFilterGetIssuesLoginFailed() {
}
}

public function testLoginWithNullPasswordIsRejected() {
try {
$this->client->mc_enum_status( $this->userName, null);
$this->fail( "Should have failed." );
} catch ( SoapFault $e) {
$this->assertIsLoginFailure( $e );
}
}

public function testLoginWithEmptyPasswordIsRejected() {
try {
$this->client->mc_enum_status( $this->userName, '');
$this->fail( "Should have failed." );
} catch ( SoapFault $e) {
$this->assertIsLoginFailure( $e );
}
}

public function testLoginWithIncorrectPasswordIsRejected() {
try {
$this->client->mc_enum_status( $this->userName, "This really should be incorrect");
$this->fail( "Should have failed." );
} catch ( SoapFault $e) {
$this->assertIsLoginFailure( $e );
}
}

/**
* @param $e SoapFault
* @return void
Expand Down
1 change: 1 addition & 0 deletions tests/soap/SoapBase.php
Expand Up @@ -32,6 +32,7 @@ class SoapBase extends PHPUnit_Framework_TestCase {
protected $client;
protected $userName = 'administrator';
protected $password = 'root';
protected $email = 'root@localhost';
protected $userId = '1';

protected $mantisPath;
Expand Down

0 comments on commit ae27eae

Please sign in to comment.