Merge pull request #198 from nextcloud/backport/8835/stable11

[stable11] try to lookup a user if the uid does not resolve and autoprov is disables
This commit is contained in:
Björn Schiessle 2018-03-19 15:31:57 +01:00 committed by GitHub
commit 2e2d123bc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 1 deletions

View File

@ -99,6 +99,13 @@ class SAMLController extends Controller {
$autoProvisioningAllowed = $this->userBackend->autoprovisionAllowed();
if(!$userExists && !$autoProvisioningAllowed) {
// it is possible that the user was not logged in before and
// thus is not known to the original backend. A search can
// help with it and make the user known
$this->userManager->search($uid);
if($this->userManager->userExists($uid)) {
return;
}
throw new NoUserFoundException();
} elseif(!$userExists && $autoProvisioningAllowed) {
$this->userBackend->createUserIfNotExists($uid);

View File

@ -257,7 +257,7 @@ class SAMLControllerTest extends TestCase {
->with('user_saml', 'general-uid_mapping')
->willReturn('uid');
$this->userManager
->expects($this->once())
->expects($this->any())
->method('userExists')
->with('MyUid')
->willReturn(false);
@ -275,6 +275,57 @@ class SAMLControllerTest extends TestCase {
$this->assertEquals($expected, $this->samlController->login());
}
public function testLoginWithEnvVariableAndNotYetMappedUserWithoutProvisioning() {
$this->config
->expects($this->at(0))
->method('getAppValue')
->with('user_saml', 'type')
->willReturn('environment-variable');
$this->session
->expects($this->once())
->method('get')
->with('user_saml.samlUserData')
->willReturn([
'foo' => 'bar',
'uid' => 'MyUid',
'bar' => 'foo',
]);
$this->config
->expects($this->at(1))
->method('getAppValue')
->with('user_saml', 'general-uid_mapping')
->willReturn('uid');
$this->userManager
->expects($this->exactly(2))
->method('userExists')
->with('MyUid')
->willReturnOnConsecutiveCalls(false, true);
$this->userManager
->expects($this->once())
->method('get')
->with('MyUid')
->willReturn($this->createMock(IUser::class));
$this->urlGenerator
->expects($this->once())
->method('getAbsoluteUrl')
->with('/')
->willReturn('https://nextcloud.com/absolute/');
$this->urlGenerator
->expects($this->never())
->method('linkToRouteAbsolute');
$this->userBackend
->expects($this->once())
->method('autoprovisionAllowed')
->willReturn(false);
$this->userBackend
->expects($this->once())
->method('getCurrentUserId')
->willReturn('MyUid');
$expected = new RedirectResponse('https://nextcloud.com/absolute/');
$this->assertEquals($expected, $this->samlController->login());
}
public function testNotProvisioned() {
$expected = new TemplateResponse('user_saml', 'notProvisioned', [], 'guest');
$this->assertEquals($expected, $this->samlController->notProvisioned());