Skip to content

Commit 91e7495

Browse files
Update: New Tests (#35)
* Update pom.xml * fix: response id * Create TestU2F.java * Fix: u2f optional headers * update existing tests * update webauthn test to validateCheckWebauthn * Create TestGetTokenInfo * update and format tests * update tests add new tests * Update tests * some updates for the comments * rm IPILogger and use PILogImplementation() * formatting * Update TestTriggerChallenge.java * Update TestTriggerChallenge.java + only hotp + testWrongServerURL + testNoUsername * Update TestGetTokenInfo and TestRollout * rm redundant tests * Add another case for validateCheckSerial * Add error case for TestValidateCheck + Update TestValidateCheckSerial + rm TestErrors * rm pollingIntervals * Update TestWebAuthn + rm redundant TestServiceAccount * Create TestPollTransaction.java * Update TestU2F + update TestPollTransaction + update TestWebAuthn * TestValidateCheck add tearDown Co-authored-by: Nils Behlen <29949516+nilsbehlen@users.noreply.github.com>
1 parent e36c1ff commit 91e7495

20 files changed

Lines changed: 1099 additions & 1023 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ target/
33
sdk-java.iml
44
dependency-reduced-pom.xml
55
*.iml
6+
/src/test/java/org/privacyidea/TestBuildHelper.java

pom.xml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<artifactId>maven-surefire-plugin</artifactId>
2121
<version>2.12.4</version>
2222
<configuration>
23-
<skipTests>true</skipTests>
23+
<skipTests>false</skipTests>
2424
</configuration>
2525
</plugin>
2626

@@ -81,30 +81,15 @@
8181
<dependency>
8282
<groupId>org.mock-server</groupId>
8383
<artifactId>mockserver-junit-rule</artifactId>
84-
<version>5.12.0</version>
84+
<version>5.13.0</version>
8585
<scope>test</scope>
8686
</dependency>
8787

8888
<dependency>
8989
<groupId>org.slf4j</groupId>
9090
<artifactId>slf4j-simple</artifactId>
9191
<version>1.7.36</version>
92-
</dependency>
93-
94-
<!-- Needed for MockServer if JDK >=16 -->
95-
<dependency>
96-
<groupId>org.bouncycastle</groupId>
97-
<artifactId>bcprov-jdk15on</artifactId>
98-
<version>1.70</version>
99-
<scope>test</scope>
100-
</dependency>
101-
102-
<dependency>
103-
<groupId>org.bouncycastle</groupId>
104-
<artifactId>bcpkix-jdk15on</artifactId>
105-
<version>1.70</version>
10692
<scope>test</scope>
10793
</dependency>
108-
10994
</dependencies>
11095
</project>

src/main/java/org/privacyidea/Endpoint.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.net.ssl.TrustManager;
2828
import javax.net.ssl.X509TrustManager;
2929

30+
import okhttp3.Call;
3031
import okhttp3.Callback;
3132
import okhttp3.FormBody;
3233
import okhttp3.HttpUrl;
@@ -108,6 +109,7 @@ void sendRequestAsync(String endpoint, Map<String, String> params, Map<String, S
108109
{
109110
privacyIDEA.error("Server url could not be parsed: " + (piconfig.serverURL + endpoint));
110111
// Invoke the callback to terminate the thread that called this method.
112+
// TODO
111113
callback.onFailure(null,
112114
new IOException("Request could not be created because the url could not be parsed"));
113115
return;
@@ -188,4 +190,4 @@ void sendRequestAsync(String endpoint, Map<String, String> params, Map<String, S
188190
//privacyIDEA.log("HEADERS:\n" + request.headers().toString());
189191
client.newCall(request).enqueue(callback);
190192
}
191-
}
193+
}

src/main/java/org/privacyidea/PIConfig.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class PIConfig
2626
String serviceAccountName = "";
2727
String serviceAccountPass = "";
2828
String serviceAccountRealm = "";
29-
List<Integer> pollingIntervals = new ArrayList<>();
3029
boolean disableLog = false;
3130
String userAgent = "";
3231

@@ -35,4 +34,4 @@ public PIConfig(String serverURL, String userAgent)
3534
this.serverURL = serverURL;
3635
this.userAgent = userAgent;
3736
}
38-
}
37+
}

src/main/java/org/privacyidea/PIConstants.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ private PIConstants()
3939
public static final String HEADER_AUTHORIZATION = "Authorization";
4040
public static final String HEADER_USER_AGENT = "User-Agent";
4141

42-
// Will be used if single value from config cannot be parsed
43-
public static final int DEFAULT_POLLING_INTERVAL = 1;
44-
// Will be used if no intervals are specified
45-
public static final List<Integer> DEFAULT_POLLING_ARRAY = Arrays.asList(4, 2, 1, 1, 2);
46-
4742
// TOKEN TYPES
4843
public static final String TOKEN_TYPE_PUSH = "push";
4944
public static final String TOKEN_TYPE_OTP = "otp";

src/main/java/org/privacyidea/PIResponse.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public class PIResponse
5151

5252
public boolean pushAvailable()
5353
{
54-
return multichallenge.stream()
55-
.anyMatch(c -> TOKEN_TYPE_PUSH.equals(c.getType()));
54+
return multichallenge.stream().anyMatch(c -> TOKEN_TYPE_PUSH.equals(c.getType()));
5655
}
5756

5857
/**
@@ -152,8 +151,7 @@ public String mergedSignRequest()
152151
}
153152
if (webAuthnSignRequests.size() == 1)
154153
{
155-
return webAuthnSignRequests.get(0)
156-
.signRequest();
154+
return webAuthnSignRequests.get(0).signRequest();
157155
}
158156

159157
WebAuthn webAuthn = webAuthnSignRequests.get(0);

src/main/java/org/privacyidea/PrivacyIDEA.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.concurrent.Future;
3030
import java.util.concurrent.ThreadPoolExecutor;
3131
import java.util.concurrent.TimeUnit;
32-
import java.util.concurrent.atomic.AtomicBoolean;
3332

3433
import static org.privacyidea.PIConstants.ENDPOINT_AUTH;
3534
import static org.privacyidea.PIConstants.ENDPOINT_POLLTRANSACTION;
@@ -147,6 +146,14 @@ public PIResponse validateCheckSerial(String serial, String otp, Map<String, Str
147146
return this.validateCheckSerial(serial, otp, null, headers);
148147
}
149148

149+
/**
150+
* @see PrivacyIDEA#validateCheckSerial(String, String, String, Map)
151+
*/
152+
public PIResponse validateCheckSerial(String serial, String otp, String transactionId)
153+
{
154+
return this.validateCheckSerial(serial, otp, transactionId, Collections.emptyMap());
155+
}
156+
150157
/**
151158
* Send a request to /validate/check with the serial rather than the username to identify the token.
152159
*
@@ -185,15 +192,14 @@ public PIResponse validateCheckWebAuthn(String user, String transactionId, Strin
185192
*
186193
* @param user username
187194
* @param transactionId transactionId
188-
* @param webAuthnSignResponse the WebAuthnSignResponse as returned from the
195+
* @param webAuthnSignResponse the WebAuthnSignResponse as returned from the browser
189196
* @param origin server name that was used for
190197
* @param headers optional headers for the request
191198
* @return PIResponse or null if error
192199
*/
193200
public PIResponse validateCheckWebAuthn(String user, String transactionId, String webAuthnSignResponse,
194201
String origin, Map<String, String> headers)
195202
{
196-
197203
Map<String, String> params = new LinkedHashMap<>();
198204
// Standard validateCheck data
199205
params.put(USER, user);
@@ -213,12 +219,20 @@ public PIResponse validateCheckWebAuthn(String user, String transactionId, Strin
213219
return this.parser.parsePIResponse(response);
214220
}
215221

222+
/**
223+
* @see PrivacyIDEA#validateCheckU2F(String, String, String, Map)
224+
*/
225+
public PIResponse validateCheckU2F(String user, String transactionId, String signResponse)
226+
{
227+
return this.validateCheckU2F(user, transactionId, signResponse, Collections.emptyMap());
228+
}
229+
216230
/**
217231
* Sends a request to /validate/check with the data required to authenticate a U2F token.
218232
*
219233
* @param user username
220234
* @param transactionId transactionId
221-
* @param u2fSignResponse the U2F Sign Response as returned from the
235+
* @param u2fSignResponse the U2F Sign Response as returned from the browser
222236
* @return PIResponse or null if error
223237
*/
224238
public PIResponse validateCheckU2F(String user, String transactionId, String u2fSignResponse,
@@ -549,7 +563,6 @@ public static class Builder
549563
private String serviceAccountPass = "";
550564
private String serviceAccountRealm = "";
551565
private String userAgent = "";
552-
private List<Integer> pollingIntervals = Collections.singletonList(1);
553566
private IPILogger logger = null;
554567
private boolean disableLog = false;
555568
private IPISimpleLogger simpleLogBridge = null;
@@ -641,19 +654,6 @@ public Builder serviceRealm(String serviceAccountRealm)
641654
return this;
642655
}
643656

644-
/**
645-
* Set the intervals at which the polling is done when using asyncPollTransaction.
646-
* The last number will be repeated if the end of the list is reached.
647-
*
648-
* @param intervals list of integers that represent seconds
649-
* @return Builder
650-
*/
651-
public Builder pollingIntervals(List<Integer> intervals)
652-
{
653-
this.pollingIntervals = intervals;
654-
return this;
655-
}
656-
657657
/**
658658
* Disable logging completely regardless of any set loggers.
659659
*
@@ -673,9 +673,8 @@ public PrivacyIDEA build()
673673
configuration.serviceAccountName = serviceAccountName;
674674
configuration.serviceAccountPass = serviceAccountPass;
675675
configuration.serviceAccountRealm = serviceAccountRealm;
676-
configuration.pollingIntervals = pollingIntervals;
677676
configuration.disableLog = disableLog;
678677
return new PrivacyIDEA(configuration, logger, simpleLogBridge);
679678
}
680679
}
681-
}
680+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.privacyidea;
2+
3+
public class PILogImplementation implements IPILogger
4+
{
5+
@Override
6+
public void log(String message)
7+
{
8+
System.out.println(message);
9+
}
10+
11+
@Override
12+
public void error(String message)
13+
{
14+
System.out.println(message);
15+
}
16+
17+
@Override
18+
public void log(Throwable t)
19+
{
20+
t.printStackTrace();
21+
}
22+
23+
@Override
24+
public void error(Throwable t)
25+
{
26+
t.printStackTrace();
27+
}
28+
}

0 commit comments

Comments
 (0)