1 <?php namespace Tests\Auth;
5 class OpenIdTest extends TestCase
8 public function setUp(): void
11 // Set default config for OpenID Connect
13 'auth.method' => 'openid',
14 'auth.defaults.guard' => 'openid',
15 'openid.name' => 'SingleSignOn-Testing',
16 'openid.email_attribute' => 'email',
17 'openid.display_name_attributes' => ['given_name', 'family_name'],
18 'openid.external_id_attribute' => 'uid',
19 'openid.openid_overrides' => null,
20 'openid.openid.clientId' => 'testapp',
21 'openid.openid.clientSecret' => 'testpass',
22 'openid.openid.publicKey' => $this->testCert,
23 'openid.openid.idTokenIssuer' => 'https://openid.local',
24 'openid.openid.urlAuthorize' => 'https://openid.local/auth',
25 'openid.openid.urlAccessToken' => 'https://openid.local/token',
29 public function test_openid_overrides_functions_as_expected()
31 $json = '{"urlAuthorize": "https://openid.local/custom"}';
32 config()->set(['openid.openid_overrides' => $json]);
34 $req = $this->get('/openid/login');
35 $redirect = $req->headers->get('location');
36 $this->assertStringStartsWith('https://openid.local/custom', $redirect, 'Login redirects to SSO location');
39 public function test_login_option_shows_on_login_page()
41 $req = $this->get('/login');
42 $req->assertSeeText('SingleSignOn-Testing');
43 $req->assertElementExists('form[action$="/openid/login"][method=POST] button');
46 public function test_login()
48 $req = $this->post('/openid/login');
49 $redirect = $req->headers->get('location');
51 $this->assertStringStartsWith('https://openid.local/auth', $redirect, 'Login redirects to SSO location');
52 $this->assertFalse($this->isAuthenticated());
55 public function test_openid_routes_are_only_active_if_openid_enabled()
57 config()->set(['auth.method' => 'standard']);
58 $getRoutes = ['/logout', '/metadata', '/sls'];
59 foreach ($getRoutes as $route) {
60 $req = $this->get('/openid' . $route);
61 $this->assertPermissionError($req);
64 $postRoutes = ['/login', '/acs'];
65 foreach ($postRoutes as $route) {
66 $req = $this->post('/openid' . $route);
67 $this->assertPermissionError($req);
71 public function test_forgot_password_routes_inaccessible()
73 $resp = $this->get('/password/email');
74 $this->assertPermissionError($resp);
76 $resp = $this->post('/password/email');
77 $this->assertPermissionError($resp);
79 $resp = $this->get('/password/reset/abc123');
80 $this->assertPermissionError($resp);
82 $resp = $this->post('/password/reset');
83 $this->assertPermissionError($resp);
86 public function test_standard_login_routes_inaccessible()
88 $resp = $this->post('/login');
89 $this->assertPermissionError($resp);
91 $resp = $this->get('/logout');
92 $this->assertPermissionError($resp);
95 public function test_user_invite_routes_inaccessible()
97 $resp = $this->get('/register/invite/abc123');
98 $this->assertPermissionError($resp);
100 $resp = $this->post('/register/invite/abc123');
101 $this->assertPermissionError($resp);
104 public function test_user_register_routes_inaccessible()
106 $resp = $this->get('/register');
107 $this->assertPermissionError($resp);
109 $resp = $this->post('/register');
110 $this->assertPermissionError($resp);