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

remove dead code related to activating users and setting passwords #170

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 0 additions & 49 deletions application/common/components/adapters/IdpIdBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,6 @@ public function init()
parent::init();
}

/**
* Activate a user.
*
* @param string $employeeId The Employee ID of the user to activate.
* @throws Exception
*/
public function activateUser(string $employeeId)
{
$this->getClient()->updateUser([
'employee_id' => $employeeId,
'active' => 'yes',
]);
}

/**
* Attempt to authenticate using the given credentials, getting back
* information about the authenticated user (if the credentials were
* acceptable) or null (if unacceptable).
*
* @param string $username The username.
* @param string $password The password (in plaintext).
* @return User|null User information (if valid), or null.
* @throws Exception
*/
public function authenticate(string $username, string $password)
{
$authenticatedUserInfo = $this->getClient()->authenticate(
$username,
$password
);
if ($authenticatedUserInfo === null) {
return null;
}
return new User($authenticatedUserInfo);
}

/**
* Create a user with the given information.
*
Expand Down Expand Up @@ -154,19 +118,6 @@ public function listUsers($fields = null): array
return self::getAsUsers($result);
}

/**
* Set the password for the specified user.
*
* @param string $employeeId The Employee ID of the user whose password we
* are trying to set.
* @param string $password The desired (new) password, in plaintext.
* @throws Exception
*/
public function setPassword(string $employeeId, string $password)
{
$this->getClient()->setPassword($employeeId, $password);
}

/**
* Update the specified user with the given information.
*
Expand Down
15 changes: 0 additions & 15 deletions application/common/components/adapters/fakes/FakeIdBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ public function __construct(array $usersByEmployeeId = [], array $config = [])
parent::__construct($config);
}

public function activateUser(string $employeeId)
{
$this->usersByEmployeeId[$employeeId]['active'] = 'yes';
}

public function authenticate(string $username, string $password)
{
throw new NotSupportedException();
}

public function createUser(array $config = [])
{
/*
Expand Down Expand Up @@ -86,11 +76,6 @@ public function listUsers($fields = null)
return $results;
}

public function setPassword(string $employeeId, string $password)
{
throw new NotSupportedException();
}

public function updateUser(array $config = [])
{
if (array_key_exists('email', $config) && empty($config['email'])) {
Expand Down
30 changes: 0 additions & 30 deletions application/common/interfaces/IdBrokerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,6 @@

interface IdBrokerInterface
{
/**
* Activate a user.
*
* @param string $employeeId The Employee ID of the user to activate.
* @throws Exception
*/
public function activateUser(string $employeeId);

/**
* Attempt to authenticate using the given credentials, getting back
* information about the authenticated user (if the credentials were
* acceptable) or null (if unacceptable).
*
* @param string $username The username.
* @param string $password The password (in plaintext).
* @return User|null User information (if valid), or null.
* @throws Exception
*/
public function authenticate(string $username, string $password);

/**
* Create a user with the given information.
*
Expand Down Expand Up @@ -72,16 +52,6 @@ public function getUser(string $employeeId);
*/
public function listUsers($fields = null);

/**
* Set the password for the specified user.
*
* @param string $employeeId The Employee ID of the user whose password we
* are trying to set.
* @param string $password The desired (new) password, in plaintext.
* @throws Exception
*/
public function setPassword(string $employeeId, string $password);

/**
* Update the specified user with the given information.
*
Expand Down
95 changes: 2 additions & 93 deletions application/features/bootstrap/IdpIdBrokerIntegrationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ protected function generateDummyPassword()
}

/**
* @Given a user exists
* @Given an active user exists
*/
public function aUserExists()
public function anActiveUserExists()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be a bad idea to also have this assert that the user is active, since that is what it's name now conveys.

{
$newUser = $this->idBroker->createUser($this->testUserData);
Assert::assertNotNull($newUser);
Expand All @@ -85,23 +85,6 @@ public function thatUserIsNotActive()
Assert::assertEquals('no', $user->getActive());
}

/**
* @When I activate that user
*/
public function iActivateThatUser()
{
// Activate the user.
$this->idBroker->activateUser(
$this->testUserData['employee_id']
);

// Confirm that it worked.
$user = $this->idBroker->getUser(
$this->testUserData['employee_id']
);
Assert::assertEquals('yes', $user->getActive());
}

/**
* @Then that user should now be active
*/
Expand All @@ -113,30 +96,6 @@ public function thatUserShouldNowBeActive()
Assert::assertEquals('yes', $user->getActive());
}

/**
* @Given that user has a password
*/
public function thatUserHasAPassword()
{
$this->testUserData['password'] = $this->generateDummyPassword();

$this->idBroker->setPassword(
$this->testUserData['employee_id'],
$this->testUserData['password']
);
}

/**
* @When I try to authenticate as that user
*/
public function iTryToAuthenticateAsThatUser()
{
$this->result = $this->idBroker->authenticate(
$this->testUserData['username'],
$this->testUserData['password']
);
}

/**
* @Then I should receive back information about that user
*/
Expand Down Expand Up @@ -180,16 +139,6 @@ public function thatUserShouldNowExist()
Assert::assertSame($this->testUserData['email'], $user->getEmail());
}

/**
* @Given that user is active
*/
public function thatUserIsActive()
{
$this->idBroker->activateUser(
$this->testUserData['employee_id']
);
}

/**
* @When I deactivate that user
*/
Expand Down Expand Up @@ -268,46 +217,6 @@ public function eachEntryInTheResultingListShouldHaveUserInformation()
}
}

/**
* @When I set that user's password to something else
*/
public function iSetThatUsersPasswordToSomethingElse()
{
$this->oldPassword = $this->testUserData['password'];
$this->newPassword = $this->generateDummyPassword();

$this->testUserData['password'] = $this->newPassword;

$this->idBroker->setPassword(
$this->testUserData['employee_id'],
$this->newPassword
);
}

/**
* @Then I should NOT be able to authenticate with the old password
*/
public function iShouldNotBeAbleToAuthenticateWithTheOldPassword()
{
$authenticatedUser = $this->idBroker->authenticate(
$this->testUserData['username'],
$this->oldPassword
);
Assert::assertNull($authenticatedUser);
}

/**
* @Then I SHOULD be able to authenticate with the new password
*/
public function iShouldBeAbleToAuthenticateWithTheNewPassword()
{
$authenticatedUser = $this->idBroker->authenticate(
$this->testUserData['username'],
$this->newPassword
);
Assert::assertNotNull($authenticatedUser);
}

/**
* @When I update that user
*/
Expand Down
26 changes: 3 additions & 23 deletions application/features/idp-id-broker-integration.feature
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@

Feature: Integration with IdP ID Broker

Scenario: Activate user
Given a user exists
And that user is not active
When I activate that user
Then that user should now be active

Scenario: Authenticate
Given a user exists
And that user has a password
When I try to authenticate as that user
Then I should receive back information about that user

Scenario: Create user
Given a user does not exist
When I create that user
Then that user should now exist

Scenario: Deactivate user
Given a user exists
And that user is active
Given an active user exists
When I deactivate that user
Then that user should now NOT be active

Scenario: Get user
Given a user exists
Given an active user exists
When I get that user
Then I should receive back information about that user

Expand All @@ -35,14 +22,7 @@ Feature: Integration with IdP ID Broker
Then I should receive a list of at least 3 users
And each entry in the resulting list should have user information

Scenario: Set password
Given a user exists
And that user has a password
When I set that user's password to something else
Then I should NOT be able to authenticate with the old password
And I SHOULD be able to authenticate with the new password

Scenario: Update user
Given a user exists
Given an active user exists
When I update that user
Then when I get that user I should receive the updated information