Allow to automatically assign SAML users to a group based on SAML attributes

This commit is contained in:
Jan Böhmer 2023-02-27 23:47:42 +01:00
parent 6a06a24296
commit 5e85c52a57
6 changed files with 151 additions and 11 deletions

View file

@ -62,4 +62,27 @@ class SamlUserFactoryTest extends WebTestCase
$this->assertEquals('IT', $user->getDepartment());
$this->assertEquals('j.doe@invalid.invalid', $user->getEmail());
}
public function testMapSAMLRolesToLocalGroupID()
{
$mapping = [
'employee' => 1,
'admin' => 2,
'manager' => 3,
'administrator' => 2,
'*' => 4,
];
//Test if mapping works
$this->assertEquals(1, $this->service->mapSAMLRolesToLocalGroupID(['employee'], $mapping));
//Only the first valid mapping should be used
$this->assertEquals(1, $this->service->mapSAMLRolesToLocalGroupID(['employee', 'admin'], $mapping));
$this->assertSame(2, $this->service->mapSAMLRolesToLocalGroupID(['does_not_matter', 'admin', 'employee'], $mapping));
//Test if mapping is case sensitive
$this->assertEquals(4, $this->service->mapSAMLRolesToLocalGroupID(['ADMIN'], $mapping));
//Test that wildcard mapping works
$this->assertEquals(4, $this->service->mapSAMLRolesToLocalGroupID(['entry1', 'entry2'], $mapping));
$this->assertEquals(4, $this->service->mapSAMLRolesToLocalGroupID([], $mapping));
}
}