-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for parseFidoSerNumExtenstion
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...rver-attestation/src/test/scala/com/yubico/webauthn/attestation/CertificateUtilSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.yubico.webauthn.attestation | ||
|
||
import com.yubico.webauthn.TestAuthenticator | ||
import com.yubico.webauthn.data.ByteArray | ||
import org.bouncycastle.asn1.DEROctetString | ||
import org.bouncycastle.asn1.x500.X500Name | ||
import org.junit.runner.RunWith | ||
import org.scalatest.funspec.AnyFunSpec | ||
import org.scalatest.matchers.should.Matchers.convertToAnyShouldWrapper | ||
import org.scalatestplus.junit.JUnitRunner | ||
|
||
import java.security.cert.X509Certificate | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class CertificateUtilSpec extends AnyFunSpec { | ||
describe("parseFidoSerNumExtension") { | ||
val idFidoGenCeSernum = "1.3.6.1.4.1.45724.1.1.2" | ||
it("should correctly parse the serial number from a valid certificate with the id-fido-gen-ce-sernum extension.") { | ||
val goodCert: X509Certificate = TestAuthenticator | ||
.generateAttestationCertificate( | ||
name = new X500Name( | ||
"O=Yubico, C=SE, OU=Authenticator Attestation" | ||
), | ||
extensions = List( | ||
( | ||
idFidoGenCeSernum, | ||
false, | ||
new DEROctetString(Array[Byte](0, 1, 2, 3)), | ||
) | ||
), | ||
) | ||
._1 | ||
|
||
val result = new ByteArray( | ||
CertificateUtil | ||
.parseFidoSerNumExtension(goodCert) | ||
.get | ||
) | ||
result.shouldEqual(ByteArray.fromHex("00010203")); | ||
} | ||
|
||
} | ||
|
||
} |