1919import org .cloudfoundry .AbstractIntegrationTest ;
2020import org .cloudfoundry .reactor .ConnectionContext ;
2121import org .cloudfoundry .reactor .TokenProvider ;
22+ import org .cloudfoundry .uaa .authorizations .AuthorizeByAuthorizationCodeGrantApiRequest ;
2223import org .cloudfoundry .uaa .tokens .CheckTokenRequest ;
2324import org .cloudfoundry .uaa .tokens .GetTokenByAuthorizationCodeRequest ;
25+ import org .cloudfoundry .uaa .tokens .GetTokenByAuthorizationCodeResponse ;
2426import org .cloudfoundry .uaa .tokens .GetTokenByClientCredentialsRequest ;
2527import org .cloudfoundry .uaa .tokens .GetTokenByClientCredentialsResponse ;
2628import org .cloudfoundry .uaa .tokens .GetTokenByOneTimePasscodeRequest ;
3335import org .cloudfoundry .uaa .tokens .GetTokenKeyResponse ;
3436import org .cloudfoundry .uaa .tokens .ListTokenKeysRequest ;
3537import org .cloudfoundry .uaa .tokens .RefreshTokenRequest ;
38+ import org .cloudfoundry .uaa .tokens .RefreshTokenResponse ;
3639import org .cloudfoundry .uaa .tokens .TokenFormat ;
3740import org .cloudfoundry .uaa .tokens .TokenKey ;
3841import org .junit .Ignore ;
4346import reactor .test .StepVerifier ;
4447
4548import java .time .Duration ;
46- import java .util .concurrent .TimeoutException ;
4749
4850import static org .assertj .core .api .Assertions .assertThat ;
4951
@@ -58,12 +60,18 @@ public final class TokensTest extends AbstractIntegrationTest {
5860 @ Autowired
5961 private ConnectionContext connectionContext ;
6062
63+ @ Autowired
64+ private String password ;
65+
6166 @ Autowired
6267 private TokenProvider tokenProvider ;
6368
6469 @ Autowired
6570 private UaaClient uaaClient ;
6671
72+ @ Autowired
73+ private String username ;
74+
6775 @ Test
6876 public void checkTokenNotAuthorized () {
6977 this .tokenProvider .getToken (this .connectionContext )
@@ -72,26 +80,25 @@ public void checkTokenNotAuthorized() {
7280 .token (token )
7381 .clientId (this .clientId )
7482 .clientSecret (this .clientSecret )
75- .scope ("password.write" )
76- .scope ("scim.userids" )
83+ .scope ("password.write" , "scim.userids" )
7784 .build ()))
7885 .as (StepVerifier ::create )
7986 .consumeErrorWith (t -> assertThat (t ).isInstanceOf (UaaException .class ).hasMessage ("access_denied: Access is denied" ))
8087 .verify (Duration .ofMinutes (5 ));
8188 }
8289
83- //TODO: Ready to Implement - use test authorizationCode
84- @ Ignore ("Ready to Implement - use test authorizationCode" )
8590 @ Test
8691 public void getTokenByAuthorizationCode () {
87- this .uaaClient .tokens ()
88- .getByAuthorizationCode (GetTokenByAuthorizationCodeRequest .builder ()
89- .authorizationCode ("some auth code" )
90- .clientId (this .clientId )
91- .clientSecret (this .clientSecret )
92- .build ())
92+ requestGetAuthorizationCode (this .uaaClient , this .clientId )
93+ .then (authorizationCode -> this .uaaClient .tokens ()
94+ .getByAuthorizationCode (GetTokenByAuthorizationCodeRequest .builder ()
95+ .authorizationCode (authorizationCode )
96+ .clientId (this .clientId )
97+ .clientSecret (this .clientSecret )
98+ .build ()))
99+ .map (GetTokenByAuthorizationCodeResponse ::getTokenType )
93100 .as (StepVerifier ::create )
94- .expectNextCount ( 1 )
101+ .expectNext ( "bearer" )
95102 .expectComplete ()
96103 .verify (Duration .ofMinutes (5 ));
97104 }
@@ -111,52 +118,50 @@ public void getTokenByClientCredentials() {
111118 .verify (Duration .ofMinutes (5 ));
112119 }
113120
114- //TODO: Ready to Implement - use test one-time passcode
115- @ Ignore ("Ready to Implement - use test one-time passcode" )
121+ //TODO: Ready to Implement - Await https://github.com/cloudfoundry/cf-java-client/issues/862 to get passcode
122+ @ Ignore ("Ready to Implement - Await https://github.com/cloudfoundry/cf-java-client/issues/862 to get passcode" )
116123 @ Test
117124 public void getTokenByOneTimePasscode () {
118125 this .uaaClient .tokens ()
119126 .getByOneTimePasscode (GetTokenByOneTimePasscodeRequest .builder ()
120- .passcode ("Some passcode" )
127+ .passcode ("some passcode" )
121128 .clientId (this .clientId )
122129 .clientSecret (this .clientSecret )
123130 .tokenFormat (TokenFormat .OPAQUE )
124131 .build ())
125- .map (GetTokenByOneTimePasscodeResponse ::getTokenType )
132+ .map (GetTokenByOneTimePasscodeResponse ::getAccessToken )
126133 .as (StepVerifier ::create )
127134 .expectNext ("bearer" )
128- .expectComplete ();
135+ .expectComplete ()
136+ .verify (Duration .ofMinutes (5 ));
129137 }
130138
131- //TODO: Ready to Implement - use test openid authorizationCode
132- @ Ignore ("Ready to Implement - use test openid authorizationCode" )
133139 @ Test
134140 public void getTokenByOpenId () {
135- this .uaaClient .tokens ()
136- .getByOpenId (GetTokenByOpenIdRequest .builder ()
137- .authorizationCode ("Some authorization code" )
138- .clientId (this .clientId )
139- .clientSecret (this .clientSecret )
140- .tokenFormat (TokenFormat .OPAQUE )
141- .build ())
141+ requestGetAuthorizationCode (this .uaaClient , this .clientId )
142+ .then (authorizationCode -> this .uaaClient .tokens ()
143+ .getByOpenId (GetTokenByOpenIdRequest .builder ()
144+ .authorizationCode (authorizationCode )
145+ .clientId (this .clientId )
146+ .clientSecret (this .clientSecret )
147+ .tokenFormat (TokenFormat .OPAQUE )
148+ .build ()))
142149 .map (GetTokenByOpenIdResponse ::getTokenType )
143150 .as (StepVerifier ::create )
144151 .expectNext ("bearer" )
145152 .expectComplete ()
146153 .verify (Duration .ofMinutes (5 ));
147154 }
148155
149- //TODO: Ready to Implement - use test username and password
150- @ Ignore ("Ready to Implement - use test username and password" )
151156 @ Test
152157 public void getTokenByPassword () {
153158 this .uaaClient .tokens ()
154159 .getByPassword (GetTokenByPasswordRequest .builder ()
155- .password ("a-password" )
156- .username ("a-username" )
157160 .clientId (this .clientId )
158161 .clientSecret (this .clientSecret )
162+ .password (this .password )
159163 .tokenFormat (TokenFormat .OPAQUE )
164+ .username (this .username )
160165 .build ())
161166 .map (GetTokenByPasswordResponse ::getTokenType )
162167 .as (StepVerifier ::create )
@@ -199,21 +204,40 @@ public void listTokenKeys() {
199204 .verify (Duration .ofMinutes (5 ));
200205 }
201206
202- //TODO: Ready to Implement - use test refresh token
203- @ Ignore ("Ready to Implement - use test refresh token" )
204207 @ Test
205208 public void refreshToken () {
206- this .uaaClient .tokens ()
207- .refresh (RefreshTokenRequest .builder ()
208- .tokenFormat (TokenFormat .OPAQUE )
209- .clientId (this .clientId )
210- .clientSecret (this .clientSecret )
211- .refreshToken ("a-refresh-token" )
212- .build ())
209+ getRequestToken (this .uaaClient , this .clientId , this .clientSecret , this .password , this .username )
210+ .then (refreshToken -> this .uaaClient .tokens ()
211+ .refresh (RefreshTokenRequest .builder ()
212+ .tokenFormat (TokenFormat .OPAQUE )
213+ .clientId (this .clientId )
214+ .clientSecret (this .clientSecret )
215+ .refreshToken (refreshToken )
216+ .build ()))
217+ .map (RefreshTokenResponse ::getTokenType )
213218 .as (StepVerifier ::create )
214- .expectNextCount ( 1 )
219+ .expectNext ( "bearer" )
215220 .expectComplete ()
216221 .verify (Duration .ofMinutes (5 ));
217222 }
218223
224+ private static Mono <String > getRequestToken (UaaClient uaaClient , String clientId , String clientSecret , String password , String username ) {
225+ return uaaClient .tokens ()
226+ .getByPassword (GetTokenByPasswordRequest .builder ()
227+ .clientId (clientId )
228+ .clientSecret (clientSecret )
229+ .password (password )
230+ .tokenFormat (TokenFormat .OPAQUE )
231+ .username (username )
232+ .build ())
233+ .map (GetTokenByPasswordResponse ::getRefreshToken );
234+ }
235+
236+ private static Mono <String > requestGetAuthorizationCode (UaaClient uaaClient , String clientId ) {
237+ return uaaClient .authorizations ()
238+ .authorizationCodeGrantApi (AuthorizeByAuthorizationCodeGrantApiRequest .builder ()
239+ .clientId (clientId )
240+ .build ());
241+ }
242+
219243}
0 commit comments