This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from InfoSec812/limit-gapps-domain
Added support for only allowing a single GApps domain
- Loading branch information
Showing
5 changed files
with
64 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,20 @@ public void callback_on_successful_authentication() throws IOException, Interrup | |
assertThat(userRequest.getPath()).startsWith("/oauth2/v1/userinfo"); | ||
} | ||
|
||
/** | ||
* Second phase: Google redirects browser to SonarQube at /oauth/callback/google?code={the verifier code}. | ||
* This SonarQube web service sends two requests to Google: | ||
* <ul> | ||
* <li>get an access token</li> | ||
* <li>get the profile (login, name) of the authenticated user</li> | ||
* </ul> | ||
*/ | ||
@Test | ||
public void callback_on_successful_authentication_without_domain() throws IOException, InterruptedException { | ||
settings.removeProperty("sonar.auth.google.limitOauthDomain"); | ||
callback_on_successful_authentication(); | ||
} | ||
|
||
@Test | ||
public void callback_throws_OAE_if_error_when_requesting_user_profile() throws IOException, InterruptedException { | ||
google.enqueue(newSuccessfulAccessTokenResponse()); | ||
|
@@ -142,6 +156,28 @@ public void callback_throws_OAE_if_error_when_requesting_user_profile() throws I | |
assertThat(callbackContext.redirectSent.get()).isFalse(); | ||
} | ||
|
||
@Test | ||
public void callback_redirects_to_unauthorized_if_domain_does_not_match() throws IOException, InterruptedException { | ||
google.enqueue(newSuccessfulAccessTokenResponse()); | ||
// https://accounts.google.com/o/oauth2/token fails | ||
google.enqueue(new MockResponse().setResponseCode(200).setBody("{\n"+ | ||
" \"email\": \"[email protected]\",\n" + | ||
" \"verified_email\": true,\n" + | ||
" \"name\": \"John Smith\",\n" + | ||
" \"given_name\": \"John\",\n" + | ||
" \"family_name\": \"Smith\",\n" + | ||
" \"picture\": \"https://lh3.googleusercontent.com/-AAAAAAAA/AAAAAAAAAAA/AAAAAAAAAAA/AAAAAAAAAA/photo.jpg\",\n" + | ||
" \"locale\": \"en-US\"\n" + | ||
"}")); | ||
|
||
HttpServletRequest request = newRequest("the-verifier-code"); | ||
DumbCallbackContext callbackContext = new DumbCallbackContext(request); | ||
underTest.callback(callbackContext); | ||
|
||
assertThat(callbackContext.csrfStateVerified.get()).isFalse(); | ||
assertThat(callbackContext.userIdentity).isNull(); | ||
} | ||
|
||
/** | ||
* Response sent by Bitbucket to SonarQube when generating an access token | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters