GeezerVison is showing github.com — test: expose test-jar and mock classes in oauth2 (#1224) · googleapis/google-cloud-java@22916dd
File treeExpand file treeCollapse file tree Open diff view settings javatests/com/google/auth
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: google-auth-library-java/appengine/pom.xml +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 75 | 75 | <dependency> | 76 | 76 | <groupId>com.google.auth</groupId> | 77 | 77 | <artifactId>google-auth-library-oauth2-http</artifactId> | 78 | | - <type>test-jar</type> | 79 | 78 | <scope>test</scope> | | 79 | + <type>test-jar</type> | | 80 | + <classifier>testlib</classifier> | 80 | 81 | </dependency> | 81 | 82 | </dependencies> | 82 | 83 | </project> |
Collapse file Copy file name to clipboardExpand all lines: google-auth-library-java/oauth2_http/javatests/com/google/auth/http/HttpCredentialsAdapterTest.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 42 | 42 | import com.google.api.client.http.HttpResponse; | 43 | 43 | import com.google.api.client.http.HttpTransport; | 44 | 44 | import com.google.auth.Credentials; | 45 | | -import com.google.auth.oauth2.GoogleCredentialsTest.MockTokenServerTransportFactory; | 46 | 45 | import com.google.auth.oauth2.MockTokenCheckingTransport; | | 46 | +import com.google.auth.oauth2.MockTokenServerTransportFactory; | 47 | 47 | import com.google.auth.oauth2.OAuth2Credentials; | 48 | 48 | import com.google.auth.oauth2.UserCredentials; | 49 | 49 | import java.io.IOException; | |
Collapse file Copy file name to clipboardExpand all lines: google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 52 | 52 | import com.google.auth.ServiceAccountSigner.SigningException; | 53 | 53 | import com.google.auth.TestUtils; | 54 | 54 | import com.google.auth.http.HttpTransportFactory; | 55 | | -import com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory; | 56 | 55 | import java.io.IOException; | 57 | 56 | import java.net.URI; | 58 | 57 | import java.util.ArrayDeque; | |
Collapse file Copy file name to clipboardExpand all lines: google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/DefaultCredentialsProviderTest.java -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 47 | 47 | import com.google.auth.TestUtils; | 48 | 48 | import com.google.auth.http.HttpTransportFactory; | 49 | 49 | import com.google.auth.oauth2.ComputeEngineCredentialsTest.MockMetadataServerTransportFactory; | 50 | | -import com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory; | 51 | | -import com.google.auth.oauth2.GoogleCredentialsTest.MockTokenServerTransportFactory; | 52 | 50 | import java.io.BufferedReader; | 53 | 51 | import java.io.ByteArrayInputStream; | 54 | 52 | import java.io.File; | |
Collapse file Copy file name to clipboardExpand all lines: google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/DownscopedCredentialsTest.java +2-4Lines changed: 2 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -204,8 +204,7 @@ public void builder_noTransport_defaults() throws IOException { | 204 | 204 |
| 205 | 205 | private static GoogleCredentials getServiceAccountSourceCredentials(boolean canRefresh) | 206 | 206 | throws IOException { | 207 | | - GoogleCredentialsTest.MockTokenServerTransportFactory transportFactory = | 208 | | - new GoogleCredentialsTest.MockTokenServerTransportFactory(); | | 207 | + MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory(); | 209 | 208 |
| 210 | 209 | | 211 | 210 |
| @@ -228,8 +227,7 @@ private static GoogleCredentials getServiceAccountSourceCredentials(boolean canR | 228 | 227 | } | 229 | 228 |
| 230 | 229 | private static GoogleCredentials getUserSourceCredentials() { | 231 | | - GoogleCredentialsTest.MockTokenServerTransportFactory transportFactory = | 232 | | - new GoogleCredentialsTest.MockTokenServerTransportFactory(); | | 230 | + MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory(); | 233 | 231 | transportFactory.transport.addClient("clientId", "clientSecret"); | 234 | 232 | transportFactory.transport.addRefreshToken("refreshToken", "accessToken"); | 235 | 233 | AccessToken accessToken = new AccessToken("accessToken", new Date()); | |
Collapse file Copy file name to clipboardExpand all lines: google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GdchCredentialsTest.java +7-5Lines changed: 7 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 46 | 46 | import com.google.api.client.testing.http.FixedClock; | 47 | 47 | import com.google.api.client.util.Clock; | 48 | 48 | import com.google.auth.TestUtils; | 49 | | -import com.google.auth.oauth2.GoogleCredentialsTest.MockTokenServerTransportFactory; | 50 | 49 | import java.io.File; | 51 | 50 | import java.io.IOException; | 52 | 51 | import java.io.InputStream; | @@ -510,11 +509,14 @@ public void refreshAccessToken_correct() throws IOException { | 510 | 509 | GdchCredentials credentials = GdchCredentials.fromJson(json, transportFactory); | 511 | 510 | GdchCredentials gdchWithAudience = credentials.createWithGdchAudience(API_AUDIENCE); | 512 | 511 |
| 513 | | - gdchWithAudience.clock = new FixedClock(0L); | | 512 | + GdchCredentialsTestUtil.registerGdchCredentialWithMockTransport( | | 513 | + gdchWithAudience, | | 514 | + transportFactory.transport, | | 515 | + PROJECT_ID, | | 516 | + SERVICE_IDENTITY_NAME, | | 517 | + tokenString, | | 518 | + TOKEN_SERVER_URI); | 514 | 519 |
| 515 | | - transportFactory.transport.addGdchServiceAccount( | 516 | | - GdchCredentials.getIssuerSubjectValue(PROJECT_ID, SERVICE_IDENTITY_NAME), tokenString); | 517 | | - transportFactory.transport.setTokenServerUri(TOKEN_SERVER_URI); | 518 | 520 | AccessToken accessToken = gdchWithAudience.refreshAccessToken(); | 519 | 521 | assertNotNull(accessToken); | 520 | 522 | assertEquals(tokenString, accessToken.getTokenValue()); | |
Collapse file Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package com.google.auth.oauth2; | | 2 | + | | 3 | +import com.google.api.client.testing.http.FixedClock; | | 4 | +import java.io.IOException; | | 5 | +import java.net.URI; | | 6 | +import java.util.Map; | | 7 | + | | 8 | +public class GdchCredentialsTestUtil { | | 9 | + public static void registerGdchCredentialWithMockTransport( | | 10 | + GdchCredentials credentials, | | 11 | + MockTokenServerTransport transport, | | 12 | + String projectId, | | 13 | + String serviceIdentityName, | | 14 | + String tokenString, | | 15 | + URI tokenServerUri) { | | 16 | + credentials.clock = new FixedClock(0L); | | 17 | + transport.addGdchServiceAccount( | | 18 | + GdchCredentials.getIssuerSubjectValue(projectId, serviceIdentityName), tokenString); | | 19 | + transport.setTokenServerUri(tokenServerUri); | | 20 | + } | | 21 | + | | 22 | + public static GdchCredentials fromJson( | | 23 | + Map<String, Object> json, MockTokenServerTransportFactory transportFactory) | | 24 | + throws IOException { | | 25 | + return GdchCredentials.fromJson(json, transportFactory); | | 26 | + } | | 27 | +} |
Collapse file Copy file name to clipboardExpand all lines: google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java -22Lines changed: 0 additions & 22 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 33 | 33 |
| 34 | 34 | import static org.junit.Assert.*; | 35 | 35 |
| 36 | | -import com.google.api.client.http.HttpTransport; | 37 | | -import com.google.api.client.testing.http.MockHttpTransport; | 38 | 36 | import com.google.api.client.util.Clock; | 39 | 37 | import com.google.auth.TestUtils; | 40 | 38 | import com.google.auth.http.HttpTransportFactory; | @@ -93,26 +91,6 @@ public class GoogleCredentialsTest extends BaseSerializationTest { | 93 | 91 | private static final Collection<String> DEFAULT_SCOPES = | 94 | 92 | Collections.unmodifiableCollection(Arrays.asList("scope3")); | 95 | 93 |
| 96 | | - static class MockHttpTransportFactory implements HttpTransportFactory { | 97 | | - | 98 | | - MockHttpTransport transport = new MockHttpTransport(); | 99 | | - | 100 | | - @Override | 101 | | - public HttpTransport create() { | 102 | | - return transport; | 103 | | - } | 104 | | - } | 105 | | - | 106 | | - public static class MockTokenServerTransportFactory implements HttpTransportFactory { | 107 | | - | 108 | | - public MockTokenServerTransport transport = new MockTokenServerTransport(); | 109 | | - | 110 | | - @Override | 111 | | - public HttpTransport create() { | 112 | | - return transport; | 113 | | - } | 114 | | - } | 115 | | - | 116 | 94 | @Test | 117 | 95 | public void getApplicationDefault_nullTransport_throws() throws IOException { | 118 | 96 | try { | |
Collapse file Copy file name to clipboardExpand all lines: google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/ImpersonatedCredentialsTest.java -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 52 | 52 | import com.google.auth.ServiceAccountSigner.SigningException; | 53 | 53 | import com.google.auth.TestUtils; | 54 | 54 | import com.google.auth.http.HttpTransportFactory; | 55 | | -import com.google.auth.oauth2.GoogleCredentialsTest.MockTokenServerTransportFactory; | 56 | 55 | import com.google.common.collect.ImmutableList; | 57 | 56 | import com.google.common.collect.ImmutableSet; | 58 | 57 | import java.io.ByteArrayOutputStream; | |
Collapse file Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package com.google.auth.oauth2; | | 2 | + | | 3 | +import com.google.api.client.http.HttpTransport; | | 4 | +import com.google.api.client.testing.http.MockHttpTransport; | | 5 | +import com.google.auth.http.HttpTransportFactory; | | 6 | + | | 7 | +public class MockHttpTransportFactory implements HttpTransportFactory { | | 8 | + | | 9 | + MockHttpTransport transport = new MockHttpTransport(); | | 10 | + | | 11 | + @Override | | 12 | + public HttpTransport create() { | | 13 | + return transport; | | 14 | + } | | 15 | +} |
|