GoogleHelper { static boolean isValidAudience(Tokeninfo tokenInfo) { final String audience = tokenInfo.getAudience(); if (config.getGoogleClientID().equals(audience)) { return true; } else { final int index = audience.indexOf('-'); if (index != -1) { final String prefix = audience.substring(0, index); return config.getExternalGoogleClientIdPrefixes().contains(prefix); } } return false; } private  GoogleHelper(); static void setConfig(DockstoreWebserviceConfiguration config); static boolean updateGoogleUserData(String token, User user); static void updateUserFromGoogleUserinfoplus(Userinfoplus userinfo, User user); static Optional<String> getValidAccessToken(Token token); static Optional<Userinfoplus> userinfoplusFromToken(String token); static TokenResponse getTokenResponse(String googleClientID, String googleClientSecret, String code, String redirectUri);  }
@Test public void isValidAudience() { final DockstoreWebserviceConfiguration config = new DockstoreWebserviceConfiguration(); config.setGoogleClientID(AUDIENCE1); config.getExternalGoogleClientIdPrefixes().add(EXTERNAL_PREFIX); GoogleHelper.setConfig(config); final Tokeninfo tokeninfo = Mockito.mock(Tokeninfo.class); when(tokeninfo.getAudience()).thenReturn(AUDIENCE1).thenReturn(EXTERNAL_AUDIENCE).thenReturn(INVALID_AUDIENCE); Assert.assertTrue(GoogleHelper.isValidAudience(tokeninfo)); Assert.assertTrue(GoogleHelper.isValidAudience(tokeninfo)); Assert.assertFalse(GoogleHelper.isValidAudience(tokeninfo)); }