2021-06-26 23:23:15 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Auth;
|
2019-11-17 21:26:43 +08:00
|
|
|
|
2023-05-18 00:56:55 +08:00
|
|
|
use BookStack\Users\Models\Role;
|
|
|
|
use BookStack\Users\Models\User;
|
2020-04-04 08:16:05 +08:00
|
|
|
use Tests\TestCase;
|
2019-11-17 21:26:43 +08:00
|
|
|
|
2019-12-22 21:17:14 +08:00
|
|
|
class Saml2Test extends TestCase
|
2019-11-17 21:26:43 +08:00
|
|
|
{
|
2021-10-31 04:29:59 +08:00
|
|
|
protected function setUp(): void
|
2019-11-17 21:26:43 +08:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
// Set default config for SAML2
|
|
|
|
config()->set([
|
2021-06-26 23:23:15 +08:00
|
|
|
'auth.method' => 'saml2',
|
|
|
|
'auth.defaults.guard' => 'saml2',
|
|
|
|
'saml2.name' => 'SingleSignOn-Testing',
|
|
|
|
'saml2.email_attribute' => 'email',
|
|
|
|
'saml2.display_name_attributes' => ['first_name', 'last_name'],
|
|
|
|
'saml2.external_id_attribute' => 'uid',
|
|
|
|
'saml2.user_to_groups' => false,
|
|
|
|
'saml2.group_attribute' => 'user_groups',
|
|
|
|
'saml2.remove_from_groups' => false,
|
|
|
|
'saml2.onelogin_overrides' => null,
|
|
|
|
'saml2.onelogin.idp.entityId' => 'http://saml.local/saml2/idp/metadata.php',
|
|
|
|
'saml2.onelogin.idp.singleSignOnService.url' => 'http://saml.local/saml2/idp/SSOService.php',
|
|
|
|
'saml2.onelogin.idp.singleLogoutService.url' => 'http://saml.local/saml2/idp/SingleLogoutService.php',
|
|
|
|
'saml2.autoload_from_metadata' => false,
|
|
|
|
'saml2.onelogin.idp.x509cert' => $this->testCert,
|
|
|
|
'saml2.onelogin.debug' => false,
|
2021-05-08 20:07:25 +08:00
|
|
|
'saml2.onelogin.security.requestedAuthnContext' => true,
|
2019-11-17 21:26:43 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_metadata_endpoint_displays_xml_as_expected()
|
|
|
|
{
|
|
|
|
$req = $this->get('/saml2/metadata');
|
|
|
|
$req->assertHeader('Content-Type', 'text/xml; charset=UTF-8');
|
|
|
|
$req->assertSee('md:EntityDescriptor');
|
|
|
|
$req->assertSee(url('/saml2/acs'));
|
|
|
|
}
|
|
|
|
|
2022-10-16 16:50:08 +08:00
|
|
|
public function test_metadata_endpoint_loads_when_autoloading_with_bad_url_set()
|
|
|
|
{
|
|
|
|
config()->set([
|
|
|
|
'saml2.autoload_from_metadata' => true,
|
|
|
|
'saml2.onelogin.idp.entityId' => 'http://192.168.1.1:9292',
|
|
|
|
'saml2.onelogin.idp.singleSignOnService.url' => null,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$req = $this->get('/saml2/metadata');
|
|
|
|
$req->assertOk();
|
|
|
|
$req->assertHeader('Content-Type', 'text/xml; charset=UTF-8');
|
|
|
|
$req->assertSee('md:EntityDescriptor');
|
|
|
|
}
|
|
|
|
|
2019-11-17 21:26:43 +08:00
|
|
|
public function test_onelogin_overrides_functions_as_expected()
|
|
|
|
{
|
|
|
|
$json = '{"sp": {"assertionConsumerService": {"url": "https://example.com/super-cats"}}, "contactPerson": {"technical": {"givenName": "Barry Scott", "emailAddress": "barry@example.com"}}}';
|
|
|
|
config()->set(['saml2.onelogin_overrides' => $json]);
|
|
|
|
|
|
|
|
$req = $this->get('/saml2/metadata');
|
|
|
|
$req->assertSee('https://example.com/super-cats');
|
|
|
|
$req->assertSee('md:ContactPerson');
|
2021-10-27 05:04:18 +08:00
|
|
|
$req->assertSee('<md:GivenName>Barry Scott</md:GivenName>', false);
|
2019-11-17 21:26:43 +08:00
|
|
|
}
|
2019-11-18 03:15:37 +08:00
|
|
|
|
|
|
|
public function test_login_option_shows_on_login_page()
|
|
|
|
{
|
|
|
|
$req = $this->get('/login');
|
|
|
|
$req->assertSeeText('SingleSignOn-Testing');
|
2022-07-23 22:10:18 +08:00
|
|
|
$this->withHtml($req)->assertElementExists('form[action$="/saml2/login"][method=POST] button');
|
2019-11-18 03:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_login()
|
|
|
|
{
|
2020-02-02 20:00:41 +08:00
|
|
|
$req = $this->post('/saml2/login');
|
2019-11-18 03:15:37 +08:00
|
|
|
$redirect = $req->headers->get('location');
|
|
|
|
$this->assertStringStartsWith('http://saml.local/saml2/idp/SSOService.php', $redirect, 'Login redirects to SSO location');
|
|
|
|
|
|
|
|
config()->set(['saml2.onelogin.strict' => false]);
|
|
|
|
$this->assertFalse($this->isAuthenticated());
|
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$acsPost = $this->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
|
|
|
$redirect = $acsPost->headers->get('Location');
|
|
|
|
$acsId = explode('?id=', $redirect)[1];
|
|
|
|
$this->assertTrue(strlen($acsId) > 12);
|
|
|
|
|
|
|
|
$this->assertStringContainsString('/saml2/acs?id=', $redirect);
|
|
|
|
$this->assertTrue(cache()->has('saml2_acs:' . $acsId));
|
|
|
|
|
|
|
|
$acsGet = $this->get($redirect);
|
|
|
|
$acsGet->assertRedirect('/');
|
|
|
|
$this->assertFalse(cache()->has('saml2_acs:' . $acsId));
|
|
|
|
|
|
|
|
$this->assertTrue($this->isAuthenticated());
|
|
|
|
$this->assertDatabaseHas('users', [
|
|
|
|
'email' => 'user@example.com',
|
|
|
|
'external_auth_id' => 'user',
|
|
|
|
'email_confirmed' => false,
|
|
|
|
'name' => 'Barry Scott',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_acs_process_id_randomly_generated()
|
|
|
|
{
|
|
|
|
$acsPost = $this->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
|
|
|
$redirectA = $acsPost->headers->get('Location');
|
|
|
|
|
|
|
|
$acsPost = $this->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
|
|
|
$redirectB = $acsPost->headers->get('Location');
|
|
|
|
|
|
|
|
$this->assertFalse($redirectA === $redirectB);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_process_acs_endpoint_cant_be_called_with_invalid_id()
|
|
|
|
{
|
|
|
|
$resp = $this->get('/saml2/acs');
|
|
|
|
$resp->assertRedirect('/login');
|
|
|
|
$this->followRedirects($resp)->assertSeeText('Login using SingleSignOn-Testing failed, system did not provide successful authorization');
|
|
|
|
|
|
|
|
$resp = $this->get('/saml2/acs?id=abc123');
|
|
|
|
$resp->assertRedirect('/login');
|
|
|
|
$this->followRedirects($resp)->assertSeeText('Login using SingleSignOn-Testing failed, system did not provide successful authorization');
|
2019-11-18 03:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_group_role_sync_on_login()
|
|
|
|
{
|
|
|
|
config()->set([
|
2021-06-26 23:23:15 +08:00
|
|
|
'saml2.onelogin.strict' => false,
|
|
|
|
'saml2.user_to_groups' => true,
|
2019-11-18 03:15:37 +08:00
|
|
|
'saml2.remove_from_groups' => false,
|
|
|
|
]);
|
|
|
|
|
2021-10-31 04:29:59 +08:00
|
|
|
$memberRole = Role::factory()->create(['external_auth_id' => 'member']);
|
2019-11-18 03:15:37 +08:00
|
|
|
$adminRole = Role::getSystemRole('admin');
|
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
|
|
|
$user = User::query()->where('external_auth_id', '=', 'user')->first();
|
2019-11-18 03:15:37 +08:00
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$userRoleIds = $user->roles()->pluck('id');
|
|
|
|
$this->assertContains($memberRole->id, $userRoleIds, 'User was assigned to member role');
|
|
|
|
$this->assertContains($adminRole->id, $userRoleIds, 'User was assigned to admin role');
|
2019-11-18 03:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_group_role_sync_removal_option_works_as_expected()
|
|
|
|
{
|
|
|
|
config()->set([
|
2021-06-26 23:23:15 +08:00
|
|
|
'saml2.onelogin.strict' => false,
|
|
|
|
'saml2.user_to_groups' => true,
|
2019-11-18 03:15:37 +08:00
|
|
|
'saml2.remove_from_groups' => true,
|
|
|
|
]);
|
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$acsPost = $this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
|
|
|
$user = User::query()->where('external_auth_id', '=', 'user')->first();
|
2019-11-18 03:15:37 +08:00
|
|
|
|
2021-10-31 04:29:59 +08:00
|
|
|
$randomRole = Role::factory()->create(['external_auth_id' => 'random']);
|
2021-10-20 20:30:45 +08:00
|
|
|
$user->attachRole($randomRole);
|
|
|
|
$this->assertContains($randomRole->id, $user->roles()->pluck('id'));
|
2019-11-18 03:15:37 +08:00
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
auth()->logout();
|
|
|
|
$acsPost = $this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
|
|
|
$this->assertNotContains($randomRole->id, $user->roles()->pluck('id'));
|
2019-11-18 03:15:37 +08:00
|
|
|
}
|
|
|
|
|
2020-02-02 20:00:41 +08:00
|
|
|
public function test_logout_link_directs_to_saml_path()
|
2019-11-18 03:15:37 +08:00
|
|
|
{
|
|
|
|
config()->set([
|
|
|
|
'saml2.onelogin.strict' => false,
|
|
|
|
]);
|
|
|
|
|
2023-01-21 19:08:34 +08:00
|
|
|
$resp = $this->actingAs($this->users->editor())->get('/');
|
2022-07-23 22:10:18 +08:00
|
|
|
$this->withHtml($resp)->assertElementContains('form[action$="/saml2/logout"] button', 'Logout');
|
2019-11-18 03:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_logout_sls_flow()
|
|
|
|
{
|
|
|
|
config()->set([
|
|
|
|
'saml2.onelogin.strict' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$handleLogoutResponse = function () {
|
|
|
|
$this->assertTrue($this->isAuthenticated());
|
|
|
|
|
|
|
|
$req = $this->get('/saml2/sls');
|
|
|
|
$req->assertRedirect('/');
|
|
|
|
$this->assertFalse($this->isAuthenticated());
|
|
|
|
};
|
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
2019-11-18 03:15:37 +08:00
|
|
|
|
2021-11-15 05:13:24 +08:00
|
|
|
$req = $this->post('/saml2/logout');
|
2021-10-20 20:30:45 +08:00
|
|
|
$redirect = $req->headers->get('location');
|
|
|
|
$this->assertStringStartsWith('http://saml.local/saml2/idp/SingleLogoutService.php', $redirect);
|
2023-04-28 20:54:51 +08:00
|
|
|
$sloData = $this->parseSamlDataFromUrl($redirect, 'SAMLRequest');
|
|
|
|
$this->assertStringContainsString('<samlp:SessionIndex>_4fe7c0d1572d64b27f930aa6f236a6f42e930901cc</samlp:SessionIndex>', $sloData);
|
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$this->withGet(['SAMLResponse' => $this->sloResponseData], $handleLogoutResponse);
|
2019-11-18 03:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_logout_sls_flow_when_sls_not_configured()
|
|
|
|
{
|
|
|
|
config()->set([
|
2021-06-26 23:23:15 +08:00
|
|
|
'saml2.onelogin.strict' => false,
|
2019-11-18 03:15:37 +08:00
|
|
|
'saml2.onelogin.idp.singleLogoutService.url' => null,
|
|
|
|
]);
|
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
|
|
|
$this->assertTrue($this->isAuthenticated());
|
2019-11-18 03:15:37 +08:00
|
|
|
|
2021-11-15 05:13:24 +08:00
|
|
|
$req = $this->post('/saml2/logout');
|
2021-10-20 20:30:45 +08:00
|
|
|
$req->assertRedirect('/');
|
|
|
|
$this->assertFalse($this->isAuthenticated());
|
2019-11-18 03:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_dump_user_details_option_works()
|
|
|
|
{
|
|
|
|
config()->set([
|
2021-06-26 23:23:15 +08:00
|
|
|
'saml2.onelogin.strict' => false,
|
2019-11-18 03:15:37 +08:00
|
|
|
'saml2.dump_user_details' => true,
|
|
|
|
]);
|
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$acsPost = $this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
|
|
|
$acsPost->assertJsonStructure([
|
|
|
|
'id_from_idp',
|
|
|
|
'attrs_from_idp' => [],
|
|
|
|
'attrs_after_parsing' => [],
|
|
|
|
]);
|
2019-11-18 03:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_saml_routes_are_only_active_if_saml_enabled()
|
|
|
|
{
|
2020-02-02 20:00:41 +08:00
|
|
|
config()->set(['auth.method' => 'standard']);
|
2021-11-15 05:13:24 +08:00
|
|
|
$getRoutes = ['/metadata', '/sls'];
|
2019-11-18 03:15:37 +08:00
|
|
|
foreach ($getRoutes as $route) {
|
|
|
|
$req = $this->get('/saml2' . $route);
|
2020-02-02 21:10:21 +08:00
|
|
|
$this->assertPermissionError($req);
|
2019-11-18 03:15:37 +08:00
|
|
|
}
|
|
|
|
|
2021-11-15 05:13:24 +08:00
|
|
|
$postRoutes = ['/login', '/acs', '/logout'];
|
2019-11-18 03:15:37 +08:00
|
|
|
foreach ($postRoutes as $route) {
|
|
|
|
$req = $this->post('/saml2' . $route);
|
2020-02-02 21:10:21 +08:00
|
|
|
$this->assertPermissionError($req);
|
2019-11-18 03:15:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-02 21:10:21 +08:00
|
|
|
public function test_forgot_password_routes_inaccessible()
|
|
|
|
{
|
|
|
|
$resp = $this->get('/password/email');
|
|
|
|
$this->assertPermissionError($resp);
|
|
|
|
|
|
|
|
$resp = $this->post('/password/email');
|
|
|
|
$this->assertPermissionError($resp);
|
|
|
|
|
|
|
|
$resp = $this->get('/password/reset/abc123');
|
|
|
|
$this->assertPermissionError($resp);
|
|
|
|
|
|
|
|
$resp = $this->post('/password/reset');
|
|
|
|
$this->assertPermissionError($resp);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_standard_login_routes_inaccessible()
|
|
|
|
{
|
|
|
|
$resp = $this->post('/login');
|
|
|
|
$this->assertPermissionError($resp);
|
|
|
|
|
2021-11-15 05:13:24 +08:00
|
|
|
$resp = $this->post('/logout');
|
2020-02-02 21:10:21 +08:00
|
|
|
$this->assertPermissionError($resp);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_user_invite_routes_inaccessible()
|
|
|
|
{
|
|
|
|
$resp = $this->get('/register/invite/abc123');
|
|
|
|
$this->assertPermissionError($resp);
|
|
|
|
|
|
|
|
$resp = $this->post('/register/invite/abc123');
|
|
|
|
$this->assertPermissionError($resp);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_user_register_routes_inaccessible()
|
|
|
|
{
|
|
|
|
$resp = $this->get('/register');
|
|
|
|
$this->assertPermissionError($resp);
|
|
|
|
|
|
|
|
$resp = $this->post('/register');
|
|
|
|
$this->assertPermissionError($resp);
|
|
|
|
}
|
|
|
|
|
2020-02-03 01:31:00 +08:00
|
|
|
public function test_email_domain_restriction_active_on_new_saml_login()
|
|
|
|
{
|
|
|
|
$this->setSettings([
|
2021-06-26 23:23:15 +08:00
|
|
|
'registration-restrict' => 'testing.com',
|
2020-02-03 01:31:00 +08:00
|
|
|
]);
|
|
|
|
config()->set([
|
|
|
|
'saml2.onelogin.strict' => false,
|
|
|
|
]);
|
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$acsPost = $this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
|
|
|
$acsPost->assertSeeText('That email domain does not have access to this application');
|
|
|
|
$this->assertFalse(auth()->check());
|
|
|
|
$this->assertDatabaseMissing('users', ['email' => 'user@example.com']);
|
2020-02-03 01:31:00 +08:00
|
|
|
}
|
|
|
|
|
2020-08-05 00:54:50 +08:00
|
|
|
public function test_group_sync_functions_when_email_confirmation_required()
|
|
|
|
{
|
|
|
|
setting()->put('registration-confirmation', 'true');
|
|
|
|
config()->set([
|
2021-06-26 23:23:15 +08:00
|
|
|
'saml2.onelogin.strict' => false,
|
|
|
|
'saml2.user_to_groups' => true,
|
2020-08-05 00:54:50 +08:00
|
|
|
'saml2.remove_from_groups' => false,
|
|
|
|
]);
|
|
|
|
|
2021-10-31 04:29:59 +08:00
|
|
|
$memberRole = Role::factory()->create(['external_auth_id' => 'member']);
|
2020-08-05 00:54:50 +08:00
|
|
|
$adminRole = Role::getSystemRole('admin');
|
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$acsPost = $this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
2020-09-06 00:26:48 +08:00
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$this->assertEquals('http://localhost/register/confirm', url()->current());
|
|
|
|
$acsPost->assertSee('Please check your email and click the confirmation button to access BookStack.');
|
|
|
|
/** @var User $user */
|
|
|
|
$user = User::query()->where('external_auth_id', '=', 'user')->first();
|
2020-08-05 00:54:50 +08:00
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$userRoleIds = $user->roles()->pluck('id');
|
|
|
|
$this->assertContains($memberRole->id, $userRoleIds, 'User was assigned to member role');
|
|
|
|
$this->assertContains($adminRole->id, $userRoleIds, 'User was assigned to admin role');
|
|
|
|
$this->assertFalse(boolval($user->email_confirmed), 'User email remains unconfirmed');
|
2020-08-05 00:54:50 +08:00
|
|
|
|
2021-08-08 04:18:59 +08:00
|
|
|
$this->assertNull(auth()->user());
|
2020-08-05 00:54:50 +08:00
|
|
|
$homeGet = $this->get('/');
|
2021-08-08 04:18:59 +08:00
|
|
|
$homeGet->assertRedirect('/login');
|
2020-08-05 00:54:50 +08:00
|
|
|
}
|
|
|
|
|
2020-09-26 23:43:06 +08:00
|
|
|
public function test_login_where_existing_non_saml_user_shows_warning()
|
|
|
|
{
|
|
|
|
$this->post('/saml2/login');
|
|
|
|
config()->set(['saml2.onelogin.strict' => false]);
|
|
|
|
|
|
|
|
// Make the user pre-existing in DB with different auth_id
|
|
|
|
User::query()->forceCreate([
|
2021-06-26 23:23:15 +08:00
|
|
|
'email' => 'user@example.com',
|
2020-09-26 23:43:06 +08:00
|
|
|
'external_auth_id' => 'old_system_user_id',
|
2021-06-26 23:23:15 +08:00
|
|
|
'email_confirmed' => false,
|
|
|
|
'name' => 'Barry Scott',
|
2020-09-26 23:43:06 +08:00
|
|
|
]);
|
|
|
|
|
2021-10-20 20:30:45 +08:00
|
|
|
$acsPost = $this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
|
|
|
|
$this->assertFalse($this->isAuthenticated());
|
|
|
|
$this->assertDatabaseHas('users', [
|
|
|
|
'email' => 'user@example.com',
|
|
|
|
'external_auth_id' => 'old_system_user_id',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$acsPost->assertSee('A user with the email user@example.com already exists but with different credentials');
|
2020-09-26 23:43:06 +08:00
|
|
|
}
|
|
|
|
|
2021-05-08 20:07:25 +08:00
|
|
|
public function test_login_request_contains_expected_default_authncontext()
|
|
|
|
{
|
|
|
|
$authReq = $this->getAuthnRequest();
|
|
|
|
$this->assertStringContainsString('samlp:RequestedAuthnContext Comparison="exact"', $authReq);
|
|
|
|
$this->assertStringContainsString('<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>', $authReq);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_false_idp_authncontext_option_does_not_pass_authncontext_in_saml_request()
|
|
|
|
{
|
|
|
|
config()->set(['saml2.onelogin.security.requestedAuthnContext' => false]);
|
|
|
|
$authReq = $this->getAuthnRequest();
|
|
|
|
$this->assertStringNotContainsString('samlp:RequestedAuthnContext', $authReq);
|
|
|
|
$this->assertStringNotContainsString('<saml:AuthnContextClassRef>', $authReq);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_array_idp_authncontext_option_passes_value_as_authncontextclassref_in_request()
|
|
|
|
{
|
|
|
|
config()->set(['saml2.onelogin.security.requestedAuthnContext' => ['urn:federation:authentication:windows', 'urn:federation:authentication:linux']]);
|
|
|
|
$authReq = $this->getAuthnRequest();
|
|
|
|
$this->assertStringContainsString('samlp:RequestedAuthnContext', $authReq);
|
|
|
|
$this->assertStringContainsString('<saml:AuthnContextClassRef>urn:federation:authentication:windows</saml:AuthnContextClassRef>', $authReq);
|
|
|
|
$this->assertStringContainsString('<saml:AuthnContextClassRef>urn:federation:authentication:linux</saml:AuthnContextClassRef>', $authReq);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getAuthnRequest(): string
|
|
|
|
{
|
|
|
|
$req = $this->post('/saml2/login');
|
|
|
|
$location = $req->headers->get('Location');
|
2023-04-28 20:54:51 +08:00
|
|
|
return $this->parseSamlDataFromUrl($location, 'SAMLRequest');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function parseSamlDataFromUrl(string $url, string $paramName): string
|
|
|
|
{
|
|
|
|
$query = explode('?', $url)[1];
|
2021-05-08 20:07:25 +08:00
|
|
|
$params = [];
|
|
|
|
parse_str($query, $params);
|
2021-06-26 23:23:15 +08:00
|
|
|
|
2023-04-28 20:54:51 +08:00
|
|
|
return gzinflate(base64_decode($params[$paramName]));
|
2021-05-08 20:07:25 +08:00
|
|
|
}
|
|
|
|
|
2019-11-18 03:15:37 +08:00
|
|
|
protected function withGet(array $options, callable $callback)
|
|
|
|
{
|
|
|
|
return $this->withGlobal($_GET, $options, $callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function withGlobal(array &$global, array $options, callable $callback)
|
|
|
|
{
|
|
|
|
$original = [];
|
|
|
|
foreach ($options as $key => $val) {
|
|
|
|
$original[$key] = $global[$key] ?? null;
|
|
|
|
$global[$key] = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
$callback();
|
|
|
|
|
|
|
|
foreach ($options as $key => $val) {
|
|
|
|
$val = $original[$key];
|
|
|
|
if ($val) {
|
|
|
|
$global[$key] = $val;
|
|
|
|
} else {
|
|
|
|
unset($global[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The post data for a callback for single-sign-in.
|
|
|
|
* Provides the following attributes:
|
|
|
|
* array:5 [
|
2021-06-26 23:23:15 +08:00
|
|
|
* "uid" => array:1 [
|
|
|
|
* 0 => "user"
|
|
|
|
* ]
|
|
|
|
* "first_name" => array:1 [
|
|
|
|
* 0 => "Barry"
|
|
|
|
* ]
|
|
|
|
* "last_name" => array:1 [
|
|
|
|
* 0 => "Scott"
|
|
|
|
* ]
|
|
|
|
* "email" => array:1 [
|
|
|
|
* 0 => "user@example.com"
|
|
|
|
* ]
|
|
|
|
* "user_groups" => array:2 [
|
|
|
|
* 0 => "member"
|
|
|
|
* 1 => "admin"
|
|
|
|
* ]
|
|
|
|
* ].
|
2019-11-18 03:15:37 +08:00
|
|
|
*/
|
|
|
|
protected $acsPostData = 'PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDphc3NlcnRpb24iIElEPSJfNGRkNDU2NGRjNzk0MDYxZWYxYmFhMDQ2N2Q3OTAyOGNlZDNjZTU0YmVlIiBWZXJzaW9uPSIyLjAiIElzc3VlSW5zdGFudD0iMjAxOS0xMS0xN1QxNzo1MzozOVoiIERlc3RpbmF0aW9uPSJodHRwOi8vYm9va3N0YWNrLmxvY2FsL3NhbWwyL2FjcyIgSW5SZXNwb25zZVRvPSJPTkVMT0dJTl82YTBmNGYzOTkzMDQwZjE5ODdmZDM3MDY4YjUyOTYyMjlhZDUzNjFjIj48c2FtbDpJc3N1ZXI+aHR0cDovL3NhbWwubG9jYWwvc2FtbDI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