Skip to content

Commit 4c47266

Browse files
authored
Merge pull request #108 from Yubico/spotless
Set up Spotless with google-java-format
2 parents bcf46d9 + 3262eae commit 4c47266

File tree

151 files changed

+9443
-9508
lines changed

Some content is hidden

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

151 files changed

+9443
-9508
lines changed

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ buildscript {
44
}
55
dependencies {
66
classpath 'com.cinnober.gradle:semver-git:2.5.0'
7+
classpath 'com.diffplug.spotless:spotless-plugin-gradle:5.11.0'
78
}
89
}
910
plugins {
@@ -63,6 +64,7 @@ allprojects {
6364
ext.dirtyMarker = "-DIRTY"
6465

6566
apply plugin: 'com.cinnober.gradle.semver-git'
67+
apply plugin: 'com.diffplug.spotless'
6668
apply plugin: 'idea'
6769

6870
group = 'com.yubico'
@@ -91,6 +93,13 @@ subprojects {
9193

9294
maven { url "https://repo.maven.apache.org/maven2" }
9395
}
96+
97+
spotless {
98+
java {
99+
googleJavaFormat()
100+
}
101+
}
102+
tasks.check.dependsOn spotlessCheck
94103
}
95104

96105
allprojects {

doc/development.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ and the `webauthn-server-core-minimal` module is hosted in `webauthn-server-core
1414
We intend to eliminate the `webauthn-server-core-bundle` subproject in the next major version release,
1515
and return the current `webauthn-server-core-minimal` module to the `webauthn-server-core` module name.
1616
This naming inconsistency should be fixed along with this.
17+
18+
19+
Code formatting
20+
---
21+
22+
Use `./gradlew spotlessApply` to run the automatic code formatter.
23+
You can also run it in continuous mode as `./gradlew --continuous spotlessApply`
24+
to reformat whenever a file changes.

test-dependent-projects/java-dep-webauthn-server-attestation/src/main/java/com/yubico/test/compilability/ThisShouldCompile.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77

88
public class ThisShouldCompile {
99

10-
public AttestationResolver getResolver() {
11-
return new AttestationResolver() {
12-
@Override
13-
public Optional<com.yubico.webauthn.attestation.Attestation> resolve(X509Certificate attestationCertificate, List<X509Certificate> certificateChain) {
14-
return Optional.empty();
15-
}
16-
17-
@Override
18-
public com.yubico.webauthn.attestation.Attestation untrustedFromCertificate(X509Certificate attestationCertificate) {
19-
return null;
20-
}
21-
};
22-
}
10+
public AttestationResolver getResolver() {
11+
return new AttestationResolver() {
12+
@Override
13+
public Optional<com.yubico.webauthn.attestation.Attestation> resolve(
14+
X509Certificate attestationCertificate, List<X509Certificate> certificateChain) {
15+
return Optional.empty();
16+
}
2317

18+
@Override
19+
public com.yubico.webauthn.attestation.Attestation untrustedFromCertificate(
20+
X509Certificate attestationCertificate) {
21+
return null;
22+
}
23+
};
24+
}
2425
}
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
11
package com.yubico.webauthn.attestation;
22

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertTrue;
5+
36
import java.io.IOException;
47
import java.net.URL;
58
import java.util.Enumeration;
69
import java.util.NoSuchElementException;
710
import java.util.jar.Manifest;
811
import org.junit.Test;
912

10-
import static org.junit.Assert.assertEquals;
11-
import static org.junit.Assert.assertTrue;
12-
1313
public class ManifestInfoTest {
1414

15-
private static String lookup(String key) throws IOException {
16-
final Enumeration<URL> resources = AttestationResolver.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
17-
18-
while (resources.hasMoreElements()) {
19-
final URL resource = resources.nextElement();
20-
final Manifest manifest = new Manifest(resource.openStream());
21-
if ("java-webauthn-server-attestation".equals(manifest.getMainAttributes().getValue("Implementation-Id"))) {
22-
return manifest.getMainAttributes().getValue(key);
23-
}
24-
}
25-
throw new NoSuchElementException("Could not find \"" + key + "\" in manifest.");
26-
}
27-
28-
@Test
29-
public void standardImplementationPropertiesAreSet() throws IOException {
30-
assertTrue(lookup("Implementation-Title").contains("attestation"));
31-
assertTrue(lookup("Implementation-Version").matches("^\\d+\\.\\d+\\.\\d+(-.*)?"));
32-
assertEquals("Yubico", lookup("Implementation-Vendor"));
15+
private static String lookup(String key) throws IOException {
16+
final Enumeration<URL> resources =
17+
AttestationResolver.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
18+
19+
while (resources.hasMoreElements()) {
20+
final URL resource = resources.nextElement();
21+
final Manifest manifest = new Manifest(resource.openStream());
22+
if ("java-webauthn-server-attestation"
23+
.equals(manifest.getMainAttributes().getValue("Implementation-Id"))) {
24+
return manifest.getMainAttributes().getValue(key);
25+
}
3326
}
34-
35-
@Test
36-
public void customImplementationPropertiesAreSet() throws IOException {
37-
assertTrue(lookup("Git-Commit").matches("^[a-f0-9]{40}$"));
38-
}
39-
27+
throw new NoSuchElementException("Could not find \"" + key + "\" in manifest.");
28+
}
29+
30+
@Test
31+
public void standardImplementationPropertiesAreSet() throws IOException {
32+
assertTrue(lookup("Implementation-Title").contains("attestation"));
33+
assertTrue(lookup("Implementation-Version").matches("^\\d+\\.\\d+\\.\\d+(-.*)?"));
34+
assertEquals("Yubico", lookup("Implementation-Vendor"));
35+
}
36+
37+
@Test
38+
public void customImplementationPropertiesAreSet() throws IOException {
39+
assertTrue(lookup("Git-Commit").matches("^[a-f0-9]{40}$"));
40+
}
4041
}
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,75 @@
11
package com.yubico.webauthn;
22

3+
import static org.junit.Assert.assertTrue;
4+
35
import COSE.CoseException;
46
import com.yubico.webauthn.data.AttestationObject;
57
import com.yubico.webauthn.data.RelyingPartyIdentity;
68
import java.io.IOException;
79
import java.security.NoSuchAlgorithmException;
8-
import java.security.PublicKey;
10+
import java.security.Security;
911
import java.security.spec.InvalidKeySpecException;
12+
import java.util.Arrays;
1013
import org.junit.Test;
1114
import org.mockito.Mockito;
1215

13-
import java.security.Security;
14-
import java.util.Arrays;
15-
16-
import static org.junit.Assert.assertTrue;
17-
import static org.junit.Assert.fail;
18-
1916
/**
20-
* Test that the BouncyCastle provider is not loaded by default
21-
* when depending on the <code>webauthn-server-core-minimal</code> package.
17+
* Test that the BouncyCastle provider is not loaded by default when depending on the <code>
18+
* webauthn-server-core-minimal</code> package.
2219
*
23-
* Motivation: https://github.com/Yubico/java-webauthn-server/issues/97
20+
* <p>Motivation: https://github.com/Yubico/java-webauthn-server/issues/97
2421
*/
2522
public class BouncyCastleProviderPresenceTest {
2623

27-
@Test(expected = ClassNotFoundException.class)
28-
public void bouncyCastleProviderIsNotInClasspath() throws ClassNotFoundException {
29-
Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
30-
}
24+
@Test(expected = ClassNotFoundException.class)
25+
public void bouncyCastleProviderIsNotInClasspath() throws ClassNotFoundException {
26+
Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
27+
}
3128

32-
@Test
33-
public void bouncyCastleProviderIsNotLoadedByDefault() {
34-
assertTrue(
35-
Arrays.stream(Security.getProviders())
36-
.noneMatch(prov -> prov.getName().toLowerCase().contains("bouncy"))
37-
);
38-
}
29+
@Test
30+
public void bouncyCastleProviderIsNotLoadedByDefault() {
31+
assertTrue(
32+
Arrays.stream(Security.getProviders())
33+
.noneMatch(prov -> prov.getName().toLowerCase().contains("bouncy")));
34+
}
3935

40-
@Test
41-
public void bouncyCastleProviderIsNotLoadedAfterInstantiatingRelyingParty() {
42-
// The RelyingParty constructor has the possible side-effect of loading the BouncyCastle provider
43-
RelyingParty.builder()
44-
.identity(RelyingPartyIdentity.builder().id("foo").name("foo").build())
45-
.credentialRepository(Mockito.mock(CredentialRepository.class))
46-
.build();
36+
@Test
37+
public void bouncyCastleProviderIsNotLoadedAfterInstantiatingRelyingParty() {
38+
// The RelyingParty constructor has the possible side-effect of loading the BouncyCastle
39+
// provider
40+
RelyingParty.builder()
41+
.identity(RelyingPartyIdentity.builder().id("foo").name("foo").build())
42+
.credentialRepository(Mockito.mock(CredentialRepository.class))
43+
.build();
4744

48-
assertTrue(
49-
Arrays.stream(Security.getProviders())
50-
.noneMatch(prov ->
45+
assertTrue(
46+
Arrays.stream(Security.getProviders())
47+
.noneMatch(
48+
prov ->
5149
prov.getName().equals("BC")
52-
|| prov.getClass().getCanonicalName().contains("bouncy")
53-
));
54-
}
50+
|| prov.getClass().getCanonicalName().contains("bouncy")));
51+
}
5552

56-
@Test
57-
public void bouncyCastleProviderIsNotLoadedAfterAttemptingToLoadEddsaKey() throws IOException, CoseException, NoSuchAlgorithmException, InvalidKeySpecException {
58-
try {
59-
WebAuthnCodecs.importCosePublicKey(
60-
new AttestationObject(RegistrationTestData.Packed$.MODULE$.BasicAttestationEdDsa().attestationObject())
61-
.getAuthenticatorData()
62-
.getAttestedCredentialData()
63-
.get()
64-
.getCredentialPublicKey()
65-
);
66-
} catch (NoSuchAlgorithmException e) {
67-
// OK
68-
}
69-
70-
assertTrue(
71-
Arrays.stream(Security.getProviders())
72-
.noneMatch(prov ->
73-
prov.getName().equals("BC")
74-
|| prov.getClass().getCanonicalName().contains("bouncy")
75-
));
53+
@Test
54+
public void bouncyCastleProviderIsNotLoadedAfterAttemptingToLoadEddsaKey()
55+
throws IOException, CoseException, NoSuchAlgorithmException, InvalidKeySpecException {
56+
try {
57+
WebAuthnCodecs.importCosePublicKey(
58+
new AttestationObject(
59+
RegistrationTestData.Packed$.MODULE$.BasicAttestationEdDsa().attestationObject())
60+
.getAuthenticatorData()
61+
.getAttestedCredentialData()
62+
.get()
63+
.getCredentialPublicKey());
64+
} catch (NoSuchAlgorithmException e) {
65+
// OK
7666
}
7767

68+
assertTrue(
69+
Arrays.stream(Security.getProviders())
70+
.noneMatch(
71+
prov ->
72+
prov.getName().equals("BC")
73+
|| prov.getClass().getCanonicalName().contains("bouncy")));
74+
}
7875
}

test-dependent-projects/java-dep-webauthn-server-core/src/main/java/com/yubico/test/compilability/ThisShouldCompile.java

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,50 @@
1212

1313
public class ThisShouldCompile {
1414

15-
public RelyingParty getRp() {
16-
return RelyingParty.builder()
17-
.identity(RelyingPartyIdentity.builder()
18-
.id("localhost")
19-
.name("Example RP")
20-
.build())
21-
.credentialRepository(new CredentialRepository() {
22-
@Override public Set<PublicKeyCredentialDescriptor> getCredentialIdsForUsername(String username) { return null; }
23-
@Override public Optional<ByteArray> getUserHandleForUsername(String username) { return Optional.empty(); }
24-
@Override public Optional<String> getUsernameForUserHandle(ByteArray userHandle) { return Optional.empty(); }
25-
@Override public Optional<RegisteredCredential> lookup(ByteArray credentialId, ByteArray userHandle) { return Optional.empty(); }
26-
@Override public Set<RegisteredCredential> lookupAll(ByteArray credentialId) { return null; }
27-
})
28-
.build();
29-
}
30-
31-
public ByteArray getByteArray() {
32-
ByteArray a = new ByteArray(new byte[] {1, 2, 3, 4});
33-
byte[] b = a.getBytes();
34-
return a;
35-
}
36-
37-
public PublicKeyCredentialType getPublicKeyCredentialType() {
38-
PublicKeyCredentialType a = PublicKeyCredentialType.PUBLIC_KEY;
39-
String b = a.toJsonString();
40-
return a;
41-
}
15+
public RelyingParty getRp() {
16+
return RelyingParty.builder()
17+
.identity(RelyingPartyIdentity.builder().id("localhost").name("Example RP").build())
18+
.credentialRepository(
19+
new CredentialRepository() {
20+
@Override
21+
public Set<PublicKeyCredentialDescriptor> getCredentialIdsForUsername(
22+
String username) {
23+
return null;
24+
}
4225

26+
@Override
27+
public Optional<ByteArray> getUserHandleForUsername(String username) {
28+
return Optional.empty();
29+
}
4330

31+
@Override
32+
public Optional<String> getUsernameForUserHandle(ByteArray userHandle) {
33+
return Optional.empty();
34+
}
35+
36+
@Override
37+
public Optional<RegisteredCredential> lookup(
38+
ByteArray credentialId, ByteArray userHandle) {
39+
return Optional.empty();
40+
}
41+
42+
@Override
43+
public Set<RegisteredCredential> lookupAll(ByteArray credentialId) {
44+
return null;
45+
}
46+
})
47+
.build();
48+
}
49+
50+
public ByteArray getByteArray() {
51+
ByteArray a = new ByteArray(new byte[] {1, 2, 3, 4});
52+
byte[] b = a.getBytes();
53+
return a;
54+
}
55+
56+
public PublicKeyCredentialType getPublicKeyCredentialType() {
57+
PublicKeyCredentialType a = PublicKeyCredentialType.PUBLIC_KEY;
58+
String b = a.toJsonString();
59+
return a;
60+
}
4461
}

0 commit comments

Comments
 (0)