Skip to content

Commit

Permalink
WIP: integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blizzz committed Nov 16, 2022
1 parent 1055402 commit 3e2d177
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
7 changes: 7 additions & 0 deletions tests/integration/features/Shibboleth.feature
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Feature: Shibboleth
And The setting "security-wantAssertionsSigned" is set to "1"
And The setting "saml-attribute-mapping-email_mapping" is set to "urn:oid:0.9.2342.19200300.100.1.3"
And The setting "saml-attribute-mapping-displayName_mapping" is set to "urn:oid:2.5.4.42 urn:oid:2.5.4.4"
And The setting "saml-attribute-mapping-quota_mapping" is set to "quota"
And The setting "saml-attribute-mapping-group_mapping" is set to "groups"
When I send a GET request to "http://localhost/index.php/login"
Then I should be redirected to "https://localhost:4443/idp/profile/SAML2/Redirect/SSO"
And I send a POST request to "https://localhost:4443/idp/profile/SAML2/Redirect/SSO?execution=e1s1" with the following data
Expand All @@ -89,7 +91,12 @@ Feature: Shibboleth
And I should be redirected to "http://localhost/index.php/apps/dashboard/"
And The user value "id" should be "student1"
And The user value "email" should be "[email protected]"
And The user value "quota.total" should be "209715200"
And The user value "display-name" should be "Stud Ent"
And The user value "groups" should be "Astrophysics, Students"
And the group "Astrophysics" should exists
And the group "SAML_Astrophysics" should exists
And the group "SAML_Students" should exists
And The last login timestamp of "student1" should not be empty

Scenario: Authenticating using Shibboleth with SAML with custom redirect URL
Expand Down
55 changes: 48 additions & 7 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,27 +228,49 @@ public function theResponseShouldBeASamlRedirectPageThatGetsSubmitted() {
* @param string $value
* @throws UnexpectedValueException
*/
public function thUserValueShouldBe($key, $value) {
public function thUserValueShouldBe(string $key, string $value): void {
$this->response = $this->client->request(
'GET',
'http://localhost/ocs/v1.php/cloud/user',
[
'headers' => [
'OCS-APIRequest' => 'true',
],
'query' => [
'format' => 'json',
]
]
);

$xml = simplexml_load_string($this->response->getBody());
/** @var array $responseArray */
$responseArray = json_decode(json_encode((array)$xml), true);
$responseArray = (json_decode($this->response->getBody(), true))['ocs'];

if (!isset($responseArray['data'][$key]) || count((array)$responseArray['data'][$key]) === 0) {
if (strpos($key, '.') !== false) {
// support nested arrays, specify the key seperated by "."s, e.g. quota.total
$keys = explode('.', $key);
if (isset($responseArray['data'][$keys[0]])) {
$source = $responseArray['data'];
foreach ($keys as $subKey) {
if (isset ($source[$subKey])) {
$source = $source[$subKey];
if (!is_array($source)) {
$actualValue = $source;
}
} else {
break;
}
}
}
}

if (count((array)$responseArray['data'][$key]) === 0) {
$responseArray['data'][$key] = '';
}
$actualValue = $responseArray['data'][$key];
$actualValue = $actualValue ?? $responseArray['data'][$key];
if (is_array($actualValue)) {
$actualValue = implode(', ', $actualValue);
}

if ($actualValue !== $value) {
if ((string)$actualValue !== $value) {
throw new UnexpectedValueException(
sprintf(
'Expected %s as value but got %s',
Expand Down Expand Up @@ -303,4 +325,23 @@ public function theLastLoginTimestampOfShouldNotBeEmpty($uid) {
public function theEnvironmentVariableIsSetTo($key, $value) {
file_put_contents(__DIR__ . '/../../../../../../.htaccess', "\nSetEnv $key $value\n", FILE_APPEND);
}

/**
* @Given /^the group "([^"]*)" should exists$/
*/
public function theGroupShouldExists(string $gid): void {
$response = shell_exec(
sprintf(
'sudo -u apache %s %s group:info --output=json %s',
PHP_BINARY,
__DIR__ . '/../../../../../../occ',
$gid
)
);

$responseArray = json_decode($response, true);
if (!isset($responseArray['groupID']) || $responseArray['groupID'] !== $gid) {
throw new UnexpectedValueException('Group does not exist');
}
}
}

0 comments on commit 3e2d177

Please sign in to comment.