66import com .venafi .vcert .sdk .connectors .ZoneConfiguration ;
77import com .venafi .vcert .sdk .endpoint .Authentication ;
88import feign .FeignException ;
9+ import feign .FeignException .Unauthorized ;
10+
911import org .apache .commons .codec .digest .DigestUtils ;
1012import org .bouncycastle .jce .provider .BouncyCastleProvider ;
1113import org .bouncycastle .openssl .PEMParser ;
@@ -61,19 +63,11 @@ void authenticate() throws VCertException {
6163 @ Test
6264 @ DisplayName ("Authenticate with credentials from Config object" )
6365 void authenticateNoParameter () throws VCertException {
64- Authentication authentication = Authentication .builder ()
65- .user (System .getenv ("TPPUSER" ))
66- .password (System .getenv ("TPPPASSWORD" ))
67- .scope ("certificate:manage,revoke,discover" )
68- .build ();
69-
70- classUnderTest .credentials (authentication );
66+ TokenInfo localInfo = classUnderTest .getAccessToken ();
7167
72- TokenInfo info = classUnderTest .getAccessToken ();
73-
74- assertThat (info ).isNotNull ();
75- assertThat (info .accessToken ()).isNotNull ();
76- assertThat (info .refreshToken ()).isNotNull ();
68+ assertThat (localInfo ).isNotNull ();
69+ assertThat (localInfo .accessToken ()).isNotNull ();
70+ assertThat (localInfo .refreshToken ()).isNotNull ();
7771 }
7872
7973 @ Test
@@ -87,7 +81,11 @@ void authenticateInvalid(){
8781
8882 classUnderTest .credentials (authentication );
8983
90- assertThrows (VCertException .class , () ->classUnderTest .getAccessToken ());
84+ assertThrows (Unauthorized .class , () ->classUnderTest .getAccessToken ());
85+
86+ // After setting invalid credentials to TPP, setting variable <info> to null
87+ // will allow for new token to be authorized
88+ TppTokenConnectorAT .info = null ;
9189 }
9290
9391 @ Test
@@ -334,12 +332,20 @@ void refreshTokenInvalid() throws VCertException{
334332 classUnderTest .credentials (invalidCredentials );
335333
336334 assertThrows (VCertException .class , () -> classUnderTest .refreshAccessToken ("vcert-sdk" ));
335+
336+ // After setting invalid credentials to TPP, setting variable <info> to null
337+ // will allow for new token to be authorized
338+ TppTokenConnectorAT .info = null ;
337339 }
338340
339341 @ Test
340342 void revokeToken () throws VCertException {
341343 int status = classUnderTest .revokeAccessToken ();
342344 assertThat (status ).isEqualTo (200 );
345+
346+ // After revoking the current token, setting variable <info> to null
347+ // will allow for new token to be authorized
348+ TppTokenConnectorAT .info = null ;
343349 }
344350
345351 @ Test
@@ -351,5 +357,9 @@ void revokeTokenInvalid() throws VCertException{
351357 classUnderTest .credentials (invalidCredentials );
352358
353359 assertThrows (VCertException .class , () ->classUnderTest .revokeAccessToken ());
360+
361+ // After setting invalid credentials to TPP, setting variable <info> to null
362+ // will allow for new token to be authorized
363+ TppTokenConnectorAT .info = null ;
354364 }
355365}
0 commit comments