Skip to content

Commit afbf86e

Browse files
authored
Merge pull request #109 from Yubico/spotless-scala
Set up Scala code formatting
2 parents 4c47266 + 45b5440 commit afbf86e

File tree

47 files changed

+6219
-3207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+6219
-3207
lines changed

build.gradle

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ buildscript {
55
dependencies {
66
classpath 'com.cinnober.gradle:semver-git:2.5.0'
77
classpath 'com.diffplug.spotless:spotless-plugin-gradle:5.11.0'
8+
classpath 'io.github.cosmicsilence:gradle-scalafix:0.1.8'
89
}
910
}
1011
plugins {
@@ -98,6 +99,9 @@ subprojects {
9899
java {
99100
googleJavaFormat()
100101
}
102+
scala {
103+
scalafmt('2.6.3').configFile(rootProject.file('scalafmt.conf'))
104+
}
101105
}
102106
tasks.check.dependsOn spotlessCheck
103107
}
@@ -124,14 +128,23 @@ String getGitCommit() {
124128

125129
subprojects { project ->
126130

127-
if (project.hasProperty('sourceCompatibility')) {
128-
sourceCompatibility = 1.8
129-
targetCompatibility = 1.8
131+
if (project.plugins.hasPlugin('scala')) {
132+
project.scalafix {
133+
configFile = rootProject.file('scalafix.conf')
134+
}
135+
dependencies.scalafix('com.github.liancheng:organize-imports_2.13:0.5.0')
136+
project.tasks.scalafix.dependsOn(project.tasks.spotlessApply)
137+
project.tasks.checkScalafix.dependsOn(project.tasks.spotlessCheck)
138+
project.tasks.spotlessApply.finalizedBy(project.tasks.scalafix)
139+
project.tasks.spotlessCheck.finalizedBy(project.tasks.checkScalafix)
130140
}
131141

132142
tasks.withType(JavaCompile) {
133143
options.encoding = 'UTF-8'
134144
}
145+
tasks.withType(ScalaCompile) {
146+
scalaCompileOptions.additionalParameters = ['-Wunused']
147+
}
135148

136149
tasks.withType(AbstractArchiveTask) {
137150
from(rootProject.file('COPYING'))

scalafix.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
rules = [
2+
OrganizeImports
3+
]
4+
5+
OrganizeImports {
6+
expandRelative = true
7+
removeUnused = true
8+
}

scalafmt.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trailingCommas = multiple
2+
rewrite.rules = [ExpandImportSelectors, SortModifiers]
3+
newlines.avoidForSimpleOverflow = [tooLong]

webauthn-server-attestation/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
plugins {
22
id 'java-library'
33
id 'scala'
4+
id 'io.github.cosmicsilence.scalafix'
45
}
56

67
description = 'Yubico WebAuthn attestation subsystem'
78

89
project.ext.publishMe = true
910

11+
sourceCompatibility = 1.8
12+
targetCompatibility = 1.8
13+
1014
evaluationDependsOn(':webauthn-server-core-minimal')
1115

1216
dependencies {

webauthn-server-attestation/src/test/scala/com/yubico/webauthn/attestation/DeviceIdentificationSpec.scala

Lines changed: 84 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,65 +24,89 @@
2424

2525
package com.yubico.webauthn.attestation
2626

27-
import java.util.Collections
28-
2927
import com.yubico.internal.util.CertificateParser
3028
import com.yubico.internal.util.JacksonCodecs
31-
import com.yubico.webauthn.attestation.resolver.SimpleAttestationResolver
32-
import com.yubico.webauthn.attestation.resolver.SimpleTrustResolver
33-
import com.yubico.webauthn.test.RealExamples
3429
import com.yubico.webauthn.FinishRegistrationOptions
3530
import com.yubico.webauthn.RelyingParty
3631
import com.yubico.webauthn.attestation.Transport.LIGHTNING
3732
import com.yubico.webauthn.attestation.Transport.NFC
3833
import com.yubico.webauthn.attestation.Transport.USB
34+
import com.yubico.webauthn.attestation.resolver.SimpleAttestationResolver
35+
import com.yubico.webauthn.attestation.resolver.SimpleTrustResolver
3936
import com.yubico.webauthn.data.PublicKeyCredentialCreationOptions
4037
import com.yubico.webauthn.data.PublicKeyCredentialParameters
4138
import com.yubico.webauthn.test.Helpers
39+
import com.yubico.webauthn.test.RealExamples
4240
import org.junit.runner.RunWith
4341
import org.scalatest.FunSpec
4442
import org.scalatest.Matchers
4543
import org.scalatestplus.junit.JUnitRunner
4644

45+
import java.util.Collections
4746
import scala.jdk.CollectionConverters._
4847

49-
5048
@RunWith(classOf[JUnitRunner])
5149
class DeviceIdentificationSpec extends FunSpec with Matchers {
5250

5351
def metadataService(metadataJson: String): StandardMetadataService = {
54-
val metadata = Collections.singleton(JacksonCodecs.json().readValue(metadataJson, classOf[MetadataObject]))
52+
val metadata = Collections.singleton(
53+
JacksonCodecs.json().readValue(metadataJson, classOf[MetadataObject])
54+
)
5555
new StandardMetadataService(
56-
new SimpleAttestationResolver(metadata, SimpleTrustResolver.fromMetadata(metadata))
56+
new SimpleAttestationResolver(
57+
metadata,
58+
SimpleTrustResolver.fromMetadata(metadata),
59+
)
5760
)
5861
}
5962

6063
describe("A RelyingParty with the default StandardMetadataService") {
6164

6265
describe("correctly identifies") {
63-
def check(expectedName: String, testData: RealExamples.Example, transports: Set[Transport]): Unit = {
64-
val rp = RelyingParty.builder()
66+
def check(
67+
expectedName: String,
68+
testData: RealExamples.Example,
69+
transports: Set[Transport],
70+
): Unit = {
71+
val rp = RelyingParty
72+
.builder()
6573
.identity(testData.rp)
6674
.credentialRepository(Helpers.CredentialRepository.empty)
6775
.metadataService(new StandardMetadataService())
6876
.build()
6977

70-
val result = rp.finishRegistration(FinishRegistrationOptions.builder()
71-
.request(PublicKeyCredentialCreationOptions.builder()
72-
.rp(testData.rp)
73-
.user(testData.user)
74-
.challenge(testData.attestation.challenge)
75-
.pubKeyCredParams(List(PublicKeyCredentialParameters.ES256).asJava)
76-
.build())
77-
.response(testData.attestation.credential)
78-
.build());
78+
val result = rp.finishRegistration(
79+
FinishRegistrationOptions
80+
.builder()
81+
.request(
82+
PublicKeyCredentialCreationOptions
83+
.builder()
84+
.rp(testData.rp)
85+
.user(testData.user)
86+
.challenge(testData.attestation.challenge)
87+
.pubKeyCredParams(
88+
List(PublicKeyCredentialParameters.ES256).asJava
89+
)
90+
.build()
91+
)
92+
.response(testData.attestation.credential)
93+
.build()
94+
);
7995

80-
result.isAttestationTrusted should be (true)
81-
result.getAttestationMetadata.isPresent should be (true)
82-
result.getAttestationMetadata.get.getDeviceProperties.isPresent should be (true)
83-
result.getAttestationMetadata.get.getDeviceProperties.get().get("displayName") should equal (expectedName)
84-
result.getAttestationMetadata.get.getTransports.isPresent should be (true)
85-
result.getAttestationMetadata.get.getTransports.get.asScala should equal (transports)
96+
result.isAttestationTrusted should be(true)
97+
result.getAttestationMetadata.isPresent should be(true)
98+
result.getAttestationMetadata.get.getDeviceProperties.isPresent should be(
99+
true
100+
)
101+
result.getAttestationMetadata.get.getDeviceProperties
102+
.get()
103+
.get("displayName") should equal(expectedName)
104+
result.getAttestationMetadata.get.getTransports.isPresent should be(
105+
true
106+
)
107+
result.getAttestationMetadata.get.getTransports.get.asScala should equal(
108+
transports
109+
)
86110
}
87111

88112
it("a YubiKey NEO.") {
@@ -98,7 +122,11 @@ class DeviceIdentificationSpec extends FunSpec with Matchers {
98122
check("YubiKey 5 NFC", RealExamples.YubiKey5Nfc, Set(USB, NFC))
99123
}
100124
it("a newer YubiKey 5 NFC.") {
101-
check("YubiKey 5/5C NFC", RealExamples.YubiKey5NfcPost5cNfc, Set(USB, NFC))
125+
check(
126+
"YubiKey 5/5C NFC",
127+
RealExamples.YubiKey5NfcPost5cNfc,
128+
Set(USB, NFC),
129+
)
102130
}
103131
it("a YubiKey 5C NFC.") {
104132
check("YubiKey 5/5C NFC", RealExamples.YubiKey5cNfc, Set(USB, NFC))
@@ -116,21 +144,33 @@ class DeviceIdentificationSpec extends FunSpec with Matchers {
116144
check("Security Key by Yubico", RealExamples.SecurityKey2, Set(USB))
117145
}
118146
it("a Security Key NFC by Yubico.") {
119-
check("Security Key NFC by Yubico", RealExamples.SecurityKeyNfc, Set(USB, NFC))
147+
check(
148+
"Security Key NFC by Yubico",
149+
RealExamples.SecurityKeyNfc,
150+
Set(USB, NFC),
151+
)
120152
}
121153
}
122154
}
123155

124156
describe("The default AttestationResolver") {
125157
describe("successfully identifies") {
126-
def check(expectedName: String, testData: RealExamples.Example, transports: Set[Transport]): Unit = {
158+
def check(
159+
expectedName: String,
160+
testData: RealExamples.Example,
161+
transports: Set[Transport],
162+
): Unit = {
127163
val cert = CertificateParser.parseDer(testData.attestationCert.getBytes)
128-
val resolved = StandardMetadataService.createDefaultAttestationResolver().resolve(cert)
129-
resolved.isPresent should be (true)
130-
resolved.get.getDeviceProperties.isPresent should be (true)
131-
resolved.get.getDeviceProperties.get.get("displayName") should equal (expectedName)
132-
resolved.get.getTransports.isPresent should be (true)
133-
resolved.get.getTransports.get.asScala should equal (transports)
164+
val resolved = StandardMetadataService
165+
.createDefaultAttestationResolver()
166+
.resolve(cert)
167+
resolved.isPresent should be(true)
168+
resolved.get.getDeviceProperties.isPresent should be(true)
169+
resolved.get.getDeviceProperties.get.get("displayName") should equal(
170+
expectedName
171+
)
172+
resolved.get.getTransports.isPresent should be(true)
173+
resolved.get.getTransports.get.asScala should equal(transports)
134174
}
135175

136176
it("a YubiKey NEO.") {
@@ -146,7 +186,11 @@ class DeviceIdentificationSpec extends FunSpec with Matchers {
146186
check("YubiKey 5 NFC", RealExamples.YubiKey5Nfc, Set(USB, NFC))
147187
}
148188
it("a newer YubiKey 5 NFC.") {
149-
check("YubiKey 5/5C NFC", RealExamples.YubiKey5NfcPost5cNfc, Set(USB, NFC))
189+
check(
190+
"YubiKey 5/5C NFC",
191+
RealExamples.YubiKey5NfcPost5cNfc,
192+
Set(USB, NFC),
193+
)
150194
}
151195
it("a YubiKey 5C NFC.") {
152196
check("YubiKey 5/5C NFC", RealExamples.YubiKey5cNfc, Set(USB, NFC))
@@ -164,7 +208,11 @@ class DeviceIdentificationSpec extends FunSpec with Matchers {
164208
check("Security Key by Yubico", RealExamples.SecurityKey2, Set(USB))
165209
}
166210
it("a Security Key NFC by Yubico.") {
167-
check("Security Key NFC by Yubico", RealExamples.SecurityKeyNfc, Set(USB, NFC))
211+
check(
212+
"Security Key NFC by Yubico",
213+
RealExamples.SecurityKeyNfc,
214+
Set(USB, NFC),
215+
)
168216
}
169217
}
170218
}

0 commit comments

Comments
 (0)