summaryrefslogtreecommitdiffstats
path: root/athenz-identity-provider-service/src/test/java
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2019-09-20 14:41:33 +0200
committerMartin Polden <mpolden@mpolden.no>2019-09-20 15:08:41 +0200
commite9caf7649d7bb235cdec15cb9593b9a0eac29c28 (patch)
treee309ed7d52d46c145127ac2999e7782f7f8c8c1a /athenz-identity-provider-service/src/test/java
parenteb50e5195dab5662a5a9011c0b7ca69ecf8b64c4 (diff)
Implement helper class for creating certificates
Diffstat (limited to 'athenz-identity-provider-service/src/test/java')
-rw-r--r--athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/CertificatesTest.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/CertificatesTest.java b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/CertificatesTest.java
new file mode 100644
index 00000000000..4e306d9a70e
--- /dev/null
+++ b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/ca/CertificatesTest.java
@@ -0,0 +1,33 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.ca;
+
+import com.yahoo.security.KeyAlgorithm;
+import com.yahoo.security.KeyUtils;
+import com.yahoo.test.ManualClock;
+import org.junit.Test;
+
+import java.time.Duration;
+
+import static java.time.temporal.ChronoUnit.SECONDS;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author mpolden
+ */
+public class CertificatesTest {
+
+ @Test
+ public void expiry() {
+ var clock = new ManualClock();
+ var certificates = new Certificates(clock);
+ var csr = CertificateTester.createCsr();
+ var keyPair = KeyUtils.generateKeypair(KeyAlgorithm.EC, 256);
+ var caCertificate = CertificateTester.createCertificate("CA", keyPair);
+ var certificate = certificates.create(csr, caCertificate, keyPair.getPrivate());
+ var now = clock.instant();
+
+ assertEquals(now.minus(Duration.ofHours(1)).truncatedTo(SECONDS), certificate.getNotBefore().toInstant());
+ assertEquals(now.plus(Duration.ofDays(30)).truncatedTo(SECONDS), certificate.getNotAfter().toInstant());
+ }
+
+}