diff --git a/tests/integration/features/Shibboleth.feature b/tests/integration/features/Shibboleth.feature index ab0636daf..822343230 100644 --- a/tests/integration/features/Shibboleth.feature +++ b/tests/integration/features/Shibboleth.feature @@ -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 @@ -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 "student1@idptestbed.edu" + 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 diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index ec82d0c5a..7c914d800 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -228,7 +228,7 @@ 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', @@ -236,19 +236,41 @@ public function thUserValueShouldBe($key, $value) { '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', @@ -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'); + } + } }