|
| 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