Skip to content

Commit d68f1f8

Browse files
committed
adds more tests
1 parent 66597c2 commit d68f1f8

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

u2f-ref-code/java/src/com/google/u2f/server/impl/U2FServerReferenceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ public SecurityKeyData processRegistrationResponse(RegistrationResponse registra
127127
List<Transports> transports = null;
128128
try {
129129
transports = U2fAttestation.Parse(attestationCertificate).getTransports();
130-
} catch (CertificateParsingException e1) {
131-
Log.warning("Could not parse transports extension " + e1.getMessage());
130+
} catch (CertificateParsingException e) {
131+
Log.warning("Could not parse transports extension " + e.getMessage());
132132
}
133133

134134
Log.info("-- Parsed rawRegistrationResponse --");
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.google.u2f.server.impl.attestation.u2f;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
6+
7+
import com.google.u2f.TestVectors;
8+
import com.google.u2f.server.data.SecurityKeyData.Transports;
9+
10+
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
import org.junit.runners.JUnit4;
13+
14+
import java.security.cert.CertificateParsingException;
15+
import java.util.List;
16+
17+
/**
18+
* Unit tests for {@link U2fAttestation}
19+
*/
20+
@RunWith(JUnit4.class)
21+
public class U2fAttestationTest extends TestVectors {
22+
@Test
23+
public void testValidCertOneTransport() throws Exception {
24+
U2fAttestation attestation = U2fAttestation.Parse(TRUSTED_CERTIFICATE_ONE_TRANSPORT);
25+
26+
assertNotNull(attestation);
27+
List<Transports> transports = attestation.getTransports();
28+
assertEquals(1, transports.size());
29+
assertTrue(transports.contains(Transports.BLUETOOTH_BREDR));
30+
}
31+
32+
@Test(expected = CertificateParsingException.class)
33+
public void testMalformedCert() throws Exception {
34+
U2fAttestation.Parse(TRUSTED_CERTIFICATE_MALFORMED_TRANSPORTS_EXTENSION);
35+
}
36+
37+
@Test(expected = CertificateParsingException.class)
38+
public void testValidCertNoTransports() throws Exception {
39+
U2fAttestation.Parse(TRUSTED_CERTIFICATE_2);
40+
}
41+
42+
@Test
43+
public void testValidCertMultipleTransports() throws Exception {
44+
U2fAttestation attestation = U2fAttestation.Parse(TRUSTED_CERTIFICATE_MULTIPLE_TRANSPORTS);
45+
46+
assertNotNull(attestation);
47+
List<Transports> transports = attestation.getTransports();
48+
assertEquals(3, transports.size());
49+
assertTrue(transports.contains(Transports.BLUETOOTH_BREDR));
50+
assertTrue(transports.contains(Transports.BLUETOOTH_LOW_ENERGY));
51+
assertTrue(transports.contains(Transports.NFC));
52+
}
53+
}

0 commit comments

Comments
 (0)