File tree Expand file tree Collapse file tree
main/java/com/infisical/sdk
test/java/com/infisical/sdk Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ private void onAuthenticate(String accessToken) {
3232 this .authClient = new AuthClient (apiClient , this ::onAuthenticate );
3333 }
3434
35+ public String GetAccessToken () {
36+ return this .apiClient .GetAccessToken ();
37+ }
38+
3539 public AuthClient Auth () {
3640 return this .authClient ;
3741 }
Original file line number Diff line number Diff line change @@ -48,6 +48,10 @@ public String GetBaseUrl() {
4848 return this .baseUrl ;
4949 }
5050
51+ public String GetAccessToken () {
52+ return this .accessToken ;
53+ }
54+
5155 @ SuppressWarnings (value = "lombok" )
5256 public OkHttpClient getClient () {
5357 return this .client ;
Original file line number Diff line number Diff line change @@ -60,6 +60,10 @@ public void SetAccessToken(String accessToken) {
6060 this .onAuthenticate .accept (accessToken );
6161 }
6262
63+ public void RevokeToken () throws InfisicalException {
64+ RevokeToken (this .apiClient .GetAccessToken ());
65+ }
66+
6367 public void RevokeToken (String accessToken ) throws InfisicalException {
6468 RevokeTokenInput input = RevokeTokenInput .builder ().accessToken (accessToken ).build ();
6569
Original file line number Diff line number Diff line change 11package com .infisical .sdk ;
22
33import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
4+ import static org .junit .jupiter .api .Assertions .assertThrows ;
45
56import java .util .List ;
67
1617public class InfisicalSdkTest {
1718 private static final Logger logger = LoggerFactory .getLogger (InfisicalSdkTest .class );
1819
20+ @ Test
21+ public void TestRevokeToken () {
22+ EnvironmentVariables envVars = new EnvironmentVariables ();
23+
24+ InfisicalSdk sdk = new InfisicalSdk (new SdkConfig .Builder ().withSiteUrl (envVars .getSiteUrl ()).build ());
25+
26+ assertDoesNotThrow (() -> {
27+ sdk .Auth ().UniversalAuthLogin (envVars .getMachineIdentityClientId (), envVars .getMachineIdentityClientSecret ());
28+ });
29+
30+ String token = sdk .GetAccessToken ();
31+ assertDoesNotThrow (() -> sdk .Auth ().RevokeToken ());
32+
33+ // Verify the token is actually revoked — revoking it again should fail
34+ assertThrows (InfisicalException .class , () -> sdk .Auth ().RevokeToken (token ));
35+ }
36+
1937 @ Test
2038 public void TestListSecrets () {
2139 EnvironmentVariables envVars = new EnvironmentVariables ();
Original file line number Diff line number Diff line change @@ -21,6 +21,29 @@ public class AuthClientTest {
2121 @ Mock
2222 private ApiClient apiClient ;
2323
24+ @ Test
25+ public void RevokeToken_noArg_throwsWhenNoTokenIsSet () {
26+ when (apiClient .GetAccessToken ()).thenReturn (null );
27+ AuthClient authClient = new AuthClient (apiClient , token -> {});
28+
29+ InfisicalException ex = assertThrows (InfisicalException .class , () -> authClient .RevokeToken ());
30+ assertEquals ("Access token is required" , ex .getMessage ());
31+ }
32+
33+ @ Test
34+ public void RevokeToken_noArg_callsPostWithStoredToken () throws InfisicalException {
35+ when (apiClient .GetBaseUrl ()).thenReturn ("http://localhost" );
36+ when (apiClient .GetAccessToken ()).thenReturn ("stored-token-456" );
37+ AuthClient authClient = new AuthClient (apiClient , token -> {});
38+
39+ authClient .RevokeToken ();
40+
41+ verify (apiClient ).post (
42+ eq ("http://localhost/api/v1/auth/token/revoke" ),
43+ any (RevokeTokenInput .class ),
44+ eq (Void .class ));
45+ }
46+
2447 @ Test
2548 public void RevokeToken_throwsWhenAccessTokenIsNull () {
2649 AuthClient authClient = new AuthClient (apiClient , token -> {});
You can’t perform that action at this time.
0 commit comments