File tree Expand file tree Collapse file tree 3 files changed +29
-15
lines changed
oauth2_http/javatests/com/google/auth Expand file tree Collapse file tree 3 files changed +29
-15
lines changed Original file line number Diff line number Diff line change 5656import java .util .HashMap ;
5757import java .util .List ;
5858import java .util .Map ;
59+ import java .util .TimeZone ;
5960import javax .annotation .Nullable ;
6061
6162/** Utilities for test code under com.google.auth. */
@@ -150,8 +151,10 @@ public static HttpResponseException buildHttpResponseException(
150151 public static String getDefaultExpireTime () {
151152 Calendar calendar = Calendar .getInstance ();
152153 calendar .setTime (new Date ());
153- calendar .add (Calendar .SECOND , 3000 );
154- return new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'" ).format (calendar .getTime ());
154+ calendar .add (Calendar .SECOND , 300 );
155+ SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'" );
156+ dateFormat .setTimeZone (TimeZone .getTimeZone ("UTC" ));
157+ return dateFormat .format (calendar .getTime ());
155158 }
156159
157160 private TestUtils () {}
Original file line number Diff line number Diff line change 3838import static org .junit .Assert .assertNotNull ;
3939import static org .junit .Assert .assertNull ;
4040import static org .junit .Assert .assertSame ;
41+ import static org .junit .Assert .assertThrows ;
4142import static org .junit .Assert .assertTrue ;
4243import static org .junit .Assert .fail ;
4344
@@ -1243,7 +1244,6 @@ public void testRefresh_trustBoundarySuccess() throws IOException {
12431244 TrustBoundary trustBoundary = credentials .getTrustBoundary ();
12441245 assertNotNull (trustBoundary );
12451246 assertEquals (TestUtils .TRUST_BOUNDARY_ENCODED_LOCATION , trustBoundary .getEncodedLocations ());
1246- TrustBoundary .setEnvironmentProviderForTest (null );
12471247 }
12481248
12491249 @ Test
@@ -1262,15 +1262,15 @@ public void testRefresh_trustBoundaryFails_incorrectAudience() throws IOExceptio
12621262 .setTokenUrl (TOKEN_URL )
12631263 .build ();
12641264
1265- try {
1266- credentials . refresh ();
1267- fail ( "Expected IOException to be thrown." );
1268- } catch ( IOException e ) {
1269- assertEquals (
1270- "The provided audience is not in the correct format for a workforce pool." ,
1271- e . getMessage ());
1272- }
1273- TrustBoundary . setEnvironmentProviderForTest ( null );
1265+ IOException exception =
1266+ assertThrows (
1267+ IOException . class ,
1268+ () -> {
1269+ credentials . refresh ();
1270+ });
1271+ assertEquals (
1272+ "The provided audience is not in the correct format for a workforce pool." ,
1273+ exception . getMessage () );
12741274 }
12751275
12761276 @ Test
Original file line number Diff line number Diff line change 3636import static org .junit .Assert .assertNotNull ;
3737import static org .junit .Assert .assertNull ;
3838import static org .junit .Assert .assertSame ;
39+ import static org .junit .Assert .assertThrows ;
3940import static org .junit .Assert .assertTrue ;
4041import static org .junit .Assert .fail ;
4142
@@ -1287,15 +1288,25 @@ public void getTrustBoundaryUrl_workforce() throws IOException {
12871288 assertEquals (expectedUrl , credentials .getTrustBoundaryUrl ());
12881289 }
12891290
1290- @ Test ( expected = IOException . class )
1291- public void getTrustBoundaryUrl_invalidAudience_throws () throws IOException {
1291+ @ Test
1292+ public void getTrustBoundaryUrl_invalidAudience_throws () {
12921293 ExternalAccountCredentials credentials =
12931294 TestExternalAccountCredentials .newBuilder ()
12941295 .setAudience ("invalid-audience" )
12951296 .setSubjectTokenType ("subject_token_type" )
12961297 .setCredentialSource (new TestCredentialSource (FILE_CREDENTIAL_SOURCE_MAP ))
12971298 .build ();
1298- credentials .getTrustBoundaryUrl ();
1299+
1300+ IOException exception =
1301+ assertThrows (
1302+ IOException .class ,
1303+ () -> {
1304+ credentials .getTrustBoundaryUrl ();
1305+ });
1306+
1307+ assertEquals (
1308+ "The provided audience is not in a valid format for either a workload identity pool or a workforce pool." ,
1309+ exception .getMessage ());
12991310 }
13001311
13011312 @ Test
You can’t perform that action at this time.
0 commit comments