-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
233 additions
and
30 deletions.
There are no files selected for viewing
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
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
4 changes: 4 additions & 0 deletions
4
webauthn-server-core/src/main/java/com/yubico/webauthn/data/AuthenticatorTransportTest.java
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,4 @@ | ||
package com.yubico.webauthn.data; | ||
|
||
public class AuthenticatorTransportTest { | ||
} |
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
82 changes: 82 additions & 0 deletions
82
...uthn-server-core/src/test/scala/com/yubico/webauthn/data/AuthenticatorTransportSpec.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,82 @@ | ||
// Copyright (c) 2019, Yubico AB | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are met: | ||
// | ||
// 1. Redistributions of source code must retain the above copyright notice, this | ||
// list of conditions and the following disclaimer. | ||
// | ||
// 2. Redistributions in binary form must reproduce the above copyright notice, | ||
// this list of conditions and the following disclaimer in the documentation | ||
// and/or other materials provided with the distribution. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
package com.yubico.webauthn.data | ||
|
||
import org.junit.runner.RunWith | ||
import org.scalatest.FunSpec | ||
import org.scalatest.Matchers | ||
import org.scalatest.junit.JUnitRunner | ||
import org.scalatest.prop.GeneratorDrivenPropertyChecks | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class AuthenticatorTransportSpec extends FunSpec with Matchers with GeneratorDrivenPropertyChecks { | ||
|
||
describe("The AuthenticatorTransport type") { | ||
|
||
describe("has the constant") { | ||
it("USB.") { | ||
AuthenticatorTransport.USB.getId should equal ("usb") | ||
} | ||
it("NFC.") { | ||
AuthenticatorTransport.NFC.getId should equal ("nfc") | ||
} | ||
it("BLE.") { | ||
AuthenticatorTransport.BLE.getId should equal ("ble") | ||
} | ||
it("INTERNAL.") { | ||
AuthenticatorTransport.INTERNAL.getId should equal ("internal") | ||
} | ||
} | ||
|
||
it("has a values() function.") { | ||
AuthenticatorTransport.values().length should equal (4) | ||
AuthenticatorTransport.values() should not be theSameInstanceAs (AuthenticatorTransport.values()) | ||
} | ||
|
||
it("has a valueOf(name) function mimicking that of an enum type.") { | ||
AuthenticatorTransport.valueOf("USB") should be theSameInstanceAs AuthenticatorTransport.USB | ||
AuthenticatorTransport.valueOf("NFC") should be theSameInstanceAs AuthenticatorTransport.NFC | ||
AuthenticatorTransport.valueOf("BLE") should be theSameInstanceAs AuthenticatorTransport.BLE | ||
AuthenticatorTransport.valueOf("INTERNAL") should be theSameInstanceAs AuthenticatorTransport.INTERNAL | ||
an[IllegalArgumentException] should be thrownBy { | ||
AuthenticatorTransport.valueOf("foo") | ||
} | ||
} | ||
|
||
it("can contain any value.") { | ||
forAll { transport: String => | ||
AuthenticatorTransport.of(transport).getId should equal (transport) | ||
} | ||
} | ||
|
||
it("has an of(id) function which returns the corresponding constant instance if applicable, and a new instance otherwise.") { | ||
for { constant <- AuthenticatorTransport.values() } { | ||
AuthenticatorTransport.of(constant.getId) should equal (constant) | ||
AuthenticatorTransport.of(constant.getId) should be theSameInstanceAs constant | ||
AuthenticatorTransport.of(constant.getId.toUpperCase) should not equal constant | ||
} | ||
} | ||
} | ||
} |
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
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
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
57 changes: 57 additions & 0 deletions
57
yubico-util/src/test/scala/com/yubico/internal/util/ComparableUtilSpec.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,57 @@ | ||
package com.yubico.internal.util | ||
|
||
import org.junit.runner.RunWith | ||
import org.scalacheck.Gen | ||
import org.scalacheck.Arbitrary.arbitrary | ||
import org.scalatest.junit.JUnitRunner | ||
import org.scalatest.prop.GeneratorDrivenPropertyChecks | ||
import org.scalatest.FunSpec | ||
import org.scalatest.Matchers | ||
|
||
import _root_.scala.collection.JavaConverters._ | ||
|
||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class ComparableUtilSpec extends FunSpec with Matchers with GeneratorDrivenPropertyChecks { | ||
|
||
def sameSizeSets[T](implicit gent: Gen[T]): Gen[(Set[T], Set[T])] = for { | ||
n: Int <- Gen.chooseNum(0, 100) | ||
a: Set[T] <- Gen.containerOfN[Set, T](n, gent) | ||
b: Set[T] <- Gen.containerOfN[Set, T](n, gent) | ||
} yield (a, b) | ||
|
||
def toJava(s: Set[Int]): java.util.SortedSet[Integer] = | ||
new java.util.TreeSet[Integer](s.map(new Integer(_)).asJava) | ||
|
||
describe("compareComparableSets") { | ||
it("sorts differently-sized sets in order of cardinality.") { | ||
forAll { (a: Set[Int], b: Set[Int]) => | ||
whenever(a.size != b.size) { | ||
val comp = ComparableUtil.compareComparableSets(toJava(a), toJava(b)) | ||
if (a.size < b.size) { | ||
comp should be < 0 | ||
} else { | ||
comp should be > 0 | ||
} | ||
} | ||
} | ||
} | ||
|
||
it("sorts same-sized sets like sorted lists.") { | ||
forAll(sameSizeSets(arbitrary[Int])) { case (a, b) => | ||
whenever(a.size == b.size) { | ||
val comp = ComparableUtil.compareComparableSets(toJava(a), toJava(b)) | ||
|
||
val aList = a.toList.sorted | ||
val bList = b.toList.sorted | ||
val firstDiff = aList.zip(bList).find({ case (a, b) => a != b }) | ||
firstDiff match { | ||
case Some((a, b)) => comp should equal (a.compareTo(b)) | ||
case None => comp should equal (0) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |