File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed
main/java/io/grpc/s2a/internal/handshaker/tokenmanager
test/java/io/grpc/s2a/internal/handshaker Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,11 @@ public static void setAccessToken(String token) {
4141 accessToken = token ;
4242 }
4343
44+ @ VisibleForTesting
45+ public static String getAccessToken () {
46+ return accessToken ;
47+ }
48+
4449 private SingleTokenFetcher (String token ) {
4550 this .token = token ;
4651 }
@@ -54,4 +59,4 @@ public String getDefaultToken() {
5459 public String getToken (S2AIdentity identity ) {
5560 return token ;
5661 }
57- }
62+ }
Original file line number Diff line number Diff line change 2020import io .grpc .s2a .internal .handshaker .S2AIdentity ;
2121import io .grpc .s2a .internal .handshaker .tokenmanager .SingleTokenFetcher ;
2222import java .util .Optional ;
23+ import org .junit .AfterClass ;
2324import org .junit .BeforeClass ;
2425import org .junit .Rule ;
2526import org .junit .Test ;
3132public final class GetAuthenticationMechanismsTest {
3233 @ Rule public final Expect expect = Expect .create ();
3334 private static final String TOKEN = "access_token" ;
35+ private static String originalAccessToken ;
3436
3537 @ BeforeClass
3638 public static void setUpClass () {
39+ originalAccessToken = SingleTokenFetcher .getAccessToken ();
3740 // Set the token that the client will use to authenticate to the S2A.
3841 SingleTokenFetcher .setAccessToken (TOKEN );
3942 }
4043
44+ @ AfterClass
45+ public static void tearDownClass () {
46+ SingleTokenFetcher .setAccessToken (originalAccessToken );
47+ }
48+
4149 @ Test
4250 public void getAuthMechanisms_emptyIdentity_success () {
4351 expect
@@ -58,4 +66,4 @@ public void getAuthMechanisms_nonEmptyIdentity_success() {
5866 .setToken ("access_token" )
5967 .build ()));
6068 }
61- }
69+ }
Original file line number Diff line number Diff line change 2020
2121import io .grpc .s2a .internal .handshaker .S2AIdentity ;
2222import java .util .Optional ;
23+ import org .junit .After ;
2324import org .junit .Before ;
2425import org .junit .Test ;
2526import org .junit .runner .RunWith ;
@@ -30,11 +31,19 @@ public final class SingleTokenAccessTokenManagerTest {
3031 private static final S2AIdentity IDENTITY = S2AIdentity .fromSpiffeId ("spiffe_id" );
3132 private static final String TOKEN = "token" ;
3233
34+ private String originalAccessToken ;
35+
3336 @ Before
3437 public void setUp () {
38+ originalAccessToken = SingleTokenFetcher .getAccessToken ();
3539 SingleTokenFetcher .setAccessToken (null );
3640 }
3741
42+ @ After
43+ public void tearDown () {
44+ SingleTokenFetcher .setAccessToken (originalAccessToken );
45+ }
46+
3847 @ Test
3948 public void getDefaultToken_success () throws Exception {
4049 SingleTokenFetcher .setAccessToken (TOKEN );
@@ -68,4 +77,4 @@ public void create_success() throws Exception {
6877 public void create_noEnvironmentVariable () throws Exception {
6978 assertThat (AccessTokenManager .create ()).isEmpty ();
7079 }
71- }
80+ }
You can’t perform that action at this time.
0 commit comments