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: when:
matrix: matrix:
TESTS: php7.1 TESTS: php7.1
shibboleth-integration-tests: integration-tests:
image: nextcloudci/user_saml_shibboleth:user_saml_shibboleth-3 image: nextcloudci/user_saml_shibboleth:user_saml_shibboleth-5
environment: environment:
- CORE_BRANCH=master - CORE_BRANCH=master
commands: commands:
@ -119,7 +119,7 @@ pipeline:
- cd /var/www/html/apps/user_saml/tests/integration && vendor/bin/behat - cd /var/www/html/apps/user_saml/tests/integration && vendor/bin/behat
when: when:
matrix: matrix:
TESTS: shibboleth-integration-tests TESTS: integration-tests
matrix: matrix:
include: include:
@ -128,4 +128,4 @@ matrix:
- TESTS: php7.1 - TESTS: php7.1
- TESTS: check-app-compatbility - TESTS: check-app-compatbility
- TESTS: signed-off-check - 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'; $type = 'saml';
break; break;
case 'environment-variable': case 'environment-variable':
\OC::$server->getSession()->set('user_saml.samlUserData', $_SERVER);
$type = 'environment-variable'; $type = 'environment-variable';
break; break;
} }
@ -76,7 +75,7 @@ $redirectSituation = false;
if(!$cli && if(!$cli &&
!$userSession->isLoggedIn() && !$userSession->isLoggedIn() &&
\OC::$server->getRequest()->getPathInfo() === '/login' && \OC::$server->getRequest()->getPathInfo() === '/login' &&
$type === 'saml') { $type !== '') {
$redirectSituation = true; $redirectSituation = true;
} }

View file

@ -127,6 +127,7 @@ class SAMLController extends Controller {
break; break;
case 'environment-variable': case 'environment-variable':
$ssoUrl = $this->urlGenerator->getAbsoluteURL('/'); $ssoUrl = $this->urlGenerator->getAbsoluteURL('/');
$this->session->set('user_saml.samlUserData', $_SERVER);
try { try {
$this->autoprovisionIfPossible($this->session->get('user_saml.samlUserData')); $this->autoprovisionIfPossible($this->session->get('user_saml.samlUserData'));
} catch (NoUserFoundException $e) { } 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 */ /** @BeforeScenario */
public function before() { public function before() {
$jar = new \GuzzleHttp\Cookie\FileCookieJar('/tmp/cookies_' . md5(openssl_random_pseudo_bytes(12)));
$this->client = new \GuzzleHttp\Client([ $this->client = new \GuzzleHttp\Client([
'cookies' => true, 'cookies' => $jar,
'verify' => false, 'verify' => false,
'allow_redirects' => [ 'allow_redirects' => [
'referer' => true, '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 $classMap = array();
private $classMapAuthoritative = false; private $classMapAuthoritative = false;
private $missingClasses = array(); private $missingClasses = array();
private $apcuPrefix;
public function getPrefixes() public function getPrefixes()
{ {
@ -272,26 +271,6 @@ class ClassLoader
return $this->classMapAuthoritative; 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. * Registers this instance as an autoloader.
* *
@ -334,6 +313,11 @@ class ClassLoader
*/ */
public function findFile($class) 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 // class map lookup
if (isset($this->classMap[$class])) { if (isset($this->classMap[$class])) {
return $this->classMap[$class]; return $this->classMap[$class];
@ -341,12 +325,6 @@ class ClassLoader
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false; return false;
} }
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php'); $file = $this->findFileWithExtension($class, '.php');
@ -355,10 +333,6 @@ class ClassLoader
$file = $this->findFileWithExtension($class, '.hh'); $file = $this->findFileWithExtension($class, '.hh');
} }
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) { if (false === $file) {
// Remember that this class does not exist. // Remember that this class does not exist.
$this->missingClasses[$class] = true; $this->missingClasses[$class] = true;

View file

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