-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #358 from silinternational/feature/IDP-1183-sync-g…
…oogle-sheet-to-external-groups [IDP-1183, partial] Revise "external groups" API endpoints
- Loading branch information
Showing
12 changed files
with
354 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,24 +44,6 @@ types: | |
"code": 0, | ||
"status": 400 | ||
} | ||
GroupsExternalUpdate: | ||
type: object | ||
properties: | ||
email_address: string | ||
app_prefix: | ||
type: string | ||
description: > | ||
The app-specific prefix, without the trailing hyphen. | ||
groups: | ||
type: string[] | ||
description: > | ||
The desired list of groups, including the app-prefix. | ||
example: | | ||
{ | ||
"email_address": "[email protected]", | ||
"app_prefix": "myapp", | ||
"groups": ["myapp-users", "myapp-managers"] | ||
} | ||
UserResponse: | ||
description: > | ||
Information on user record. Password is not included if a password | ||
|
@@ -436,25 +418,6 @@ types: | |
description: A server-side error occurred. | ||
body: | ||
type: Error | ||
/external-groups: | ||
put: | ||
description: > | ||
Update a user's list of external groups for a given app-prefix to be | ||
exactly the given list, leaving external groups with other prefixes | ||
unchanged. | ||
body: | ||
type: GroupsExternalUpdate | ||
responses: | ||
204: | ||
description: > | ||
The user's external groups for that app-prefix were updated. | ||
404: | ||
description: > | ||
No such user found. | ||
422: | ||
description: The given data does not satisfy some validation rule. | ||
body: | ||
type: Error | ||
/{employee_id}: | ||
get: | ||
description: Get information about a specific user. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
application/features/bootstrap/GroupsExternalSyncContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
namespace Sil\SilIdBroker\Behat\Context; | ||
|
||
use Behat\Gherkin\Node\TableNode; | ||
use common\models\User; | ||
use Webmozart\Assert\Assert; | ||
|
||
class GroupsExternalSyncContext extends GroupsExternalContext | ||
{ | ||
/** | ||
* The lists of external groups for use by these tests. Example: | ||
* ``` | ||
* [ | ||
* 'wiki' => [ | ||
* '[email protected]' => 'wiki-one,wiki-two', | ||
* ], | ||
* ] | ||
* ``` | ||
* @var array<string,string[]> | ||
*/ | ||
private array $externalGroupsLists = []; | ||
|
||
/** @var string[] */ | ||
private array $syncErrors; | ||
|
||
/** | ||
* @Given the following users exist, with these external groups: | ||
*/ | ||
public function theFollowingUsersExistWithTheseExternalGroups(TableNode $table) | ||
{ | ||
$dummyEmployeeId = 11110; | ||
foreach ($table as $row) { | ||
$emailAddress = $row['email']; | ||
$employeeId = ++$dummyEmployeeId; | ||
$groups = $row['groups']; | ||
|
||
$this->deleteTestUser($emailAddress); | ||
$this->createTestUser( | ||
$emailAddress, | ||
(string)$employeeId, | ||
$groups | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* @Given the :appPrefix external groups list is the following: | ||
*/ | ||
public function theExternalGroupsListIsTheFollowing(string $appPrefix, TableNode $table) | ||
{ | ||
$userGroupsMap = []; | ||
foreach ($table as $row) { | ||
$emailAddress = $row['email']; | ||
$externalGroupsCsv = $row['groups']; | ||
$userGroupsMap[$emailAddress] = $externalGroupsCsv; | ||
} | ||
$this->externalGroupsLists[$appPrefix] = $userGroupsMap; | ||
} | ||
|
||
/** | ||
* @When I sync the list of :appPrefix external groups | ||
*/ | ||
public function iSyncTheListOfExternalGroups($appPrefix) | ||
{ | ||
$this->syncErrors = User::updateUsersExternalGroups( | ||
$appPrefix, | ||
$this->externalGroupsLists[$appPrefix] | ||
); | ||
} | ||
|
||
/** | ||
* @Then there should not have been any sync errors | ||
*/ | ||
public function thereShouldNotHaveBeenAnySyncErrors() | ||
{ | ||
Assert::isEmpty($this->syncErrors, sprintf( | ||
"Unexpected sync error(s): \n%s", | ||
implode("\n", $this->syncErrors) | ||
)); | ||
} | ||
|
||
/** | ||
* @Then the following users should have the following external groups: | ||
*/ | ||
public function theFollowingUsersShouldHaveTheFollowingExternalGroups(TableNode $table) | ||
{ | ||
foreach ($table as $row) { | ||
$emailAddress = $row['email']; | ||
$expectedExternalGroups = explode(',', $row['groups']); | ||
|
||
$user = User::findByEmail($emailAddress); | ||
Assert::notNull($emailAddress, 'User not found: ' . $emailAddress); | ||
$actualExternalGroups = explode(',', $user->groups_external); | ||
|
||
sort($actualExternalGroups); | ||
sort($expectedExternalGroups); | ||
|
||
Assert::same( | ||
json_encode($actualExternalGroups, JSON_PRETTY_PRINT), | ||
json_encode($expectedExternalGroups, JSON_PRETTY_PRINT) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* @Then there should have been a sync error | ||
*/ | ||
public function thereShouldHaveBeenASyncError() | ||
{ | ||
Assert::notEmpty($this->syncErrors); | ||
foreach ($this->syncErrors as $syncError) { | ||
echo $syncError . PHP_EOL; | ||
} | ||
} | ||
} |
Oops, something went wrong.