|
39 | 39 | expect(session('social_connect_workspace'))->toBe($this->workspace->id); |
40 | 40 | }); |
41 | 41 |
|
| 42 | +test('linkedin connect requests the default scope set when LINKEDIN_EXTRA_SCOPES is unset', function () { |
| 43 | + config(['services.linkedin.extra_scopes' => null]); |
| 44 | + |
| 45 | + $captured = []; |
| 46 | + |
| 47 | + $driverMock = Mockery::mock(); |
| 48 | + $driverMock->shouldReceive('scopes') |
| 49 | + ->withArgs(function (array $scopes) use (&$captured) { |
| 50 | + $captured = $scopes; |
| 51 | + |
| 52 | + return true; |
| 53 | + }) |
| 54 | + ->andReturnSelf(); |
| 55 | + $driverMock->shouldReceive('redirect')->andReturn(Mockery::mock([ |
| 56 | + 'getTargetUrl' => 'https://www.linkedin.com/oauth/v2/authorization?test=1', |
| 57 | + ])); |
| 58 | + |
| 59 | + Socialite::shouldReceive('driver') |
| 60 | + ->with('linkedin') |
| 61 | + ->andReturn($driverMock); |
| 62 | + |
| 63 | + $this->actingAs($this->user) |
| 64 | + ->withHeader('X-Inertia', 'true') |
| 65 | + ->get(route('app.social.linkedin.connect')); |
| 66 | + |
| 67 | + expect($captured)->toEqualCanonicalizing([ |
| 68 | + 'openid', 'profile', 'email', 'w_member_social', |
| 69 | + ]); |
| 70 | +}); |
| 71 | + |
| 72 | +test('linkedin connect appends LINKEDIN_EXTRA_SCOPES to the default scope set', function () { |
| 73 | + // Backward-compatibility: ops who have legacy products approved on |
| 74 | + // their LinkedIn app (e.g. r_basicprofile) opt back in via env. |
| 75 | + config(['services.linkedin.extra_scopes' => 'r_basicprofile, r_emailaddress']); |
| 76 | + |
| 77 | + $captured = []; |
| 78 | + |
| 79 | + $driverMock = Mockery::mock(); |
| 80 | + $driverMock->shouldReceive('scopes') |
| 81 | + ->withArgs(function (array $scopes) use (&$captured) { |
| 82 | + $captured = $scopes; |
| 83 | + |
| 84 | + return true; |
| 85 | + }) |
| 86 | + ->andReturnSelf(); |
| 87 | + $driverMock->shouldReceive('redirect')->andReturn(Mockery::mock([ |
| 88 | + 'getTargetUrl' => 'https://www.linkedin.com/oauth/v2/authorization?test=1', |
| 89 | + ])); |
| 90 | + |
| 91 | + Socialite::shouldReceive('driver') |
| 92 | + ->with('linkedin') |
| 93 | + ->andReturn($driverMock); |
| 94 | + |
| 95 | + $this->actingAs($this->user) |
| 96 | + ->withHeader('X-Inertia', 'true') |
| 97 | + ->get(route('app.social.linkedin.connect')); |
| 98 | + |
| 99 | + expect($captured)->toEqualCanonicalizing([ |
| 100 | + 'openid', 'profile', 'email', 'w_member_social', |
| 101 | + 'r_basicprofile', 'r_emailaddress', |
| 102 | + ]); |
| 103 | +}); |
| 104 | + |
42 | 105 | test('linkedin oauth callback creates account', function () { |
43 | 106 | session([ |
44 | 107 | 'social_connect_workspace' => $this->workspace->id, |
|
99 | 162 | // splits on space (the OAuth 2.0 default), so approvedScopes lands as |
100 | 163 | // a single-element array with the whole CSV inside. The save path |
101 | 164 | // must normalize back to individual tokens. |
102 | | - $socialiteUser->approvedScopes = ['email,openid,profile,r_basicprofile,w_member_social']; |
| 165 | + $socialiteUser->approvedScopes = ['email,openid,profile,w_member_social']; |
103 | 166 |
|
104 | 167 | Socialite::shouldReceive('driver') |
105 | 168 | ->with('linkedin') |
|
116 | 179 |
|
117 | 180 | $account = SocialAccount::where('platform_user_id', 'abc123xyz')->first(); |
118 | 181 | expect($account->scopes)->toEqualCanonicalizing([ |
119 | | - 'email', 'openid', 'profile', 'r_basicprofile', 'w_member_social', |
| 182 | + 'email', 'openid', 'profile', 'w_member_social', |
120 | 183 | ]); |
121 | 184 | }); |
122 | 185 |
|
|
0 commit comments