Merge pull request #78 from nextcloud/add-integration-test-for-environment-variable

Add integration test for Environment Variable
This commit is contained in:
Lukas Reschke 2017-01-19 02:32:41 +01:00 committed by GitHub
commit e82897d828
7 changed files with 65 additions and 57 deletions

View File

@ -100,8 +100,8 @@ pipeline:
when:
matrix:
TESTS: php7.1
shibboleth-integration-tests:
image: nextcloudci/user_saml_shibboleth:user_saml_shibboleth-3
integration-tests:
image: nextcloudci/user_saml_shibboleth:user_saml_shibboleth-5
environment:
- CORE_BRANCH=master
commands:
@ -119,7 +119,7 @@ pipeline:
- cd /var/www/html/apps/user_saml/tests/integration && vendor/bin/behat
when:
matrix:
TESTS: shibboleth-integration-tests
TESTS: integration-tests
matrix:
include:
@ -128,4 +128,4 @@ matrix:
- TESTS: php7.1
- TESTS: check-app-compatbility
- TESTS: signed-off-check
- TESTS: shibboleth-integration-tests
- TESTS: integration-tests

View File

@ -61,7 +61,6 @@ switch($config->getAppValue('user_saml', 'type')) {
$type = 'saml';
break;
case 'environment-variable':
\OC::$server->getSession()->set('user_saml.samlUserData', $_SERVER);
$type = 'environment-variable';
break;
}
@ -76,7 +75,7 @@ $redirectSituation = false;
if(!$cli &&
!$userSession->isLoggedIn() &&
\OC::$server->getRequest()->getPathInfo() === '/login' &&
$type === 'saml') {
$type !== '') {
$redirectSituation = true;
}

View File

@ -127,6 +127,7 @@ class SAMLController extends Controller {
break;
case 'environment-variable':
$ssoUrl = $this->urlGenerator->getAbsoluteURL('/');
$this->session->set('user_saml.samlUserData', $_SERVER);
try {
$this->autoprovisionIfPossible($this->session->get('user_saml.samlUserData'));
} catch (NoUserFoundException $e) {

View File

@ -0,0 +1,27 @@
Feature: EnvironmentVariable
Scenario: Authenticating using environment variable with SSO and no check if user exists on backend
And The setting "type" is set to "environment-variable"
And The setting "general-uid_mapping" is set to "REMOTE_USER"
And The environment variable "REMOTE_USER" is set to "not-provisioned-user"
When I send a GET request to "http://localhost/index.php/login"
Then I should be redirected to "http://localhost/index.php/apps/files/"
Then I should be logged-in to Nextcloud as user "not-provisioned-user"
Scenario: Authenticating using environment variable with SSO and successful check if user exists on backend
Given A local user with uid "provisioned-user" exists
And The setting "type" is set to "environment-variable"
And The setting "general-require_provisioned_account" is set to "1"
And The setting "general-uid_mapping" is set to "REMOTE_USER"
And The environment variable "REMOTE_USER" is set to "provisioned-user"
When I send a GET request to "http://localhost/index.php/login"
Then I should be redirected to "http://localhost/index.php/apps/files/"
Then I should be logged-in to Nextcloud as user "provisioned-user"
Scenario: Authenticating using environment variable with SSO and unsuccessful check if user exists on backend
Given The setting "type" is set to "environment-variable"
And The setting "general-require_provisioned_account" is set to "1"
And The setting "general-uid_mapping" is set to "REMOTE_USER"
And The environment variable "REMOTE_USER" is set to "certainly-not-provisioned-user"
When I send a GET request to "http://localhost/index.php/login"
Then I should be redirected to "http://localhost/index.php/apps/user_saml/saml/notProvisioned"

View File

@ -36,8 +36,9 @@ class FeatureContext implements Context {
/** @BeforeScenario */
public function before() {
$jar = new \GuzzleHttp\Cookie\FileCookieJar('/tmp/cookies_' . md5(openssl_random_pseudo_bytes(12)));
$this->client = new \GuzzleHttp\Client([
'cookies' => true,
'cookies' => $jar,
'verify' => false,
'allow_redirects' => [
'referer' => true,
@ -222,4 +223,10 @@ class FeatureContext implements Context {
);
}
/**
* @Given The environment variable :key is set to :value
*/
public function theEnvironmentVariableIsSetTo($key, $value) {
file_put_contents(__DIR__ . '/../../../../../../.htaccess', "\nSetEnv $key $value\n", FILE_APPEND);
}
}

View File

@ -55,7 +55,6 @@ class ClassLoader
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
private $apcuPrefix;
public function getPrefixes()
{
@ -272,26 +271,6 @@ class ClassLoader
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
@ -334,6 +313,11 @@ class ClassLoader
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
@ -341,12 +325,6 @@ class ClassLoader
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
@ -355,10 +333,6 @@ class ClassLoader
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;

View File

@ -23,7 +23,7 @@
"suggest": {
"symfony/console": "For validating YAML files using the lint command"
},
"time": "2016-12-10T10:07:06+00:00",
"time": "2016-12-10 10:07:06",
"type": "library",
"extra": {
"branch-alias": {
@ -77,7 +77,7 @@
"suggest": {
"ext-mbstring": "For best performance"
},
"time": "2016-11-14T01:06:16+00:00",
"time": "2016-11-14 01:06:16",
"type": "library",
"extra": {
"branch-alias": {
@ -150,7 +150,7 @@
"symfony/config": "",
"symfony/yaml": ""
},
"time": "2016-11-30T14:40:17+00:00",
"time": "2016-11-30 14:40:17",
"type": "library",
"extra": {
"branch-alias": {
@ -212,7 +212,7 @@
"symfony/dependency-injection": "",
"symfony/http-kernel": ""
},
"time": "2016-10-13T06:29:04+00:00",
"time": "2016-10-13 06:29:04",
"type": "library",
"extra": {
"branch-alias": {
@ -277,7 +277,7 @@
"symfony/proxy-manager-bridge": "Generate service proxies to lazy load them",
"symfony/yaml": ""
},
"time": "2016-12-08T15:27:33+00:00",
"time": "2016-12-08 15:27:33",
"type": "library",
"extra": {
"branch-alias": {
@ -328,7 +328,7 @@
"require": {
"php": ">=5.3.0"
},
"time": "2016-10-10T12:19:37+00:00",
"time": "2016-10-10 12:19:37",
"type": "library",
"extra": {
"branch-alias": {
@ -385,7 +385,7 @@
"symfony/class-loader": "~2.8|~3.0",
"symfony/http-kernel": "~2.8|~3.0"
},
"time": "2016-11-16T22:18:16+00:00",
"time": "2016-11-16 22:18:16",
"type": "library",
"extra": {
"branch-alias": {
@ -450,7 +450,7 @@
"symfony/filesystem": "",
"symfony/process": ""
},
"time": "2016-12-11T14:34:22+00:00",
"time": "2016-12-11 14:34:22",
"type": "library",
"extra": {
"branch-alias": {
@ -501,7 +501,7 @@
"require": {
"php": ">=5.5.9"
},
"time": "2016-11-24T00:46:43+00:00",
"time": "2016-11-24 00:46:43",
"type": "library",
"extra": {
"branch-alias": {
@ -559,7 +559,7 @@
"suggest": {
"symfony/yaml": "To use the yaml reference dumper"
},
"time": "2016-12-09T07:45:17+00:00",
"time": "2016-12-09 07:45:17",
"type": "library",
"extra": {
"branch-alias": {
@ -617,7 +617,7 @@
"suggest": {
"symfony/polyfill-apcu": "For using ApcClassLoader on HHVM"
},
"time": "2016-11-29T08:26:13+00:00",
"time": "2016-11-29 08:26:13",
"type": "library",
"extra": {
"branch-alias": {
@ -665,7 +665,7 @@
"reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e",
"shasum": ""
},
"time": "2014-12-30T15:22:37+00:00",
"time": "2014-12-30 15:22:37",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -697,7 +697,7 @@
"require": {
"php": ">=5.3.3"
},
"time": "2015-09-28T16:26:35+00:00",
"time": "2015-09-28 16:26:35",
"type": "library",
"extra": {
"branch-alias": {
@ -747,7 +747,7 @@
"suggest": {
"symfony/yaml": "If you want to parse features, represented in YAML files"
},
"time": "2016-10-30T11:50:56+00:00",
"time": "2016-10-30 11:50:56",
"type": "library",
"extra": {
"branch-alias": {
@ -821,7 +821,7 @@
"behat/symfony2-extension": "for integration with Symfony2 web framework",
"behat/yii-extension": "for integration with Yii web framework"
},
"time": "2016-12-25T13:43:52+00:00",
"time": "2016-12-25 13:43:52",
"bin": [
"bin/behat"
],
@ -887,7 +887,7 @@
"require-dev": {
"phpunit/phpunit": "^4.0"
},
"time": "2016-12-20T10:07:11+00:00",
"time": "2016-12-20 10:07:11",
"type": "library",
"extra": {
"branch-alias": {
@ -937,7 +937,7 @@
"require": {
"php": ">=5.3.0"
},
"time": "2016-08-06T14:39:51+00:00",
"time": "2016-08-06 14:39:51",
"type": "library",
"extra": {
"branch-alias": {
@ -996,7 +996,7 @@
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"time": "2016-06-24T23:00:38+00:00",
"time": "2016-06-24 23:00:38",
"type": "library",
"extra": {
"branch-alias": {
@ -1056,7 +1056,7 @@
"phpunit/phpunit": "^4.0",
"psr/log": "^1.0"
},
"time": "2016-10-08T15:01:37+00:00",
"time": "2016-10-08 15:01:37",
"type": "library",
"extra": {
"branch-alias": {