-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Yubico/versions
Read all version info from manifest
- Loading branch information
Showing
11 changed files
with
184 additions
and
15 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
40 changes: 40 additions & 0 deletions
40
...hn-server-attestation/src/test/java/com/yubico/webauthn/attestation/ManifestInfoTest.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,40 @@ | ||
package com.yubico.webauthn.attestation; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Enumeration; | ||
import java.util.NoSuchElementException; | ||
import java.util.jar.Manifest; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class ManifestInfoTest { | ||
|
||
private static String lookup(String key) throws IOException { | ||
final Enumeration<URL> resources = AttestationResolver.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); | ||
|
||
while (resources.hasMoreElements()) { | ||
final URL resource = resources.nextElement(); | ||
final Manifest manifest = new Manifest(resource.openStream()); | ||
if ("java-webauthn-server-attestation".equals(manifest.getMainAttributes().getValue("Implementation-Id"))) { | ||
return manifest.getMainAttributes().getValue(key); | ||
} | ||
} | ||
throw new NoSuchElementException("Could not find \"" + key + "\" in manifest."); | ||
} | ||
|
||
@Test | ||
public void standardImplementationPropertiesAreSet() throws IOException { | ||
assertTrue(lookup("Implementation-Title").contains("attestation")); | ||
assertTrue(lookup("Implementation-Version").matches("^\\d+\\.\\d+\\.\\d+(-.*)?")); | ||
assertEquals("Yubico", lookup("Implementation-Vendor")); | ||
} | ||
|
||
@Test | ||
public void customImplementationPropertiesAreSet() throws IOException { | ||
assertTrue(lookup("Git-Commit").matches("^[a-f0-9]{40}$")); | ||
} | ||
|
||
} |
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
58 changes: 58 additions & 0 deletions
58
...ava-dep-webauthn-server-core/src/test/java/com/yubico/webauthn/meta/ManifestInfoTest.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,58 @@ | ||
package com.yubico.webauthn.meta; | ||
|
||
import com.yubico.webauthn.RelyingParty; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.time.LocalDate; | ||
import java.util.Enumeration; | ||
import java.util.NoSuchElementException; | ||
import java.util.jar.Manifest; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class ManifestInfoTest { | ||
|
||
private static String lookup(String key) throws IOException { | ||
final Enumeration<URL> resources = RelyingParty.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); | ||
|
||
while (resources.hasMoreElements()) { | ||
final URL resource = resources.nextElement(); | ||
final Manifest manifest = new Manifest(resource.openStream()); | ||
if ("java-webauthn-server".equals(manifest.getMainAttributes().getValue("Implementation-Id"))) { | ||
return manifest.getMainAttributes().getValue(key); | ||
} | ||
} | ||
throw new NoSuchElementException("Could not find \"" + key + "\" in manifest."); | ||
} | ||
|
||
@Test | ||
public void standardSpecPropertiesAreSet() throws IOException { | ||
assertTrue(lookup("Specification-Title").startsWith("Web Authentication")); | ||
assertTrue(lookup("Specification-Version").startsWith("Level")); | ||
assertEquals("World Wide Web Consortium", lookup("Specification-Vendor")); | ||
} | ||
|
||
|
||
@Test | ||
public void customSpecPropertiesAreSet() throws IOException { | ||
assertTrue(lookup("Specification-Url").startsWith("https://")); | ||
assertTrue(lookup("Specification-Url-Latest").startsWith("https://")); | ||
assertTrue(DocumentStatus.fromString(lookup("Specification-W3c-Status")).isPresent()); | ||
assertTrue(LocalDate.parse(lookup("Specification-Release-Date")).isAfter(LocalDate.of(2019, 3, 3))); | ||
} | ||
|
||
@Test | ||
public void standardImplementationPropertiesAreSet() throws IOException { | ||
assertTrue(lookup("Implementation-Title").contains("Web Authentication")); | ||
assertTrue(lookup("Implementation-Version").matches("^\\d+\\.\\d+\\.\\d+(-.*)?")); | ||
assertEquals("Yubico", lookup("Implementation-Vendor")); | ||
} | ||
|
||
@Test | ||
public void customImplementationPropertiesAreSet() throws IOException { | ||
assertTrue(lookup("Git-Commit").matches("^[a-f0-9]{40}$")); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...java-dep-webauthn-server-core/src/test/java/com/yubico/webauthn/meta/VersionInfoTest.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,42 @@ | ||
package com.yubico.webauthn.meta; | ||
|
||
import java.time.LocalDate; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Since this depends on the manifest of the core jar, and the manifest is build by Gradle, this test is likely to fail | ||
* when run in an IDE. It works as expected when run via Gradle. | ||
*/ | ||
public class VersionInfoTest { | ||
|
||
final VersionInfo versionInfo = VersionInfo.getInstance(); | ||
|
||
@Test | ||
public void specPropertiesAreSet() { | ||
final Specification spec = versionInfo.getSpecification(); | ||
assertTrue(spec.getLatestVersionUrl().toExternalForm().startsWith("https://")); | ||
assertTrue(spec.getUrl().toExternalForm().startsWith("https://")); | ||
assertTrue(spec.getReleaseDate().isAfter(LocalDate.of(2019, 3, 3))); | ||
assertNotNull(spec.getStatus()); | ||
} | ||
|
||
@Test | ||
public void implementationPropertiesAreSet() { | ||
final Implementation impl = versionInfo.getImplementation(); | ||
assertTrue(impl.getSourceCodeUrl().toExternalForm().startsWith("https://")); | ||
assertTrue(impl.getVersion().matches("^\\d+\\.\\d+\\.\\d+(-.*)?")); | ||
assertTrue(impl.getGitCommit().matches("^[a-f0-9]{40}$")); | ||
} | ||
|
||
@Test | ||
public void majorVersionIsAtLeast1() { | ||
final String version = versionInfo.getImplementation().getVersion(); | ||
String[] splits = version.split("\\."); | ||
final int majorVersion = Integer.parseInt(splits[0]); | ||
assertTrue(majorVersion >= 1); | ||
} | ||
|
||
} |
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
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