1818
1919import java .util .List ;
2020import java .util .concurrent .TimeUnit ;
21+
22+ import org .jetbrains .annotations .NotNull ;
2123import org .junit .After ;
2224import org .junit .Before ;
2325import org .junit .Test ;
@@ -111,19 +113,27 @@ public void testPushSynchronous() throws InterruptedException
111113
112114 assertEquals (2 , initialResponse .messages .size ());
113115
114- // Set the server up to respond to the polling requests twice with false
115- setPollTransactionResponse (false , 2 );
116+ // Set the server up to respond to the polling requests twice with "pending"
117+ setPollTransactionResponse (ChallengeStatus . pending , 2 );
116118
117- // Polling is controlled by the code using the sdk
119+ // Polling is controlled by the code using the java-client
118120 for (int i = 0 ; i < 2 ; i ++)
119121 {
120- assertFalse (privacyIDEA .pollTransaction (initialResponse .transactionID ));
122+ assertEquals (privacyIDEA .pollTransaction (initialResponse .transactionID ), ChallengeStatus . pending );
121123 Thread .sleep (500 );
122124 }
123125
124- // Set the server to respond with true
125- setPollTransactionResponse (true , 1 );
126- assertTrue (privacyIDEA .pollTransaction (initialResponse .transactionID ));
126+ // Set the server to respond with "declined"
127+ setPollTransactionResponse (ChallengeStatus .declined , 1 );
128+ assertEquals (privacyIDEA .pollTransaction (initialResponse .transactionID ), ChallengeStatus .declined );
129+
130+ // Set the server to respond with "accept"
131+ setPollTransactionResponse (ChallengeStatus .accept , 1 );
132+ assertEquals (privacyIDEA .pollTransaction (initialResponse .transactionID ), ChallengeStatus .accept );
133+
134+ // Set the server to respond with "none" by not including or invalid challenge_status parameter
135+ setPollTransactionResponse (ChallengeStatus .none , 1 );
136+ assertEquals (privacyIDEA .pollTransaction (initialResponse .transactionID ), ChallengeStatus .none );
127137
128138 // Now the transaction has to be finalized manually
129139 setFinalizationResponse (initialResponse .transactionID );
@@ -148,25 +158,39 @@ private void setFinalizationResponse(String transactionID)
148158 .withBody (Utils .foundMatchingChallenge ()));
149159 }
150160
151- private void setPollTransactionResponse (boolean value , int times )
161+ private void setPollTransactionResponse (ChallengeStatus challengeStatus , int times )
152162 {
153- String val = value ? "true" : "false" ;
163+ String challengeStatusParameter = getChallengeStatusParameter ( challengeStatus ) ;
154164 mockServer .when (HttpRequest .request ()
155165 .withMethod ("GET" )
156166 .withPath ("/validate/polltransaction" )
157167 .withQueryStringParameter ("transaction_id" , "02659936574063359702" ), Times .exactly (times ))
158168 .respond (HttpResponse .response ()
159- .withBody ("{\n " + " \" id\" : 1,\n " + " \" jsonrpc\" : \" 2.0\" ,\n " +
160- " \" result\" : {\n " + " \" status\" : true,\n " +
161- " \" value\" : " + val + "\n " + " },\n " +
162- " \" time\" : 1589446811.1909237,\n " +
163- " \" version\" : \" privacyIDEA 3.2.1\" ,\n " +
164- " \" versionnumber\" : \" 3.2.1\" ,\n " +
165- " \" signature\" : \" rsa_sha256_pss:\" \n " + "}" )
169+ .withBody ("{\n \" id\" : 1,\n \" jsonrpc\" : \" 2.0\" ,\n " + challengeStatusParameter +
170+ "\" result\" : {\n \" status\" : true\n },\n \" time\" : 1589446811.1909237,\n \" version\" : \" privacyIDEA 3.2.1\" ,\n " +
171+ "\" versionnumber\" : \" 3.2.1\" ,\n \" signature\" : \" rsa_sha256_pss:\" \n }" )
166172 .withDelay (TimeUnit .MILLISECONDS , 50 ));
167173 }
168174
175+ private static @ NotNull String getChallengeStatusParameter (ChallengeStatus challengeStatus )
176+ {
177+ String challengeStatusParameter = "" ;
178+ if (challengeStatus == ChallengeStatus .accept )
179+ {
180+ challengeStatusParameter = "\" detail\" : {\n \" challenge_status\" : \" accept\" \n },\n " ;
181+ }
182+ else if (challengeStatus == ChallengeStatus .declined )
183+ {
184+ challengeStatusParameter = "\" detail\" : {\n \" challenge_status\" : \" declined\" \n },\n " ;
169185
186+ }
187+ else if (challengeStatus == ChallengeStatus .pending )
188+ {
189+ challengeStatusParameter = "\" detail\" : {\n \" challenge_status\" : \" pending\" \n },\n " ;
190+ }
191+ return challengeStatusParameter ;
192+ }
193+
170194 @ After
171195 public void tearDown ()
172196 {
0 commit comments